TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
TorcsSound.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2/***************************************************************************
3 file : TorcsSound.h
4 created : Tue Apr 5 19:57:35 CEST 2005
5 copyright : (C) 2005 Christos Dimitrakakis
6 email : dimitrak@idiap.ch
7 version : $Id$
8
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#ifndef TORCS_SOUND_H
21#define TORCS_SOUND_H
22
23#define VOLUME_SLOT 0
24#define PITCH_SLOT 1
25#define FILTER_SLOT 2
26
27#include <plib/sg.h>
28#include <plib/sl.h>
29#include <AL/al.h>
30#include <AL/alc.h>
31#include <AL/alut.h>
32#include "sound_defines.h"
33
34class SoundInterface;
36
54protected:
56 int flags;
57 float MAX_VOL;
58 float volume;
59 float pitch;
60 float lowpass;
61 bool loop;
62public:
65 volume(0.0f),
66 pitch(0.0f)
67 {
68 this->flags = flags;
69
70 }
71
72 virtual ~TorcsSound() {}
73 virtual void setVolume(float vol);
74 virtual void setPitch(float pitch);
75 virtual void setLPFilter(float lp);
76 virtual void setSource(sgVec3 p, sgVec3 u) {}
77 virtual float getVolume() {return volume;}
78 virtual float getPitch() {return pitch;}
79 virtual float getLPfilter() {return lowpass;}
80 virtual void setReferenceDistance (float dist) {}
81 virtual void getSource (sgVec3 p, sgVec3 u) {}
82 //virtual void setListener(sgVec3 p, sgVec3 u) = 0;
83 virtual void play() = 0;
84 virtual void start() = 0;
85 virtual void stop() = 0;
86 virtual void resume() = 0;
87 virtual void pause() = 0;
88 virtual void update() = 0;
89 virtual bool isPlaying() = 0;
90 virtual bool isPaused() = 0;
91};
92
94class PlibTorcsSound : public TorcsSound {
95protected:
96 slSample* sample;
97 slEnvelope* volume_env;
98 slEnvelope* pitch_env;
99 slEnvelope* lowpass_env;
100 slScheduler* sched;
101 bool playing;
102 bool paused;
103public:
104 PlibTorcsSound(slScheduler* sched,
105 const char* filename,
107 bool loop = false);
108 virtual ~PlibTorcsSound();
109 virtual void setVolume(float vol);
110 //virtual void setSource(sgVec3 p, sgVec3 u);
111 //virtual void setListener (sgVec3 p, sgVec3 u);
112 virtual void play();
113 virtual void start();
114 virtual void stop();
115 virtual void resume();
116 virtual void pause();
117 virtual void update();
119 virtual bool isPlaying()
120 {
121 return playing;
122 }
123
124 virtual bool isPaused()
125 {
126 return paused;
127 }
128};
129
142public:
143 sgVec3 p_lis;
144 sgVec3 u_lis;
145 sgVec3 p_src;
146 sgVec3 u_src;
147 float a;
148 float f;
149 float lp;
150 SoundSource();
151 void update();
152 void setSource(sgVec3 p, sgVec3 u);
153 void setListener (sgVec3 p, sgVec3 u);
154};
155
156
159protected:
160 ALuint buffer;
161 ALuint source;
162 ALfloat source_position[3];
163 ALfloat source_velocity[3];
164 ALfloat zeroes[3];
165 ALfloat back[6];
166 ALfloat front[6];
168 ALfloat MAX_DISTANCE;
176public:
177 OpenalTorcsSound(const char* filename,
180 bool loop = false, bool static_pool = true);
181 virtual ~OpenalTorcsSound();
182 virtual void setVolume(float vol);
183 virtual void setPitch(float pitch);
184 virtual void setLPFilter(float lp);
185 virtual void setSource(sgVec3 p, sgVec3 u);
186 virtual void getSource (sgVec3 p, sgVec3 u);
187 virtual void setReferenceDistance (float dist);
188 //virtual void setListener (sgVec3 p, sgVec3 u);
189 virtual void play();
190 virtual void start();
191 virtual void stop();
192 virtual void resume();
193 virtual void pause();
194 virtual void update();
196 virtual bool isPlaying()
197 {
198 return playing;
199 }
200
201 virtual bool isPaused()
202 {
203 return paused;
204 }
205};
206
207
208
209
210
211
212#endif
static Point p[4]
Definition Convex.cpp:54
ALfloat front[6]
direction of front
Definition TorcsSound.h:166
virtual void pause()
ALuint buffer
buffer id
Definition TorcsSound.h:160
virtual void getSource(sgVec3 p, sgVec3 u)
bool static_pool
dynamic or static source assignment?
Definition TorcsSound.h:174
virtual void setLPFilter(float lp)
OpenalSoundInterface * itf
Handle to the interface.
Definition TorcsSound.h:173
ALfloat back[6]
direction of back
Definition TorcsSound.h:165
ALfloat zeroes[3]
just a vector of 0s
Definition TorcsSound.h:164
ALfloat source_velocity[3]
source velocity
Definition TorcsSound.h:163
ALfloat REFERENCE_DISTANCE
reference distance for sound
Definition TorcsSound.h:170
ALfloat source_position[3]
source position
Definition TorcsSound.h:162
virtual void update()
virtual void setSource(sgVec3 p, sgVec3 u)
virtual void setReferenceDistance(float dist)
virtual bool isPlaying()
Return true if playing.
Definition TorcsSound.h:196
bool is_enabled
is it available at all?
Definition TorcsSound.h:175
ALfloat MAX_DISTANCE
maximum allowed distance
Definition TorcsSound.h:168
OpenalTorcsSound(const char *filename, OpenalSoundInterface *sitf, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false, bool static_pool=true)
Create a new torcs sound.
ALuint source
source id
Definition TorcsSound.h:161
virtual void play()
ALfloat ROLLOFF_FACTOR
how fast we need to roll off
Definition TorcsSound.h:171
virtual void setPitch(float pitch)
virtual ~OpenalTorcsSound()
virtual void stop()
virtual void resume()
virtual bool isPaused()
Return true if paused.
Definition TorcsSound.h:201
int poolindex
which pool the sound is assigned to
Definition TorcsSound.h:172
virtual void start()
ALfloat MAX_DISTANCE_LOW
maximum allowed distance
Definition TorcsSound.h:169
virtual void setVolume(float vol)
bool paused
sound is paused
Definition TorcsSound.h:102
virtual void update()
Update the plib sounds.
virtual void play()
Start the sample.
slEnvelope * pitch_env
pitch envelope
Definition TorcsSound.h:98
virtual void resume()
Resume a paused sample.
PlibTorcsSound(slScheduler *sched, const char *filename, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false)
Create a new PLib sound.
slEnvelope * volume_env
volume envelope
Definition TorcsSound.h:97
virtual void stop()
Stop the sample.
slSample * sample
sample data
Definition TorcsSound.h:96
slEnvelope * lowpass_env
low pass filter envelope
Definition TorcsSound.h:99
bool playing
Sound is playing.
Definition TorcsSound.h:101
virtual void pause()
Pause a sample.
virtual ~PlibTorcsSound()
Destructor.
virtual bool isPlaying()
True if the sound is playing.
Definition TorcsSound.h:119
slScheduler * sched
plib sl scheduler (see sl.h)
Definition TorcsSound.h:100
virtual void setVolume(float vol)
Set the volume.
virtual void start()
Start the sample.
virtual bool isPaused()
Truye if the sound is paused.
Definition TorcsSound.h:124
Sound interface.
float a
Environmental attenuation.
Definition TorcsSound.h:147
float lp
Environmental filtering.
Definition TorcsSound.h:149
sgVec3 p_lis
listener position for this source
Definition TorcsSound.h:143
sgVec3 u_src
source velocity;
Definition TorcsSound.h:146
float f
Environmental frequency shift.
Definition TorcsSound.h:148
SoundSource()
Create a sound source.
sgVec3 p_src
source position
Definition TorcsSound.h:145
void update()
Calculate environmental parameters for current situation.
void setSource(sgVec3 p, sgVec3 u)
Set source position and velocity.
void setListener(sgVec3 p, sgVec3 u)
Set listener position and velocity.
sgVec3 u_lis
listener velocity for this source
Definition TorcsSound.h:144
virtual void setSource(sgVec3 p, sgVec3 u)
Definition TorcsSound.h:76
virtual float getLPfilter()
Definition TorcsSound.h:79
virtual void setReferenceDistance(float dist)
Definition TorcsSound.h:80
virtual void start()=0
virtual void update()=0
virtual bool isPlaying()=0
float MAX_VOL
Maximum volume.
Definition TorcsSound.h:57
float volume
Current volume.
Definition TorcsSound.h:58
virtual bool isPaused()=0
virtual void pause()=0
virtual float getPitch()
Definition TorcsSound.h:78
TorcsSound(int flags=(ACTIVE_VOLUME|ACTIVE_PITCH))
Consruct a sound.
Definition TorcsSound.h:64
virtual float getVolume()
Definition TorcsSound.h:77
class SoundInterface * iface
Handler to the interface.
Definition TorcsSound.h:55
virtual void getSource(sgVec3 p, sgVec3 u)
Definition TorcsSound.h:81
virtual void setPitch(float pitch)
Set the pitch.
virtual ~TorcsSound()
Destructor.
Definition TorcsSound.h:72
virtual void resume()=0
bool loop
Whether it's a looping sound.
Definition TorcsSound.h:61
int flags
Flags relating to what effects are to be used.
Definition TorcsSound.h:56
virtual void setLPFilter(float lp)
Set the filter.
virtual void stop()=0
float pitch
Current pitch.
Definition TorcsSound.h:59
virtual void setVolume(float vol)
Set the volume.
float lowpass
Current low pass filter.
Definition TorcsSound.h:60
virtual void play()=0
#define ACTIVE_PITCH
#define ACTIVE_VOLUME