private void DisposeWave() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); output.Dispose(); output = null; } } }
public void Acquire(int input_device, Signal_Type ST, int output_device) { Running = true; Channels_in = NAudio.Wave.WaveIn.GetCapabilities(input_device).Channels; Response = new List <short> [Channels_in]; block = 2 * Channels_in; WI = new NAudio.Wave.WaveInEvent(); WI.WaveFormat = new NAudio.Wave.WaveFormat(SampleFreq, 16, Channels_in); WI.DeviceNumber = input_device; WI.BufferMilliseconds = 100; WI.NumberOfBuffers = 3; WI.RecordingStopped += WI_RecordingStopped; WI.DataAvailable += WI_DataAvailable; WO.DeviceNumber = output_device; for (int c = 0; c < Channels_in; c++) { Response[c] = new List <short>(); } SignalProvider Signal; switch (ST) { case Signal_Type.Pink_Noise: Signal = new Noise_Provider(1, (int)CT_Averages, SampleFreq); break; case Signal_Type.MLS: throw new NotImplementedException(); case Signal_Type.Swept_Sine: Signal = new Sweep_Provider((float)Signal_Length, CT_Averages, 63, 20000, SampleFreq); break; case Signal_Type.Logarithmic_Swept_Sine: throw new NotImplementedException(); default: System.Windows.Forms.MessageBox.Show("Select a Signal..."); return; } TD_Signal = Signal.Signal; WO.NumberOfBuffers = 1; WO.DesiredLatency = 3000 * CT_Averages; WO.Volume = 1.0f; WO.Init(Signal); WI.StartRecording(); WO.Play(); System.Threading.Thread.Sleep((int)(Signal_Time_s * (3 + CT_Averages) * 1000)); WO.Stop(); WI.StopRecording(); System.Threading.Thread.Sleep(100); WI_RecordingStopped(this, null); }
public void DoPlay() { try { Console.WriteLine(); Console.WriteLine("playing track. press space to play/pause; ESC to stop"); System.Threading.Thread.Sleep(1000); NAudio.Wave.WaveOutEvent wavout = new NAudio.Wave.WaveOutEvent(); NAudio.Wave.WaveFileReader wavreader = new NAudio.Wave.WaveFileReader(_beatFile.GetWavFilename()); wavout.Init(wavreader); wavout.Play(); int index = 0; List <BeatInstance> bl = _beatFile.GetAllBeats(); while (wavout.PlaybackState != NAudio.Wave.PlaybackState.Stopped) { if (System.Console.KeyAvailable) { switch (System.Console.ReadKey(true).Key) { case ConsoleKey.Spacebar: if (wavout.PlaybackState == NAudio.Wave.PlaybackState.Paused) { wavout.Play(); } else if (wavout.PlaybackState == NAudio.Wave.PlaybackState.Playing) { wavout.Pause(); } break; case ConsoleKey.Escape: Console.WriteLine("stopped playback"); wavout.Stop(); break; case ConsoleKey.OemPeriod: Console.WriteLine("{0}", wavreader.CurrentTime.TotalSeconds); break; } } while (index < bl.Count && bl[index].TriggerTime <= wavreader.CurrentTime.TotalSeconds) { if (!_playQuiet) { ViewOneBeat(bl[index]); } index++; } System.Threading.Thread.Sleep(10); } wavout.Dispose(); wavreader.Dispose(); } catch (Exception ex) { throw new Exception("error playing track", ex); } }