Ejemplo n.º 1
0
 public SampleAggregator(int fftLength)
 {
     if (!IsPowerOfTwo(fftLength))
     {
         throw new ArgumentException("FFT Length must be a power of two");
     }
     this.m = (int)Math.Log(fftLength, 2.0);
     this._fftLength = fftLength;
     this._fftBuffer = new Complex[fftLength];
     Values = new float[fftLength];
     this._fftArgs = new FftEventArgs(_fftBuffer);
 }
Ejemplo n.º 2
0
        void FftCalculated(object sender, FftEventArgs e)
        {
            double[] spect = new double[e.Result.Length];
            var l = e.Result.Length;

            for (int i = 0; i < l; i++)
            {
                spect[i] = e.Result[i].X * e.Result[i].X + e.Result[i].Y * e.Result[i].Y;
            }

            double freq = FrequencyUtils.FindFundamentalFrequency(spect, _sampleAggregator.Values, SampleRate, MinFreq, MaxFreq);
            Debug.WriteLine(freq);
            var note = NoteFinder.FindNearestNote(freq);
            OnNoteDetected(note, freq);
        }