Example #1
0
 public bool Load(string path, Guid device)
 {
     var cext = path.GetExt();
     _myWaveOut = new DirectSoundOut(device);
     try
     {
         _myWaveStream = _codecs.First(v => v.Extensions.Contains(cext)).CreateWaveStream(path);
     }
     catch
     {
         return false;
     }
     if (_myWaveStream == null) return false;
     if (_myWaveStream.WaveFormat.Channels == 2)
     {
         _myBalanceSampleProvider = new BalanceSampleProvider(_myWaveStream.ToSampleProvider());
         _myVolumeSampleProvider = new VolumeSampleProvider(_myBalanceSampleProvider);
         _myBalanceSampleProvider.Pan = (float)Balance;
     }
     else _myVolumeSampleProvider = new VolumeSampleProvider(_myWaveStream.ToSampleProvider());
     _myEqualizer = new Equalizer(_myVolumeSampleProvider, _equalizerBands) { Enabled = _enableEqualizer };
     _myWaveOut.Init(_myEqualizer);
     _myWaveOut.PlaybackStopped += MyWaveOutOnPlaybackStopped;
     _myVolumeSampleProvider.Volume = (float)Volume;
     return true;
 }
Example #2
0
        public bool Load(string path, Guid device)
        {
            var cext = path.GetExt();

            _myWaveOut = new DirectSoundOut(device);
            try
            {
                _myWaveStream = _codecs.First(v => v.Extensions.Contains(cext)).CreateWaveStream(path);
            }
            catch
            {
                return(false);
            }
            if (_myWaveStream == null)
            {
                return(false);
            }
            if (_myWaveStream.WaveFormat.Channels == 2)
            {
                _myBalanceSampleProvider     = new BalanceSampleProvider(_myWaveStream.ToSampleProvider());
                _myVolumeSampleProvider      = new VolumeSampleProvider(_myBalanceSampleProvider);
                _myBalanceSampleProvider.Pan = (float)Balance;
            }
            else
            {
                _myVolumeSampleProvider = new VolumeSampleProvider(_myWaveStream.ToSampleProvider());
            }
            _myEqualizer = new Equalizer(_myVolumeSampleProvider, _equalizerBands)
            {
                Enabled = _enableEqualizer
            };
            _myWaveOut.Init(_myEqualizer);
            _myWaveOut.PlaybackStopped    += MyWaveOutOnPlaybackStopped;
            _myVolumeSampleProvider.Volume = (float)Volume;
            return(true);
        }
Example #3
0
 public void Unload()
 {
     if (_myWaveOut != null)
     {
         _myWaveOut.PlaybackStopped -= MyWaveOutOnPlaybackStopped;
         _myWaveOut.Stop();
     }
     if (_myWaveStream != null)
     {
         _myWaveStream.Dispose();
         _myWaveStream = null;
     }
     _myBalanceSampleProvider = null;
     _myVolumeSampleProvider = null;
     _myEqualizer = null;
 }