예제 #1
0
        private void UpdateSpectra()
        {
            var fftSize      = int.Parse(fftSizeTextBox.Text);
            var cepstrumSize = int.Parse(cepstrumSizeTextBox.Text);

            _hopSize = int.Parse(hopSizeTextBox.Text);

            if (fftSize != _fftSize)
            {
                _fftSize           = fftSize;
                _fft               = new Fft(fftSize);
                _cepstralTransform = new CepstralTransform(cepstrumSize, _fftSize);
            }

            if (cepstrumSize != _cepstrumSize)
            {
                _cepstrumSize      = cepstrumSize;
                _cepstralTransform = new CepstralTransform(_cepstrumSize, _fftSize);
            }

            var pos   = _hopSize * _specNo;
            var block = _signal[pos, pos + _fftSize];

            block.ApplyWindow(WindowTypes.Hamming);

            var cepstrum = _cepstralTransform.Direct(block);

            var real = new float[_fftSize];
            var imag = new float[_fftSize];

            for (var i = 0; i < 32; i++)
            {
                real[i] = cepstrum[i];
            }

            _fft.Direct(real, imag);

            var spectrum = _fft.PowerSpectrum(block, normalize: false).Samples;
            var avg      = spectrum.Average(s => LevelScale.ToDecibel(s));

            var spectrumEstimate = real.Take(_fftSize / 2 + 1)
                                   .Select(s => (float)LevelScale.FromDecibel(s * 40 / _fftSize - avg))
                                   .ToArray();

            spectrumPanel.Line     = spectrum;
            spectrumPanel.Markline = spectrumEstimate;
            spectrumPanel.ToDecibel();

            var pitch = Pitch.AutoCorrelation(block);

            cepstrumPanel.Line = cepstrum.Samples;
            cepstrumPanel.Mark = (int)(_signal.SamplingRate / pitch);
        }
예제 #2
0
        private void UpdateAutoCorrelation()
        {
            var pos   = _hopSize * _specNo;
            var block = _signal[pos, pos + _fftSize];

            var pitch = Pitch.AutoCorrelation(block);

            spectrumPanel.Mark   = (int)(_fftSize * pitch / _signal.SamplingRate);  // pitch index
            spectrumPanel.Legend = string.Format("{0:F2} Hz", pitch);

            var autoCorrelation = Operation.CrossCorrelate(block, block).Last(_fftSize);

            autoCorrPanel.Line = autoCorrelation.Samples;
            autoCorrPanel.Mark = (int)(_signal.SamplingRate / _pitchTrack[_specNo]);         // pitch index
        }