Reading audio output is stopped when audio visualizers are not in used.
2 using System.Collections.Generic;
5 namespace Visualization
8 /// BasicSpectrumProvider
10 public class BasicSpectrumProvider : FftProvider, ISpectrumProvider
12 private readonly int _sampleRate;
13 private readonly List<object> _contexts = new List<object>();
15 public BasicSpectrumProvider(int channels, int sampleRate, FftSize fftSize)
16 : base(channels, fftSize)
19 throw new ArgumentOutOfRangeException("sampleRate");
20 _sampleRate = sampleRate;
23 public int GetFftBandIndex(float frequency)
25 int fftSize = (int)FftSize;
26 double f = _sampleRate / 2.0;
27 // ReSharper disable once PossibleLossOfFraction
28 return (int)((frequency / f) * (fftSize / 2));
31 public bool GetFftData(float[] fftResultBuffer, object context)
33 if (_contexts.Contains(context))
36 _contexts.Add(context);
37 GetFftData(fftResultBuffer);
41 public override void Add(float[] samples, int count)
43 base.Add(samples, count);
48 public override void Add(float left, float right)
50 base.Add(left, right);