00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SOUND_H
00026
00027 #include <stdio.h>
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
00049
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
00061 #include "alut.h"
00062 #else
00063 #include <AL/al.h>
00064 #include <AL/alc.h>
00065
00066 #include <AL/alut.h>
00067 #endif
00068
00069 #define MAX_SOURCES 10
00070
00071 #define DISTANCE_FACTOR 0.025
00072
00073 #define VELOCITY_FACTOR 1.5
00074
00075 class SOUNDMANAGER
00076 {
00077 private:
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
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
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 };
00185
00186 #define _SOUND_H
00187 #endif