コード例 #1
0
        /// <summary>
        /// Returns an [N, 2] matrix with bin ID in column 1 and lower Herz bound in column 2 but on Mel scale
        /// </summary>
        public int[,] GetMelBinBounds()
        {
            double maxMel      = (int)MFCCStuff.Mel(this.Nyquist);
            int    melBinCount = this.FinalBinCount;
            double melPerBin   = maxMel / melBinCount;

            var binBounds = new int[this.FinalBinCount, 2];

            for (int i = 0; i < melBinCount; i++)
            {
                binBounds[i, 0] = i;
                double mel = i * melPerBin;
                binBounds[i, 1] = (int)MFCCStuff.InverseMel(mel);
            }

            return(binBounds);
        }
コード例 #2
0
        /// <summary>
        /// THIS METHOD NEEDS TO BE DEBUGGED.  HAS NOT BEEN USED IN YEARS!
        /// Use this method to generate grid lines for mel scale image
        /// Currently this method is only called from BaseSonogram.GetImage() when bool doMelScale = true;
        /// Frequencyscale.Draw1kHzLines(Image<Rgb24> bmp, bool doMelScale, int nyquist, double freqBinWidth)
        /// </summary>
        public static int[,] GetMelGridLineLocations(int gridIntervalInHertz, int nyquistFreq, int melBinCount)
        {
            double maxMel    = (int)MFCCStuff.Mel(nyquistFreq);
            double melPerBin = maxMel / melBinCount;
            int    gridCount = nyquistFreq / gridIntervalInHertz;

            var gridLines = new int[gridCount, 2];

            for (int f = 1; f <= gridCount; f++)
            {
                int herz     = f * 1000;
                int melValue = (int)MFCCStuff.Mel(herz);
                int melBinId = (int)(melValue / melPerBin);
                if (melBinId < melBinCount)
                {
                    gridLines[f - 1, 0] = melBinId;
                    gridLines[f - 1, 1] = herz;
                }
            }

            return(gridLines);
        }