public void CanPlayMonoToStereoSourceTest() { var source = new StereoToMonoSource(CodecFactory.Instance.GetCodec(testfile)); 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 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; }