C# 在Windows CE 6.0下为HDA音频设备更改音量和播放声音的接口?
我为Win-CE设备开发了C#.Net CF应用程序,但在播放声音时,扬声器音量的变化会影响实际音量,我遇到了一些问题 我使用的界面是:C# 在Windows CE 6.0下为HDA音频设备更改音量和播放声音的接口?,c#,audio,windows-ce,volume,.net-cf-3.5,C#,Audio,Windows Ce,Volume,.net Cf 3.5,我为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 但是,在
int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);
int PlaySound(string szSound, IntPtr hMod, int flags);
我使用的代码在我们的旧设备上运行良好,该设备具有以下设置:
- AC'97音频编解码器,Windows CE 5,.Net CF 2.0
- HDA音频编解码器,WindowsCE6.NETCF3.5
public不安全int SetVolume(int newVolumeInPercent)
{
UInt32 newVol=(UInt32)((双精度)(newVolumeInPercent*ushort.MaxValue)/100.0);
newVol=newVol+(newVol我需要查看您的调用代码(这里的p/invoke声明也不完整)当然。您是否知道waveOutSetVolume dwVolume分为两个字,上面的功是左通道卷,下面的功是右通道卷?您发送的值可能会影响行为(您没有显示代码的该部分)
代码在一个平台上工作,但在另一个平台上失败,这一事实向我表明,这可能是操作系统/平台问题。您是否获得了屏幕点击或其他系统事件的音频?您是否有音频控制面板小程序?您是否在注册表中查找音频驱动程序,以确保它既存在于操作系统中,也已加载谢谢你的回答。我为上述问题添加了详细信息。
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,
}