X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=source%2Fmupen64plus-audio-sdl%2Fsrc%2Fvolume.c;fp=source%2Fmupen64plus-audio-sdl%2Fsrc%2Fvolume.c;h=1c6e25cda6ba231ad47cb757e2e180fb14ff8b33;hb=852ee1c3556c09f35d264c934612845fe29c64bd;hp=0000000000000000000000000000000000000000;hpb=451ab91e3827a6384981b3300e2a7000d2eaba58;p=mupen64plus-pandora.git diff --git a/source/mupen64plus-audio-sdl/src/volume.c b/source/mupen64plus-audio-sdl/src/volume.c new file mode 100644 index 0000000..1c6e25c --- /dev/null +++ b/source/mupen64plus-audio-sdl/src/volume.c @@ -0,0 +1,88 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Mupen64plus-sdl-audio - volume.c * + * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ * + * Copyright (C) 2007-2008 Richard42 Ebenblues * + * Copyright (C) 2002 Hacktarux * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#if defined(HAS_OSS_SUPPORT) + +/* Sound volume functions. */ +#include +#include +#include +#include +#include /* close() */ +#include +#include +#include + +#include "volume.h" + +/* volSet + * Sets volume of left and right PCM channels to given percentage (0-100) value. + */ +void volSet(int percent) +{ + int ret, vol; + int mixerfd = open("/dev/mixer", O_RDONLY); + + if(mixerfd < 0) + { + perror("/dev/mixer"); + return; + } + + if(percent > 100) + percent = 100; + else if(percent < 0) + percent = 0; + + vol = (percent << 8) + percent; // set both left/right channels to same vol + ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_PCM), &vol); + if(ret < 0) + perror("Setting PCM volume"); + + close(mixerfd); +} + +/* volGet + * Returns volume of PCM channel as a percentage (0-100). + * Returns 0 on error. + */ +int volGet(void) +{ + int vol, ret; + int mixerfd = open("/dev/mixer", O_RDONLY); + + if(mixerfd < 0) + { + perror("/dev/mixer"); + return 0; + } + + ret = ioctl(mixerfd, MIXER_READ(SOUND_MIXER_PCM), &vol); + if(ret < 0) + perror("Reading PCM volume"); + + close(mixerfd); + + return vol & 0xff; // just return the left channel +} + +#endif /* defined(HAS_OSS_SUPPORT) */