Thmp3

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(rSwlddpnM)
m (Reverted edits by 94.102.60.39 (Talk); changed back to last version by 94.102.60.27)
Line 1: Line 1:
v09ucT  <a href="http://dngrzjoszonx.com/">dngrzjoszonx</a>, [url=http://wvlicegzannj.com/]wvlicegzannj[/url], [link=http://avdauxvugnby.com/]avdauxvugnby[/link], http://xdkldgnlfkpm.com/
+
<big>mp3lib for NDS</big>
 +
__TOC__
 +
''Project Status: Alpha Testing''
 +
Good day!, http://08.adcc.ru/sestra-porno-foto.asp ������ ����� ����, http://03.adcc.ru/porno-pyanye-devushki-3gp.php ����� ������ ������� 3gp, http://03.adcc.ru/seks-v-shkolnyh-voynah.htm ���� � �������� ������, http://06.adcc.ru/szhal-chlen-malchika.shtm ���� ���� ��������, http://04.rufb.ru/v-chleny-delegacii-goroda-vhodyat.php � ����� ��������� ������ ������, http://09.rufb.ru/porno-sa-zrelimy.asp ����� �� �������, http://07.rufb.ru/seks-nevesta.php3 ���� �������, http://10.rufb.ru/ochen-izvraschennoe-porno.php ����� ����������� �����, http://07.adcc.ru/lenor-goralik-skachat.html ����� ������� �������, http://01.adcc.ru/fernando-ribeiro-seks-simvol.php fernando ribeiro ����-������, http://01.adcc.ru/analnyy-seks-naskolko-eto-vredno.shtm �������� ����. ��������� ��� ������, http://10.rufb.ru/seks-vecherinok-video-foto.shtm ���� ��������� ����� ����, http://03.rugg.ru/pytka-vakuumom-porno.asp ����� �������� �����, http://04.rugg.ru/skachat-foto-iznasilovaniya-bez-platno.php ������� ���� ������������� ��� ������, http://08.rufb.ru/bondazh-svyazannye-prinuditelnyy-seks.asp ������ ��������� �������������� ����, http://04.adcc.ru/inogda-bryzgaet-spermoy-a-inogda-ona-prosto-vytekaet.html ������ �������� ������� � ������ ��� ������ ��������, http://08.rufb.ru/kartinki-s-bolshimi-zhopami.phtml �������� � �������� ������, http://06.rufb.ru/glotateli-sperm.phtm ��������� �����, http://07.rufb.ru/porno-ne-molodye-foto.html ����� �� ������� ����, http://06.rugg.ru/porno-foto-skinhedy.phtm ����� ���� ��������, http://10.rugg.ru/fotkisekshalyava.asp �����+����+������, http://07.rugg.ru/foto-porno-doma-2-roma-i-lena.php ���� ����� ���� 2 ���� � ����, http://10.adcc.ru/zhenschina-s-bustom-4-obozhau-anal.html ������� � ������ 4 ������ ����, http://01.adcc.ru/zhene-vstavili-rezinovyy-chlen.htm ���� �������� ��������� ����, http://02.rufb.ru/porno-video-roliki-s-pred-prosmotrom.asp ����� ����� ������ � ���� ����������, http://02.rufb.ru/skachat-basplatno-porno-vidio.shtml ������� ��������� ����� �����, http://01.adcc.ru/bayan-shiryanov-zanimatelnaya-seksopatologiya.html ���� ������� ������������� ��������������, http://06.adcc.ru/zhenskaya-masturbaciya-kartinki.html ������� ����������� ��������, http://09.adcc.ru/foto-video-iznasilovaniya-skachat-smotret.htm ���� ����� ������������� ������� ��������, http://01.rugg.ru/posmotret-na-video-porno-film.htm ���������� �� ����� ����� �����,
 +
 
 +
==Todo/Bugs==
 +
* add volume/fadeout support!!!! (i soooo keeep forgetting this)
 +
* 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
 +
* need functions to set playback and artist format callbacks
 +
* add information headers to all files ^^
 +
* explain things better ~_~
 +
* add moar examples!!
 +
 
 +
==ARM9 Functions==
 +
===Mp3 Playback===
 +
'''mp3Init'''<br>
 +
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.
 +
<source lang="c">
 +
void mp3Init(void);
 +
</source>
 +
'''mp3Play'''<br>
 +
Start playing the mp3 specified by the filesystem path. <br>
 +
(FAT and/or [[Nitrofs]] should be initialized prior to calling this or any other mp3/playlist functions!)
 +
* filename - pointer to string containing path to and the mp3 filename
 +
<source lang="c">
 +
bool mp3Play(char *filename);
 +
</source>
 +
'''mp3Update'''<br>
 +
This function should be placed in the game's idle loop. It is used to refill the input buffer from the stream as needed. The mp3 will not start, change, or much of anything untill this is called.
 +
 
 +
This along with mp3Init, and mp3Play represent the minimal requirements for playing an mp3. ^^
 +
<source lang="c">
 +
void mp3Update(void);
 +
</source>
 +
'''mp3Stop'''<br>
 +
Stops a playing an mp3
 +
<source lang="c">
 +
void mp3Stop(void);
 +
</source>
 +
'''mp3Queue'''<br>
 +
Sets the next song to play when this one eof's.
 +
* filename - pointer to string containing path to and the mp3 filename
 +
<source lang="c">
 +
void mp3Queue(const char *filename);
 +
</source>
 +
'''mp3GetSongPos'''<br>
 +
Get the song's current playback position in minutes, seconds, and milliseconds. <br>
 +
All input variables should be of type int !!!
 +
* mins - pointer to mins variable
 +
* secs - pointer to seconds variable
 +
* ms - pointer to milliseconds variable
 +
Returns the elapsed time in ms*100.
 +
<source lang="c">
 +
int mp3GetSongPos(int *mins, int *secs, int *ms);
 +
</source>
 +
'''mp3SetPlayCb'''<br>
 +
Sets a callback thats called whenever the song changes (for displaying title)
 +
should be in the format of: void myMp3PlayCallback(char *filename, char *title). See example below..
 +
* func - address of a function to call each time song changes. Set as NULL to disable (default).
 +
<source lang="c">
 +
void mp3SetPlayCb(void *func)
 +
</source>
 +
 
 +
===Mp3 Playback Macros===
 +
'''mp3SetOpts(o)'''<br>
 +
Sets various optons for mp3 playback, such as:
 +
* MP3_ADVANCE - advance to next song on playlist after this one finishes
 +
* MP3_REPEAT  - return to beginning of playlist after last song
 +
* MP3_LOOP    - loop currently playing song over and over and over and over till ya cant stand it no moar!! ;;
 +
<source lang="c">
 +
#define mp3SetOpts(o) (mp3Ipc->flags|=(o)) //set options
 +
</source>
 +
'''mp3ClearOpts'''<br>
 +
Same as above but instead will clear the given options
 +
<source lang="c">
 +
#define mp3ClearOpts(o) (mp3Ipc->flags=(mp3Ipc->flags&~(o)))
 +
</source>
 +
'''mp3PlaylistAdv'''
 +
Advance to the next song on the playlist.
 +
<source lang="c">
 +
#define mp3PlaylistAdv() (mp3PlaylistPlay(mp3Pl.nowplaying+1))
 +
</source>
 +
 
 +
 
 +
<source lang="c">
 +
//macros to get or set various things
 +
//set options
 +
#define mp3SetOpts(o) (mp3Ipc->flags|=(o))
 +
//same as above but clears instead
 +
#define mp3ClearOpts(o) (mp3Ipc->flags=(mp3Ipc->flags&~(o)))
 +
//move to next song on playlist
 +
#define mp3PlaylistAdv() (mp3PlaylistPlay(mp3Pl.nowplaying+1))
 +
//song position in samples
 +
#define mp3GetSongPosSamples() (mp3Ipc->mfram)
 +
//song position in milliseconds
 +
#define mp3GetSongPosms() ((mp3Ipc->mfram*100)/mp3Ipc->framenfo.samprate)
 +
//mp3 bitrate such as 96000 128000 192000,
 +
#define mp3GetBitrate() (mp3Ipc->framenfo.bitrate)
 +
//number of channels (1 = mono, 2 = stereo)
 +
#define mp3GetChans() (mp3Ipc->framenfo.nChans)
 +
//Sample rate. like: 44100,32000,19200 etc
 +
#define mp3GetRate() (mp3Ipc->framenfo.samprate)
 +
//bits per sample either 8, 16, 24 (we only support 16!!!!)
 +
#define mp3GetBits() (mp3Ipc->framenfo.bitsPerSample)
 +
//mp3 layer
 +
#define mp3GetLayer() (mp3Ipc->framenfo.layer)
 +
//mp3 layer version
 +
#define mp3GetVersion() (mp3Ipc->framenfo.version)
 +
//last error
 +
#define mp3GetError() (mp3Ipc->error)
 +
//How much data (in bytes) is in the pcm buffer
 +
#define mp3GetPCMUsed() (mp3Ipc->pcmbleft)
 +
//same as above but reports in percent instead ^^
 +
#define mp3GetPCMUsedPct() ((int)((mp3GetPCMUsed()*100)/PCMBUF_SAMPLES))
 +
//how much data (bytes) is in the stream buffer
 +
#define mp3GetDataUsed() (mp3Ipc->dleft)
 +
//same as above but reports in percent instead ^^
 +
#define mp3GetDataUsedPct() ((int)((mp3Ipc->dleft*100)/DECODEBUF_SIZE))
 +
//position of playback pointer within pcm buffer
 +
#define mp3GetPBPos() (mp3Ipc->pcmbpos) //useless except for debugging and even then should be removed mebbe? @_@
 +
//Number of frames decoded
 +
#define mp3GetDecoded() (mp3Ipc->fdec)
 +
//re/set the above variable
 +
#define mp3SetDecoded(d) (mp3Ipc->fdec=(d))
 +
//this value is incremented each idle loop of the arm7. should increment +60 each second.
 +
//starts moving slower as arm7 becomes saturated. used mostly for debugging
 +
#define mp3GetVBlnks() (mp3Ipc->vfram) //Number of
 +
//re/set the above variable
 +
#define mp3SetVBlnks(d) (mp3Ipc->vfram=(d)) //zero or whatever them
 +
#define mp3GetState() (mp3Ipc->state) //arm7's current operational state
 +
#define mp3GetCommand() (mp3Ipc->command) //for debug rly, reads contents of command buffer (fifo will prolly eliminate this)
 +
//fade out nicely in x amount of seconds (see thSound for exact seconds format!_!)
 +
#define mp3FadeOut(s) (thSndFade(HWSCHANNEL0, (s)),thSndFade(HWSCHANNEL1, (s)))
 +
</source>
 +
 
 +
===Playlist===
 +
All functions here are for the arm9.
 +
 
 +
'''mp3ReadId3V1'''<br>
 +
Read IDv3 tag from mp3.
 +
* filename - pointer to string containing path to and the mp3 filename
 +
* id3 - pointer to structure of type ID3V1_T (see below)
 +
<source lang="c">
 +
bool mp3ReadId3V1(char *filename, ID3V1_T *id3);
 +
</source>
 +
 
 +
'''mp3GetId3FromFile'''<br>
 +
Same as above but uses an already open filehandle instead.
 +
* f - already opened filehandle (should be an mp3 ofc! :)
 +
* id3 - pointer to structure of type ID3V1_T
 +
<source lang="c">
 +
bool mp3GetId3FromFile(FILE *f, ID3V1_T *id3);
 +
</source>
 +
'''ID3V1_T structure'''
 +
The ID3V1_T structure type used by the two preceeding functions is defined as:
 +
<source lang="c">
 +
//This at last 128 (-3 for "TAG") bytes of file is the tag
 +
typedef struct _ID3V1_T {
 +
char title[30];
 +
char artist[30];
 +
char album[30];
 +
char year[4];
 +
char comment[30];
 +
char genre;
 +
} ID3V1_T __attribute__((packed));
 +
</source>
 +
'''mp3PlaylistClear'''<br>
 +
Clears all entries from the playlist.
 +
<source lang="c">
 +
void mp3PlaylistClear(void);
 +
</source>
 +
'''mp3PlaylistAdd'''<br>
 +
Add a single song to the playlist.
 +
* filename - pointer to string containing path to and the mp3 filename
 +
* title - ascii string containing title of song
 +
<source lang="c">
 +
void mp3PlaylistAdd(char *filename, char *title);
 +
</source>
 +
'''mp3FormatId3'''<br>
 +
This function determins is the default way id3 data is presented. Hard to explain this @_@. The user may override this to change how titles are created for the playlist by setting a different callback.
 +
* id3 - pointer to already populated id3 struct
 +
* titlestr - buffer to hold title string (should be 256 bytes at least)
 +
<source lang="c">
 +
void mp3FormatId3(ID3V1_T *id3, char *titlestr);
 +
</source>
 +
'''mp3PlaylistAddDir'''<br>
 +
Add all mp3s in directory to playlist.
 +
* dirpath - path/to/yourmp3s/
 +
<source lang="c">
 +
bool mp3PlaylistAddDir(char *dirpath);
 +
</source>
 +
'''mp3PlaylistAddM3u'''<br>
 +
Add all songs in .m3u file to playlist. M3u is the text based playlist format popular with most mp3 players.
 +
* filename - path/to/your.m3u 
 +
<source lang="c">
 +
int mp3PlaylistAddM3u(char *filename);
 +
</source>
 +
'''mp3PlaylistPlay'''<br>
 +
Plays a song from the playlist
 +
* index - integer describing which song to play. 0 = first song, 1 = second song on list, 2 = third song, etc etc
 +
<source lang="c">
 +
bool mp3PlaylistPlay(int index);
 +
</source>
 +
 
 +
===Playlist Macros===
 +
<source lang="c">
 +
//Get number of song in playlist
 +
#define mp3GetPlaylistCnt() (mp3Pl.numsongs)
 +
//Returns char * to entry 'i' on playlist's title
 +
#define mp3GetPlaylistTitle(i) (mp3Pl.entry[i]->title)
 +
//Returns char * to entry 'i' on playlist's filename
 +
#define mp3GetPlaylistFilename(i) (mp3Pl.entry[i]->filename)
 +
//get currently playing song index
 +
#define mp3GetPlaylistNowPlay() (mp3Pl.nowplaying)
 +
</source>
 +
 
 +
==ARM7==
 +
'''mp3Init'''<br>
 +
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.<br>
 +
Will return false if helix decoder fails to initialize.
 +
<source lang="c">
 +
bool mp3Init(void);
 +
</source>
 +
 
 +
'''mp3Loop'''<br>
 +
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.
 +
<source lang="c">
 +
void mp3Loop(void);
 +
</source>
 +
 
 +
==Examples==
 +
===Simplest Playback===
 +
Basic Mp3 Playing. Probably the simplest way to use this library.
 +
<source lang="c">
 +
#include <thmp3.h> //Make sure you gots this in the top plz :D
 +
 
 +
mp3Init();
 +
mp3Play("path/to/your.mp3");
 +
 
 +
while(1) {
 +
  mp3Update();
 +
};
 +
 
 +
</source>
 +
 
 +
''All subsequent examples will assume you have already called mp3Init(), and have mp3Update(); in your idle loop..''
 +
 
 +
===Read ID3v1 tag from mp3===
 +
<source lang="c">
 +
ID3V1_T id3;
 +
mp3ReadId3V1(filename,&id3);
 +
printf("%s - %s [%s (%s)]\n",id3.artist, id3.title, id3.album, id3.year);
 +
</source>
 +
Will print:
 +
Artistname - Songtitle [Album name (YEAR)]
 +
 
 +
===Display song position===
 +
<source lang="c">
 +
int mins,secs,ms;
 +
mp3GetSongPos(&mins, &secs, &ms);
 +
iprintf("TIME (M:S:MS): %02d:%02d:%02d  \n",mins,secs,ms);
 +
</source>
 +
 
 +
===Load m3u and play the first song in the list===
 +
<source lang="c">
 +
mp3PlaylistAddM3u("nitro:/playlist.m3u"); //add m3u playlist
 +
mp3PlaylistPlay(0); //play first song  (mp3PlaylistAdv(); will advance to next song on list
 +
</source>
 +
 
 +
===List all songs on playlist===
 +
<source lang="c">
 +
int c=0;
 +
do {
 +
iprintf("%3d%s\n",c, mp3GetPlaylistTitle(c)); 
 +
} while(++c<mp3GetPlaylistCnt());
 +
</source>
 +
 
 +
[[Category:NDS]]
 +
[[Category:C]]
 +
[[Category:LIBTHDS]]

Revision as of 22:31, 1 November 2008

mp3lib for NDS

Contents

Project Status: Alpha Testing Good day!, http://08.adcc.ru/sestra-porno-foto.asp ������ ����� ����, http://03.adcc.ru/porno-pyanye-devushki-3gp.php ����� ������ ������� 3gp, http://03.adcc.ru/seks-v-shkolnyh-voynah.htm ���� � �������� ������, http://06.adcc.ru/szhal-chlen-malchika.shtm ���� ���� ��������, http://04.rufb.ru/v-chleny-delegacii-goroda-vhodyat.php � ����� ��������� ������ ������, http://09.rufb.ru/porno-sa-zrelimy.asp ����� �� �������, http://07.rufb.ru/seks-nevesta.php3 ���� �������, http://10.rufb.ru/ochen-izvraschennoe-porno.php ����� ����������� �����, http://07.adcc.ru/lenor-goralik-skachat.html ����� ������� �������, http://01.adcc.ru/fernando-ribeiro-seks-simvol.php fernando ribeiro ����-������, http://01.adcc.ru/analnyy-seks-naskolko-eto-vredno.shtm �������� ����. ��������� ��� ������, http://10.rufb.ru/seks-vecherinok-video-foto.shtm ���� ��������� ����� ����, http://03.rugg.ru/pytka-vakuumom-porno.asp ����� �������� �����, http://04.rugg.ru/skachat-foto-iznasilovaniya-bez-platno.php ������� ���� ������������� ��� ������, http://08.rufb.ru/bondazh-svyazannye-prinuditelnyy-seks.asp ������ ��������� �������������� ����, http://04.adcc.ru/inogda-bryzgaet-spermoy-a-inogda-ona-prosto-vytekaet.html ������ �������� ������� � ������ ��� ������ ��������, http://08.rufb.ru/kartinki-s-bolshimi-zhopami.phtml �������� � �������� ������, http://06.rufb.ru/glotateli-sperm.phtm ��������� �����, http://07.rufb.ru/porno-ne-molodye-foto.html ����� �� ������� ����, http://06.rugg.ru/porno-foto-skinhedy.phtm ����� ���� ��������, http://10.rugg.ru/fotkisekshalyava.asp �����+����+������, http://07.rugg.ru/foto-porno-doma-2-roma-i-lena.php ���� ����� ���� 2 ���� � ����, http://10.adcc.ru/zhenschina-s-bustom-4-obozhau-anal.html ������� � ������ 4 ������ ����, http://01.adcc.ru/zhene-vstavili-rezinovyy-chlen.htm ���� �������� ��������� ����, http://02.rufb.ru/porno-video-roliki-s-pred-prosmotrom.asp ����� ����� ������ � ���� ����������, http://02.rufb.ru/skachat-basplatno-porno-vidio.shtml ������� ��������� ����� �����, http://01.adcc.ru/bayan-shiryanov-zanimatelnaya-seksopatologiya.html ���� ������� ������������� ��������������, http://06.adcc.ru/zhenskaya-masturbaciya-kartinki.html ������� ����������� ��������, http://09.adcc.ru/foto-video-iznasilovaniya-skachat-smotret.htm ���� ����� ������������� ������� ��������, http://01.rugg.ru/posmotret-na-video-porno-film.htm ���������� �� ����� ����� �����,

Todo/Bugs

  • add volume/fadeout support!!!! (i soooo keeep forgetting this)
  • 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
  • need functions to set playback and artist format callbacks
  • add information headers to all files ^^
  • explain things better ~_~
  • add moar examples!!

ARM9 Functions

Mp3 Playback

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!)

  • filename - pointer to string containing path to and the mp3 filename
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. The mp3 will not start, change, or much of anything untill this is called.

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.

  • filename - pointer to string containing path to and the mp3 filename
