29 #include "nomlib/audio/AL/SoundSource.hpp"
36 NOM_LOG_TRACE ( NOM );
38 AL_CHECK_ERR ( alGenSources ( 1, &
source_id ) );
39 AL_CHECK_ERR ( alSourcei (
source_id, AL_BUFFER, 0 ) );
42 SoundSource::~SoundSource (
void )
44 NOM_LOG_TRACE ( NOM );
46 AL_CHECK_ERR ( alSourcei (
source_id, AL_BUFFER, 0 ) );
47 AL_CHECK_ERR ( alDeleteSources ( 1, &
source_id ) );
54 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_GAIN, &volume ) );
56 return volume * 100.f;
59 float SoundSource::getMinVolume (
void )
const
63 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_MIN_GAIN, &min_volume ) );
68 float SoundSource::getMaxVolume (
void )
const
72 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_MAX_GAIN, &max_volume ) );
77 float SoundSource::getPitch (
void )
const
81 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_PITCH, &pitch ) );
86 bool SoundSource::getLooping (
void )
const
90 AL_CHECK_ERR ( alGetSourcei (
source_id, AL_LOOPING, &looping ) );
94 case AL_TRUE:
return true;
break;
95 case AL_FALSE:
return false;
break;
101 Point3f SoundSource::getPosition (
void )
const
105 AL_CHECK_ERR ( alGetSource3f (
source_id, AL_POSITION, &position.x, &position.y,
112 Point3f SoundSource::getVelocity (
void )
const
116 AL_CHECK_ERR ( alGetSource3f (
source_id, AL_VELOCITY, &velocity.x, &velocity.y,
123 bool SoundSource::getPositionRelativeToListener (
void )
const
127 AL_CHECK_ERR ( alGetSourcei (
source_id, AL_SOURCE_RELATIVE, &relative ) );
129 return (relative != 0);
132 float SoundSource::getMinDistance (
void )
const
136 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_REFERENCE_DISTANCE, &distance ) );
141 float SoundSource::getAttenuation (
void )
const
145 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_ROLLOFF_FACTOR, &attenuation ) );
154 AL_CHECK_ERR ( alGetSourcei (
source_id, AL_BUFFER, &buffer_id ) );
161 ALfloat playback_position;
163 AL_CHECK_ERR ( alGetSourcef (
source_id, AL_SEC_OFFSET, &playback_position ) );
165 return playback_position;
172 AL_CHECK_ERR ( alGetSourcei (
source_id, AL_SOURCE_STATE, &state ) );
177 case AL_STOPPED:
return Stopped;
178 case AL_PAUSED:
return Paused;
179 case AL_PLAYING:
return Playing;
187 AL_CHECK_ERR ( alSourcef (
source_id, AL_GAIN, gain * 0.01f ) );
190 void SoundSource::setMinVolume (
float gain )
192 AL_CHECK_ERR ( alSourcef (
source_id, AL_MIN_GAIN, gain ) );
195 void SoundSource::setMaxVolume (
float gain )
197 AL_CHECK_ERR ( alSourcef (
source_id, AL_MAX_GAIN, gain ) );
200 void SoundSource::setPitch (
float pitch )
202 AL_CHECK_ERR ( alSourcef (
source_id, AL_PITCH, pitch ) );
205 void SoundSource::setLooping (
bool loops )
207 AL_CHECK_ERR ( alSourcei (
source_id, AL_LOOPING, loops ) );
210 void SoundSource::setPosition (
float x,
float y,
float z )
212 AL_CHECK_ERR ( alSource3f (
source_id, AL_POSITION, x, y, z ) );
215 void SoundSource::setPosition (
const Point3f& position )
217 this->setPosition ( position.x, position.y, position.z );
220 void SoundSource::setVelocity (
float x,
float y,
float z )
222 AL_CHECK_ERR ( alSource3f (
source_id, AL_VELOCITY, x, y, z ) );
225 void SoundSource::setVelocity (
const Point3f& velocity )
227 this->setVelocity ( velocity.x, velocity.y, velocity.z );
230 void SoundSource::setPositionRelativeToListener (
bool relative )
232 AL_CHECK_ERR ( alSourcei (
source_id, AL_SOURCE_RELATIVE, relative ) );
235 void SoundSource::setMinDistance (
float distance )
237 AL_CHECK_ERR ( alSourcef (
source_id, AL_REFERENCE_DISTANCE, distance ) );
240 void SoundSource::setAttenuation (
float attenuation )
242 AL_CHECK_ERR ( alSourcef (
source_id, AL_ROLLOFF_FACTOR, attenuation ) );
247 AL_CHECK_ERR ( alSourcef (
source_id, AL_SEC_OFFSET, seconds ) );
void setPlayPosition(float seconds)
Set playback position of source in seconds.
void setVolume(float gain)
int32 getBufferID(void) const
Obtain buffer identifier of source.
SoundStatus getStatus(void) const
Obtain current state of sound.
float getVolume(void) const
uint32 source_id
Source identification; used by OpenAL.
float getPlayPosition(void) const
Obtain the current playback position of source in seconds.
SoundSource(void)
Constructor can only be called from deriving classes.