19#ifndef SOUND_INTERFACE_H
20#define SOUND_INTERFACE_H
28#define logmsg printf ("# "); printf
30#define logmsg empty_log
48#define VOLUME_CUTOFF 0.001f
140 bool loop =
false,
bool static_pool =
true) = 0;
147 for (
int i=0; i<4; i++) {
225 int n_cars, sgVec3 p_obs, sgVec3 u_obs,
226 sgVec3 c_obs = NULL, sgVec3 a_obs = NULL)
235 fprintf (stderr,
"Warning, gain setting not supported\n");
306 bool loop =
false,
bool static_pool =
true);
340 pool[i].currentOwner = NULL;
341 pool[i].in_use =
false;
342 alGenSources(1, &(
pool[i].source));
343 int error = alGetError();
344 if (error != AL_NO_ERROR) {
345 printf(
"OpenAL error, allocating dynamic source index %d\n", i);
350 printf(
" Dynamic Sources: requested: %d, created: %d\n",
nbsources, this->nbsources);
356 alDeleteSources(1, &(
pool[i].source));
364 if (sound ==
pool[*index].currentOwner) {
366 *source =
pool[*index].source;
368 pool[*index].in_use =
true;
376 int i, firstfree = -1;
378 if (
pool[i].in_use ==
false && firstfree < 0) {
389 pool[firstfree].currentOwner = sound;
390 pool[firstfree].in_use =
true;
391 *source =
pool[firstfree].source;
399 if (sound ==
pool[*index].currentOwner) {
400 pool[*index].in_use =
false;
409 sound ==
pool[*index].currentOwner &&
410 true ==
pool[*index].in_use)
struct QSoundChar_ QSoundChar
struct QueueSoundMap_ QueueSoundMap
A queue containing mappings between sounds and sound sources.
int sortSndPriority(const void *a, const void *b)
SoundPriState
Current state of sound.
struct SoundPri_ SoundPri
Sound priority, used to sort cars according to amplitude attenuation.
static void empty_log(const char *s,...)
Manages the source sound of each individual car.
virtual void muteForMenu()
virtual void setGlobalGain(float g)
virtual TorcsSound * addSample(const char *filename, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false, bool static_pool=true)
int OSI_MAX_STATIC_SOURCES
int n_static_sources_in_use
virtual void setNCars(int n_cars)
void DopplerShift(SoundChar *sound, float *p_src, float *u_src, float *p, float *u)
struct OpenalSoundInterface::SoundChar_ SoundChar
static const int OSI_MIN_DYNAMIC_SOURCES
Define this to use the OpenAL Doppler.
virtual float getGlobalGain()
OpenalSoundInterface(float sampling_rate, int n_channels)
virtual SharedSourcePool * getSourcePool(void)
virtual ~OpenalSoundInterface()
virtual void SetMaxSoundCar(CarSoundData **car_sound_data, QueueSoundMap *smap)
virtual bool getStaticSource(ALuint *source)
SharedSourcePool * sourcepool
virtual void initSharedSourcePool()
virtual void update(CarSoundData **car_sound_data, int n_cars, sgVec3 p_obs, sgVec3 u_obs, sgVec3 c_obs, sgVec3 a_obs)
virtual TorcsSound * addSample(const char *filename, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false, bool static_pool=true)
virtual void setGlobalGain(float g)
virtual ~PlibSoundInterface()
virtual slScheduler * getScheduler()
void SetMaxSoundCar(CarSoundData **car_sound_data, QueueSoundMap *smap)
PlibSoundInterface(float sampling_rate, int n_channels)
void DopplerShift(SoundChar *sound, float *p_src, float *u_src, float *p, float *u)
virtual void setNCars(int n_cars)
std::vector< TorcsSound * > sound_list
virtual void update(CarSoundData **car_sound_data, int n_cars, sgVec3 p_obs, sgVec3 u_obs, sgVec3 c_obs=NULL, sgVec3 a_obs=NULL)
struct PlibSoundInterface::SoundChar_ SoundChar
virtual float getGlobalGain()
bool releaseSource(TorcsSound *sound, int *index)
SharedSourcePool(int nbsources)
bool getSource(TorcsSound *sound, ALuint *source, bool *needs_init, int *index)
bool isSourceActive(TorcsSound *sound, int *index)
virtual ~SharedSourcePool()
SoundInterface(float sampling_rate, int n_channels)
Make a new sound interface.
TorcsSound * turbo_sound
turbo spinning sound
virtual void setNCars(int n_cars)=0
Set the number of cars - must be defined in children classes.
void setGrassRideSound(const char *sound_name)
void setBangSound(const char *sound_name)
void setBottomCrashSound(const char *sound_name)
QueueSoundMap backfire_loop
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 setCrashSound(const char *sound_name, int index)
TorcsSound * metal_skid_sound
metal skidding on metal
TorcsSound * backfire_loop_sound
exhaust backfire sound
void setCurbRideSound(const char *sound_name)
void setSkidSound(const char *sound_name)
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...
void setGearChangeSound(const char *sound_name)
TorcsSound * grass_ride_sound
rolling on dirt/grass
virtual void muteForMenu()
TorcsSound * backfire_sound
one-off backfire sound
QueueSoundMap road
The following are mappings for sound prioritisation.
virtual void setGlobalGain(float g)
void setTurboSound(const char *sound_name)
TorcsSound * curb_ride_sound
rolling on curb
virtual void update(CarSoundData **car_sound_data, int n_cars, sgVec3 p_obs, sgVec3 u_obs, sgVec3 c_obs=NULL, sgVec3 a_obs=NULL)
Update sound for a given observer.
float sampling_rate
sampling rate
virtual void initSharedSourcePool()
initialised the pool of shared sources
TorcsSound * crash_sound[NB_CRASH_SOUND]
list of crash sounds
TorcsSound * road_ride_sound
rolling on normal road
int n_channels
number of channels
void setGrassSkidSound(const char *sound_name)
void setAxleSound(const char *sound_name)
std::vector< TorcsSound * > sound_list
keeps track of sounds used
virtual TorcsSound * addSample(const char *filename, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false, bool static_pool=true)=0
Add a new sample - must be defined in children classes.
void setBackfireSound(const char *sound_name)
TorcsSound * gear_change_sound
sound when changing gears
void setMetalSkidSound(const char *sound_name)
virtual float getGlobalGain()
TorcsSound * bottom_crash_sound
bang when crashing from a great height
int n_engine_sounds
number of simultaneous engines
void setBackfireLoopSound(const char *sound_name)
virtual ~SoundInterface()
Destructor - does nothing.
void setRoadRideSound(const char *sound_name)
int curCrashSnd
holds current crash sound used - the sound cycles
SoundPri * engpri
the engine priority, used for sorting
TorcsSound * bang_sound
sounds when suspension fully compressed
static CarSoundData ** car_sound_data
A queue containing mappings between sounds and sound sources.
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.
Sound priority, used to sort cars according to amplitude attenuation.
TorcsSound * currentOwner