CSCore: How to apply an effect during audio capture

◇◆丶佛笑我妖孽 提交于 2019-12-11 11:09:14

问题


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.

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?


回答1:


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


来源:https://stackoverflow.com/questions/23609469/cscore-how-to-apply-an-effect-during-audio-capture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!