[music-dsp] WDM for low(er) latency?

Iain iain at idcl.co.uk
Sun Mar 20 05:26:21 EST 2005


What latency are you aiming for?

You can get down to 20 - 30 mS with DirectShow or DirectSound.  In both
cases the minimum latency is gated by the system mixer (KMixer if I recall)
which has a 20 - 30 mS buffer.  The Audio input devices in Direct Show have
a typical latency of 500 MS, but you can change this by setting the
preferred buffer size IAMBufferNegotiation interface before connecting the
filter up.  You can get the latency of the input device quite low, but you
are still faced with the 20 - 30 mS KMixer delay.

If you want to get down to say 2 mS then you will probably need to use the
kernel streaming drivers (WDM Streaming System devices / WDM Streaming
capture devices).  These will work quite nicely with latencies as low as 2
mS.  Though as you say there are questions about if this is the long term
model that MS will use (though they WILL be supported for quite some time, I
would expect).

HOWEVER.  This is black art area.  The documentation is sparse even by
Direct Show standards and most of it is in the DDK area (which is obscure
even by MS standards!).

Some factors here are.

1.	You will need to mess with thread or process priority to prevent
system operations from blocking the audio (causing breakup).
2.	You will have to take exclusive control over the device.  You cannot
mix streams from other processes (like an standard audio player).
3.	You will see a great deal of device dependency.  My tests were with
a midiman delta 1010 and the latency related properties seemed unsupported
instead you controlled latency through the control panel.


Iain

-----Original Message-----
From: music-dsp-bounces at ceait.calarts.edu
[mailto:music-dsp-bounces at ceait.calarts.edu] On Behalf Of James Chandler Jr
Sent: 19 March 2005 17:06
To: music-dsp
Subject: [music-dsp] WDM for low(er) latency?

We have been using MME for a long time, which isn't low latency, but is
simple, 
very reliable, and works for 99.9 percent of customers. Have lately been
dipping 
our feet into ASIO, mainly for low latency softsynth playthru. ASIO seems 
working well.

Would like to improve Windows Driver latency as much as possible without
making 
a big science project out of it. Kernel Streaming support is probably too
big a 
learning curve, since ASIO will in most cases deliver equivalent results,
except 
for folks who don't have ASIO soundcards and can't/won't use generic drivers

like ASIO4ALL. Anyway, Microsoft has been threatening to deprecate kernel 
streaming for what, 4 years now?

Spent half of yesterday googling third-party references on WDM support, but 
there isn't as much third-party info as expected, except for game sound.
Spent 
the other half of the day re-reading the latest MS DirectShow and
DirectSound 
documentation.

On XP SP2, as best I can tell, the minimum practical latency achievable with

MME, on two soundcards I tested, appears to be in the ballpark of 200 mS
(44K 16 
bit stereo).

That figure was measured with a WOMDone callback function to flag returned 
buffers, and a hi-res 1 millisecond timer thread polling for returned buffer

flags. No PostMessage delays that I can see in the test code. Maybe there
are 
some soundcards that give better MME latency than that, but it sure looks
(at 
least on my computers) XP is using a 32768 byte MME sound output buffer, and
if 
its output mixing buffer gets much emptier than 32768 bytes, you get
dropouts 
regardless of how many small buffers you use, and how promptly you
refill/resend 
returned buffers.

Perhaps Microsoft adjusted those details in SP2 or DirectX 9? Think I did
the 
same tests a year ago showing the minimum MME latency closer to 100 mS (on
the 
same test computers), but maybe remembering wrong.

It would be nice to at least get Windows sound latency below 50 mS for 'most

customers with generic soundcards', with extra points if able to dip below
20 mS 
for folks with decent soundcards.

As far as I can tell, other than 'Kernel Streaming', there are two routes to

more directly talk to WDM drivers, DirectSound and DirectShow. Are there
API's I 
missed?

Both DirectSound and DirectShow seem about equally complex to implement 
from-scratch.

DirectShow MIGHT be less complicated to implement. For playback would only
have 
to write an ASYNC pull-model source filter and wire it to a Render filter.
For 
sound input, probably just wire a Capture filter to a push-model destination

filter I already have.

DirectSound is a bit off-putting because of the API's game-orientation. At
least 
I already know a bit about DirectShow. Enough to know it can sometimes take
too 
much hacking before DirectShow actually works as expected (GRIN).

Which approach is most likely to give low-latency without becoming a long 
science project? Have tested some Softsynth plugins that use DirectSound in 
standalone mode, which have pretty good realtime MIDI play-thru latency. So 
apparently at least DirectSound is capable of doing the task? Haven't heard
of 
sequencers/softsynths using DirectShow for realtime i/o, but that doesn't
mean 
it isn't common.

Thanks

JCJR 

--
dupswapdrop -- the music-dsp mailing list and website: 
subscription info, FAQ, source code archive, list archive, book reviews, dsp
links 
http://shoko.calarts.edu/musicdsp 
http://ceait.calarts.edu/mailman/listinfo/music-dsp




More information about the music-dsp mailing list