private void SetupSampleSource(ISampleSource aSampleSource) { const FftSize fftSize = FftSize.Fft4096; //create a spectrum provider which provides fft data based on some input var 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 = 50, BarSpacing = 2, 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); _waveSource = notificationSource.ToWaveSource(16); }
/// <summary> /// /// </summary> private void StartAudioVisualization() { //Open the default device iSoundIn = new WasapiLoopbackCapture(); //Our loopback capture opens the default render device by default so the following is not needed //iSoundIn.Device = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Console); iSoundIn.Initialize(); SoundInSource soundInSource = new SoundInSource(iSoundIn); ISampleSource source = soundInSource.ToSampleSource(); const FftSize fftSize = FftSize.Fft2048; //create a spectrum provider which provides fft data based on some input BasicSpectrumProvider spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize); //linespectrum and voiceprint3dspectrum used for rendering some fft data //in oder to get some fft data, set the previously created spectrumprovider iLineSpectrum = new LineSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = false, // Does not matter since we hacked it BarCount = 16, BarSpacing = 1, IsXLogScale = true, // Does not matter since we hacked it ScalingStrategy = ScalingStrategy.Decibel // Does not matter since we hacked it }; //the SingleBlockNotificationStream is used to intercept the played samples var notificationSource = new SingleBlockNotificationStream(source); //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); iWaveSource = notificationSource.ToWaveSource(16); // We need to read from our source otherwise SingleBlockRead is never called and our spectrum provider is not populated byte[] buffer = new byte[iWaveSource.WaveFormat.BytesPerSecond / 2]; soundInSource.DataAvailable += (s, aEvent) => { int read; while ((read = iWaveSource.Read(buffer, 0, buffer.Length)) > 0) { ; } }; //Start recording iSoundIn.Start(); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { var openFileDialog = new OpenFileDialog() { Filter = CodecFactory.SupportedFilesFilterEn, Title = "Select a file..." }; if (openFileDialog.ShowDialog() == DialogResult.OK) { Stop(); const FftSize fftSize = FftSize.Fft4096; IWaveSource source = CodecFactory.Instance.GetCodec(openFileDialog.FileName); var spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize); _lineSpectrum = new LineSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, BarCount = 50, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; _voicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, PointCount = 200, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource()); notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right); _source = notificationSource.ToWaveSource(16); _soundOut = new WasapiOut(); _soundOut.Initialize(_source.ToMono()); _soundOut.Play(); timer1.Start(); propertyGridTop.SelectedObject = _lineSpectrum; propertyGridBottom.SelectedObject = _voicePrint3DSpectrum; } }
private void SetupSampleSource(ISampleSource aSampleSource) { const FftSize fftSize = FftSize.Fft128; var spectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels, aSampleSource.WaveFormat.SampleRate, fftSize); _lineSpectrum = new LineSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, BarCount = 50, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Linear }; var notificationSource = new SingleBlockNotificationStream(aSampleSource); notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right); _source = notificationSource.ToWaveSource(16); }
/// <summary> /// Setup the spectrum analyzer /// </summary> public static void SetupSampleSource(ISampleSource aSampleSource) { FFTSize = FftSize.Fft2048; SpectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels, aSampleSource.WaveFormat.SampleRate, FFTSize); m_SpectrumAnalyzer = new SpectrumAnalyzer(FFTSize) { SpectrumProvider = SpectrumProvider, UseAverage = true, BarCount = NumberOfAnalysisBars, UseLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; var notificationSource = new SingleBlockNotificationStream(aSampleSource); notificationSource.SingleBlockRead += (s, a) => SpectrumProvider.Add(a.Left, a.Right); m_Source = notificationSource.ToWaveSource(16); }
private void NotificationSource_SingleBlockRead(object sender, SingleBlockReadEventArgs e) { spectrumProvider.Add(e.Left, e.Right); }
private void SingleBlockNotificationStream_SingleBlockRead(object sender, SingleBlockReadEventArgs e) { basicSpectrumProvider.Add(e.Left, e.Right); }
private void SingleBlockNotificationStream_SingleBlockRead(object sender, SingleBlockReadEventArgs e) { _lineSpectrumProvider.Add(e.Left, e.Right); _spectrogramProvider.Add(e.Left, e.Right); _oscilloscope.Add(e.Left, e.Right); }
private void SetupSampleSource(ISampleSource aSampleSource) { const FftSize fftSize = FftSize.Fft4096; //create a spectrum provider which provides fft data based on some input spectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels, aSampleSource.WaveFormat.SampleRate, fftSize); //spectrumProvider.GetFftData() //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 = 50, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; _voicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, PointCount = 1, IsXLogScale = false, ScalingStrategy = ScalingStrategy.Linear, MaximumFrequency = 100, MinimumFrequency = 20 }; _DigitallineSpectrum = new LineSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, BarCount = 50, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; _DigitalBassPrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) { Colors = new Color[2] { Color.Black, Color.Red }, SpectrumProvider = spectrumProvider, UseAverage = false, PointCount = 1, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Linear, MaximumFrequency = 250, MinimumFrequency = 20 }; _DigitalMedioPrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) { Colors = new Color[2] { Color.Black, Color.Green }, SpectrumProvider = spectrumProvider, UseAverage = false, PointCount = 1, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Linear, MaximumFrequency = 3000, MinimumFrequency = 250 }; _DigitaltreblePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) { Colors = new Color[2] { Color.Black, Color.Blue }, SpectrumProvider = spectrumProvider, UseAverage = false, PointCount = 1, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Linear, MaximumFrequency = 16000, MinimumFrequency = 3000 }; _GenericlineSpectrum = new LineSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, BarCount = 50, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; _GenericvoicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize) { SpectrumProvider = spectrumProvider, UseAverage = true, PointCount = 200, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt, MaximumFrequency = 20000, MinimumFrequency = 20 }; //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); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { var openFileDialog = new OpenFileDialog() { Filter = CodecFactory.SupportedFilesFilterEn, Title = "Select a file..." }; if (openFileDialog.ShowDialog() == DialogResult.OK) { Stop(); const FftSize fftSize = FftSize.Fft4096; //open the selected file ISampleSource source = CodecFactory.Instance.GetCodec(openFileDialog.FileName) .ToSampleSource() .AppendSource(x => new PitchShifter(x), out _pitchShifter); //create a spectrum provider which provides fft data based on some input var spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.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 = 50, BarSpacing = 2, IsXLogScale = true, ScalingStrategy = ScalingStrategy.Sqrt }; _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(source); //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); //play the audio _soundOut = new WasapiOut(); _soundOut.Initialize(_source); _soundOut.Play(); timer1.Start(); propertyGridTop.SelectedObject = _lineSpectrum; propertyGridBottom.SelectedObject = _voicePrint3DSpectrum; } }