ar1st0crat / NWaves

.NET DSP library with a lot of audio processing functions
MIT License
462 stars 71 forks source link

MFCC extractor: Index was outside the bounds of the array #11

Closed stefanpantic closed 5 years ago

stefanpantic commented 5 years ago

I am getting the following exception when I try to compute MFCC on my .wav file.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at NWaves.Transforms.Dct4.Direct(Single[] input, Single[] output)
   at NWaves.FeatureExtractors.MfccExtractor.ProcessFrame(Single[] block)
   at NWaves.FeatureExtractors.Base.FeatureExtractor.ComputeFrom(Single[] samples, Int32 startSample, Int32 endSample)
   at MFCC.Example.Main(String[] args) in /home/stefan/Documents/work/ls_records/mfcc/WavMFCC/Program.cs:line 58

Here's my code where I construct the extractor.

        private static readonly MfccExtractor MfccExtractor = new MfccExtractor(
            16000,
            32,
            0.025,
            0.01,
            fftSize: 1024,
            preEmphasis: 0.97,
            includeEnergy:true,
            dctType: "4",
            nonLinearity:NonLinearityType.LogE);

Changing the feature count from 32 to a smaller number, say 13 passes and doesn't throw the exception.

ar1st0crat commented 5 years ago

Hi! Dct in MFCC is used for compressing data (dimensionality reduction similar to PCA). So it makes no sense to specify number of coefficients bigger than number of mel filters. If you need 32 coeffs for some reason, then make sure the filterbankSize >= 32.

stefanpantic commented 5 years ago

Thanks :D