include/sound.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            sound.h
00003  *
00004  *  Fri May 13 19:01:29 2005
00005  *  Copyright  2005  Joe Venzon
00006  *  joe@venzon.net
00007  ****************************************************************************/
00008 
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024  
00025 #ifndef _SOUND_H
00026 
00027 #include <stdio.h>                      // Header File For Standard Input/Output
00028 #include <GL/gl.h>
00029 #include <GL/glu.h>
00030 #include <SDL/SDL.h>
00031 #ifdef __APPLE__
00032 #include <SDL_image/SDL_image.h>
00033 #else
00034 #include <SDL/SDL_image.h>
00035 #endif
00036 #include <string>
00037 #include <iostream>
00038 #include <fstream>
00039 #include <cmath>
00040 #include <cassert>
00041 #include <stdlib.h>
00042 
00043 #include <map>
00044 
00045 #include "camera.h"
00046 #include "utility.h"
00047 
00048 //#include "backdrop.h"
00049 //#include "weather.h"
00050 
00051 #include "globals.h"
00052 
00053 using namespace std;
00054 
00055 #define MAX_BUFFERS 50
00056 
00057 #ifdef __APPLE__
00058        #include <OpenAL/al.h>
00059        #include <OpenAL/alc.h>
00060        //#include <OpenAL/alut.h> // Mac OS X 10.4.7 broke alut
00061            #include "alut.h"
00062 #else
00063        #include <AL/al.h>
00064        #include <AL/alc.h>
00065        //#include <AL/alu.h>
00066        #include <AL/alut.h>
00067 #endif
00068 
00069 #define MAX_SOURCES 10
00070 
00071 #define DISTANCE_FACTOR 0.025
00072 //#define VELOCITY_FACTOR 1.0/DISTANCE_FACTOR
00073 #define VELOCITY_FACTOR 1.5
00074 
00075 class SOUNDMANAGER
00076 {
00077 private:
00078         // Buffers to hold sound data.
00079         /*ALuint * buffers;
00080         int buf_cur;
00081         string * buf_fn;
00082         
00083         // Sources are points of emitting sound.
00084         ALuint sources[MAX_SOURCES];
00085         bool source_free[MAX_SOURCES];
00086 
00087         bool muted;
00088 
00089         bool disable;
00090 
00091         float master_volume;*/
00092 
00093         ALCdevice* mSoundDevice;
00094         ALCcontext* mSoundContext;
00095 
00096         bool init;
00097         bool disabled;
00098         bool loaded;
00099         
00100         map <string, ALuint> buffers;
00101         vector <ALuint> sources;
00102         vector <bool> source_free;
00103         
00104         float master_volume;
00105         
00106         void Load();
00107         
00108         void LoadSoundFile(string filename);
00109         
00110         void UnloadWave(ALvoid* data);
00111         bool LoadWave(string fname, ALenum *format, ALvoid **data, ALsizei *size, ALsizei *freq, ALboolean *loop);
00112         bool IDMatchesString(const char * id, const char * str);
00113         
00114 public:
00115         SOUNDMANAGER() {init=false;disabled=false;loaded=false;master_volume=1.0;}
00116         ~SOUNDMANAGER() {Deinit();}
00117         
00118         void Init();
00119         void Deinit();
00120         void Reload();
00121         void Unload();
00122         void DisableAllSound() {disabled=true;}
00123         void SetMasterVolume(float newvol) {master_volume = newvol; if (master_volume < 0) master_volume = 0; if (master_volume > 1) master_volume = 1;}
00124         float GetMasterVolume() {return master_volume;}
00125         void UpdateSettings() { float sound_vol; settings.Get( "sound.volume", sound_vol ); SetMasterVolume( sound_vol ); }
00126         void MuteAll();
00127         void UnMuteAll();
00128         
00129         void SetListenerPos(VERTEX pos);
00130         void SetListenerVel(VERTEX vel);
00131         void SetListenerOrientation(VERTEX at, VERTEX up);
00132         void SetPosVel(int sid, VERTEX coord, VERTEX tvel);
00133         void SetListener(VERTEX campos, VERTEX camvel, VERTEX at, VERTEX up);
00134         void SetPitch(int sid, float pitch);
00135         void SetGain(int sid, float gain);
00136         void SetPos(int sid, VERTEX pos);
00137         void SetVel(int sid, VERTEX vel);
00138         
00139         ALuint NewSource(string buffername);
00140         ALuint NewSource(string buffername, bool & error);
00141         void StopSource(int sid);
00142         void PlaySource(int idx);
00143         void Update() {}
00144         
00145         // Gentoo
00146         /*ALCdevice* mSoundDevice;
00147         ALCcontext* mSoundContext;
00148         
00149         void Load();
00150         void LoadAllSoundFiles();
00151         void LoadSoundFile(string filename);
00152         ~SOUNDMANAGER();
00153         SOUNDMANAGER();
00154 
00155         void SetListenerPos(VERTEX pos);
00156         void SetListenerVel(VERTEX vel);
00157         void SetListenerOrientation(VERTEX at, VERTEX up);
00158 
00159         void SetMasterVolume(float newvol) {master_volume = newvol; if (master_volume < 0) master_volume = 0; if (master_volume > 1) master_volume = 1;}
00160         float GetMasterVolume() {return master_volume;}
00161 
00162         void UpdateSettings() { float sound_vol; settings.Get( "sound.volume", sound_vol ); SetMasterVolume( sound_vol ); }
00163 
00164         ALuint NewSource(string buffername);
00165 
00166         void PlaySource(int idx);
00167         void SetPitch(int sid, float pitch);
00168         void SetGain(int sid, float gain);
00169         void SetPos(int sid, VERTEX pos);
00170         void SetVel(int sid, VERTEX vel);
00171 
00172         void MuteAll();
00173         void UnMuteAll();
00174         //ALuint GetSource(string buffername);
00175         
00176         void Update() {}
00177         void StopSource(int sid);
00178 
00179         void DisableAllSound();
00180         void EnableAllSound();
00181                 
00182         void SetPosVel(int sid, VERTEX coord, VERTEX tvel);
00183         void SetListener(VERTEX campos, VERTEX camvel, VERTEX at, VERTEX up);*/
00184 };
00185 
00186 #define _SOUND_H
00187 #endif

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6