Click here to Skip to main content
12,300,260 members (52,293 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# audio
I have a small piece of code that I used to change the wave volume of on windows XP. I used

[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
 
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);

When I use this code on windwos 7. and change volume

int NewVolume = ((ushort.MaxValue / 10) * currentVolume);
// Set the same volume for both the left and the right channels
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
// Set the volume
                waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);

The volume is not getting changed. When i opened the master volume window of win7 I could see the volume level bar getting changed but the volume change was not happening.

I know there are other ways to do the same thing on windows 7 but I was just wondering why the volume is not changing if my function call is able to set the volume bar to the required level?
Posted 29-Feb-12 0:41am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

since Windows Vista/7 MS changed the access to control volume, mixers, etc. and it's called the coreaudio API.
Here are some links, I'm sure you can work something out with it:

http://msdn.microsoft.com/en-us/library/ms678715.aspx?ppud=4[^]
Vista Core Audio API Master Volume Control[^]
http://rongchaua.net/blog/c-adjust-master-volume-in-vista-and-windows-7/[^]

You can also use or have a look at NAudio Wrapper:
http://naudio.codeplex.com/[^]

Good Luck Wink | ;)
Regards
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I made the experience that the waveOutSetVolume and waveOutGetVolume Functions only change the volume ouput of your current application and not the master system volume. therefore the volume is raised or lowered but you dont see any change on the master volume scrollbar. open the mixer and take a look there.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 8 Mar 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100