Wave Callback

  • Thread starter Thread starter brettsbignose
  • Start date Start date
B

brettsbignose

Hello,
I am writing an application that plays with a buffer that I obtained
from the sound card using the wave APIs. I was looping, or polling, to
check when the data was delivered, but I wish to use the callback that
is listed in the MSDN. I can't seem to figure out how to implement
this into VB.NET. I also can't figure out how to grab the address of
the subroutine that will be called and hold it so that the garbage
collecter doesn't move it. Any help would be appreciated. I've found
lots of examples in C and even one in VB, but I can't seem to move them
over. If possible, could give me some example code to help me on my
way? Here are a few things I found on the web that may be of interest
to you:

The MSDN page on waveInProc:
http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_waveinproc.asp

http://www.pcreview.co.uk/forums/thread-1433610.php

Code example:
http://www.codeproject.com/useritems/julienT.asp
http://www.eggheadcafe.com/ng/microsoft.public.win32.programmer.mmedia/post581858.asp
http://www.lancs.ac.uk/ug/brownjl/pages/code/control/audio.cpp
http://www.jcomeau.com/src/wavein/rec.c


Thanks,
Brett

P.S. Also, the MSDN states that I can't have any system calls inside
my callback or I'll deadlock. Can I RaiseEvent somewhere in my
program? Is this acceptable? On top of that, I see people using the
waveAPI inside their callbacks?!?!?!? Did I miss some sort of upgrade
to the MSDN?
 
I can't seem to figure out how to implement
this into VB.NET.

You declare a delegate that matches the callback signature and pass
that to the API. In this case I guess it would look like this

Delegate Sub waveInProc(hwi As IntPtr, uMsg As UInteger, dwInstance As
IntPtr, dwParam1 As IntPtr, dwParam2 As IntPtr)

I also can't figure out how to grab the address of
the subroutine that will be called and hold it so that the garbage
collecter doesn't move it.

The GC doesn't move code. You just have to make sure you hold a
reference to the delegate instance so it stays valid as long as the
callback is in use.

Can I RaiseEvent somewhere in my program? Is this acceptable?
Yes


On top of that, I see people using the waveAPI inside their callbacks?!?!?!?

Maybe they didn't read the docs. Or maybe the wave API itself doesn't
count as "system-defined functions", that sentance is kind of vague.


Mattias
 
The GC doesn't move code. You just have to make sure you hold a
reference to the delegate instance so it stays valid as long as the
callback is in use.

What do you mean by that statement? If I declare the delegate, why is
there an instance of it? I'm not sure I quite understand your point.
I have read the section of the MSDN that spoke on delegates, and it
basically says the same thing you do, though I don't quite understand
what either of you mean. The only code example is for a case when the
initial call(EnumWindows I think) does not return until all of the
callbacks have been made and completed. This is not so for my case.

Thank you very much Mattias! You are quite helpful!
Brett
 
If I declare the delegate, why is there an instance of it?

There isn't until you create one. And you have to create one to pass
to waveInOpen.

I'm not sure I quite understand your point.

My point is just that you should keep a reference to the delegate
instance you pass in, or bad things can eventually happen.


Mattias
 
Back
Top