Audio.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 //SDL_mixer doesn't like mixing different rates when using OGG
00029 //This should match the same as the SFX and OGG Music which is 22khz
00030 #define SAMPLERATE  22050
00031 
00032 class SFX_cached;
00033 class Flex;
00034 
00035 /*
00036  *  Music:
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 //---- Audio -----------------------------------------------------------
00050 
00051 class Audio 
00052 {
00053 private:
00054   UNREPLICATABLE_CLASS(Audio);
00055   static  Audio *self;
00056   static  int *bg2si_sfxs;  // Converts BG sfx's to SI sfx's.
00057   bool truthful_;
00058   bool speech_enabled, music_enabled, effects_enabled;
00059   bool allow_music_looping;
00060   bool SDL_open;
00061   SFX_cached *sfxs;   // ->list of cached .wav snd. effects.
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;     // Holds .wav sound effects.
00071 
00072 private:
00073   // You never allocate an Audio object directly, you rather access it using get_ptr()
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   // Given BG sfx, get SI if playing SI.
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); // Dump any audio streams
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

Generated on Mon Jul 9 14:42:40 2007 for ExultEngine by  doxygen 1.5.1