【问题标题】:Sound with equalizer [closed]带均衡器的声音[关闭]
【发布时间】:2014-03-27 22:53:08
【问题描述】:

几天以来,我一直在尝试使用 C# 创建均衡器。 看过 NAudio 很多时间,但我找不到任何可以与 naudio 配合使用的均衡器。 几天后,我终于来到了@stackoverflow,希望你知道一种使用 c# 创建均衡器的方法。

PS:我也试用了 System.Media.SoundPlayer。但是那个 SoundPlayer 甚至不支持任何与 dsp 相关的东西。那么是否有另一个音频库可以与外部“纯”音频一起使用?

【问题讨论】:

    标签: c# audio equalizer cscore


    【解决方案1】:

    那么是否有另一个音频库可以与外部“纯”音频一起使用?

    是的,有一个:https://cscore.codeplex.com

    根据EqualizerSample,你可以这样使用均衡器:

    using CSCore;
    using CSCore.Codecs;
    using CSCore.SoundOut;
    using CSCore.Streams;
    using System;
    using System.Threading;
    
    ...
    
    private static void Main(string[] args)
    {
        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(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].SetGain(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);
        }
    }
    

    您可以根据需要配置均衡器。由于它 100% 实时运行,所有更改都会立即应用。如果需要,还可以单独访问修改每个频道。

    【讨论】:

    • 嗨!今天我更新了CSCORE,它解决了一个问题,但又带来了另一个问题!现在的问题是使用均衡器与以前不同(此代码),我不知道如何使用它。你能帮我吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 2016-01-03
    相关资源
    最近更新 更多