private void StopCSCore() { if (_soundOut != null) { _soundOut.Stop(); _soundOut.Dispose(); _soundOut = null; } if (_soundIn != null) { _soundIn.Stop(); _soundIn.Dispose(); _soundIn = null; } if (_source != null) { _source.Dispose(); _source = null; } if (_lineSpectrum != null) { _lineSpectrum = null; } }
const FftSize fftSize = FftSize.Fft4096; //4096 sample values /// <summary> /// /// </summary> /// <param name="aSampleSource"></param> private void SetupSampleSource(ISampleSource aSampleSource) { //create a spectrum provider which provides fft data based on some input spectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels, aSampleSource.WaveFormat.SampleRate, fftSize); //linespectrum and voiceprint3dspectrum used for rendering some fft data //in oder to get some fft data, set the previously created spectrumprovider _lineSpectrum = new LineSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, BarCount = 128, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt, MaximumFrequency = 20000, MinimumFrequency = 20, }; /* * _voicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) * { * SpectrumProvider = spectrumProvider, * UseAverage = true, * PointCount = 200, * IsXLogScale = true, * ScalingStrategy = ScalingStrategy.Sqrt * }; */ //the SingleBlockNotificationStream is used to intercept the played samples var notificationSource = new SingleBlockNotificationStream(aSampleSource); //pass the intercepted samples as input data to the spectrumprovider (which will calculate a fft based on them) notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right); _source = notificationSource.ToWaveSource(16); }