TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
SoundInterface.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : PlibSoundInterface.cpp
4 created : Thu Apr 7 04:21 CEST 2005
5 copyright : (C) 2005-2024 Christos Dimitrakakis, Bernhard Wymann
6 email : berniw@bluewin.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "SoundInterface.h"
20#include "CarSoundData.h"
21
23{
24 this->sampling_rate = sampling_rate;
25 this->n_channels = n_channels;
26 int i;
27 for (i = 0; i<4; i++) {
28 skid_sound[i]=NULL;
29 }
30 road_ride_sound=NULL;
33 curb_ride_sound =NULL;
35 axle_sound=NULL;
36 turbo_sound=NULL;
38 for (i = 0; i<NB_CRASH_SOUND; i++) {
39 crash_sound[i]=NULL;
40 }
41 curCrashSnd = 0;
42 bang_sound=NULL;
45
47
48 int MAX_N_ENGINE_SOUNDS = 8;
49 if (n_engine_sounds<1) {
51 fprintf (stderr, "Warning: maybe insufficient channels\n");
52 } else if (n_engine_sounds > MAX_N_ENGINE_SOUNDS) {
53 n_engine_sounds = MAX_N_ENGINE_SOUNDS;
54 }
55}
56
58{
59 float max_vol = 0.0f;
60 int max_id = 0;
61 for (int id=0; id<n_cars; id++) {
62 CarSoundData* sound_data = car_sound_data[id];
63 QSoundChar CarSoundData::*p2schar = smap->schar;
64 QSoundChar* schar = &(sound_data->*p2schar);
65 float vol = sound_data->attenuation * schar->a;
66 if (vol > max_vol) {
67 max_vol = vol;
68 max_id = id;
69 }
70 }
71 smap->id = max_id;
72 smap->max_vol = max_vol;
73}
74
76{
77 int id = smap->id;
78 float max_vol = smap->max_vol;
79 QSoundChar CarSoundData::*p2schar = smap->schar;
80 QSoundChar* schar = &(car_sound_data[id]->*p2schar);
81 TorcsSound* snd = smap->snd;
82
83 sgVec3 p;
84 sgVec3 u;
85
86 car_sound_data[id]->getCarPosition(p);
87 car_sound_data[id]->getCarSpeed(u);
88 snd->setSource (p, u);
89 snd->setVolume (schar->a);
90 snd->setPitch (schar->f);
91 snd->update();
92 if (max_vol > VOLUME_CUTOFF) {
93 snd->start();
94 } else {
95 snd->stop();
96 }
97}
static Point p[4]
Definition Convex.cpp:54
struct QSoundChar_ QSoundChar
struct QueueSoundMap_ QueueSoundMap
A queue containing mappings between sounds and sound sources.
#define VOLUME_CUTOFF
Manages the source sound of each individual car.
float attenuation
global distance attenuation
SoundInterface(float sampling_rate, int n_channels)
Make a new sound interface.
TorcsSound * turbo_sound
turbo spinning sound
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.
TorcsSound * metal_skid_sound
metal skidding on metal
TorcsSound * backfire_loop_sound
exhaust backfire sound
TorcsSound * grass_skid_sound
skidding on dirt/grass
TorcsSound * axle_sound
axle/gear spinning sound
TorcsSound * skid_sound[4]
set of skid sounds, one per tyre
void SetMaxSoundCar(CarSoundData **car_sound_data, QueueSoundMap *smap)
Using the smap->id, get the appropriate entry in car_sound_data and call apprioriate methods for smap...
TorcsSound * grass_ride_sound
rolling on dirt/grass
TorcsSound * curb_ride_sound
rolling on curb
float sampling_rate
sampling rate
TorcsSound * crash_sound[NB_CRASH_SOUND]
list of crash sounds
TorcsSound * road_ride_sound
rolling on normal road
int n_channels
number of channels
TorcsSound * gear_change_sound
sound when changing gears
TorcsSound * bottom_crash_sound
bang when crashing from a great height
int n_engine_sounds
number of simultaneous engines
int curCrashSnd
holds current crash sound used - the sound cycles
TorcsSound * bang_sound
sounds when suspension fully compressed
A generic TORCS sound.
Definition TorcsSound.h:53
virtual void setSource(sgVec3 p, sgVec3 u)
Definition TorcsSound.h:76
virtual void start()=0
virtual void update()=0
virtual void setPitch(float pitch)
Set the pitch.
virtual void stop()=0
virtual void setVolume(float vol)
Set the volume.
static CarSoundData ** car_sound_data
Definition grsound.cpp:38
#define NB_CRASH_SOUND
float max_vol
Max.
int id
The id of the car producing the sound, used for retrieving doppler effects etc.
QSoundChar CarSoundData::* schar
The calculated sound characteristic.
TorcsSound * snd
The raw sound.