示例#1
0
        /// <summary>
        /// 返回语谱图,语谱图是一个二维数组,大小为frameSize*frameSize
        /// </summary>
        /// <param name="stereos"></param>
        /// <returns></returns>
        public WaveMap GetSpectrogram(List <Stereo> stereos, float shiftNumber = 0, float deviation = 0, float threshold = 0)
        {
            if (stereos == null)
            {
                Console.WriteLine("ConsoleMorphVOXPro.WaveDeal.Spectrogram->GetSpectrogram");
                return(null);
            }

            int startNumber = 0;

            int wavMapLength = (frameSize / 2) * frameSize - frameZip * (frameSize / 2 - 1);

            float[,] spectrogramLMap = new float[mapSize, mapSize];
            float[,] spectrogramRMap = new float[mapSize, mapSize];
            int test = 0;

            //最后一帧舍弃
            for (int i = 0; i < mapSize && frameSize + startNumber <= stereos.Count; i++)
            {
                Complex[] complicesL = new Complex[frameSize];
                Complex[] complicesR = new Complex[frameSize];
                for (int j = 0; j < frameSize; j++)
                {
                    double hamm = Hamming(j, frameSize);
                    complicesL[j] = new Complex(stereos[j + startNumber].Left * hamm, 0);
                    complicesR[j] = new Complex(stereos[j + startNumber].Right * hamm, 0);
                }
                double[] spectrumMapL = GetSpectrum(complicesL);
                double[] spectrumMapR = GetSpectrum(complicesR);
                int      setPosition  = (mapSize - frameSize / 2) / 2;
                for (int j = 0; j < frameSize / 2; j++)
                {
                    spectrogramLMap[i, j + setPosition] = (float)spectrumMapL[j];
                    spectrogramRMap[i, j + setPosition] = (float)spectrumMapR[j];
                }
                startNumber = startNumber + frameSize - frameZip;
                test++;
            }
            WaveMap waveMap = new WaveMap
            {
                LeftSpectrogram  = spectrogramLMap,
                RightSpectrogram = spectrogramRMap,
                ShiftNumber      = shiftNumber,
                Threshold        = threshold,
                Deviation        = deviation
            };

            return(waveMap);

            //---------------//----------------//Test:
            //startNumber+ wavMapLength < stereos.Count//原先的表达式
            //大于一半就能用
            //List<WaveMap> waveMaps = new List<WaveMap>();
            //while (startNumber+ wavMapLength <= stereos.Count)
            //{
            //    float[,] spectrogramLMap = new float[frameSize / 2, frameSize / 2];
            //    float[,] spectrogramRMap = new float[frameSize / 2, frameSize / 2];
            //    for (int i = 0; i < frameSize / 2; i++)
            //    {
            //        Complex[] complicesL = new Complex[frameSize];
            //        Complex[] complicesR = new Complex[frameSize];
            //        double []test1=new double[frameSize];
            //        for (int j = 0; j < frameSize; j++)
            //        {
            //            test1[j] = stereos[j  + startNumber].Left;
            //            complicesL[j] = new Complex(stereos[j  + startNumber].Left * Hamming(j, frameSize), 0);
            //            complicesR[j] = new Complex(stereos[j  + startNumber].Right * Hamming(j, frameSize), 0);
            //        }
            //        double[] spectrumMapL = GetSpectrum(complicesL);
            //        double[] spectrumMapR = GetSpectrum(complicesR);
            //        for (int j = 0; j < frameSize / 2; j++)
            //        {
            //            spectrogramLMap[i, j] = (float)spectrumMapL[j];
            //            spectrogramRMap[i, j] = (float)spectrumMapR[j];
            //        }
            //        startNumber = startNumber + frameSize - frameZip;
            //    }
            //    WaveMap waveMap = new WaveMap
            //    {
            //        LeftSpectrogram = spectrogramLMap,
            //        RightSpectrogram = spectrogramRMap,
            //        ShiftNumber = shiftNumber,
            //        Threshold = threshold,
            //        Deviation = deviation
            //    };
            //    waveMaps.Add(waveMap);
            //}


            //return waveMaps;
        }