Desktop Functions: ![]() Smart Device Functions:
|
waveOutPrepareHeader (winmm)
C# Signature:
[DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)] VB Signature:
Declare Function waveOutPrepareHeader Lib "winmm.dll" (TODO) As TODO User-Defined Types:None. Alternative Managed API:Do you know one? Please contribute it! Notes:None. Tips & Tricks:The same WAVEHDR structure used with waveOutPrepareHeader() is also used with the waveOutWrite() and waveOutUnPrepareHeader() functions. The latter is called after the audio playback has been stopped with a call to waveOutReset(); The audio driver will asynchronously set the WHDR_DONE bit in WAVEHDR.dwflags when it has released the audio data block. This means that the WAVEHDR struct passed to the waveOutWrite() function must be allocated in unmanaged memory so it will survive after the call to waveOutWrite(). What I do is preallocate a block of unmanaged memory in my class's Open() method:
waveHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(waveHdr)); Then in the output method I use this:
waveHdr.lpData = wavedata; // audio buffer Now we are ready to write:
if ((MMRESULT = waveOutWrite(waveDevice, waveHdrPtr, Marshal.SizeOf(waveHdr))) != MMSYSERR_NOERROR) When we are done listening to this playback:
while ((waveHdr.dwFlags & WHDR_DONE) == 0) // wait for it When the WHDR_DONE bit sets we can call the waveOutUnPrepareHeader() function to release the resources previously set up:
if ((MMRESULT = waveOutUnprepareHeader(waveDevice, waveHdrPtr, Marshal.SizeOf(waveHdr))) != MMSYSERR_NOERROR) I release the unmanaged memory allocated in the Open() method in the class's Close method:
Marshal.FreeHGlobal(waveHdrPtr); Sample Code:Please add some! Please edit this page!Do you have...
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more). |
|