开发者

Interface to change volume and play sound for HDA Audio device under Windows CE 6.0?

开发者 https://www.devze.com 2023-03-16 07:52 出处:网络
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.

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 stat开发者_运维问答ic 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!


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?

0

精彩评论

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

关注公众号