Windows CE 6.0下HDA音频设备改变音量和播放声音的接口?

发布于 2024-11-17 09:36:08 字数 1692 浏览 3 评论 0原文

我为 Win CE 设备开发 C# .Net CF 应用程序,并且在播放声音时更改扬声器音量以影响实际音量时遇到问题。

我使用的界面是:

int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);
int PlaySound(string szSound, IntPtr hMod, int flags);

我使用的代码与具有以下设置的旧设备配合良好:

  • AC'97 音频编解码器、Windows CE 5、.Net CF 2.0。

但是,在新设备上可以播放声音,但我无法更改音量。设置如下:

  • HDA 音频编解码器、Windows CE 6、.Net CF 3.5。

我不确定这个问题是否出在 Windows CE 6 操作系统映像中(例如缺少/不正确的音频驱动程序),或者是否我在 C# 代码中使用了不正确的接口。

非常欢迎任何帮助和想法!

谢谢,

Karl

其他详细信息:

代码:

    public unsafe int SetVolume(int newVolumeInPercent)
    {
        UInt32 newVol = (UInt32)((double)(newVolumeInPercent * ushort.MaxValue) / 100.0);
        newVol = newVol + (newVol << 16);

        int resultSetVolume = waveOutSetVolume(IntPtr.Zero, newVol);

        return (int)Math.Round((double)resultSetVolume * 100 / ushort.MaxValue);
    }

    public void playSound(string soundFile)
    {
        PlaySound(soundFile, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME));
    }

    [DllImport("CoreDll.dll")]
    private extern static int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);

    [DllImport("CoreDll.dll", EntryPoint = "PlaySound", SetLastError = true)]
    private extern static int PlaySound(string szSound, IntPtr hMod, int flags);

    private enum Flags
    {
        SND_ASYNC = 0x0001,
        SND_FILENAME = 0x00020000,
    }

正如您在代码中看到的,我对左通道和右通道都使用参数百分比音量。

使用Windows CE Remote Process Viewer,我可以看到音频驱动程序(即“jwavehda.dll”)已加载。还加载了“waveapi.dll”(通用 Window wave api?)。

点击屏幕时我确实会听到声音,并且使用“PlaySound”功能我可以播放波形文件。唯一的问题是我无法影响音量。

谢谢!

I develop C# .Net CF applications for a Win CE device, and am having problems getting the speaker volume change to affect actual volume when playing sound.

The interface I use is:

int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);
int PlaySound(string szSound, IntPtr hMod, int flags);

The code I use worked well with our old device which had the following setup:

  • AC'97 Audio codec, Windows CE 5, .Net CF 2.0.

However, on the new device the sound is played but I'm not able to change the volume. The setup is as follows:

  • HDA Audio codec, Windows CE 6, .Net CF 3.5.

I am uncertain whether this problem is within the Windows CE 6 OS image (e.g. missing/incorrect audio driver), or if I use the incorrect interface in my C# code.

Any help and ideas are most welcome!

Thanks,

Karl

Additional details:

Code:

    public unsafe int SetVolume(int newVolumeInPercent)
    {
        UInt32 newVol = (UInt32)((double)(newVolumeInPercent * ushort.MaxValue) / 100.0);
        newVol = newVol + (newVol << 16);

        int resultSetVolume = waveOutSetVolume(IntPtr.Zero, newVol);

        return (int)Math.Round((double)resultSetVolume * 100 / ushort.MaxValue);
    }

    public void playSound(string soundFile)
    {
        PlaySound(soundFile, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME));
    }

    [DllImport("CoreDll.dll")]
    private extern static int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);

    [DllImport("CoreDll.dll", EntryPoint = "PlaySound", SetLastError = true)]
    private extern static int PlaySound(string szSound, IntPtr hMod, int flags);

    private enum Flags
    {
        SND_ASYNC = 0x0001,
        SND_FILENAME = 0x00020000,
    }

As you see in the code, I use the argument percentage volume for both the left and right channel.

Using Windows CE Remote Process Viewer, I can see that the audio driver (i.e. "jwavehda.dll") is loaded. Also the "waveapi.dll" (generic Window wave api?) is loaded.

I do get sound when tapping the screen, and using the "PlaySound" function I am able to play a wave file. The only problem is that I cannot affect the volume.

Thanks!

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

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

发布评论

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

评论(1

话少情深 2024-11-24 09:36:08

我需要查看您的调用代码(这里的 p/invoke 声明也不完整)以确保确定。您是否知道 waveOutSetVolume dwVolume 分为两个字,上面的工作是左声道音量,下面的工作是右声道音量?您发送的值可能会影响行为(您没有显示代码的该部分)。

代码在一个平台上运行但在另一个平台上失败这一事实表明,这可能是操作系统/平台问题。您是否能获得屏幕点击或其他系统事件等音频?你有音频控制面板小程序吗?您是否在注册表中查找音频驱动程序以确保它存在于操作系统中并且也已加载?

I'd need to see your calling code (and your p/invoke declaration here are incomplete as well) to be sure. Are you aware that the waveOutSetVolume dwVolume is split into two words, the upper work being the left channel volume and the lower work being the right channel volume? The value you're sending in might be affecting the behavior (you didn't show that part of your code).

The fact that the code worked on one platform but fails on another indicates to me that it's likely an OS/Platform issue. Do you get audio for things like screen taps or other system events? Do you have an audio control panel applet? Did you look for an audio driver in the registry to make sure it both exists in the OS and is also loaded?

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