Example #1
0
        private static double GetFilteredMax(
            double low,
            double high,
            float[] audioData
            )
        {
            double lowFreq      = AudioInput.EstimateFreq(low, 144.4505);
            int    lowBinIndex  = (int)AudioInput.GetFrequencyBinUnrounded(lowFreq);
            double highFreq     = AudioInput.EstimateFreq(high, 144.4505);
            int    highBinIndex = (int)Math.Ceiling(AudioInput.GetFrequencyBinUnrounded(highFreq));

            return(audioData.Skip(lowBinIndex).Take(highBinIndex - lowBinIndex + 1).Max());
        }
Example #2
0
        private void Update(object sender, NAudio.Wave.WaveInEventArgs args)
        {
            this.Volume = recordingDevice.AudioMeterInformation.MasterPeakValue;
            lock (this.maxAudioDataLevels) {
                short[] values = new short[args.Buffer.Length / 2];
                for (int i = 0; i < args.BytesRecorded; i += 2)
                {
                    values[i / 2] = (short)((args.Buffer[i + 1] << 8) | args.Buffer[i]);
                }
                this.unanalyzedValues.AddRange(values);

                if (this.unanalyzedValues.Count >= fftSize)
                {
                    this.GenerateAudioData();
                    this.unanalyzedValues.Clear();
                }

                foreach (var pair in this.config.levelDriverPresets)
                {
                    if (pair.Value.Source != LevelDriverSource.Audio)
                    {
                        continue;
                    }
                    AudioLevelDriverPreset preset = (AudioLevelDriverPreset)pair.Value;
                    double filteredMax            = AudioInput.GetFilteredMax(
                        preset.FilterRangeStart,
                        preset.FilterRangeEnd,
                        this.AudioData
                        );
                    if (this.maxAudioDataLevels.ContainsKey(preset.Name))
                    {
                        this.maxAudioDataLevels[preset.Name] = Math.Max(
                            this.maxAudioDataLevels[preset.Name],
                            filteredMax
                            );
                    }
                    else
                    {
                        this.maxAudioDataLevels[preset.Name] = filteredMax;
                    }
                }
                this.UpdateEnergyHistory();
            }
        }
Example #3
0
        public double LevelForChannel(int channelIndex)
        {
            double?midiLevel =
                this.config.beatBroadcaster.CurrentMidiLevelDriverValueForChannel(
                    channelIndex
                    );

            if (midiLevel.HasValue)
            {
                return(midiLevel.Value);
            }
            if (!this.config.channelToAudioLevelDriverPreset.ContainsKey(channelIndex))
            {
                return(this.Volume);
            }
            string audioPreset =
                this.config.channelToAudioLevelDriverPreset[channelIndex];

            if (
                audioPreset == null ||
                !this.config.levelDriverPresets.ContainsKey(audioPreset) ||
                !(this.config.levelDriverPresets[audioPreset] is AudioLevelDriverPreset)
                )
            {
                return(0.0);
            }
            AudioLevelDriverPreset preset =
                (AudioLevelDriverPreset)this.config.levelDriverPresets[audioPreset];

            if (preset.FilterRangeStart == 0.0 && preset.FilterRangeEnd == 1.0)
            {
                return(this.Volume);
            }
            var maxLevel = this.maxAudioDataLevels.ContainsKey(preset.Name)
        ? this.maxAudioDataLevels[preset.Name]
        : 1.0;

            return(AudioInput.GetFilteredMax(
                       preset.FilterRangeStart,
                       preset.FilterRangeEnd,
                       this.AudioData
                       ) / maxLevel);
        }
Example #4
0
        public Operator(Configuration config)
        {
            this.config = config;
              this.stopwatch = new Stopwatch();
              this.stopwatch.Start();

              this.inputs = new List<Input>();
              var audio = new AudioInput(config);
              this.inputs.Add(audio);
              var midi = new MidiInput(config);
              this.inputs.Add(midi);

              this.outputs = new List<Output>();
              var hue = new HueOutput(config);
              this.outputs.Add(hue);
              var board = new CartesianTeensyOutput(config);
              this.outputs.Add(board);
              var dome = new LEDDomeOutput(config);
              this.outputs.Add(dome);
              var whyFire = new WhyFireOutput(config);
              this.outputs.Add(whyFire);

              this.visualizers = new List<Visualizer>();
              this.visualizers.Add(new HueAudioVisualizer(
            this.config,
            audio,
            hue
              ));
              this.visualizers.Add(new LEDPanelVolumeVisualizer(
            this.config,
            audio,
            board
              ));
              this.visualizers.Add(new HueSolidColorVisualizer(
            this.config,
            hue
              ));
              this.visualizers.Add(new HueSilentVisualizer(
            this.config,
            audio,
            hue
              ));
              this.visualizers.Add(new LEDPanelMidiVisualizer(
            this.config,
            midi,
            board
              ));
              this.visualizers.Add(new LEDDomeMidiTestVisualizer(
            this.config,
            midi,
            dome
              ));
              this.visualizers.Add(new LEDDomeStrandTestVisualizer(
            this.config,
            dome
              ));
              this.visualizers.Add(new LEDDomeVolumeVisualizer(
            this.config,
            audio,
            dome
              ));
              this.visualizers.Add(new LEDDomeFlashVisualizer(
            this.config,
            audio,
            midi,
            dome
              ));
              this.visualizers.Add(new WhyFireMidiVisualizer(
            this.config,
            midi,
            whyFire
              ));
        }
Example #5
0
 public MadmomHandler(Configuration config, AudioInput audio)
 {
     this.config = config;
     this.audio  = audio;
     this.config.PropertyChanged += ConfigUpdated;
 }