CSCore:如何在音频捕获期间应用效果 [英] CSCore: How to apply an effect during audio capture

查看:177
本文介绍了CSCore:如何在音频捕获期间应用效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:我已经发现了以下问题:

First of all: I found already this question: Is it possible to capture audio output and apply effects to it?. But it does not answer my question.

我的问题:几个月前,我问过如何使用cscore记录音频输出: http://cscore.codeplex.com/wikipage?title=Build%20a%20source%20chain&referringTitle=Documentation ,但它仅显示了如何将效果应用于回放. 我正在寻找有关如何执行操作的提示或文档.我很确定,我丢失了一些东西,但是我真的不知道如何将捕获的内容转换为类似回放的内容?

My problem: I've asked how to record the audio output with cscore a few month ago: C# recording audio from soundcard. All that works fine, but now I would like to extend my application. I would like to offer the ability to apply effects to the recorded audio in realtime. I've already found this documentation: http://cscore.codeplex.com/wikipage?title=Build%20a%20source%20chain&referringTitle=Documentation but it just shows how to apply effects on to a playback. I am looking for a hint or a documentation on how to do that. I am pretty sure, that I am missing something but I really don't know how to transform a capture to something like a playback?

推荐答案

您的方法正确.建立源链是一个很好的方法.您可以使用SoundInSource类将ISoundIn对象简单地转换为音频源( SoundInSource ).我已经修改了最后一个问题的代码:

You're on the right way. Building a source chain is a good approach. You can simply convert the ISoundIn object to an audio source by using the SoundInSource-class (SoundInSource). I've modified the code from the last question:

    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();
        }
    }

这篇关于CSCore:如何在音频捕获期间应用效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