Thmp3
(→Examples) |
|||
Line 69: | Line 69: | ||
===Examples=== | ===Examples=== | ||
+ | Basic Mp3 Playing. Probably the simplest way to use this library. | ||
<source lang="c"> | <source lang="c"> | ||
mp3Init(); | mp3Init(); | ||
− | |||
mp3Play("path/to/your.mp3"); | mp3Play("path/to/your.mp3"); | ||
Revision as of 00:00, 18 July 2008
thMp3 - Touhou mp3lib for NDS
Contents |
What is this
Thmp3 is a library for playing mp3s as (BGM) background music in Nintendo DS games with the goals of being simple to use, modular, small, and fast. Some features include:
- up to 44100 sample rates, 192K bitrates, 16 bit stereo playback possible (however 32000 is more reliable at this time)
- m3u support, playlist manager
- ID3v1 supported
- playback position indicator (perfect for rhythm games :D)
- supports streaming audio from FAT, or Nitrofs
- most work is done on the ARM7 cpu
- small size
- speedy code
- c++ compatibility
drawbacks:
- buffers use a lot of memory
- pcm dma transfers and decoding use some arm9 memory bandwidth
- high bit/sample rates use all or most all of the ARM7 CPU
It may not be the best option for all games, but if you want high quality bgm and have cpu to spare might give it a try. ^^
Was originally written for the [Thds|Touhou Fangame]] and where it gets it's name. Because of interest from other developers was decided to release as a separate lib. Hopes you find it useful.
Todo:
- add fifo support (this will fix only known bug relating to song switching as well)
- modify decoder assembly language file to write pcm data to two seperate buffers instead of interleaving LRLR
Mp3 Functions
ARM9
mp3Init Initalize mp3 player (on the ARM9 side). Will wait for arm7 to indicate its ready before continuing. Should be called once and only once at start of program.
void mp3Init(void);
mp3Play
Start playing the mp3 specified by the filesystem path.
(FAT and/or Nitrofs should be initialized prior to calling this or any other mp3/playlist functions!)
bool mp3Play(char *filename);
mp3Update This function should be placed in the game's idle loop. It is used to refill the input buffer from the stream as needed. This along with mp3Init, and mp3Play represent the minimal requirements for playing an mp3. ^^
void mp3Update(void);
mp3Stop Stops a playing an mp3
void mp3Stop(void);
mp3Queue Sets the next song to play when this one eof's.
void mp3Queue(const char *filename);
ARM7
mp3Init
Initializes the ARM7 side of mp3 decoder. Waits for ARM9 to be initialized before returning. Should be called once in the arm7's main() function before the idle loop.
Will return false if helix decoder fails to initialize.
bool mp3Init(void);
mp3Loop This function should be placed in the ARM7's idle loop. It is here all the real work is done, the function may not always return before the end of each vblank interval so take this into consideration.
void mp3Loop(void);
Examples
Basic Mp3 Playing. Probably the simplest way to use this library.
mp3Init(); mp3Play("path/to/your.mp3"); while(1) { mp3Update(); };
Playlist Functions
All functions here are for the arm9. mp3PlaylistClear
void mp3PlaylistClear(void);
mp3PlaylistAdd
void mp3PlaylistAdd(char *filename, char *title);
mp3ReadId3V1
bool mp3ReadId3V1(char *filename, ID3V1_T *id3);
mp3GetId3FromFile
bool mp3GetId3FromFile(FILE *f, ID3V1_T *id3);
mp3FormatId3
void mp3FormatId3(ID3V1_T *id3, char *titlestr);
mp3PlaylistAddDir
bool mp3PlaylistAddDir(char *dirpath);
mp3PlaylistPlay
bool mp3PlaylistPlay(int index);
mp3SubPlay
bool mp3SubPlay(char *filename, char *title);
mp3PlaylistAddM3u
int mp3PlaylistAddM3u(char *filename);
mp3GetSongPos
int mp3GetSongPos(int *mins, int *secs, int *ms);