private void button1_Click(object sender, EventArgs e) { var ofn = new OpenFileDialog(); ofn.Filter = CodecFactory.SupportedFilesFilterEN; if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Stop(); if (WasapiOut.IsSupportedOnCurrentPlatform) { _soundOut = new WasapiOut(); } else { _soundOut = new DirectSoundOut(); } var source = CodecFactory.Instance.GetCodec(ofn.FileName); source = new LoopStream(source) { EnableLoop = false }; (source as LoopStream).StreamFinished += (s, args) => Stop(); _eq = Equalizer.Create10BandEqualizer(source); _soundOut.Initialize(_eq.ToWaveSource(16)); _soundOut.Play(); } }
private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source) { source = new CSCore.Streams.LoopStream(source); soundOut.Initialize(source); soundOut.Play(); soundOut.Volume = 0.5f; Assert.AreEqual(0.5f, Math.Round(soundOut.Volume, 3)); //round => directsound may causes problems because of db => lin calculations. Thread.Sleep(50); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); Assert.AreEqual(1.0f, soundOut.Volume); }
public bool OpenFile(string filename, Func<IWaveSource, IWaveSource> oninitcallback) { if (String.IsNullOrWhiteSpace(filename)) throw new ArgumentException("filename"); try { var source = CodecFactory.Instance.GetCodec(filename); source = new LoopStream(source); (source as LoopStream).EnableLoop = false; if (source.WaveFormat.Channels == 1) source = new MonoToStereoSource(source).ToWaveSource(16); _panSource = new PanSource(source) { Pan = this.Pan }; var _notification = new SimpleNotificationSource(_panSource); _notification.DataRead += OnNotification; source = _notification.ToWaveSource(16); //source = new BufferSource(source, source.WaveFormat.BytesPerSecond * 2); _source = source; if (oninitcallback != null) SoundOutManager.Initialize(oninitcallback(source)); else SoundOutManager.Initialize(source); } catch (Exception) { return false; } RaiseUpdated(); return true; }
private void SoundOutTests(Action<ISoundOut, IWaveSource> action, bool loopStream = false) { IWaveSource source = GetWaveSource(); if (loopStream) { if (!(source is LoopStream)) source = new LoopStream(source); } ISoundOut[] soundOuts = GetSoundOuts(); foreach (var soundOut in soundOuts) { action(soundOut, source); soundOut.Dispose(); source.Position = 0; } source.Dispose(); }