zsiciarz / aquila

Aquila is a digital signal processing library for C++11.
http://aquila-dsp.org
MIT License
462 stars 112 forks source link

MFCC, unnecessary DCT reuse #42

Open sonicmouse opened 9 years ago

sonicmouse commented 9 years ago

In the class Mfcc.cpp, you have this function "calculate()",

   32     std::vector Mfcc::calculate(const SignalSource &source,
   33                                         std::size_t numFeatures)
   34     {
   35         auto spectrum = m_fft->fft(source.toArray());
   36 
   37         Aquila::MelFilterBank bank(source.getSampleFrequency(), m_inputSize);
   38         auto filterOutput = bank.applyAll(spectrum);
   39 
   40         Aquila::Dct dct;
   41         return dct.dct(filterOutput, numFeatures);
   42     }

Every time you call "calculate()", a new DCT is created (line 40). You need to pull the DCT object out of the calculate() scope and put it in the class scope privately.

You have a lot of heavy lifting in DCT, especially with the cosign tables. You even go through all the trouble of caching the cosine tables! So, take advantage of that.

The MFCC calculation will speed up tremendously, especially if you are doing tons of calculations on data that is the same size.

Great job on the library... I have been using it successfully. Ported most of it back to C++98 (had to -- working on a legacy project)

Thanks!

sqbing commented 9 years ago

@sonicmouse Hi, i am trying to port aquila to C++98, too. How is your porting library going? Any open source plan?