views:

184

answers:

2

Context: I have a piece of code that knows the value of a waveOut handle (HWAVEOUT). However the code did not create the handle, thus the WAVEFORMATEX that was passed to waveOutOpen when creating the handle is unknown.

I want to find out the contents of that WAVEFORMATEX struct that was passed to the waveOutOpen call.

Some more details where this is used: The code runs in a hook function that's invoked instead of waveOutWrite. Thus the code knows the handle value, but does not know the details of the handle creation.

Just so that people do not need to look it up:
The signature of waveOutOpen is

MMRESULT waveOutOpen(
  LPHWAVEOUT phwo,
  UINT uDeviceID,
  LPWAVEFORMATEX pwfx,
  DWORD dwCallback,
  DWORD dwInstance,
  DWORD fdwOpen
);

The signature of waveOutWrite is:

MMRESULT waveOutWrite(
  HWAVEOUT hwo,
  LPWAVEHDR pwh, 
  UINT cbwh
);

Note: I am also hooking waveOutOpen, but it could already be called before I have a hook.

A: 

You access the pwfx item of the waveOutOpen struct just as you would access any other struct.

myWaveOutOpen.pwfx.wFormatTag

Or the equivalent format in your language.

Your question is hard to understand. I'm not sure what you want...?

Tor Valamo
This is part of a project hooking waveOut APIs in order to capture the sound being played back. The parameters of the wave being played back can be obtained by intercepting waveOutOpen. However there is a case where the call to waveOutOpen would not be caught (that is when hooking happens after the call to waveOutOpen). HTH. Dan
Dan Cristoloveanu
+1  A: 

You can't get this information from the wave API. You'll have to get it from whoever opened the wave device.

You can get the playback rate using waveOutGetPlaybackRate(), and knowing that, you could (in theory) know cell size by timing how long it takes to play a buffer of known size. (0 is always silence) But 8 bit stereo will end up taking the same amount of time to play back as 16 bit mono. same with float/32 bit mono and 16 bit stereo.

I'd say that 99% of the time 16 bit stereo will the the right answer, but when you guess wrong, the result sounds really bad (and loud!) so guessing may not be a good idea.

You can also use waveOutMessage() to send custom messages to the wave driver. It's possible that there is some custom_query_wave_format message, but there is no message like that defined in the standard. It's assumed that whoever opened the wave device will keep track of what format (s)he opened it with.

John Knoeller
Good answer, +1, I'll give it a try. If it suits my needs, I'll also accept it soon. Thanks. Dan.
Dan Cristoloveanu