title: Interface to change volume and play sound for HDA Audio device under Windows CE 6.0?
body: <p>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.</p>
  
  <p>The interface I use is:</p>
  
  <pre><code>int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);
  int PlaySound(string szSound, IntPtr hMod, int flags);
  </code></pre>
  
  <p>The code I use worked well with our old device which had the following setup:</p>
  
  <ul>
  <li>AC'97 Audio codec, Windows CE 5, .Net CF 2.0.</li>
  </ul>
  
  <p>However, on the new device the sound is played but I'm not able to change the volume. The setup is as follows:</p>
  
  <ul>
  <li>HDA Audio codec, Windows CE 6, .Net CF 3.5.</li>
  </ul>
  
  <p>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.</p>
  
  <p>Any help and ideas are most welcome!</p>
  
  <p>Thanks,</p>
  
  <p>Karl</p>
  
  <p>Additional details:</p>
  
  <p>Code:</p>
  
  <pre><code>    public unsafe int SetVolume(int newVolumeInPercent)
      {
          UInt32 newVol = (UInt32)((double)(newVolumeInPercent * ushort.MaxValue) / 100.0);
          newVol = newVol + (newVol &lt;&lt; 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,
      }
  </code></pre>
  
  <p>As you see in the code, I use the argument percentage volume for both the left and right channel.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thanks!</p>