예제 #1
0
 public AudioLeds()
 {
     //this.messageSender = new SimulationMessageSender();
     this.messageSender = Serial.Instance;
     Serial.onData     += onData;
     this.messageSender.Open();
     this.messageSender.SendValue(64, Codes.MessageType.BRIGHTNESS);
     this.builder = new MessageBuilder
     {
         MessageType = Codes.MessageType.CONTROL_AUDIOBANDS
     };
     this.buffer = new SmoothBuffer(10, 0.2f, true);
     this.max    = new SmoothBuffer(1, 0.05f, true);
     new Thread(this.updater).Start();
 }
예제 #2
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();
            }
        }