Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Corrupted audio captures with Managed DirectX

117 views
Skip to first unread message

Mark

unread,
Sep 3, 2007, 2:18:50 PM9/3/07
to
Hi,

I've been developing some audio analysis software using .NET and MDX,
which performs a long recording and records specific events.

The problem is that the recordings are invariably corrupted. The
corruptions are relatively infrequent (maybe every hour or three), and
do not appear related to anything that I can change in the program, or
in DirectX settings.

The corruption is quite characteristic - it's essentially a bunch of
dropped samples (probably several hundred or several thousand).
Importantly, this corruption occurs in the middle of a Directsound
buffer (between notification points if notification is used), and
whether or not I use notification, or simply poll the read cursor
position. Buffer size makes no difference, I've tried allocating buffers
from 1 second to several minutes. Similarly, changing the capture
thread's priority makes no difference.

The analysis program never lags behind the audio buffer (by more than 1
polling interval - I've tried as low as 50 ms, and polling intervals are
never missed). CPU usage is around 2%, and the corruption is not clearly
related to high CPU usage, disk activity, background tasks, network
activity, graphics activity, or any other identifiable cause.

On my main development machine (Core 2 Duo, 2GB RAM, Intel P965) I've
tried both on-board sound (Analog devices SoundMax) and a PCI card
(Creative X-fi), using Vista Home Premium 32 bit. I've tried all driver
versions, BIOS versions, etc. that I can lay my hands on. The machine
has been thoroughly tested for stability, and passes every diagnostic
test I can lay my hands on. I've also tried testing 1 sound system, with
the other disabled, or removed.

I've also managed to reproduce the same problem on an older test machine
(AMD 2500+, Win 2k, Creative Live) but as it's not my main machine I
haven't been tested it thoroughly with instrumented versions of the code.