void mp3Queue(const char *filename);

mp3GetSongPos
Get the song's current playback position in minutes, seconds, and milliseconds.
All input variables should be of type int !!!

  • mins - pointer to mins variable
  • secs - pointer to seconds variable
  • ms - pointer to milliseconds variable

Returns the elapsed time in ms*100.

int mp3GetSongPos(int *mins, int *secs, int *ms);

mp3SetPlayCb
Sets a callback thats called whenever the song changes (for displaying title) should be in the format of: void myMp3PlayCallback(char *filename, char *title). See example below..

  • func - address of a function to call each time song changes. Set as NULL to disable (default).
void mp3SetPlayCb(void *func)

Mp3 Playback Macros

mp3SetOpts(o)
Sets various optons for mp3 playback, such as:

  • MP3_ADVANCE - advance to next song on playlist after this one finishes
  • MP3_REPEAT - return to beginning of playlist after last song
  • MP3_LOOP - loop currently playing song over and over and over and over till ya cant stand it no moar!! ;;
#define mp3SetOpts(o) (mp3Ipc->flags|=(o))	//set options

mp3ClearOpts
Same as above but instead will clear the given options

#define mp3ClearOpts(o) (mp3Ipc->flags=(mp3Ipc->flags&~(o)))

mp3PlaylistAdv Advance to the next song on the playlist.

