/* sound.cpp - sounds, oddly enough Copyright (C) 2006-20077 Mark boyd 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 fun to play, 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. */ #include #include #include "sound.h" #include "debug.h" #include "dirs.h" //This file is essentially the minimum amount of work on top of SDL_mixer to make it usable namespace sound { std::map sounds; } void sound::init() { if (Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,1024)<0) DBG_WHINE("Sound init failed\n"); Mix_AllocateChannels(16); #define SOUND(A,B) sounds[A]=Mix_LoadWAV((dirs::sound_dir+"/"+B).c_str()); #include "sound_table.h" #undef SOUND } void sound::play(sound::snd_id s) { sound::play(s, 1.0); } void sound::play(sound::snd_id s, float volume) { Mix_Chunk *chunk=sounds[s]; if (chunk) { int nchan=Mix_AllocateChannels(-1); for(int i=0; i(volume*MIX_MAX_VOLUME)); Mix_PlayChannel(i, chunk, 0); return; } } } } void sound::kill() { for(std::map::iterator i=sounds.begin(); i!=sounds.end(); ++i) { Mix_FreeChunk(i->second); } Mix_CloseAudio(); }