1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus-sdl-audio - volume.c *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2007-2008 Richard42 Ebenblues *
5 * Copyright (C) 2002 Hacktarux *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23 #if defined(HAS_OSS_SUPPORT)
25 /* Sound volume functions. */
26 #include <sys/soundcard.h>
27 #include <sys/types.h>
29 #include <sys/ioctl.h>
30 #include <unistd.h> /* close() */
38 * Sets volume of left and right PCM channels to given percentage (0-100) value.
40 void volSet(int percent)
43 int mixerfd = open("/dev/mixer", O_RDONLY);
56 vol = (percent << 8) + percent; // set both left/right channels to same vol
57 ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_PCM), &vol);
59 perror("Setting PCM volume");
65 * Returns volume of PCM channel as a percentage (0-100).
71 int mixerfd = open("/dev/mixer", O_RDONLY);
79 ret = ioctl(mixerfd, MIXER_READ(SOUND_MIXER_PCM), &vol);
81 perror("Reading PCM volume");
85 return vol & 0xff; // just return the left channel
88 #endif /* defined(HAS_OSS_SUPPORT) */