Ciao! :)
carlosedp wrote:I have added support for MP3 and OGG playback inside my current Stackless Python port.
Wow, very good work. :)
I also tried (without C knowledge) to add mp3 playback some month ago, but failed. ;)
If you used the mp3player.c file be aware that this loads all the file into memory and Python (at least the fraca7's port) have only about 17mb ram available for the script.
Does OGG playback stream the file?
Many thanks, it seems a very good port to me. :)
EDIT: Maybe you can use this to retrieve file info (you can use it after MP3_Load()).
If you want here you can also find code to read the ID3v1 tag:
http://forums.ps2dev.org/viewtopic.php? ... hlight=id3
Code: Select all
struct MP3Info
{
int fileSize;
char layer[10];
int kbit;
long hz;
char mode[50];
char emphasis[10];
mad_timer_t length;
char strLength[10];
int frames;
};
void getInfo(){
int FrameCount = 0;
struct mad_stream stream;
struct mad_header header;
mad_stream_init (&stream);
mad_header_init (&header);
MP3_info.fileSize = size;
mad_timer_reset(&MP3_info.length);
mad_stream_buffer (&stream, ptr, size);
while (1){
if (mad_header_decode (&header, &stream) == -1){
if (MAD_RECOVERABLE(stream.error)){
continue;
}else{
break;
}
}
//Informazioni solo dal primo frame:
if (FrameCount == 0){
switch (header.layer) {
case MAD_LAYER_I:
strcpy(MP3_info.layer,"I");
break;
case MAD_LAYER_II:
strcpy(MP3_info.layer,"II");
break;
case MAD_LAYER_III:
strcpy(MP3_info.layer,"III");
break;
default:
strcpy(MP3_info.layer,"unknown");
break;
}
MP3_info.kbit = header.bitrate / 1000;
MP3_info.hz = header.samplerate;
switch (header.mode) {
case MAD_MODE_SINGLE_CHANNEL:
strcpy(MP3_info.mode, "single channel");
break;
case MAD_MODE_DUAL_CHANNEL:
strcpy(MP3_info.mode, "dual channel");
break;
case MAD_MODE_JOINT_STEREO:
strcpy(MP3_info.mode, "joint (MS/intensity) stereo");
break;
case MAD_MODE_STEREO:
strcpy(MP3_info.mode, "normal LR stereo");
break;
default:
strcpy(MP3_info.mode, "unknown");
break;
}
switch (header.emphasis) {
case MAD_EMPHASIS_NONE:
strcpy(MP3_info.emphasis,"no");
break;
case MAD_EMPHASIS_50_15_US:
strcpy(MP3_info.emphasis,"50/15 us");
break;
case MAD_EMPHASIS_CCITT_J_17:
strcpy(MP3_info.emphasis,"CCITT J.17");
break;
case MAD_EMPHASIS_RESERVED:
strcpy(MP3_info.emphasis,"reserved(!)");
break;
default:
strcpy(MP3_info.emphasis,"unknown");
break;
}
}
//Conteggio frame e durata totale:
FrameCount++;
mad_timer_add (&MP3_info.length, header.duration);
}
mad_header_finish (&header);
mad_stream_finish (&stream);
MP3_info.frames = FrameCount;
//Formatto in stringa la durata totale:
mad_timer_string(MP3_info.length, MP3_info.strLength, "%02lu:%02u:%02u", MAD_UNITS_HOURS, MAD_UNITS_MILLISECONDS, 0);
}
struct MP3Info MP3_GetInfo()
{
return MP3_info;
}
Ciaooo
Sakya