//We will play the .wav file when we click the play response button private void playButton_Click(object sender, EventArgs e) { //We we haven't started playing the response. if (waveReader == null) { waveReader = new NAudio.Wave.WaveFileReader(recordFileName); outputSound = new NAudio.Wave.DirectSoundOut(); outputSound.Init(new NAudio.Wave.WaveChannel32(waveReader)); outputSound.Play(); playResponseButton.Text = "Pause Response"; stopResponseButton.Enabled = true; questionCheckedListBox.Enabled = false; } else { if (outputSound.PlaybackState == NAudio.Wave.PlaybackState.Playing) { outputSound.Pause(); playResponseButton.Text = "Play Response"; } else if (outputSound.PlaybackState == NAudio.Wave.PlaybackState.Paused) { outputSound.Play(); playResponseButton.Text = "Pause Response"; } } }
private void DisposeWave() { if (outputSound != null) { if (outputSound.PlaybackState == NAudio.Wave.PlaybackState.Playing) { outputSound.Stop(); } outputSound.Dispose(); outputSound = null; } if (waveReader != null) { waveReader.Dispose(); waveReader = null; } if (waveSource != null) { waveSource.Dispose(); waveSource = null; } if (waveFile != null) { waveFile.Dispose(); waveFile = null; } }
public DirectSoundPlayer(INetworkChatCodec c) : base(c) { waveProvider = new BufferedWaveProvider(codec.RecordFormat); wavePlayer = new DirectSoundOut(); wavePlayer.Init(waveProvider); }
private void Listening() { //Прослушиваем по адресу IPEndPoint localIP = myEpAudio; BufferedWaveProvider bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 1)); // WaveOut player = new WaveOut(); DirectSoundOut player = new DirectSoundOut(); do { try { byte[] receiveBytes = client2.Receive(ref localIP); //добавляем данные в буфер, откуда output будет воспроизводить звук bufferedWaveProvider.AddSamples(receiveBytes, 0, receiveBytes.Length); player.Init(bufferedWaveProvider); player.Play(); //player.Dispose(); } catch (Exception ex) { // MessageBox.Show(ex.Message); } } while (true); }
public bool SetAudioEndpoint(string dev, bool usedefault = false) { System.Collections.ObjectModel.ReadOnlyCollection <DirectSoundDevice> list = DirectSoundDeviceEnumerator.EnumerateDevices(); DirectSoundDevice dsd = null; if (dev != null) // active selection { dsd = list.FirstOrDefault(x => x.Description.Equals(dev)); // find if (dsd == null && !usedefault) // if not found, and don't use the default (used by constructor) { return(false); } } DirectSoundOut dso = new DirectSoundOut(100, System.Threading.ThreadPriority.Highest); // seems good quality at 200 ms latency if (dso == null) // if no DSO, fail.. { return(false); } if (dsd != null) { dso.Device = dsd.Guid; } else { DirectSoundDevice def = DirectSoundDevice.DefaultDevice; dso.Device = def.Guid; // use default GUID } NullWaveSource nullw = new NullWaveSource(10); try { dso.Initialize(nullw); // check it takes it.. may not if no sound devices there.. dso.Stop(); nullw.Dispose(); } catch { nullw.Dispose(); dso.Dispose(); return(false); } if (aout != null) // clean up last { aout.Stopped -= Output_Stopped; aout.Stop(); aout.Dispose(); } aout = dso; aout.Stopped += Output_Stopped; return(true); }
public void CanPlayMonoToStereoSourceTest() { var source = new StereoToMonoSource(GlobalTestConfig.TestMp3().ToStereo().ToSampleSource()); Assert.AreEqual(1, source.WaveFormat.Channels); var monoSource = new MonoToStereoSource(source); Assert.AreEqual(2, monoSource.WaveFormat.Channels); ISoundOut soundOut; if (WasapiOut.IsSupportedOnCurrentPlatform) { soundOut = new WasapiOut(); } else { soundOut = new DirectSoundOut(); } soundOut.Initialize(monoSource.ToWaveSource(16)); soundOut.Play(); Thread.Sleep((int)Math.Min(source.GetMilliseconds(source.Length), 60000)); soundOut.Dispose(); }
public void Dispose() { if (this.WaveFileReader != null) { this.WaveFileReader.Dispose(); } this.WaveFileReader = null; if (this.WaveChannel != null) { this.WaveChannel.Dispose(); } this.WaveChannel = null; if (this.MemoryStream != null) { this.MemoryStream.Dispose(); } this.MemoryStream = null; if (this.DirectSoundOut != null) { this.DirectSoundOut.Dispose(); } this.DirectSoundOut = null; }
public void PlayFromBeginning() { Console.WriteLine("Starting playback..."); using (var waveFileReader = new WaveFileReader(_waveFileWriter.Filename)) using (var waveChannel32 = new WaveChannel32(waveFileReader) { PadWithZeroes = false }) using (var directSoundOut = new DirectSoundOut()) { var totalBytes = waveFileReader.Length; var totalTime = waveFileReader.TotalTime; Console.WriteLine($"Playing {totalBytes}bytes ({totalTime})"); directSoundOut.Init(waveChannel32); directSoundOut.Play(); while (directSoundOut.PlaybackState != PlaybackState.Stopped) { Thread.Sleep(20); } directSoundOut.Stop(); Console.WriteLine("Recording ended."); } }
private void AudioLoader() { waveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 1)); waveProvider.DiscardOnBufferOverflow = true; waveOut = new DirectSoundOut(); waveOut.Init(waveProvider); waveOut.Volume = VideoConf.vol; }
public DeviceManager() { AudioMixer = new GameBoyAudioMixer(); var player = new DirectSoundOut(); player.Init(AudioMixer); player.Play(); }
public void PlayRecording(string path) { DisposeAll(); reader = new WaveFileReader(path); player = new DirectSoundOut(); player.Init(new WaveChannel32(reader)); player.Play(); }
/// <summary> /// インスタンスを破棄する /// </summary> protected override void Dispose() { if (this._audioRender is not null) { this._audioRender?.Dispose(); this._audioRender = null; } }
public SynthThread() { synth = new Synthesizer(Properties.Settings.Default.SampleRate, 2, Properties.Settings.Default.BufferSize, Properties.Settings.Default.BufferCount, Properties.Settings.Default.poly); mseq = new MidiFileSequencer(synth); synth_provider = new SynthWaveProvider(synth, mseq); direct_out = new DirectSoundOut(Properties.Settings.Default.Latency); direct_out.Init(synth_provider); }
public Audio() { _output = new DirectSoundOut(); _soundbuffer = new BufferedWaveProvider(new WaveFormat(SAMPLE_RATE, 1)); _soundbuffer.BufferLength = ((SAMPLE_RATE / 60) * 20); //Aproxx 20 frames of sound in buffer _soundbuffer.DiscardOnBufferOverflow = true; _output.Init(_soundbuffer); }
private void timerFFT_Tick(object sender, EventArgs e) { if (Output == null) { Output = new DirectSoundOut(); } app.RunAnalysis(); }
private void PlayMusic_Load(object sender, EventArgs e) { lblTenBaiHat.Text = _mtenbaihat; directSoundOutReceive = new DirectSoundOut(); directSoundOutReceive.Volume = 1.0f; directSoundOutReceive.Init(waveChannel32Receive); directSoundOutReceive.Play(); }
/// <summary> /// フォームのクロージング処理 /// Wave関連オブジェクトのDispose処理を担当 /// </summary> private void Form1_FormClosing(object sender, FormClosingEventArgs e) { output?.Dispose(); output = null; stream?.Dispose(); stream = null; }
void wavePlayer_PlaybackStopped(object sender, StoppedEventArgs e) { // dispose of wave output if (_waveOut != null) { _waveOut.Dispose(); _waveOut = null; } }
static void Main(string[] args) { IWavePlayer waveOutDevice; WaveStream mainOutputStream; string fileName = @"C:\Users\Yuval\Sources\PracticeSharpProject\Audio\Ringtone 01.wma"; Console.WriteLine("Initiailizing NAudio"); try { waveOutDevice = new DirectSoundOut(50); } catch (Exception driverCreateException) { Console.WriteLine(String.Format("{0}", driverCreateException.Message)); return; } mainOutputStream = CreateInputStream(fileName); try { waveOutDevice.Init(mainOutputStream); } catch (Exception initException) { Console.WriteLine(String.Format("{0}", initException.Message), "Error Initializing Output"); return; } Console.WriteLine("NAudio Total Time: " + (mainOutputStream as WaveChannel32).TotalTime); Console.WriteLine("Playing WMA.."); waveOutDevice.Volume = 1.0f; waveOutDevice.Play(); Console.ReadKey(); Console.WriteLine("Seeking to new time: 00:00:20.."); (mainOutputStream as WaveChannel32).CurrentTime = new TimeSpan(0, 0, 20); Console.ReadKey(); Console.WriteLine("Hit key to stop.."); waveOutDevice.Stop(); Console.WriteLine("Finished.."); mainOutputStream.Dispose(); waveOutDevice.Dispose(); Console.WriteLine("Press key to exit..."); Console.ReadKey(); }
static MusicFile() { soundOut = new DirectSoundOut(); codecFactory = CodecFactory.Instance; soundOut.Stopped += (sender, args) => { FileFinishedPlaying?.Invoke(LastFilePlayed); }; }
private void InitWAV(string filePath) { //source ActiveStream = new WaveFileReader(filePath); directSoundOut = new DirectSoundOut(); directSoundOut.Init(new WaveChannel32(ActiveStream)); }
public static void PlayWAV(string path) { WaveFileReader wave = new WaveFileReader(path); DirectSoundOut output = new DirectSoundOut(); output.Init(wave); output.Play(); }
/// <summary> /// Intialize the WaveOut Device and set Volume /// </summary> public void Initialize(Guid deviceGuid) { directOut = new DirectSoundOut(deviceGuid); CurrentDeviceGuid = deviceGuid; directOut.Init(volumeChannel); Settings.Set(Setting.OutputDeviceGuid, deviceGuid.ToString()); Settings.WriteSettings(); }
public void BeginLoopback() { if (waveIn != null && waveOut == null) { waveOut = new DirectSoundOut(DirectSoundOut.DSDEVID_DefaultPlayback, 300); waveOut.Init(new WaveInProvider(waveIn)); waveOut.Play(); } }
/// <inheritdoc /> public void Open() { _circularBuffer = new CircularSampleBuffer(BufferSize * BufferCount); _context = new DirectSoundOut(100); _context.Init(this); ((EventEmitter)Ready).Trigger(); }
public void EndLoopback() { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } }
private void button2_Click(object sender, EventArgs e) { Stream play = new MemoryStream(File.ReadAllBytes(path2)); mp3 = new Mp3FileReader(play); output = new DirectSoundOut(); output.Init(mp3); output.Play(); }
private void play_Click(object sender, EventArgs e) { Stream play = new MemoryStream(audiobyte); mp3 = new Mp3FileReader(play); output = new DirectSoundOut(); output.Init(mp3); output.Play(); }
public void Play() { var reader = new WaveFileReader(SongToPlay); var MediaPlayer = new DirectSoundOut(); var loop = new LoopStream(reader); MediaPlayer.Init(new WaveChannel32(loop)); MediaPlayer.Play(); }
public NoiseWindow() { InitializeComponent(); waveTone = new WaveTone(this.sldFreq.Value, this.sldAmpl.Value); stream = new BlockAlignReductionStream(waveTone); output = new DirectSoundOut(); output.Init(stream); }