52 volume_env =
new slEnvelope(1, SL_SAMPLE_ONE_SHOT);
55 pitch_env =
new slEnvelope(1, SL_SAMPLE_ONE_SHOT);
58 lowpass_env =
new slEnvelope(1, SL_SAMPLE_ONE_SHOT);
125 sample->adjustVolume (vol);
207 float u_rel_src = 0.0f;
208 float u_rel_lis = 0.0f;
211 for (i=0; i<3; i++) {
223 p_rel = 0.01f + sqrt(p_rel);
224 float p_cosx =
p[0]/p_rel;
225 float p_cosy =
p[1]/p_rel;
226 float p_cosz =
p[2]/p_rel;
227 float p_x_comp = u[0]*p_cosx;
228 float p_y_comp = u[1]*p_cosy;
229 float p_z_comp = u[2]*p_cosz;
230 float p_x_src =
u_src[0]*p_cosx;
231 float p_y_src =
u_src[1]*p_cosy;
232 float p_z_src =
u_src[2]*p_cosz;
233 float p_x_lis =
u_lis[0]*p_cosx;
234 float p_y_lis =
u_lis[1]*p_cosy;
235 float p_z_lis =
u_lis[2]*p_cosz;
236 u_rel = (p_y_comp + p_x_comp + p_z_comp);
237 u_rel_src = (p_y_src + p_x_src + p_z_src);
238 u_rel_lis = (p_y_lis + p_x_lis + p_z_lis);
248 float rolloff = 0.5f;
249 float atten = ref / ( ref + rolloff * (p_rel - ref));
253 float atten_filter =
MIN (atten, 1.0f);
254 lp = exp(atten_filter - 1.0f);
264 for (
int i=0; i<3; i++) {
274 for (
int i=0; i<3; i++) {
306 for (i = 0; i<3; i++) {
314 int error = alGetError();
315 if (error != AL_NO_ERROR) {
316 printf(
"Uncatched OpenAL Error on entry: %d with file %s\n", error, filename);
319 alGenBuffers (1, &
buffer);
320 error = alGetError();
321 if (error != AL_NO_ERROR) {
322 printf(
"OpenAL Error: %d, alGenBuffers failed %s\n", error, filename);
333 alutLoadWAVFile((ALbyte *) filename, &format, &wave, &size, &freq, &srcloop);
334 error = alGetError();
335 if (error != AL_NO_ERROR) {
336 printf(
"OpenAL Error: %d, could not load %s\n", error, filename);
338 alDeleteBuffers(1, &
buffer);
345 alBufferData (
buffer, format, wave, size, freq);
346 error = alGetError();
347 if (error != AL_NO_ERROR) {
348 printf(
"OpenAL Error: %d, alBufferData %s\n", error, filename);
350 alDeleteBuffers(1, &
buffer);
357 alutUnloadWAV(format, wave, size, freq);
358 error = alGetError();
359 if (error != AL_NO_ERROR) {
360 printf(
"OpenAL Error: %d, alutUnloadWAV %s\n", error, filename);
370 printf(
" No static sources left: %s\n", filename);
372 alDeleteBuffers(1, &
buffer);
381 error = alGetError();
382 if (error != AL_NO_ERROR) {
383 printf(
"OpenAL Error: %d, alSourcefv AL_POSITION %s\n", error, filename);
387 error = alGetError();
388 if (error != AL_NO_ERROR) {
389 printf(
"OpenAL Error: %d, alSourcefv AL_VELOCITY %s\n", error, filename);
393 error = alGetError();
394 if (error != AL_NO_ERROR) {
395 printf(
"OpenAL Error: %d, alSourcei AL_BUFFER %s\n", error, filename);
399 if (error != AL_NO_ERROR) {
400 printf(
"OpenAL Error: %d, alSourcei AL_LOOPING %s\n", error, filename);
404 if (error != AL_NO_ERROR) {
405 printf(
"OpenAL Error: %d, alSourcef AL_MAX_DISTANCE %s\n", error, filename);
409 if (error != AL_NO_ERROR) {
410 printf(
"OpenAL Error: %d, alSourcef AL_REFERENCE_DISTANCE %s\n", error, filename);
414 if (error != AL_NO_ERROR) {
415 printf(
"OpenAL Error: %d, alSourcef AL_ROLLOFF_FACTOR %s\n", error, filename);
418 alSourcef (
source, AL_GAIN, 0.0f);
419 if (error != AL_NO_ERROR) {
420 printf(
"OpenAL Error: %d, alSourcef AL_GAIN %s\n", error, filename);
428 alDeleteSources(1, &
source);
431 alDeleteBuffers(1, &
buffer);
455 alSourcef (
source, AL_REFERENCE_DISTANCE, dist);
458 if (
itf->getSourcePool()->isSourceActive(
this, &
poolindex)) {
459 alSourcef (
source, AL_REFERENCE_DISTANCE, dist);
468 for (
int i=0; i<3; i++) {
477 for (
int i=0; i<3; i++) {
513 alSourcef (
source, AL_GAIN, 0.0f);
539 if (
itf->getSourcePool()->releaseSource(
this, &
poolindex)) {
565 ALfloat zero_velocity[3] = {0.0f, 0.0f, 0.0f};
569 alSourcefv (
source, AL_VELOCITY, zero_velocity);
574 if (
itf->getSourcePool()->isSourceActive(
this, &
poolindex)) {
576 alSourcefv (
source, AL_VELOCITY, zero_velocity);
virtual bool getStaticSource(ALuint *source)
virtual void getSource(sgVec3 p, sgVec3 u)
bool static_pool
dynamic or static source assignment?
virtual void setLPFilter(float lp)
OpenalSoundInterface * itf
Handle to the interface.
ALfloat zeroes[3]
just a vector of 0s
ALfloat source_velocity[3]
source velocity
ALfloat REFERENCE_DISTANCE
reference distance for sound
ALfloat source_position[3]
source position
virtual void setSource(sgVec3 p, sgVec3 u)
virtual void setReferenceDistance(float dist)
bool is_enabled
is it available at all?
ALfloat MAX_DISTANCE
maximum allowed distance
OpenalTorcsSound(const char *filename, OpenalSoundInterface *sitf, int flags=(ACTIVE_VOLUME|ACTIVE_PITCH), bool loop=false, bool static_pool=true)
Create a new torcs sound.
ALfloat ROLLOFF_FACTOR
how fast we need to roll off
virtual void setPitch(float pitch)
virtual ~OpenalTorcsSound()
int poolindex
which pool the sound is assigned to
ALfloat MAX_DISTANCE_LOW
maximum allowed distance
virtual void setVolume(float vol)
bool paused
sound is paused
virtual void update()
Update the plib sounds.
virtual void play()
Start the sample.
slEnvelope * pitch_env
pitch envelope
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
virtual void stop()
Stop the sample.
slSample * sample
sample data
slEnvelope * lowpass_env
low pass filter envelope
bool playing
Sound is playing.
virtual void pause()
Pause a sample.
virtual ~PlibTorcsSound()
Destructor.
slScheduler * sched
plib sl scheduler (see sl.h)
virtual void setVolume(float vol)
Set the volume.
virtual void start()
Start the sample.
float a
Environmental attenuation.
float lp
Environmental filtering.
sgVec3 p_lis
listener position for this source
sgVec3 u_src
source velocity;
float f
Environmental frequency shift.
SoundSource()
Create a sound source.
sgVec3 p_src
source position
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
float MAX_VOL
Maximum volume.
float volume
Current volume.
TorcsSound(int flags=(ACTIVE_VOLUME|ACTIVE_PITCH))
Consruct a sound.
virtual void setPitch(float pitch)
Set the pitch.
bool loop
Whether it's a looping sound.
int flags
Flags relating to what effects are to be used.
virtual void setLPFilter(float lp)
Set the filter.
float pitch
Current pitch.
virtual void setVolume(float vol)
Set the volume.
float lowpass
Current low pass filter.