Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Mp3 decoder too slow on NiosII

Hi,all

I'm now designing a mp3 player for DE2 board, which use libmad for mp3 decoding. But currently, the speed is too slow for real time playing. The core is NiosII fastest core,i cache=8kb, d cache=16kb, cpu clk is set to 100MHz. It still require 380s to decode a 274s mp3 file. Can anyone tell me, is it reasonable?

I have also tried to add custom instruction to replace the macro "mad_f_mul" in libmad, but the decoding speed remain the same or even worse. I can't understand it.

The platform I'm using is QuartusII 9.1.

any guidelines, thx!

20 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I recommend tuning the system clock back to find out how much slack you have. For example I wouldn't rely on it being 'realtime' if it fails to keep up if you drop the frequency 10%. Also -O2 should give you better performance.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have tried -O2 and -O3, but the same problem occurs which is the program don't enter the decoding progress. I use an external interrupt to set a begin decoding flag and poll this flag in the main function. When using -O2 or -O3, the beginning flag is set correctly, but the polling didn't work. If I set a breakpoint there, the program shall never go to that part of the main function. I don't know what does optimization really do under different level. Can you give some idea about it?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It might be how the polling is implemented. Are you familiar with the keyword 'volatile'? http://en.wikipedia.org/wiki/volatile_variable Variables that should be volatile are one of the many things that you can look out for once you start increasing the optimization level. When you declare a variable volatile you are basically telling the compiler that the value can change at any time without the CPU being involved (a key characteristic of a register in a slave port). If that doesn't help maybe you can copy the code you think is the culprit into this post and one of us can figure out why the optimization level is causing problems. *Usually* these problems are caused by the application code and corner cases that the developer hasn't thought of, I say usually since -O3 can sometimes bring in some surprises :)

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You are right. Declaring the variables 'volatile' solved the problem immediately. The decoding time for 274s mp3 decreased to 127s under -O3. Thanks a lot.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    @ BadOmen

    correct changing from -O2 to -O3 might introduce hardcore bugs with -O3 we had to add -fno-rename-registers to get rid of some functional differencies between DEBUG and RELEASE version
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes, but the final program include not only the mp3 decoding. You may need to find the part you need. And the program is not with me right now. I'm not sure I still have it. How can I share the code to you?