1 #pragma once 2 3 /** Handles sound samples and music. 4 */ 5 6 #include <string> 7 using std::string; 8 9 #include "resources.h" 10 11 #if defined(__ANDROID__) 12 #include <sdl_mixer.h> 13 #elif defined(__DragonFly__) 14 #include <SDL2/SDL_mixer.h> 15 #else 16 #include <SDL_mixer.h> 17 #endif 18 19 bool initSound(); 20 void updateSound(); 21 void freeSound(); 22 23 namespace Gigalomania { 24 class Sample : public TrackedObject { 25 bool is_music; 26 Mix_Music *music; 27 Mix_Chunk *chunk; 28 int channel; 29 30 string text; 31 Sample(bool is_music,Mix_Music * music,Mix_Chunk * chunk)32 Sample(bool is_music, Mix_Music *music, Mix_Chunk *chunk) : is_music(is_music), music(music), chunk(chunk) { 33 channel = -1; 34 } 35 public: Sample()36 Sample() : is_music(false), music(NULL), chunk(NULL) { 37 // create dummy Sample 38 } 39 virtual ~Sample(); getClass()40 virtual const char *getClass() const { return "CLASS_SAMPLE"; } 41 void play(int ch, int loops); 42 //bool isPlaying() const; 43 void fadeOut(int duration_ms); 44 void setVolume(float volume); setText(const char * text)45 void setText(const char *text) { 46 this->text = text; 47 } 48 49 static void pauseMusic(); 50 static void unpauseMusic(); 51 static void pauseChannel(int ch); 52 static void unpauseChannel(int ch); 53 54 static Sample *loadSample(const char *filename, bool iff = false); 55 static Sample *loadSample(string filename, bool iff = false); 56 static Sample *loadMusic(const char *filename); 57 }; 58 } 59 60 using namespace Gigalomania; 61 62 const int SOUND_CHANNEL_SAMPLES = 0; 63 const int SOUND_CHANNEL_MUSIC = 1; 64 const int SOUND_CHANNEL_FX = 2; 65 const int SOUND_CHANNEL_BIPLANE = 3; 66 const int SOUND_CHANNEL_BOMBER = 4; 67 const int SOUND_CHANNEL_SPACESHIP = 5; 68 69 inline void playSample(Sample *sample, int channel = SOUND_CHANNEL_SAMPLES, int loops = 0) { 70 sample->play(channel, loops); 71 } 72 73 bool isPlaying(int ch); 74 75 bool errorSound(); 76 void resetErrorSound(); 77