[wdmaudiodev] Re: very low latency audio and a C# UI? - SOME GOOD INFO

  • From: "Voelkel, Andy" <andy.voelkel@xxxxxxxxxxxxxxx>
  • To: <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Thu, 26 Feb 2009 20:15:42 -0800

I finally hit upon the right search term for google and found this:

 

http://msdn.microsoft.com/en-us/library/74169f59(VS.71).aspx 

 

Managed and Unmanaged Threading in Microsoft Windows

Management of all threads is done through the Thread
<http://msdn.microsoft.com/en-us/library/system.threading.thread(VS.71).
aspx>  class, including threads created by the common language runtime
and those created outside the runtime that enter the managed environment
to execute code. The runtime monitors all the threads in its process
that have ever executed code within the managed execution environment.
It does not track any other threads. Threads can enter the managed
execution environment through COM interop (because the runtime exposes
managed objects as COM objects to the unmanaged world), the COM
DllGetClassObject() function, and platform invoke.

I also found the blog of one of the developers who works on the gc. It
seems to indicate that only managed threads (as defined above,
presumably) are suspended by the gc. See here:

 

http://blogs.msdn.com/maoni/ 

 

So if I am not-misinterpreting the information, it sounds as if Jerry's
suggestion (as well as a number of other techniques) would work, as long
as the real time thread is not initiated in managed code and never
enters managed code. That doesn't sound too hard to arrange.

 

Yoo hoo. I'm unstuck (for the moment). I hope this information has been
of use to someone else on the list.

 

- Andy

 

________________________________

From: wdmaudiodev-bounce@xxxxxxxxxxxxx
[mailto:wdmaudiodev-bounce@xxxxxxxxxxxxx] On Behalf Of Voelkel, Andy
Sent: Thursday, February 26, 2009 7:57 PM
To: wdmaudiodev@xxxxxxxxxxxxx
Subject: [wdmaudiodev] Re: very low latency audio and a C# UI?

 

Hi Jerry,

 

Yes, the UI would be for routing/levels and visualization (VU meters),
it would not have to process the audio stream.

 

My first reaction to your suggestion was to wonder why I didn't think of
it. But after thinking about, I wonder: A C++ dll will run in the
process space of the caller, a .NET app, and all the threads created
will belong to that process. When the .NET gc runs and "suspends all
threads", will it know not to suspend the thread that was created by the
C++ dll for callbacks from, say, an ASIO driver? I have not run across
the information that would allow me to answer this question. It seems
possible that the CLR would suspend all the threads of the process, and
glitches would occur at low latency. It is also possible that the CLR
would be smart enough to know not to.

 

Does anyone know the answer to this question? Or where to go to find out
the answer?

 

I'll check out the blog.

 

- Andy

 

________________________________

From: wdmaudiodev-bounce@xxxxxxxxxxxxx
[mailto:wdmaudiodev-bounce@xxxxxxxxxxxxx] On Behalf Of Jerry Evans
Sent: Thursday, February 26, 2009 11:54 AM
To: wdmaudiodev@xxxxxxxxxxxxx
Subject: [wdmaudiodev] Re: very low latency audio and a C# UI?

 

Andy

Just to clarify - if your DSP code is C++, then what role for the C#
components. Is the UI control only (routing/levels/etc) or is the UI a
more active participant:  does it actually have to process the audio
stream in some way?

I'd package the DSP code into a C++ DLL and export a narrow API for the
C# code to call. Your primary audio thread is created within the DLL and
has a signalling/control mechanism based on shared events or somesuch.
That is all pretty easy to organise. I think you could get read access
to the audio stream without too much trouble as well - treat the C#
audio sink as a slow output device to account for GC and interop
overhead etc. 

The blog here might be of interest:
http://geekswithblogs.net/robp/archive/2008/08/13/speedy-c-part-3-unders
tanding-memory-references-pinned-objects-and.aspx

HTH & keep us posted - I'm sure we'll have to face this issue before too
long.

Jerry

Voelkel, Andy wrote: 

Hi Tim,

 

Thanks. That helps, just to know it is possible. One of the things I
don't know how to do create an "unmanaged threads". I was under the
impression that threads themselves aren't managed or unmanaged, only
code was. And therefore I don't know how to arrange it so that the gc
knows that my low latency thread doesn't contain unmanaged code and
thereform doesn't suspend it". Do you have any book or other reading
recommendations that would enlighten me on such issues? 

 

- Andy

 



CONFIDENTIALITY NOTICE: This e-mail transmission, and any documents,
files or previous e-mail messages attached to it, may contain
information that is confidential and/or legally privileged. If you are
not the intended recipient, or a person responsible for delivering it to
the intended recipient, please DO NOT disclose the contents to another
person, store or copy the information in any medium, or use any of the
information contained in or attached to this transmission for any
purpose. If you have received this transmission in error, please
immediately notify the sender by reply email or at
mailto:privacy@xxxxxxxxxxxxxxx, and destroy the original transmission
and its attachments without reading or saving in any manner.

For further information about Plantronics - the Company, its products,
brands, partners, please visit our website www.plantronics.com. 

Other related posts:

  • » [wdmaudiodev] Re: very low latency audio and a C# UI? - SOME GOOD INFO - Voelkel, Andy