/* MiniMP3 and LibCTRU streaming example
* Author: Kaleb Provost (kprovost7314)
* Desc: A PoC that plays MP3 Files
*/
#include <3ds.h>
#include <stdio.h>
#include "minimp3.h"
#include "libc.h"
#include "Bokuboku_mp3.h"
#define SAMPLERATE 48000
#define SAMPLESPERBUFF (SAMPLERATE / 30)
int bytes_left;
signed short sample_buf[MP3_MAX_SAMPLES_PER_FRAME];
int frame_size;
static unsigned char *stream_pos = 0;
int main(int argc, char **argv)
{
//Initialize gfx (note: not needed if you're using SF2Dlib)
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
printf("Streaming A MP3 file with Minimp3 and LibCTRU\n");
// Initialize NDSP for audio
ndspInit();
/* Set the NDSP for Stereo playback. *
* You can switch from Stereo to Mono or Surrond *
* (see libctru's ndsp.h) */
//You can (possibly) use minimp3's channel set
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16);
//Set the sample rate to the defined one above
//Is possible with MiniMP3 instead of LibCTRU
ndspChnSetRate(0, SAMPLERATE);
// Name the ndspWaveBuf struct
ndspWaveBuf waveBuf;
// Name the info struct from minimp3.h
mp3_info_t info;
info.sample_rate = 48000;
waveBuf.sequence_id = "Bokuboku.mp3";
mp3_decoder_t mp3;
bytes_left -= 100;
// Minimp3 code
// check if the result is valid
// If not:
if (!stream_pos) {
printf("Error: cannot open Boku-Boku.Infinite!\n");
return 1;
// If it is:
} else {
ndspChnIsPlaying(0);
ndspChnWaveBufAdd(0, &waveBuf);
printf("Now Playing: Boku-Boku.Infinite\n");
}
mp3 = mp3_create();
mp3_decode(mp3, stream_pos, bytes_left, sample_buf, &info);
if (!frame_size) {
printf("\nError: not a valid MP3 audio file!\n");
return 1;
}
// Main loop
while (aptMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
//hidKeysHeld returns information about which buttons are currently pressed (regardless if they were pressed or not pressed in the previous frame)
//hidKeysUp returns information about which buttons are not pressed but were pressed in the previous frame
u32 kDown = hidKeysDown();
if (kDown & KEY_START) break; // break in order to return to hbmenu
// YOU WANT TO LEAVE ME?????
/*
I'11 FL00D thE // SYSTEM f0r3v3r
JK, Y0u'11 c0M3 b4ck
1 kn0w y0u wi11
*/
// Flush and swap framebuffers, this is needed for rendering these will not be needed when using SF2D lib
gfxFlushBuffers();
gfxSwapBuffers();
//Wait for VBlank, this is needed for rendering these will not be needed when using SF2D lib
gspWaitForVBlank();
}
// Close the MP3 file
mp3_done(mp3);
ndspExit();
gfxExit();
return 0;
}