views:

566

answers:

4

I'd like to programmatically set volume in Windows, Mac and Ubuntu using C/C++. Command line also can but C/C++ preferred. Thank you in advance!

+1  A: 

For Windows, use the Windows APIs waveOutSetVolume and waveOutGetVolume

Aziz
+1 Thanks Aziz. Does it have the same effect as adjusting the speaker icon on the Taskbar?
Viet
+3  A: 

Just a hint, In windows the 'philosophy' around volume adjustment has changed between XP and Vista/7. Code that would change the master volume on XP will only change the application specific volume setting in the mixer on Vista and 7.

Here is a good blog post by one of the MS audio dev team regarding this: Larry Osterman's Blog

Here are some codeproject pages that might prove useful:

For XP

For Vista +

Also, there are a few powerpoint presentations regarding the new api's here: AMP Summit ppts. The Audio Endpoints in Windows Vista presentation has some good info.

As for OsX and Ubuntu, i have no idea.

YoungPony
+1 Great find Neeul! I wish I could vote more.
Viet
+3  A: 

For Linux using ALSA sound system, you can use following command:

amixer set Master 50%
el.pescado
+1 Thanks! Does it have the same effect as adjusting the speaker icon on the Taskbar? This one does not look like C system call but thanks anyway.
Viet
It is a shell command, you can execute it with system() or fork()/exec(). And yes, it has the same effect as adjusting taskbar volume control.
el.pescado
I wish I knew C/C++ functions to do the same thing. Thanks anyway :)
Viet
Then you should look into ALSA library (http://www.alsa-project.org/alsa-doc/alsa-lib/group___mixer.html), which isn't very well documented, or peek into amixer sources;)
el.pescado
+1 Thanks. Wil do.
Viet
A: 

Here is an article (with code) about setting the master volume in Vista with C/C++:

http://blogs.msdn.com/b/larryosterman/archive/2007/03/06/how-do-i-change-the-master-volume-in-windows-vista.aspx

Xenu