查询 HWAVEOUT 句柄的波形格式

发布于 2024-08-12 18:12:58 字数 614 浏览 13 评论 0原文

上下文:我有一段代码知道 waveOut 句柄 (HWAVEOUT) 的值。然而,代码没有创建句柄,因此在创建句柄时传递给waveOutOpen 的WAVEFORMATEX 是未知的。

我想找出传递给 waveOutOpen 调用的 WAVEFORMATEX 结构的内容。

使用此功能的更多细节:代码在调用的钩子函数中运行,而不是在 waveOutWrite 中运行。因此,代码知道句柄值,但不知道句柄创建的详细信息。

只是为了让人们不需要查找它:
waveOutOpen 的签名是

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

waveOutWrite 的签名是:

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

注意:我也在挂钩waveOutOpen,但在我挂钩之前它可能已经被调用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2024-08-19 18:12:58

您无法从 wave API 获取此信息。你必须从打开波动设备的人那里获取它。

您可以使用waveOutGetPlaybackRate() 获取播放速率,并且知道这一点后,您可以(理论上)通过计时播放已知大小的缓冲区所需的时间来了解单元格大小。 (0 始终是静音)但 8 位立体声最终将花费与 16 位单声道相同的时间来播放。与浮点/32 位单声道和 16 位立体声相同。

我想说 99% 的情况下 16 位立体声都会得到正确的答案,但是当您猜错时,结果听起来真的很糟糕(而且很大声!),所以猜测可能不是一个好主意。

您还可以使用waveOutMessage()将自定义消息发送到wave驱动程序。可能存在一些 custom_query_wave_format 消息,但没有像标准中定义的消息。假定打开波形设备的人都会跟踪他打开它的格式。

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.

财迷小姐 2024-08-19 18:12:58

您可以像访问任何其他结构一样访问 waveOutOpen 结构的 pwfx 项。

myWaveOutOpen.pwfx.wFormatTag

或者您语言的等效格式。

你的问题很难理解。我不确定你想要什么...?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文