public Microphone(MMDevice mmd) { // Here you decide what you want to use as the waveIn. // There are many options in NAudio and you can use other streams/files. // Note that the code varies for each different source. waveIn = new WasapiCapture(mmd); waveIn.DataAvailable += OnDataAvailable; sampleAggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); sampleAggregator.PerformFFT = true; }
private void OpenFile(string fileName) { try { var inputStream = new AudioFileReader(fileName); fileStream = inputStream; var aggregator = new SampleAggregator(inputStream); aggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; aggregator.PerformFFT = true; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); playbackDevice.Init(aggregator); } catch (Exception e) { MessageBox.Show(e.Message, "Problem opening file"); CloseFile(); } }
public AudioEngine(string fileName) { try { var inputStream = new AudioFileReader(fileName); fileStream = inputStream; var aggregator = new SampleAggregator(inputStream) { NotificationCount = inputStream.WaveFormat.SampleRate / 100, PerformFFT = true }; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); } catch (Exception e) { Console.WriteLine(e.Message, "Problem opening file"); CloseFile(); } }
public SoundProcessor(string fileName) { try { var inputStream = new AudioFileReader(fileName); _fileStream = inputStream; _fftSampleProvider = new FftSampleProvider(inputStream); _fftSampleProvider.FftCalculated += (result) => FftCalculated?.Invoke(result); _playbackDevice = new WaveOut { DesiredLatency = 200 }; _playbackDevice.Init(_fftSampleProvider); } catch (Exception ex) { CloseFile(); throw ex; } }
private void OpenFile(string fileName) { try { var inputStream = new MediaFoundationReader(fileName); fileStream = inputStream; SampleAggregator = new SampleAggregator(fileStream.ToSampleProvider()); SampleAggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; SampleAggregator.PerformFFT = true; SampleAggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); SampleAggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); Volume = 0.5f; playbackDevice.Volume = Volume; playbackDevice.Init(SampleAggregator); } catch (Exception e) { MessageBox.Show(e.Message, "Проблема открытия файла"); CloseFile(); } }
private void OpenFile(string fileName, bool isVorbis = false) { try { if (isVorbis) { var inputStream = new VorbisWaveReader(fileName); fileStream = inputStream; var aggregator = new AudioSampleAggregator(inputStream); aggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; aggregator.PerformFFT = true; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); playbackDevice.Init(aggregator); playbackDevice.PlaybackStopped += OnPlaybackStopped; } else { var inputStream = new AudioFileReader(fileName); fileStream = inputStream; var aggregator = new AudioSampleAggregator(inputStream); aggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; aggregator.PerformFFT = true; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); playbackDevice.Init(aggregator); playbackDevice.PlaybackStopped += OnPlaybackStopped; } } catch (Exception) { CloseFile(); throw; } }
protected virtual void OnFftCalculated(SampleProcessor.FftEventArgs e) { FftCalculated?.Invoke(this, e); }
protected virtual void OnFftCalculated(FftEventArgs e) { FftCalculated?.Invoke(this, e); }