Beispiel #1
0
        private static void InitializeNAudio(string fileName)
        {
            // Create the output device to play on
            _waveOutDevice = new WaveOut();

            // Create the input wave
            _waveReader       = new Mp3FileReader(fileName);
            _blockAlignStream = new BlockAlignReductionStream(_waveReader);
            _waveChannel      = new WaveChannel32(_blockAlignStream);

            // Attach a handler to the channel sample event
            _waveChannel.Sample += new EventHandler <SampleEventArgs>(_waveChannel_Sample);

            // Create the input provider
            _inputProvider = new AdvancedBufferedWaveProvider(_waveChannel.WaveFormat);
            _inputProvider.MaxQueuedBuffers = 100;

            _soundTouchSharp.SetSampleRate(_waveChannel.WaveFormat.SampleRate);
            _soundTouchSharp.SetChannels(_waveChannel.WaveFormat.Channels);

            _soundTouchSharp.SetTempoChange(0);
            _soundTouchSharp.SetPitchSemiTones(0);
            _soundTouchSharp.SetRateChange(0);

            _soundTouchSharp.SetTempo(1.0f);
            _soundTouchSharp.SetSetting(SoundTouchSharp.SoundTouchSettings.SETTING_USE_QUICKSEEK, 0);
            ApplyTimeStretchProfiles();



            // Initialize the device
            _waveOutDevice.Init(_inputProvider);
            _waveOutDevice.Play();
        }
Beispiel #2
0
        public static void Cleanup()
        {
            try
            {
                if (_inputProvider != null)
                {
                    if (_inputProvider is IDisposable)
                    {
                        (_inputProvider as IDisposable).Dispose();
                    }
                    _inputProvider = null;
                }

                if (_currentWaveChannel != null)
                {
                    _currentWaveChannel.Dispose();
                    _currentWaveChannel = null;
                }

                if (_blockAlignStream != null)
                {
                    _blockAlignStream.Dispose();
                    _blockAlignStream = null;
                }

                if (_waveReader != null)
                {
                    _waveReader.Dispose();
                    _waveReader = null;
                }

                if (_waveOutDevice != null)
                {
                    _waveOutDevice.Dispose();
                    _waveOutDevice = null;
                }
            }
            catch (System.NullReferenceException exception)
            {
                // We probably tried to dispose of an object that didn't exist
                // Write some debug output so we can check this later
                Console.WriteLine(exception.Message);
            }
            catch (System.Exception exception)
            {
                // Something weird happened
                Console.WriteLine(exception.Message);
            }
        }
Beispiel #3
0
        private static void InitializeNAudio(string fileName)
        {
            // Create the output device to play on
            _waveOutDevice = new WaveOut();

            // Create the input wave
            _waveReader = new Mp3FileReader(fileName);
            _blockAlignStream = new BlockAlignReductionStream(_waveReader);
            _waveChannel = new WaveChannel32(_blockAlignStream);

            // Attach a handler to the channel sample event
            _waveChannel.Sample += new EventHandler<SampleEventArgs>(_waveChannel_Sample);

            // Create the input provider
            _inputProvider = new AdvancedBufferedWaveProvider(_waveChannel.WaveFormat);
            _inputProvider.MaxQueuedBuffers = 100;

            _soundTouchSharp.SetSampleRate(_waveChannel.WaveFormat.SampleRate);
            _soundTouchSharp.SetChannels(_waveChannel.WaveFormat.Channels);

            _soundTouchSharp.SetTempoChange(0);
            _soundTouchSharp.SetPitchSemiTones(0);
            _soundTouchSharp.SetRateChange(0);

            _soundTouchSharp.SetTempo(1.0f);
            _soundTouchSharp.SetSetting(SoundTouchSharp.SoundTouchSettings.SETTING_USE_QUICKSEEK, 0);
            ApplyTimeStretchProfiles();

            // Initialize the device
            _waveOutDevice.Init(_inputProvider);
            _waveOutDevice.Play();
        }
Beispiel #4
0
        public static void Cleanup()
        {
            try
            {
                if (_inputProvider != null)
                {
                    if (_inputProvider is IDisposable)
                    {
                        (_inputProvider as IDisposable).Dispose();
                    }
                    _inputProvider = null;
                }

                if (_currentWaveChannel != null)
                {
                    _currentWaveChannel.Dispose();
                    _currentWaveChannel = null;
                }

                if (_blockAlignStream != null)
                {
                    _blockAlignStream.Dispose();
                    _blockAlignStream = null;
                }

                if (_waveReader != null)
                {
                    _waveReader.Dispose();
                    _waveReader = null;
                }

                if (_waveOutDevice != null)
                {
                    _waveOutDevice.Dispose();
                    _waveOutDevice = null;
                }
            }
            catch (System.NullReferenceException exception)
            {
                // We probably tried to dispose of an object that didn't exist
                // Write some debug output so we can check this later
                Console.WriteLine(exception.Message);
            }
            catch (System.Exception exception)
            {
                // Something weird happened
                Console.WriteLine(exception.Message);
            }
        }