25 #undef USE_OPENAL_DOPPLER 35 ALfloat far_away[] = { 0.0
f, 0.0f, 1000.0f };
36 ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f };
37 ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
38 dev = alcOpenDevice( NULL );
40 throw (
"Could not open device");
45 cc = alcCreateContext(
dev, NULL);
47 alcCloseDevice(
dev );
48 throw (
"Could not create context.");
51 alcMakeContextCurrent(
cc );
58 const int MAX_SOURCES = 1024;
60 ALuint sourcelist[MAX_SOURCES];
61 for (sources = 0; sources < MAX_SOURCES; sources++) {
62 alGenSources(1, &sourcelist[sources]);
63 if (alGetError() != AL_NO_ERROR) {
69 for (clear = 0; clear < sources; clear++) {
70 if (alIsSource(sourcelist[clear])) {
71 alDeleteSources(1, &sourcelist[clear]);
72 if (alGetError() != AL_NO_ERROR) {
73 printf(
"Error in probing OpenAL sources.\n");
76 printf(
"Error in probing OpenAL sources.\n");
85 ALuint bufferlist[MAX_SOURCES];
86 for (buffers = 0; buffers < MAX_SOURCES; buffers++) {
87 alGenBuffers(1, &bufferlist[buffers]);
88 if (alGetError() != AL_NO_ERROR) {
93 for (clear = 0; clear < buffers; clear++) {
94 if (alIsBuffer(bufferlist[clear])) {
95 alDeleteBuffers(1, &bufferlist[clear]);
96 if (alGetError() != AL_NO_ERROR) {
97 printf(
"Error in probing OpenAL buffers.\n");
100 printf(
"Error in probing OpenAL buffers.\n");
106 printf(
"OpenAL backend info:\n Vendor: %s\n Renderer: %s\n Version: %s\n", alGetString(AL_VENDOR), alGetString(AL_RENDERER), alGetString(AL_VERSION));
107 printf(
" Available sources: %d%s\n",
OSI_MAX_SOURCES, (sources >= MAX_SOURCES) ?
" or more" :
"");
108 printf(
" Available buffers: %d%s\n",
OSI_MAX_BUFFERS, (buffers >= MAX_SOURCES) ?
" or more" :
"");
110 alDistanceModel ( AL_INVERSE_DISTANCE );
111 int error = alGetError();
112 if (error != AL_NO_ERROR) {
113 printf(
"OpenAL Error: %d alDistanceModel\n", error);
116 alDopplerFactor (1.0f);
119 error = alGetError();
120 if (error != AL_NO_ERROR) {
121 printf(
"OpenAL Error: %d alDopplerX\n", error);
125 alListenerfv(AL_POSITION, far_away );
126 alListenerfv(AL_VELOCITY, zeroes );
127 alListenerfv(AL_ORIENTATION, front );
128 error = alGetError();
129 if (error != AL_NO_ERROR) {
130 printf(
"OpenAL Error: %d alListenerfv\n", error);
152 for (
unsigned int i=0; i<
sound_list.size(); i++) {
156 alcDestroyContext (
cc);
157 alcCloseDevice (
dev);
181 ALfloat listener_pos[3];
183 ALfloat listener_orientation[6];
184 ALfloat zeros[] = {0.0f, 0.0f, 0.0f};
187 for (i = 0; i<3; i++) {
188 listener_pos[i] = p_obs[i];
190 listener_orientation[i] = c_obs[i];
191 listener_orientation[i+3] = a_obs[i];
194 alListenerfv(AL_POSITION, listener_pos );
195 #ifdef USE_OPENAL_DOPPLER 196 alListenerfv(AL_VELOCITY, listener_speed );
198 alListenerfv(AL_VELOCITY, zeros);
200 alListenerfv(AL_ORIENTATION, listener_orientation );
203 for (i = 0; i<n_cars; i++) {
224 for (i = n_cars - 1; i >= 0; i--) {
233 #ifdef USE_OPENAL_DOPPLER 249 float max_skid_vol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
250 int max_skid_id[4] = {0,0,0,0};
252 for (
id = 0;
id<n_cars;
id++) {
254 for (
int j=0; j<4; j++) {
256 if (skvol > max_skid_vol[j]) {
257 max_skid_vol[j] = skvol;
263 for (i = 0; i<4; i++) {
264 int id = max_skid_id[i];
268 #ifdef USE_OPENAL_DOPPLER 322 for (
id = 0;
id<n_cars;
id++) {
325 sgVec3 u = {0, 0, 0};
326 if (sound_data->
crash) {
339 if (sound_data->
bang) {
375 alListenerf(AL_GAIN, 0.0f);
392 alGenSources (1, source);
393 int error = alGetError();
394 if (error != AL_NO_ERROR) {
414 sgVec3 u = {0.0f, 0.0f, 0.0f};
417 #ifdef USE_OPENAL_DOPPLER 422 #ifdef USE_OPENAL_DOPPLER
int n_static_sources_in_use
void update()
Calculate environmental parameters for current situation.
QSoundChar engine_backfire
static CarSoundData ** car_sound_data
TorcsSound * bang_sound
sounds when suspension fully compressed
SharedSourcePool * sourcepool
int curCrashSnd
holds current crash sound used - the sound cycles
TorcsSound * getEngineSound()
virtual void setPitch(float pitch)
Set the pitch.
A queue containing mappings between sounds and sound sources.
virtual void muteForMenu()
TorcsSound * bottom_crash_sound
bang when crashing from a great height
QSoundChar CarSoundData::* schar
The calculated sound characteristic.
TorcsSound * curb_ride_sound
rolling on curb
void setSource(sgVec3 p, sgVec3 u)
Set source position and velocity.
Manages the source sound of each individual car.
TorcsSound * backfire_loop_sound
exhaust backfire sound
TorcsSound * grass_skid_sound
skidding on dirt/grass
TorcsSound * turbo_sound
turbo spinning sound
virtual bool getStaticSource(ALuint *source)
virtual TorcsSound * addSample(const char *filename, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false, bool static_pool=true)
TorcsSound * road_ride_sound
rolling on normal road
virtual void update(CarSoundData **car_sound_data, int n_cars, sgVec3 p_obs, sgVec3 u_obs, sgVec3 c_obs, sgVec3 a_obs)
virtual void setSource(sgVec3 p, sgVec3 u)
void setListener(sgVec3 p, sgVec3 u)
Set listener position and velocity.
QueueSoundMap backfire_loop
float f
Environmental frequency shift.
static const int OSI_MIN_DYNAMIC_SOURCES
Define this to use the OpenAL Doppler.
float attenuation
global distance attenuation
TorcsSound * snd
The raw sound.
float a
Environmental attenuation.
virtual void setVolume(float vol)
Set the volume.
SoundPri * engpri
the engine priority, used for sorting
virtual void setReferenceDistance(float dist)
QSoundChar drag_collision
virtual void SetMaxSoundCar(CarSoundData **car_sound_data, QueueSoundMap *smap)
OpenalSoundInterface(float sampling_rate, int n_channels)
virtual float getGlobalGain()
void SortSingleQueue(CarSoundData **car_sound_data, QueueSoundMap *smap, int n_cars)
Find the max amplitude sound in car_sound_data and put it in smap.
void getCarPosition(sgVec3 p)
QueueSoundMap road
The following are mappings for sound prioritisation.
std::vector< TorcsSound * > sound_list
keeps track of sounds used
TorcsSound * gear_change_sound
sound when changing gears
virtual ~OpenalSoundInterface()
virtual void initSharedSourcePool()
int n_engine_sounds
number of simultaneous engines
void getCarSpeed(sgVec3 u)
void copyEngPri(SoundPri &epri)
TorcsSound * crash_sound[NB_CRASH_SOUND]
list of crash sounds
int OSI_MAX_STATIC_SOURCES
TorcsSound * metal_skid_sound
metal skidding on metal
TorcsSound * grass_ride_sound
rolling on dirt/grass
virtual void setNCars(int n_cars)
int sortSndPriority(const void *a, const void *b)
TorcsSound * axle_sound
axle/gear spinning sound
TorcsSound * skid_sound[4]
set of skid sounds, one per tyre
int id
The id of the car producing the sound, used for retrieving doppler effects etc.
Sound priority, used to sort cars according to amplitude attenuation.