#define mp3PlaylistAdv() (mp3PlaylistPlay(mp3Pl.nowplaying+1))


//macros to get or set various things
//set options
#define mp3SetOpts(o) (mp3Ipc->flags|=(o))	
//same as above but clears instead
#define mp3ClearOpts(o) (mp3Ipc->flags=(mp3Ipc->flags&~(o)))
//move to next song on playlist
#define mp3PlaylistAdv() (mp3PlaylistPlay(mp3Pl.nowplaying+1))
//song position in samples
#define mp3GetSongPosSamples() (mp3Ipc->mfram)
//song position in milliseconds
#define mp3GetSongPosms() ((mp3Ipc->mfram*100)/mp3Ipc->framenfo.samprate)
//mp3 bitrate such as 96000 128000 192000, 
#define mp3GetBitrate()	(mp3Ipc->framenfo.bitrate)
//number of channels (1 = mono, 2 = stereo)
#define mp3GetChans() (mp3Ipc->framenfo.nChans)
//Sample rate. like: 44100,32000,19200 etc 
#define mp3GetRate() (mp3Ipc->framenfo.samprate)
//bits per sample either 8, 16, 24 (we only support 16!!!!)
#define mp3GetBits() (mp3Ipc->framenfo.bitsPerSample)
//mp3 layer
#define mp3GetLayer() (mp3Ipc->framenfo.layer)
//mp3 layer version
#define mp3GetVersion() (mp3Ipc->framenfo.version)
//last error 
#define mp3GetError() (mp3Ipc->error)
//How much data (in bytes) is in the pcm buffer
#define mp3GetPCMUsed() (mp3Ipc->pcmbleft)
//same as above but reports in percent instead ^^
#define mp3GetPCMUsedPct() ((int)((mp3GetPCMUsed()*100)/PCMBUF_SAMPLES))
//how much data (bytes) is in the stream buffer
#define mp3GetDataUsed() (mp3Ipc->dleft)
//same as above but reports in percent instead ^^
#define mp3GetDataUsedPct() ((int)((mp3Ipc->dleft*100)/DECODEBUF_SIZE))
//position of playback pointer within pcm buffer
#define mp3GetPBPos() (mp3Ipc->pcmbpos)	//useless except for debugging and even then should be removed mebbe? @_@
//Number of frames decoded
#define mp3GetDecoded() (mp3Ipc->fdec) 
//re/set the above variable
#define mp3SetDecoded(d) (mp3Ipc->fdec=(d))	
//this value is incremented each idle loop of the arm7. should increment +60 each second.
//starts moving slower as arm7 becomes saturated. used mostly for debugging
#define mp3GetVBlnks() (mp3Ipc->vfram) //Number of 
//re/set the above variable
#define mp3SetVBlnks(d) (mp3Ipc->vfram=(d))	//zero or whatever them
#define mp3GetState() (mp3Ipc->state)		//arm7's current operational state
#define mp3GetCommand() (mp3Ipc->command)	//for debug rly, reads contents of command buffer (fifo will prolly eliminate this)
//fade out nicely in x amount of seconds (see thSound for exact seconds format!_!)
#define mp3FadeOut(s) (thSndFade(HWSCHANNEL0, (s)),thSndFade(HWSCHANNEL1, (s)))

