【问题标题】:CSCore: How to apply an effect during audio captureCSCore:如何在音频捕获期间应用效果
【发布时间】:2014-05-12 12:46:25
【问题描述】:

首先:我已经找到了这个问题:Is it possible to capture audio output and apply effects to it?。但它没有回答我的问题。

我的问题:几个月前我问过如何用 cscore 录制音频输出:C# recording audio from soundcard。一切正常,但现在我想扩展我的应用程序。我想提供对录制的音频实时应用效果的能力。我已经找到了这个文档:http://cscore.codeplex.com/wikipage?title=Build%20a%20source%20chain&referringTitle=Documentation,但它只是展示了如何将效果应用于回放。 我正在寻找有关如何执行此操作的提示或文档。我很确定,我遗漏了一些东西,但我真的不知道如何将捕获转换为回放之类的东西?

【问题讨论】:

    标签: audio audio-recording effects cscore


    【解决方案1】:

    你是在正确的方式。构建源链是一个很好的方法。您可以使用SoundInSource-class (SoundInSource) 简单地将ISoundIn 对象转换为音频源。我已经修改了上一个问题的代码:

        using (WasapiCapture capture = new WasapiLoopbackCapture())
        {
            //if nessesary, you can choose a device here
            //to do so, simply set the device property of the capture to any MMDevice
            //to choose a device, take a look at the sample here: http://cscore.codeplex.com/
    
            //initialize the selected device for recording
            capture.Initialize();
    
            //create a wavewriter to write the data to
            using (WaveWriter w = new WaveWriter("dump.wav", capture.WaveFormat))
            {
                //convert the ISoundIn object into an audio source
                //make sure, that the ISoundIn object is already initialized
                var captureSource = new SoundInSource(capture){ FillWithZeros = false }; 
    
                //build any source chain
                var echoEffect = new DmoEchoEffect(captureSource);
    
                int read = 0;
                var buffer = new byte[echoEffect.WaveFormat.BytesPerSecond]; //buffer to read from the source chain
    
                captureSource.DataAvailable += (s, e) =>
                {
                    while ((read = echoEffect.Read(buffer, 0, buffer.Length)) > 0) //read all available data from the source chain
                    {
                        w.Write(buffer, 0, read); //write the read data to the wave file
                    }
                };
    
                //start recording
                capture.Start();
    
                Console.ReadKey();
    
                //stop recording
                capture.Stop();
            }
        }
    

    【讨论】:

    • 这就是我想要的。所以如果我是对的,我可以建立我想要的每一个源链吗?
    猜你喜欢
    • 2019-06-05
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 2014-06-28
    • 2015-02-02
    相关资源
    最近更新 更多