1 /* 2 * Schism Tracker - a cross-platform Impulse Tracker clone 3 * copyright (c) 2003-2005 Storlek <storlek@rigelseven.com> 4 * copyright (c) 2005-2008 Mrs. Brisby <mrs.brisby@nimh.org> 5 * copyright (c) 2009 Storlek & Mrs. Brisby 6 * copyright (c) 2010-2012 Storlek 7 * URL: http://schismtracker.org/ 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 #include "headers.h" 24 25 #include "util.h" 26 #include "sdlmain.h" 27 #include "osdefs.h" 28 29 static int (*__volume_get_max)(void) = NULL; 30 static void (*__volume_read)(int *left, int *right) = NULL; 31 static void (*__volume_write)(int left, int right) = NULL; 32 33 34 void volume_setup(void) 35 { 36 char *drv, drv_buf[256]; 37 38 drv = SDL_AudioDriverName(drv_buf,sizeof(drv_buf)); 39 40 #ifdef USE_ALSA 41 if ((!drv && !__volume_get_max) 42 || (drv && (!strcmp(drv, "alsa")))) { 43 __volume_get_max = alsa_volume_get_max; 44 __volume_read = alsa_volume_read; 45 __volume_write = alsa_volume_write; 46 } 47 #endif 48 #ifdef USE_OSS 49 if ((!drv && !__volume_get_max) 50 || (drv && (!strcmp(drv, "oss") || !strcmp(drv, "dsp")))) { 51 __volume_get_max = oss_volume_get_max; 52 __volume_read = oss_volume_read; 53 __volume_write = oss_volume_write; 54 } 55 #endif 56 #ifdef MACOSX 57 if ((!drv && !__volume_get_max) 58 || (drv && (!strcmp(drv, "coreaudio") || !strcmp(drv, "macosx")))) { 59 __volume_get_max = macosx_volume_get_max; 60 __volume_read = macosx_volume_read; 61 __volume_write = macosx_volume_write; 62 } 63 #endif 64 #ifdef WIN32 65 if ((!drv && !__volume_get_max) 66 || (drv && (!strcmp(drv, "waveout") || !strcmp(drv, "dsound")))) { 67 __volume_get_max = win32mm_volume_get_max; 68 __volume_read = win32mm_volume_read; 69 __volume_write = win32mm_volume_write; 70 } 71 #endif 72 } 73 74 75 int volume_get_max(void) 76 { 77 if (__volume_get_max) return __volume_get_max(); 78 return 1; /* Can't return 0, that breaks things. */ 79 } 80 void volume_read(int *left, int *right) 81 { 82 if (__volume_read) __volume_read(left,right); 83 else { *left=0; *right=0; } 84 } 85 void volume_write(int left, int right) 86 { 87 if (__volume_write) __volume_write(left,right); 88 } 89