cancel
Showing results for 
Search instead for 
Did you mean: 

Playing MP3 with Libmad (Urgent Help Needed)

kwanweipeng
Associate II
Posted on December 03, 2014 at 03:58

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
8 REPLIES 8
jjmz
Associate II
Posted on December 03, 2014 at 08:24

Hi,

It seems that your code is trying to read from the file the same number of data that you output to the DAC, which is abviously wrong, since the MP3 data is compressed.

Long time ago, I have used Libmad on the STM32F4. You can find my old code here : http://jjmz.free.fr/?p=210

JJ

kwanweipeng
Associate II
Posted on December 03, 2014 at 10:12

Hi,

Thanks for your kind reply! May I know is your code compiled under the Linux platform instead of the IAR? Cause I am facing a lot of problem in IAR. Can you please advise which platform is more suitable?

Thanks a lot.

Sincerely,

Kwan

jjmz
Associate II
Posted on December 03, 2014 at 14:17

Yes it was compiled under Linux, with Gnu GCC Arm embedded ( https://launchpad.net/gcc-arm-embedded ). The basis was also the WAV example from the STM32F4 discovery platform.

kwanweipeng
Associate II
Posted on December 03, 2014 at 16:54

May I know is it applicable to run this under the FreeRTOS? Thanks a lot.

kwanweipeng
Associate II
Posted on December 04, 2014 at 05:08

Hello,

May I know what is this function ''Audio_MAL_Play(wave_buf0, wave_buf1, 4*1152);''

doing in the mad.c (the ''enum mad_flow output'') there. Cause I don't see there is any function like this in the original code there. And, which function are you using for playing the sound out to the codec? Thanks in advance.

Sincerely,

Kwan

jjmz
Associate II
Posted on December 04, 2014 at 07:59

Maybe I should have pointed you to http://jjmz.free.fr/?p=91

as it was the closest to the wav example. Then I progressively

adapted the code to use ChibiOS functions instead of the SPL

functions. Some maybe (and honestly I don't remember) the

function is a ChibiOS provided one (I have not included ChibiOS

in the ar file).

Concerning your previous question : yes I think that FreeRTOS would

be o too.

kwanweipeng
Associate II
Posted on December 04, 2014 at 09:43

Hello,

I done implement the part as given by the first example, but still no sound coming out from the audio port. I think I stuck somewhere around the output part there. After reading through the first and second example given, I still a bit confusing in the output part regarding how to switch the buffer. Here are my code for the output part:-

enum
mad_flow output(
void
*data, 
struct
mad_header 
const
*header, 
struct
mad_pcm *pcm)
{
unsigned 
int
nchannels, nsamples;
mad_fixed_t 
const
*left_ch, *right_ch;
signed sample;
uint16_t *output=wavebuffer_1;
uint16_t *write_buf;
int
i;
nchannels = pcm->channels;
nsamples = pcm->length;
left_ch = pcm->samples[0];
right_ch = pcm->samples[1];
output = wavebuffer_0;
write_buf = output;
while
(nsamples--)
{
sample = scale(*left_ch++);
*output++ = sample;
if
(nchannels == 2) sample = scale(*right_ch++);
*output++=sample;
}
if
(playing==0)
{
BSP_AUDIO_OUT_Play((uint16_t*)&wavebuffer_1, 4*1152);
playing = 1;
}
else
{
BSP_AUDIO_OUT_Play((uint16_t*)&wavebuffer_0, 4*1152);
playing = 0;
}
return
MAD_FLOW_CONTINUE;
}

May I know what is my mistake over here? Thanks a lot. Your kindness is really sincerely appreciated. Sincerely, Kwan
kwanweipeng
Associate II
Posted on December 04, 2014 at 09:54

Hello,

This is my full project

-> https://www.dropbox.com/s/dko2oo4ux3lut9x/Audio_playback_and_record.zip?dl=0

I have done implementing it in FreeRTOS before going for the mp3 decoding. The two main C files for decoding and playing the mp3 are in the mad.c and waveplayer.c.