CSCore loopback recording when muted
Asked Answered
C

1

3

I'm using CSCore.WasapiLoopbackCapture to record system sound. But when there is no sound in system, it doesn't record at all! For instance, while playing music and recording it, the output file's duration is less than the track's. I want it to continue recording even when there is no sound in the system but I didn't find any property to control this behavior. Here is my code snippet:

WasapiCapture waveLoop = new WasapiLoopbackCapture();
waveLoop.Initialize();
waveLoop.DataAvailable += waveLoop_DataAvailable;
waveLoop.Stopped += waveLoop_Stopped;
waveLoop.Start();
Clowers answered 10/6, 2014 at 7:45 Comment(0)
C
5

There is no "nice" solution for your "problem". But your problem already got described here:

Another oddity is that WASAPI will only push data down to the render endpoint when there are active streams. When nothing is playing, there is nothing to capture.

That means that there is nothing you can do against that behavior. If there is nothing playing, nothing will be captured. The easiest solution is:

But my particular favorite way of handling this is to run silence.exe. That way there are never any "nothing is playing" glitches, because there's always something playing.

So just make sure your application or any other application plays silence. That would be a way to make sure that your application records silence instead of interrupting the capture.

Countercurrent answered 10/6, 2014 at 10:49 Comment(7)
Thanks. And where should I find this silence.exe? Can't it be achieved in .net without running another assembly?Clowers
Of course it can. For example, you can achieve it with CSCore.Countercurrent
Could you give me some hints? I'm pretty new to CSCore!Clowers
Well. You basically just need to implement a new WaveSource. E.g. something like this: pastebin.com/9MYM3yFN. After that, just follow this tutorial: cscore.codeplex.com/…. Replace return CodecFactory.Instance.GetCodec(@"C:\Temp\sound.mp3"); by new SilenceGenerator(). That's all.Countercurrent
And how can I distinguish this silence? When recording I'm showing a wave form to inform the user. How can I check if there is only silence, in DataAvailable event?Clowers
Well. That is a bit too complex to answer in a single comment. Better ask a new question.Countercurrent
Hey! thank you thefiloe, just to add that in your pastebin sample, we must replace line 13: "get { throw new NotImplementedException(); }" by "get { return _waveFormat; }". It's pretty easy to figure out but not that obvious at first glanceTantalate

© 2022 - 2024 — McMap. All rights reserved.