public SampleAggregator(int fftLength)
 {
     if (!this.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];
     this.fftArgs   = new FftEventArgs(this.fftBuffer);
 }
Esempio n. 2
0
        private static float[] calculateFrequencies(FftEventArgs e, bool useLog)
        {
            var fftPoints   = e.Result.Length;
            var freqsPoints = fftPoints / 2;
            var freqs       = new float[freqsPoints];

            for (int i = 0; i < freqsPoints; i++)
            {
                var fftLeft  = Math.Abs(e.Result[i].X + e.Result[i].Y);
                var fftRight = Math.Abs(e.Result[fftPoints - 1 - i].X + e.Result[fftPoints - 1].Y);

                freqs[i] = fftLeft + fftRight;
            }

            return(freqs);
        }
Esempio n. 3
0
        private void fftCalculated(object sender, FftEventArgs e)
        {
            bool useLog = false;

            float[] freqs = calculateFrequencies(e, useLog);

            float[] averages = this.calculateLogAverages(freqs);
            float[] bands    = this.calculateBands(freqs);

            const float smoothness = 0.5f;

            if (this.lineBuffer == null)
            {
                this.lineBuffer = new SmoothBuffer(averages.Length, smoothness, true);
            }
            if (this.bandBuffer == null)
            {
                this.bandBuffer = new SmoothBuffer(bands.Length, smoothness, true);
            }

            var bufferedAverage = this.lineBuffer.ApplyBuffer(averages);
            var bufferedBands   = this.bandBuffer.ApplyBuffer(bands);

            this.audioLeds.Show(bands);

            var showGraphics = false;

            if (showGraphics)
            {
                float scale = this.getScale(averages);
                this.GFX.Clear(Color.FromArgb(20, Color.Black));
                this.drawBands(bufferedBands, scale);
                this.draw(bufferedAverage, DrawMode.Line, scale);
                this.finishDraw();
            }
        }