#include <source_al.h>
Inheritance diagram for NLSOUND::CSourceAL:
Note: the creation/deletion of sources and the setting of their rolloff factor are done in CSoundDriverAL.
The EAX extensions are not available on all sound cards, and currently not at all on Linux.
For arguments as 3D vectors, use the NeL vector coordinate system (not OpenAL/OpenGL's one).
Nevrax France
Definition at line 53 of file source_al.h.
Public Member Functions | |
CSourceAL (ALuint sourcename=AL_NONE) | |
Constructor. | |
virtual IBuffer * | getStaticBuffer () |
Set the next source that is to be played immediately after the present source. | |
ALuint | sourceName () |
Return the OpenAL source name. | |
virtual | ~CSourceAL () |
Destructor. | |
Source properties | |
virtual void | getCone (float &innerAngle, float &outerAngle, float &outerGain) const |
Get the cone angles (in radian). | |
virtual void | getDirection (NLMISC::CVector &dir) const |
Get the direction vector. | |
virtual float | getGain () const |
Get the gain. | |
virtual void | getMinMaxDistances (float &mindist, float &maxdist) const |
Get the min and max distances. | |
virtual float | getPitch () const |
Get the pitch. | |
virtual const NLMISC::CVector & | getPos () const |
virtual bool | getSourceRelativeMode () const |
Get the source relative mode. | |
virtual void | getVelocity (NLMISC::CVector &vel) const |
Get the velocity vector. | |
virtual void | setCone (float innerAngle, float outerAngle, float outerGain) |
Set the cone angles (in radian) and gain (in [0 , 1]) (default: 2PI, 2PI, 0) (3D mode only). | |
virtual void | setDirection (const NLMISC::CVector &dir) |
Set the direction vector (3D mode only) (default: (0,0,0) as non-directional). | |
virtual void | setEAXProperty (uint prop, void *value, uint valuesize) |
Set any EAX source property if EAX available. | |
virtual void | setGain (float gain) |
virtual void | setMinMaxDistances (float mindist, float maxdist, bool deferred) |
Set the min and max distances (default: 1, MAX_FLOAT) (3D mode only). | |
virtual void | setPitch (float pitch) |
virtual void | setPos (const NLMISC::CVector &pos, bool deffered=true) |
virtual void | setSourceRelativeMode (bool mode) |
Set the source relative mode. If true, positions are interpreted relative to the listener position (default: false). | |
virtual void | setVelocity (const NLMISC::CVector &vel, bool deferred) |
Set the velocity vector (3D mode only) (default: (0,0,0)). | |
Playback control | |
virtual bool | getLooping () const |
Return the looping state. | |
virtual bool | isPlaying () const |
Return the playing state. | |
virtual bool | isStopped () const |
Return true if playing is finished or stop() has been called. | |
virtual void | pause () |
Pause. Call play() to resume. | |
virtual bool | play () |
Play the static buffer (or stream in and play). | |
virtual void | setLooping (bool l) |
Set looping on/off for future playbacks (default: off). | |
virtual void | stop () |
Stop playing. | |
virtual bool | update () |
Update the source (e.g. continue to stream the data in). | |
Playback control | |
virtual uint32 | getTime () |
Returns the number of milliseconds the source has been playing. | |
Source properties | |
virtual void | setAlpha (double a) |
Testing. | |
Initialization | |
virtual void | setStaticBuffer (IBuffer *buffer) |
Protected Attributes | |
ILoader * | _Loader |
Private Attributes | |
NLMISC::CVector | _Pos |
ALuint | _SourceName |
|
Constructor.
Definition at line 47 of file source_al.cpp.
00047 : ISource(), _SourceName(sourcename) 00048 {} |
|
Destructor.
Definition at line 54 of file source_al.cpp. References NLSOUND::CSoundDriverAL::removeSource().
00055 {
00056 CSoundDriverAL *sdal = CSoundDriverAL::instance();
00057 sdal->removeSource( this );
00058 }
|
|
Get the cone angles (in radian).
Implements NLSOUND::ISource. Definition at line 400 of file source_al.cpp. References NLMISC::degToRad(), and TestALError.
00401 { 00402 float ina, outa; 00403 alGetSourcef( _SourceName, AL_CONE_INNER_ANGLE, &ina ); 00404 innerAngle = degToRad(ina); 00405 alGetSourcef( _SourceName, AL_CONE_OUTER_ANGLE, &outa ); 00406 outerAngle = degToRad(outa); 00407 alGetSourcef( _SourceName, AL_CONE_OUTER_GAIN, &outerGain ); 00408 TestALError(); 00409 } |
|
Get the direction vector.
Implements NLSOUND::ISource. Definition at line 280 of file source_al.cpp. References NLMISC::CVector::set(), TestALError, and v.
00281 { 00282 ALfloat v[3]; 00283 alGetSourcefv( _SourceName, AL_DIRECTION, v ); 00284 TestALError(); 00285 // Coordsys conversion 00286 dir.set( v[0], -v[2], v[1] ); 00287 } |
|
Get the gain.
Implements NLSOUND::ISource. Definition at line 307 of file source_al.cpp. References TestALError.
00308 { 00309 ALfloat gain; 00310 alGetSourcef( _SourceName, AL_GAIN, &gain ); 00311 TestALError(); 00312 return gain; 00313 } |
|
Return the looping state.
Implements NLSOUND::ISource. Definition at line 104 of file source_al.cpp. References TestALError.
00105 { 00106 ALint b; 00107 alGetSourcei( _SourceName, AL_LOOPING, &b ); 00108 TestALError(); 00109 return ( b == AL_TRUE ); 00110 } |
|
Get the min and max distances.
Implements NLSOUND::ISource. Definition at line 376 of file source_al.cpp. References TestALError.
00377 { 00378 alGetSourcef( _SourceName, AL_REFERENCE_DISTANCE, &mindist ); 00379 alGetSourcef( _SourceName, AL_MAX_DISTANCE, &maxdist ); 00380 TestALError(); 00381 } |
|
Get the pitch.
Implements NLSOUND::ISource. Definition at line 330 of file source_al.cpp. References TestALError.
00331 { 00332 ALfloat pitch; 00333 alGetSourcef( _SourceName, AL_PITCH, &pitch ); 00334 TestALError(); 00335 return pitch; 00336 } |
|
Get the position vector. See setPos() for details. Implements NLSOUND::ISource. Definition at line 229 of file source_al.cpp.
00230 { 00231 return _Pos; 00232 /* 00233 ALfloat v[3]; 00234 alGetSourcefv( _SourceName, AL_POSITION, v ); 00235 TestALError(); 00236 // Coordsys conversion 00237 pos.set( v[0], -v[2], v[1] ); 00238 */ 00239 } |
|
Get the source relative mode.
Implements NLSOUND::ISource. Definition at line 352 of file source_al.cpp. References TestALError.
00353 { 00354 ALint b; 00355 alGetSourcei( _SourceName, AL_SOURCE_RELATIVE, &b ); 00356 TestALError(); 00357 return (b==AL_TRUE); 00358 } |
|
Set the next source that is to be played immediately after the present source.
Implements NLSOUND::ISource. Definition at line 75 of file source_al.h.
00075 { /* TODO */ return NULL; } |
|
Returns the number of milliseconds the source has been playing.
Reimplemented in NLSOUND::CSourceDSound. Definition at line 101 of file source.h. References uint32. Referenced by NLSOUND::CSimpleSource::getTime().
00101 { return 0; }
|
|
Get the velocity vector.
Implements NLSOUND::ISource. Definition at line 256 of file source_al.cpp. References NLMISC::CVector::set(), TestALError, and v.
00257 { 00258 ALfloat v[3]; 00259 alGetSourcefv( _SourceName, AL_VELOCITY, v ); 00260 TestALError(); 00261 // Coordsys conversion 00262 vel.set( v[0], -v[2], v[1] ); 00263 } |
|
Return the playing state.
Implements NLSOUND::ISource. Definition at line 181 of file source_al.cpp. References TestALError.
00182 { 00183 ALint srcstate; 00184 alGetSourcei( _SourceName, AL_SOURCE_STATE, &srcstate ); 00185 TestALError(); 00186 return (srcstate == AL_PLAYING); 00187 } |
|
Return true if playing is finished or stop() has been called.
Implements NLSOUND::ISource. Definition at line 193 of file source_al.cpp. References TestALError.
00194 { 00195 ALint srcstate; 00196 alGetSourcei( _SourceName, AL_SOURCE_STATE, &srcstate ); 00197 TestALError(); 00198 return (srcstate == AL_STOPPED); 00199 } |
|
Pause. Call play() to resume.
Implements NLSOUND::ISource. Definition at line 160 of file source_al.cpp.
00161 { 00162 /* TODO if ( _Buffer != NULL ) 00163 { 00164 // Static playing mode 00165 alSourcePause( _SourceName ); 00166 TestALError(); 00167 } 00168 else 00169 { 00170 // Streaming mode 00171 nlwarning( "AM: Cannot pause null buffer; streaming not implemented" ); 00172 nlstop; 00173 } 00174 */ 00175 } |
|
Play the static buffer (or stream in and play).
Implements NLSOUND::ISource. Definition at line 116 of file source_al.cpp.
00117 { 00118 /* TODO if ( _Buffer != NULL ) 00119 { 00120 // Static playing mode 00121 alSourcePlay( _SourceName ); 00122 TestALError(); 00123 } 00124 else 00125 { 00126 // Streaming mode 00127 nlwarning( "AM: Cannot play null buffer; streaming not implemented" ); 00128 nlstop; 00129 } 00130 */ 00131 // TODO : return a correct value, depending on alSourcePlay result. 00132 return true; 00133 } |
|
Testing.
Reimplemented in NLSOUND::CSourceDSound. Definition at line 154 of file source.h. Referenced by NLSOUND::CSimpleSource::play().
00154 { } |
|
Set the cone angles (in radian) and gain (in [0 , 1]) (default: 2PI, 2PI, 0) (3D mode only).
Implements NLSOUND::ISource. Definition at line 387 of file source_al.cpp. References nlassert, NLMISC::radToDeg(), and TestALError.
00388 { 00389 nlassert( (outerGain >= 0.0f) && (outerGain <= 1.0f ) ); 00390 alSourcef( _SourceName, AL_CONE_INNER_ANGLE, radToDeg(innerAngle) ); 00391 alSourcef( _SourceName, AL_CONE_OUTER_ANGLE, radToDeg(outerAngle) ); 00392 alSourcef( _SourceName, AL_CONE_OUTER_GAIN, outerGain ); 00393 TestALError(); 00394 } |
|
Set the direction vector (3D mode only) (default: (0,0,0) as non-directional).
Implements NLSOUND::ISource. Definition at line 269 of file source_al.cpp. References TestALError, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.
00270 { 00271 // Coordsys conversion 00272 alSource3f( _SourceName, AL_DIRECTION, dir.x, dir.z, -dir.y ); 00273 TestALError(); 00274 } |
|
Set any EAX source property if EAX available.
Implements NLSOUND::ISource. Definition at line 415 of file source_al.cpp.
00416 { 00417 #if EAX_AVAILABLE == 1 00418 if ( EAXSetProp != NULL ) 00419 { 00420 EAXSetProp( &DSPROPSETID_EAX_SourceProperties, prop, _SourceName, value, valuesize ); 00421 } 00422 #endif 00423 } |
|
Set the gain (volume value inside [0 , 1]) (default: 1) 0.0 -> silence 0.5 -> -6dB 1.0 -> no attenuation values > 1 (amplification) not supported by most drivers Implements NLSOUND::ISource. Definition at line 296 of file source_al.cpp. References nlassert, and TestALError.
00297 { 00298 nlassert( (gain >= 0.0f) && (gain <= 1.0f ) ); 00299 alSourcef( _SourceName, AL_GAIN, gain ); 00300 TestALError(); 00301 } |
|
Set looping on/off for future playbacks (default: off).
Implements NLSOUND::ISource. Definition at line 94 of file source_al.cpp. References TestALError.
00095 { 00096 alSourcei( _SourceName, AL_LOOPING, l?AL_TRUE:AL_FALSE ); 00097 TestALError(); 00098 } |
|
Set the min and max distances (default: 1, MAX_FLOAT) (3D mode only).
Implements NLSOUND::ISource. Definition at line 364 of file source_al.cpp. References nlassert, and TestALError.
00365 { 00366 nlassert( (mindist >= 0.0f) && (maxdist >= 0.0f) ); 00367 alSourcef( _SourceName, AL_REFERENCE_DISTANCE, mindist ); 00368 alSourcef( _SourceName, AL_MAX_DISTANCE, maxdist ); 00369 TestALError(); 00370 } |
|
Shift the frequency. 1.0f equals identity, each reduction of 50% equals a pitch shift of one octave. 0 is not a legal value. Implements NLSOUND::ISource. Definition at line 319 of file source_al.cpp. References nlassert, and TestALError.
00320 { 00321 nlassert( (pitch > 0) && (pitch <= 1.0f ) ); 00322 alSourcef( _SourceName, AL_PITCH, pitch ); 00323 TestALError(); 00324 } |
|
Set the position vector (default: (0,0,0)). 3D mode -> 3D position st mode -> x is the pan value (from left (-1) to right (1)), set y and z to 0 Implements NLSOUND::ISource. Definition at line 217 of file source_al.cpp. References TestALError.
00218 { 00219 _Pos = pos; 00220 // Coordinate system: conversion from NeL to OpenAL/GL: 00221 alSource3f( _SourceName, AL_POSITION, pos.x, pos.z, -pos.y ); 00222 TestALError(); 00223 } |
|
Set the source relative mode. If true, positions are interpreted relative to the listener position (default: false).
Implements NLSOUND::ISource. Definition at line 342 of file source_al.cpp. References TestALError. Referenced by setStaticBuffer().
00343 { 00344 alSourcei( _SourceName, AL_SOURCE_RELATIVE, mode?AL_TRUE:AL_FALSE ); 00345 TestALError(); 00346 } |
|
Set the buffer that will be played (no streaming) If the buffer is stereo, the source mode becomes stereo and the source relative mode is on, otherwise the source is considered as a 3D source. Set NULL to set "no buffer" Implements NLSOUND::ISource. Definition at line 65 of file source_al.cpp. References buffer, NLSOUND::CBufferAL::bufferName(), NLSOUND::CBufferAL::isStereo(), setSourceRelativeMode(), and TestALError.
00066 { 00067 ISource::setStaticBuffer( buffer ); 00068 00069 // Stop source 00070 alSourceStop( _SourceName ); 00071 TestALError(); 00072 00073 // Set buffer 00074 if ( buffer == NULL ) 00075 { 00076 alSourcei( _SourceName, AL_BUFFER, AL_NONE ); 00077 TestALError(); 00078 } 00079 else 00080 { 00081 CBufferAL *bufferAL = dynamic_cast<CBufferAL*>(buffer); 00082 alSourcei( _SourceName, AL_BUFFER, bufferAL->bufferName() ); 00083 TestALError(); 00084 00085 // Set relative mode if the buffer is stereo 00086 setSourceRelativeMode( bufferAL->isStereo() ); 00087 } 00088 } |
|
Set the sound loader that will be used to stream in the data to play If the buffer is stereo, the source mode becomes stereo and the source relative mode is on, otherwise the source is considered as a 3D source. Definition at line 76 of file source.h. References NLSOUND::ISource::_Loader.
00076 { _Loader = loader; } |
|
Set the velocity vector (3D mode only) (default: (0,0,0)).
Implements NLSOUND::ISource. Definition at line 245 of file source_al.cpp. References TestALError, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.
00246 { 00247 // Coordsys conversion 00248 alSource3f( _SourceName, AL_VELOCITY, vel.x, vel.z, -vel.y ); 00249 TestALError(); 00250 } |
|
Return the OpenAL source name.
Definition at line 150 of file source_al.h. Referenced by NLSOUND::CSoundDriverAL::createSource(), and NLSOUND::CSoundDriverAL::removeSource().
00150 { return _SourceName; } |
|
Stop playing.
Implements NLSOUND::ISource. Definition at line 139 of file source_al.cpp.
00140 { 00141 /* TODO if ( _Buffer != NULL ) 00142 { 00143 // Static playing mode 00144 alSourceStop( _SourceName ); 00145 TestALError(); 00146 } 00147 else 00148 { 00149 // Streaming mode 00150 nlwarning( "AM: Cannot stop null buffer; streaming not implemented" ); 00151 //nlstop; 00152 } 00153 */ 00154 } |
|
Update the source (e.g. continue to stream the data in).
Implements NLSOUND::ISource. Definition at line 205 of file source_al.cpp.
00206 { 00207 // Streaming not implemented 00208 return false; 00209 } |
|
Definition at line 170 of file source.h. Referenced by NLSOUND::ISource::ISource(), NLSOUND::ISource::setStreamLoader(), and NLSOUND::ISource::~ISource(). |
|
Definition at line 157 of file source_al.h. |
|
Definition at line 155 of file source_al.h. |