00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef AUDIO_H
00020 #define AUDIO_H
00021
00022 #include <vector>
00023 #include <SDL.h>
00024 #include <SDL_audio.h>
00025 #include "Midi.h"
00026 #include "exceptions.h"
00027
00028
00029
00030 #define SAMPLERATE 22050
00031
00032 class SFX_cached;
00033 class Flex;
00034
00035
00036
00037
00038 enum Combat_song
00039 {
00040 CSBattle_Over,
00041 CSAttacked1,
00042 CSAttacked2,
00043 CSVictory,
00044 CSRun_Away,
00045 CSDanger,
00046 CSHidden_Danger
00047 };
00048
00049
00050
00051 class Audio
00052 {
00053 private:
00054 UNREPLICATABLE_CLASS(Audio);
00055 static Audio *self;
00056 static int *bg2si_sfxs;
00057 bool truthful_;
00058 bool speech_enabled, music_enabled, effects_enabled;
00059 bool allow_music_looping;
00060 bool SDL_open;
00061 SFX_cached *sfxs;
00062 MyMidiPlayer *midi;
00063 bool initialized;
00064 SDL_AudioSpec wanted;
00065 Mix_Chunk *wave;
00066
00067 public:
00068 bool audio_enabled;
00069 SDL_AudioSpec actual;
00070 Flex *sfx_file;
00071
00072 private:
00073
00074 Audio();
00075 ~Audio();
00076 void Init(int _samplerate,int _channels);
00077
00078 uint8 * convert_VOC(uint8 *,uint32 &);
00079 void build_speech_vector(void);
00080
00081 public:
00082 friend class Tired_of_compiler_warnings;
00083 static void Init(void);
00084 static void Destroy(void);
00085 static Audio* get_ptr(void);
00086
00087
00088 static int game_sfx(int sfx)
00089 { return bg2si_sfxs ? bg2si_sfxs[sfx] : sfx; }
00090
00091 void Init_sfx(void);
00092
00093 void honest_sample_rates(void) { truthful_=true; }
00094 void cancel_streams(void);
00095
00096 void pause_audio(void);
00097 void resume_audio(void);
00098
00099 void play(uint8 *sound_data,uint32 len,bool);
00100 void playfile(const char *,bool);
00101 bool playing(void);
00102 void start_music(int num,bool continuous,int bank=0);
00103 void start_music(const char *fname,int num,bool continuous);
00104 void start_music(XMIDIEventList *midfile,bool continuous);
00105 void start_music_combat(Combat_song song,bool continuous,int bank=0);
00106 void stop_music();
00107 int play_sound_effect (int num, int volume = SDL_MIX_MAXVOLUME,
00108 int dir = 0, int repeat = 0);
00109 int play_wave_sfx(int num, int volume = SDL_MIX_MAXVOLUME,
00110 int dir = 0, int repeat = 0);
00111 void stop_sound_effects();
00112 bool start_speech(int num,bool wait=false);
00113 bool is_speech_enabled() const { return speech_enabled; }
00114 void set_speech_enabled(bool ena) { speech_enabled = ena; }
00115 bool is_music_enabled() const { return music_enabled; }
00116 void set_music_enabled(bool ena) { music_enabled = ena; }
00117 bool are_effects_enabled() const { return effects_enabled; }
00118 void set_effects_enabled(bool ena) { effects_enabled = ena; }
00119 bool is_audio_enabled() const { return audio_enabled; }
00120 void set_audio_enabled(bool ena);
00121 bool is_music_looping_allowed() const { return allow_music_looping; }
00122 void set_allow_music_looping(bool ena) { allow_music_looping = ena; }
00123 bool can_sfx(const std::string &game) const;
00124 static void channel_complete_callback(int chan);
00125
00126 bool is_track_playing(int num) {
00127 return midi && midi->is_track_playing(num);
00128 }
00129
00130 int get_sample_rate() { return actual.freq; }
00131 bool is_stereo() { return actual.channels == 2; }
00132
00133 MyMidiPlayer *get_midi() {return midi;}
00134
00135 Flex *get_sfx_file()
00136 { return sfx_file; }
00137 };
00138
00139 #endif