/// <summary> /// Changes the wave output volume for a sound device. /// </summary> /// <param name="percent">Percentage number between -100 and 100 inclusive. /// If the number begins with a plus or minus sign, the current volume level will be adjusted up or down by the indicated amount.</param> /// <param name="device">If this parameter is omitted, it defaults to 1 (the first sound device), /// which is usually the system's default device for recording and playback.</param> public static void SoundSetWaveVolume(string percent, int device) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { return; } if (string.IsNullOrEmpty(percent)) { percent = "0"; } var dev = new IntPtr(device); uint vol; char p = percent[0]; if (p == '+' || p == '-') { WindowsAPI.waveOutGetVolume(dev, out vol); vol = (uint)(vol * double.Parse(percent.Substring(1)) / 100); } else { vol = (uint)(0xfffff * (double.Parse(percent) / 100)); } WindowsAPI.waveOutSetVolume(dev, vol); // TODO: cross platform SoundSetWaveVolume }
/// <summary> /// Retrieves the wave output volume for a sound device. /// </summary> /// <param name="output">The variable to store the result.</param> /// <param name="device">If this parameter is omitted, it defaults to 1 (the first sound device), /// which is usually the system's default device for recording and playback. /// Specify a higher value to operate upon a different sound device.</param> public static void SoundGetWaveVolume(out int output, int device) { output = 0; if (Environment.OSVersion.Platform != PlatformID.Win32NT) { return; } uint vol = 0; WindowsAPI.waveOutGetVolume(new IntPtr(device), out vol); output = (int)vol; // UNDONE: cross platform SoundGetWaveVolume }