开发者

Query wave format for a HWAVEOUT handle

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.


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.


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...?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