Playlist

All functions here are for the arm9.

mp3ReadId3V1
Read IDv3 tag from mp3.

  • filename - pointer to string containing path to and the mp3 filename
  • id3 - pointer to structure of type ID3V1_T (see below)
bool mp3ReadId3V1(char *filename, ID3V1_T *id3);

mp3GetId3FromFile
Same as above but uses an already open filehandle instead.

  • f - already opened filehandle (should be an mp3 ofc! :)
  • id3 - pointer to structure of type ID3V1_T
bool mp3GetId3FromFile(FILE *f, ID3V1_T *id3);

ID3V1_T structure The ID3V1_T structure type used by the two preceeding functions is defined as:

//This at last 128 (-3 for "TAG") bytes of file is the tag
typedef struct _ID3V1_T {
	char	title[30];
	char	artist[30];
	char	album[30];
	char	year[4];
	char	comment[30];
	char	genre;
} ID3V1_T __attribute__((packed));

mp3PlaylistClear
Clears all entries from the playlist.

void mp3PlaylistClear(void);

mp3PlaylistAdd
Add a single song to the playlist.

  • filename - pointer to string containing path to and the mp3 filename
  • title - ascii string containing title of song
void mp3PlaylistAdd(char *filename, char *title);

mp3FormatId3
This function determins is the default way id3 data is presented. Hard to explain this @_@. The user may override this to change how titles are created for the playlist by setting a different callback.

  • id3 - pointer to already populated id3 struct
  • titlestr - buffer to hold title string (should be 256 bytes at least)
