Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
        private void Equal()
        {
            //CSCore.SoundOut.WaveOutDevice.DefaultDevice;
            const string    filename   = @"C:\Temp\test.mp3";
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            try
            {
                //create a source which provides audio data
                using (var source = CodecFactory.Instance.GetCodec(filename))
                {
                    //create the equalizer.
                    //You can create a custom eq with any bands you want, or you can just use the default 10 band eq.
                    Equalizer equalizer = Equalizer.Create10BandEqualizer(FluentExtensions.ToSampleSource(source));

                    //create a soundout to play the source
                    ISoundOut soundOut;
                    if (WasapiOut.IsSupportedOnCurrentPlatform)
                    {
                        soundOut = new WasapiOut();
                    }
                    else
                    {
                        soundOut = new DirectSoundOut();
                    }

                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    IWaveSource finalSource = equalizer.ToWaveSource(16); //since the equalizer is a samplesource, you have to convert it to a raw wavesource
                    soundOut.Initialize(finalSource);                     //initialize the soundOut with the previously created finalSource
                    soundOut.Play();

                    /*
                     * You can change the filter configuration of the equalizer at any time.
                     */
                    equalizer.SampleFilters[0].AverageGainDB = 20; //eq set the gain of the first filter to 20dB (if needed, you can set the gain value for each channel of the source individually)

                    //wait until the playback finished
                    //of course that is optional
                    waitHandle.WaitOne();

                    //remember to dispose and the soundout and the source
                    soundOut.Dispose();
                }
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine("Fileformat not supported: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected exception: " + ex.Message);
            }
        }
        public void TestFlatten()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    synth.SetOutputToWaveStream(stream);
                    synth.Speak("This is a test for flattening");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source    = new WaveFileReader(stream);
                    Equalizer   equalizer = Equalizer.Create10BandEqualizer(source);
                    equalizer.SampleFilters[0].SetGain(-9.6f);
                    equalizer.SampleFilters[1].SetGain(-9.6f);
                    equalizer.SampleFilters[2].SetGain(-9.6f);
                    equalizer.SampleFilters[3].SetGain(-3.9f);
                    equalizer.SampleFilters[4].SetGain(2.4f);
                    equalizer.SampleFilters[5].SetGain(11.1f);
                    equalizer.SampleFilters[6].SetGain(15.9f);
                    equalizer.SampleFilters[7].SetGain(15.9f);
                    equalizer.SampleFilters[8].SetGain(15.9f);
                    equalizer.SampleFilters[9].SetGain(16.7f);

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(equalizer.ToWaveSource());
                    soundOut.Play();

                    waitHandle.WaitOne();

                    soundOut.Dispose();
                    equalizer.Dispose();
                    source.Dispose();
                }
        }