I have made a couple of observations that could possibly lay the finger
of blame away from my code. If I'm listening to audio (mp3) at the same
time as a capture is running, at the same time that the capture suffers
corruption, the audio playback will glitch (often a few very load pops
or clicks in rapid succession). Similarly, using DirectSound on Vista,
if a 2nd application is capturing simultaneously, even at a different
sample rate (presumably it's getting data that's been on-the-fly
resampled by the Vista audio framework), that application will also
record similar corruption at a similar time. (Unfortunately, I've taken
to recording test tones because these are rather intermittant bugs, so I
can't be sure if both apps get the corruption at exactly the same time).

I'm at a bit of a loss as to where to go from here. I get the same
problem on multiple sets of hardware and multiple OSs. The only thing in
common seems to be directsound - and that may only be because I haven't
investigated WDM or WASAPI models.

An image of a corrupted test-tone waveform can be seen at:
http://www.chumpusrex.com/junk/audioglitch.png

Any advice/help on how to proceed gratefully received.

M

Chris P.

unread,
Sep 4, 2007, 11:00:40 AM9/4/07
to
On Mon, 03 Sep 2007 19:18:50 +0100, Mark wrote:

> I have made a couple of observations that could possibly lay the finger
> of blame away from my code. If I'm listening to audio (mp3) at the same
> time as a capture is running, at the same time that the capture suffers
> corruption, the audio playback will glitch (often a few very load pops
> or clicks in rapid succession). Similarly, using DirectSound on Vista,
> if a 2nd application is capturing simultaneously, even at a different
> sample rate (presumably it's getting data that's been on-the-fly
> resampled by the Vista audio framework), that application will also
> record similar corruption at a similar time. (Unfortunately, I've taken
> to recording test tones because these are rather intermittant bugs, so I
> can't be sure if both apps get the corruption at exactly the same time).
>
> I'm at a bit of a loss as to where to go from here. I get the same
> problem on multiple sets of hardware and multiple OSs. The only thing in
> common seems to be directsound - and that may only be because I haven't
> investigated WDM or WASAPI models.
>
> An image of a corrupted test-tone waveform can be seen at:
> http://www.chumpusrex.com/junk/audioglitch.png
>
> Any advice/help on how to proceed gratefully received.

I can't say that I've experienced this, but then again I haven't done the
kind of capture that would notice this.

Does a capture using DirectShow and the standard capture source exhibit
this problem? Build a simple graph with GraphEdt.exe (WindowsSDK\bin) that
has the Capture Source, AVI Mux and File Writer.

Are you capturing at the native sample rate or at a lower rate that
requires resampling?

--
http://www.chrisnet.net/code.htm
[MS MVP for DirectShow / MediaFoundation]

Mark

unread,
Sep 5, 2007, 2:31:37 PM9/5/07
to
Chris P. wrote:

> I can't say that I've experienced this, but then again I haven't done the
> kind of capture that would notice this.
>
> Does a capture using DirectShow and the standard capture source exhibit
> this problem? Build a simple graph with GraphEdt.exe (WindowsSDK\bin) that
> has the Capture Source, AVI Mux and File Writer.
>
> Are you capturing at the native sample rate or at a lower rate that
> requires resampling?
>

Thanks for the reply.

I'm afraid I've never tried DirectShow, and wouldn't know how to set it
up. Indeed, I've only ever used managed DirectX, from which DirectShow
is omitted.

As it is, I've had some fun with C# and got WDM and WASAPI captures
working. WDM shows the same glitches, as does WASAPI Shared mode.

Interestingly, I ran two copies of my code simultaneously (but not
synchronized), one compiled with DirectSound and one with WASAPI Shared
mode, and both captured exactly the same corrupted data at exactly the
same time. Both were running at native sample rate (indeed WASAPI
provides no resampling).

I'm trying an experiment with WASAPI Exclusive mode at the moment - but
I've had a lot of difficulty getting it working: The maximum capture
buffer that I can allocate is 10 ms (requests for larger buffers are
ignored) and the callback notifications never come, and one of my sound
devices will not initialize in exclusive mode whatever I do.

It'll be interesting to see what a long-term test with exclusive mode
reveals.

M

christiand

unread,
Sep 17, 2009, 7:42:27 AM9/17/09
to
Mark,

I've also been trying to get audio captue working with C#, but the sheer lack of documentation has got me stumped. Do you have any code samples you could send me to get me started?

Thanks in advance

Christian

Posted as a reply to:

Re: Corrupted audio captures with Managed DirectX

Chris P. wrote:


Thanks for the reply.

I'm afraid I've never tried DirectShow, and wouldn't know how to set it
up. Indeed, I've only ever used managed DirectX, from which DirectShow
is omitted.

As it is, I've had some fun with C# and got WDM and WASAPI captures
working. WDM shows the same glitches, as does WASAPI Shared mode.

Interestingly, I ran two copies of my code simultaneously (but not
synchronized), one compiled with DirectSound and one with WASAPI Shared
mode, and both captured exactly the same corrupted data at exactly the
same time. Both were running at native sample rate (indeed WASAPI
provides no resampling).

I'm trying an experiment with WASAPI Exclusive mode at the moment - but
I've had a lot of difficulty getting it working: The maximum capture
buffer that I can allocate is 10 ms (requests for larger buffers are
ignored) and the callback notifications never come, and one of my sound
devices will not initialize in exclusive mode whatever I do.

It'll be interesting to see what a long-term test with exclusive mode
reveals.

M

EggHeadCafe - Software Developer Portal of Choice
WCF Workflow Services Using External Data Exchange
http://www.eggheadcafe.com/tutorials/aspnet/3d49fa0d-a120-4977-842a-6dafb17b6d74/wcf-workflow-services-usi.aspx

Hp. Widmer

unread,
Sep 24, 2009, 1:47:46 AM9/24/09
to

> I've also been trying to get audio captue working with C#, but the sheer
> lack of
>documentation has got me stumped.

Read the MS document, that event based interface is suported (the pooling
not)!

May read also on the MS social formus

Cheers

HpW


0 new messages