473,473 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Wave Callback

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...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/micros...post581858.asp
http://www.lancs.ac.uk/ug/brownjl/pa...trol/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?

Dec 6 '05 #1
3 1600
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 6 '05 #2
>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

Dec 6 '05 #3
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: andrea valle | last post by:
Hi to all, I'm using wave module with success. I'm writing data to wave file. Typically I create a list of values (data) and pass it to ..writeframes(data) methods. a = wave.open("/test.wav",...
0
by: david.kettle | last post by:
Hello Python World! I've been playing with the 'wave' and 'audioop' modules in the library, and I have a question. When I tried to read a "wav" file with samples in 32-bit float, I got the...
6
by: Xanax | last post by:
Hi all, I need to produce a sine wave and use the WaveOut APi to sound it on my sound card. I also need to compute Fast Fourier Transform to modify the Sine wave. Any ideas on where to start or...
4
by: vikram | last post by:
in a stereo type of wave file i want to know what is this left & right info in a wave file??? how do i read the left & right info from a .wav file to a buffer..
3
by: VenuGopal | last post by:
hi, i want to store the WAVE FILE CONTENTS in an XML. How do i do it? thanks Venugopal
5
by: m.topczewski | last post by:
Hello, I'm a beginner in c++, i have to write a program that will take couple of segments from one wave file, and store them in another wave file to be played back later. Here's the code i have...
0
by: Simrat Kaur Sandhu | last post by:
hello friends can anybody tell me how to read data from a wave file.. i have writen code as ... class file { private: FILE *fp; char id; char *sound_buffer; //four bytes to hold 'RIFF' long...
1
by: homevista | last post by:
Part II: Wave file - How to read to a buffer Wave (or Wav) is the standard format for storing audio data on the PC. As software developers, we are interested in the internal structure of the file...
6
by: homevista | last post by:
PART III: Putting things together In part I we examined the modem to verify that it supported voice. If so, we took a note about the voice data format that we would use. In the second part, we...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.