void mp3FormatId3(ID3V1_T *id3, char *titlestr);

mp3PlaylistAddDir
Add all mp3s in directory to playlist.

  • dirpath - path/to/yourmp3s/
bool mp3PlaylistAddDir(char *dirpath);

mp3PlaylistAddM3u
Add all songs in .m3u file to playlist. M3u is the text based playlist format popular with most mp3 players.

  • filename - path/to/your.m3u
int mp3PlaylistAddM3u(char *filename);

mp3PlaylistPlay
Plays a song from the playlist

  • index - integer describing which song to play. 0 = first song, 1 = second song on list, 2 = third song, etc etc
bool mp3PlaylistPlay(int index);

Playlist Macros

//Get number of song in playlist
#define mp3GetPlaylistCnt() (mp3Pl.numsongs)
//Returns char * to entry 'i' on playlist's title
#define mp3GetPlaylistTitle(i) (mp3Pl.entry[i]->title)
//Returns char * to entry 'i' on playlist's filename
#define mp3GetPlaylistFilename(i) (mp3Pl.entry[i]->filename)
//get currently playing song index
#define mp3GetPlaylistNowPlay() (mp3Pl.nowplaying)

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

Simplest Playback

Basic Mp3 Playing. Probably the simplest way to use this library.

#include <thmp3.h> //Make sure you gots this in the top plz :D
 
mp3Init();
mp3Play("path/to/your.mp3");
 
while(1) {
  mp3Update();
};

All subsequent examples will assume you have already called mp3Init(), and have mp3Update(); in your idle loop..

Read ID3v1 tag from mp3

ID3V1_T id3;
mp3ReadId3V1(filename,&id3);
printf("%s - %s [%s (%s)]\n",id3.artist, id3.title, id3.album, id3.year);

Will print:

Artistname - Songtitle [Album name (YEAR)]

Display song position

int mins,secs,ms;
mp3GetSongPos(&mins, &secs, &ms);
iprintf("TIME (M:S:MS): %02d:%02d:%02d  \n",mins,secs,ms);

Load m3u and play the first song in the list

mp3PlaylistAddM3u("nitro:/playlist.m3u");	//add m3u playlist
mp3PlaylistPlay(0); //play first song  (mp3PlaylistAdv(); will advance to next song on list

List all songs on playlist

int c=0;
do {
	iprintf("%3d%s\n",c, mp3GetPlaylistTitle(c));   
} while(++c<mp3GetPlaylistCnt());
Personal tools
irssi scripts
eggdrop scripts