00001 00002 /* Copyright 2009 Diego Barrios Romero 00003 * 00004 * This file is part of DSMemorizer. 00005 * 00006 * DSMemorizer is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * DSMemorizer distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with DSMemorizer. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <nds.h> 00021 #include <maxmod9.h> 00022 #include <stdio.h> 00023 00024 #include "soundbank.h" 00025 #include "soundbank_bin.h" 00026 00027 #include "soundhandler.h" 00028 00029 void SoundHandler::Init() 00030 { 00031 mmInitDefaultMem((mm_addr)soundbank_bin); 00032 00033 sfx_handlers_ = new mm_sfxhand [MSL_NSAMPS]; 00034 loaded_sfx_ = new bool [MSL_NSAMPS]; 00035 sfx_available_ = new mm_sound_effect [MSL_NSAMPS]; 00036 00037 for (size_t i = 0; i < MSL_NSAMPS; ++i) 00038 loaded_sfx_[i] = false; 00039 00040 sfx_available_[ACTION].id = SFX_DEERCHASER; 00041 sfx_available_[ACTION].rate = 1024; 00042 sfx_available_[ACTION].handle = 0; 00043 sfx_available_[ACTION].volume = 128; 00044 sfx_available_[ACTION].panning = 128; 00045 00046 sfx_available_[THEME].id = SFX_FLUTE; 00047 sfx_available_[THEME].rate = 1024; 00048 sfx_available_[THEME].handle = 0; 00049 sfx_available_[THEME].volume = 255; 00050 sfx_available_[THEME].panning = 128; 00051 } 00052 00053 void SoundHandler::PlayEffect(SoundHandler::SFX sfx) 00054 { 00055 switch (sfx) 00056 { 00057 case ACTION: 00058 if (!loaded_sfx_[ACTION]) 00059 { 00060 mmLoadEffect(SFX_DEERCHASER); 00061 loaded_sfx_[ACTION] = true; 00062 } 00063 sfx_handlers_[ACTION] = mmEffectEx (&(sfx_available_[ACTION])); 00064 break; 00065 case THEME: 00066 if (!loaded_sfx_[THEME]) 00067 { 00068 mmLoadEffect(SFX_FLUTE); 00069 loaded_sfx_[THEME] = true; 00070 } 00071 sfx_handlers_[THEME] = mmEffectEx (&(sfx_available_[THEME])); 00072 break; 00073 } 00074 } 00075 00076 void SoundHandler::StopEffect(SoundHandler::SFX sfx) 00077 { 00078 switch (sfx) 00079 { 00080 case ACTION: 00081 if (loaded_sfx_[ACTION]) 00082 mmEffectCancel(sfx_handlers_[ACTION]); 00083 break; 00084 case THEME: 00085 if (loaded_sfx_[THEME]) 00086 mmEffectCancel(sfx_handlers_[THEME]); 00087 break; 00088 } 00089 } 00090 00091 void SoundHandler::UnloadEffect (SFX sfx) 00092 { 00093 mmEffectCancel(sfx_handlers_[sfx]); 00094 mmUnloadEffect(sfx_available_[sfx].id); 00095 loaded_sfx_[sfx] = false; 00096 } 00097 00098 void SoundHandler::UnloadEffects () 00099 { 00100 for (size_t i = 0; i < MSL_NSAMPS; ++i) 00101 { 00102 mmEffectCancel(sfx_handlers_[i]); 00103 mmUnloadEffect(sfx_available_[i].id); 00104 loaded_sfx_[i] = false; 00105 } 00106 } 00107 00108 SoundHandler::~SoundHandler () 00109 { 00110 UnloadEffects(); 00111 delete sfx_available_; 00112 delete sfx_handlers_; 00113 delete loaded_sfx_; 00114 }
1.5.8