filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.2k stars 454 forks source link

Loopback recording distorted in Win10 #371

Closed Ambusy closed 5 years ago

Ambusy commented 5 years ago

I have a Windows 10 Home pc with Visual Studio Community 2017. I downloaded a fresh CSCore, changed the build command to reflect the SDK on my pc, removed SoundTouchPitchAndTempo because it cannot be compiled, build the project and then executed

  1. Recorder
  2. RecorderToWma as in the projectfile
  3. RecorderToWma with output to a WMA file, as commented in the project file
  4. RecordWithSpecificFormat (44100, 16, 1) All of these give me the same distorted result. I tried Recorder and RecorderToWma on my partially defect Win7 pc with CSCore 1.0.0.5 (very old indeed) and have no problems. A copy of the exe and CSCore.dll on Win10 works fine. The faulty recording can be downloaded here: http://digilander.libero.it/ambusy/recordertowma.wma This is the result of try 3. It is the start of Mozart's Symph 36.

As all programs that use WASAPI loopback capture present the same faults, I've been trying to discover changes for Win10 in the Microsoft documentation. I found (https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/low-latency-audio#overview) this: Starting with Windows 10, the buffer size is defined by the audio driver (more details on this below). Could this be the reason that the buffers are clearly not written with adjacent data? I examined the original wave with the recorded one and found a first glitch at 00:00:00:0050 then 250ms later at 0300, 250ms later at 0550, 450ms to 1000, 450ms to 1450, 250ms to 1700, 450ms to 2150, 250ms to 2400, 250ms to 2650, 450ms to 3100, 250ms to 3350, 450ms to 3800, 250ms to 4050, 450ms to 4500, 250ms to 4750, 450ms to 5200, 250ms to 5450, 450ms to 5900, 250ms to 6150. The fault occurs after 450 or 250ms but I don]t see regularity yet. See attached images: first one shows the source with the missing part selected, second one the recording with a glitch at 00:00:00:0325 where a vertical line bridges the glitch, third one shows the missing part, 11ms. csdiff csbig

WHO can help me, as I'll have to migrate my programs to the new OS.

Tried it today 25 august 2019 on a windows 7 pro in visual studio 2019 community: same problem

Ambusy commented 5 years ago

The problem is now solved in all recorders I have tested. The line int sleepDuration = actualLatency; in function CaptureProc of WasapiCapture.cs should be modified. In the 2014 version it was actualLatency/8; I tried to lower that number down, and found that in my environment (win7pro, Vs 2019 community) if it reads: int sleepDuration = actualLatency/2; everything works fine.