1 // Crimson Fields -- a game of tactical warfare 2 // Copyright (C) 2000-2007 Jens Granseuer 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 // 18 19 /////////////////////////////////////////////////////////////// 20 // sound.h 21 /////////////////////////////////////////////////////////////// 22 23 #ifndef _INCLUDE_SOUND_H 24 #define _INCLUDE_SOUND_H 25 26 #ifndef DISABLE_SOUND 27 # include <string> 28 using namespace std; 29 30 # include "SDL_mixer.h" 31 32 # define NUM_SFX 6 // system effects; they have nothing to do with 33 // the sounds defined by a mission set 34 #endif 35 36 #ifndef MIX_MAX_VOLUME 37 # define MIX_MAX_VOLUME 0 38 #endif 39 40 class SoundEffect { 41 public: 42 SoundEffect( const char *file ); 43 ~SoundEffect( void ); 44 45 void Play( unsigned short flags ); 46 void Stop( void ); 47 48 private: 49 #ifndef DISABLE_SOUND 50 Mix_Chunk *sample; 51 int channel; 52 #endif 53 }; 54 55 56 class Audio { 57 public: 58 // sound effect identifiers 59 enum { 60 SND_GUI_ERROR = 0, 61 SND_GUI_PRESSED, 62 SND_GUI_MENU_SHOW, 63 SND_GUI_ASK, 64 SND_GAM_SELECT, 65 SND_GAM_REPAIR 66 }; 67 68 // flags for PlaySfx() 69 enum { 70 SFX_LOOP = 0x0001 71 }; 72 73 static int InitSfx( bool state, unsigned char vol ); 74 static int InitMusic( bool state, unsigned char vol ); 75 static void ShutdownSfx(); 76 static void ShutdownMusic(); 77 78 static SoundEffect *PlaySfx( unsigned short sfxid, unsigned short flags ); GetSfxState(void)79 static bool GetSfxState( void ) { return sfx_state; } 80 static void ToggleSfxState( void ); GetSfxVolume(void)81 static int GetSfxVolume( void ) { return sfx_volume; } SetSfxVolume(int vol)82 static void SetSfxVolume( int vol ) { sfx_volume = vol; } 83 84 static void PlayMusic( const char *track ); 85 static void StopMusic( int ms ); GetMusicState(void)86 static bool GetMusicState( void ) { return music_state; } 87 static void ToggleMusicState( void ); GetMusicVolume(void)88 static int GetMusicVolume( void ) { return music_volume; } 89 static void SetMusicVolume( int vol ); 90 91 private: 92 static bool sfx_state; 93 static int sfx_volume; 94 static bool music_state; 95 static int music_volume; 96 97 #ifndef DISABLE_SOUND 98 static int InitBase( void ); 99 static void ShutdownBase( void ); 100 101 static bool init_base; 102 static bool init_sfx; 103 static bool init_music; 104 static SoundEffect *sfx[NUM_SFX]; 105 static const char *sfx_files[NUM_SFX]; 106 static Mix_Music *music; 107 static string music_name; 108 #endif 109 }; 110 111 #endif /* _INCLUDE_SOUND_H */ 112 113