NLSOUND::CListenerDSound Class Reference

#include <listener_dsound.h>

Inheritance diagram for NLSOUND::CListenerDSound:

NLSOUND::IListener

Detailed Description

DirectSound listener.

For arguments as 3D vectors, use the NeL vector coordinate system (not OpenAL/OpenGL's one).

Author:
Peter Hanappe, Olivier Cado

Nevrax France

Date:
2002

Definition at line 56 of file listener_dsound.h.

Public Member Functions

 CListenerDSound (LPDIRECTSOUND3DLISTENER8 dsoundListener)
 Constructor.

void commit3DChanges ()
 Commit any changes to the 3D environment.

virtual ~CListenerDSound ()
 Deconstructor.

Listener properties
virtual float getGain () const
 Get the gain.

virtual void getOrientation (NLMISC::CVector &front, NLMISC::CVector &up) const
 Get the orientation vectors.

virtual const NLMISC::CVectorgetPos () const
virtual void getVelocity (NLMISC::CVector &vel) const
 Get the velocity vector.

virtual void setGain (float gain)
virtual void setOrientation (const NLMISC::CVector &front, const NLMISC::CVector &up)
 Set the orientation vectors (3D mode only) (default: (0,1,0), (0,0,1)).

virtual void setPos (const NLMISC::CVector &pos)
 Set the position vector (default: (0,0,0)) (3D mode only).

virtual void setVelocity (const NLMISC::CVector &vel)
 Set the velocity vector (3D mode only) (default: (0,0,0)).

Global properties
virtual float getRolloffFactor ()
 Return the rolloff factor.

virtual void setDopplerFactor (float f)
 Set the doppler factor (default: 1) to exaggerate or not the doppler effect.

virtual void setEAXProperty (uint prop, void *value, uint valuesize)
 Set any EAX listener property if EAX available.

virtual void setEnvironment (uint env, float size=7.5f)
 Set DSPROPERTY_EAXLISTENER_ENVIRONMENT and DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE if EAX available (see EAX listener properties).

virtual void setRolloffFactor (float f)
 Set the rolloff factor (default: 1) to scale the distance attenuation effect.


Static Public Member Functions

CListenerDSoundinstance ()
 Return the instance of the singleton.


Private Member Functions

void release ()
 Release all DirectSound resources.


Private Attributes

LPDIRECTSOUND3DLISTENER8 _Listener
 The DirectSound listener interface.

NLMISC::CVector _Pos

Static Private Attributes

CListenerDSound_Instance = NULL
 The instance of the singleton.


Friends

class CSoundDriverDSound


Constructor & Destructor Documentation

NLSOUND::CListenerDSound::CListenerDSound LPDIRECTSOUND3DLISTENER8  dsoundListener  ) 
 

Constructor.

Definition at line 50 of file listener_dsound.cpp.

References setRolloffFactor().

00050                                                                           : IListener()
00051 :       _Pos(CVector::Null)
00052 {
00053 #if EAX_AVAILABLE == 1
00054         _EAXListener = 0;
00055 #endif
00056         if ( _Instance == NULL )
00057         {
00058                 _Instance = this;
00059         _Listener = dsoundListener;
00060 #if MANUAL_ROLLOFF == 1
00061                 setRolloffFactor(DS3D_MINROLLOFFFACTOR);
00062 #endif
00063         }
00064         else
00065         {
00066                 //nlerror( "Listener singleton instanciated twice" );
00067         }
00068 }

NLSOUND::CListenerDSound::~CListenerDSound  )  [virtual]
 

Deconstructor.

Definition at line 71 of file listener_dsound.cpp.

References nldebug, and release().

00072 {
00073         nldebug("Destroying DirectSound listener");
00074 
00075     release();
00076         _Instance = NULL;
00077 }


Member Function Documentation

void NLSOUND::CListenerDSound::commit3DChanges  ) 
 

Commit any changes to the 3D environment.

Definition at line 322 of file listener_dsound.cpp.

Referenced by NLSOUND::CSoundDriverDSound::commit3DChanges().

00323 {
00324     if (_Listener != NULL)
00325     {
00326                 _Listener->CommitDeferredSettings();
00327         }
00328 }

float NLSOUND::CListenerDSound::getGain  )  const [virtual]
 

Get the gain.

Implements NLSOUND::IListener.

Definition at line 253 of file listener_dsound.cpp.

00254 {
00255     return CSoundDriverDSound::instance()->getGain();
00256 }

void NLSOUND::CListenerDSound::getOrientation NLMISC::CVector front,
NLMISC::CVector up
const [virtual]
 

Get the orientation vectors.

Implements NLSOUND::IListener.

Definition at line 213 of file listener_dsound.cpp.

References nlwarning, and NLMISC::CVector::set().

00214 {
00215     if (_Listener != NULL)
00216         {
00217                 D3DVECTOR vfront, vtop;
00218         if (FAILED(_Listener->GetOrientation(&vfront, &vtop)))
00219                 {
00220                         nlwarning("GetOrientation failed");
00221                         front.set(0.0f, 0.0f, 1.0f);
00222                         up.set(0.0f, 1.0f, 0.0f);
00223                 }
00224                 else
00225                 {
00226                         front.set(vfront.x, vfront.z, vfront.y);
00227                         up.set(vtop.x, vtop.z, vtop.y);
00228                 }
00229     }
00230         else
00231         {
00232                 front.set(0, 0, 1);
00233                 up.set(0, 1, 0);
00234         }
00235 }

const NLMISC::CVector & NLSOUND::CListenerDSound::getPos  )  const [virtual]
 

Get the position vector. See setPos() for details.

Implements NLSOUND::IListener.

Definition at line 125 of file listener_dsound.cpp.

Referenced by NLSOUND::CSoundDriverDSound::commit3DChanges(), and NLSOUND::CSourceDSound::play().

00126 {
00127         return _Pos;
00128 /*      return;
00129         // Coordinate system: conversion from NeL to OpenAL/GL:
00130     if (_Listener != NULL)
00131         {
00132                 D3DVECTOR v;
00133         if (FAILED(_Listener->GetPosition(&v)))
00134                 {
00135                         nlwarning("GetPosition failed");
00136                         pos.set(0.0f, 0.0f, 0.0f);
00137                 }
00138                 else
00139                 {
00140                         pos.set(v.x, v.z, v.y);
00141                 }
00142     }
00143         else
00144         {
00145                 pos.set(0, 0, 0);
00146         }
00147 */
00148 }

float NLSOUND::CListenerDSound::getRolloffFactor  )  [virtual]
 

Return the rolloff factor.

Definition at line 307 of file listener_dsound.cpp.

00308 {   
00309         if (_Listener != NULL)
00310     {
00311                 float f;
00312                 _Listener->GetRolloffFactor(&f);
00313                 return f;
00314     }
00315         else
00316         {
00317                 return 1.0;
00318         }
00319 }

void NLSOUND::CListenerDSound::getVelocity NLMISC::CVector vel  )  const [virtual]
 

Get the velocity vector.

Implements NLSOUND::IListener.

Definition at line 169 of file listener_dsound.cpp.

References nlwarning, NLMISC::CVector::set(), and v.

00170 {
00171     if (_Listener != NULL)
00172         {
00173                 D3DVECTOR v;
00174         if (FAILED(_Listener->GetVelocity(&v)))
00175                 {
00176                         nlwarning("GetVelocity failed");
00177                         vel.set(0.0f, 0.0f, 0.0f);
00178                 }
00179                 else
00180                 {
00181                         vel.set(v.x, v.z, v.y);
00182                 }
00183     }
00184         else
00185         {
00186                 vel.set(0, 0, 0);       
00187         }
00188 }

CListenerDSound* NLSOUND::CListenerDSound::instance  )  [inline, static]
 

Return the instance of the singleton.

Definition at line 69 of file listener_dsound.h.

00069 { return _Instance; }

void NLSOUND::CListenerDSound::release  )  [private]
 

Release all DirectSound resources.

Definition at line 83 of file listener_dsound.cpp.

Referenced by ~CListenerDSound().

00084 {
00085     if (_Listener != NULL)
00086     {
00087         _Listener->Release();
00088                 _Listener = NULL;
00089     }
00090 #if EAX_AVAILABLE == 1
00091         if (_EAXListener != NULL)
00092         {
00093                 _EAXListener->Release();
00094                 _EAXListener = NULL;
00095         }
00096 #endif
00097 }

void NLSOUND::CListenerDSound::setDopplerFactor float  f  )  [virtual]
 

Set the doppler factor (default: 1) to exaggerate or not the doppler effect.

Implements NLSOUND::IListener.

Definition at line 262 of file listener_dsound.cpp.

References nlwarning.

00263 {
00264     if (_Listener != NULL)
00265     {
00266                 if (f > DS3D_MAXDOPPLERFACTOR)
00267                 {
00268                         f = DS3D_MAXDOPPLERFACTOR;
00269                 }
00270                 else if (f < DS3D_MINDOPPLERFACTOR)
00271                 {
00272                         f = DS3D_MINDOPPLERFACTOR;
00273                 }
00274 
00275         if (FAILED(_Listener->SetDopplerFactor(f, DS3D_DEFERRED)))
00276                 {
00277                         nlwarning("SetDopplerFactor failed");
00278                 }
00279     }
00280 }

void NLSOUND::CListenerDSound::setEAXProperty uint  prop,
void *  value,
uint  valuesize
[virtual]
 

Set any EAX listener property if EAX available.

Implements NLSOUND::IListener.

Definition at line 357 of file listener_dsound.cpp.

References nlwarning, res, uint, and value.

00358 {
00359 #ifdef EAX_AVAILABLE
00360         if (_EAXListener == NULL)
00361         {
00362                 _EAXListener = CSoundDriverDSound::instance()->createPropertySet(NULL);
00363         }
00364         if ( _EAXListener != NULL )
00365         {
00366                 HRESULT res = _EAXListener->Set(DSPROPSETID_EAX_ListenerProperties, prop, NULL, 0, value, valuesize );
00367                 if (res != S_OK)
00368                         nlwarning("Setting EAX listener prop #%d fail : %x", prop, res);
00369         }
00370 #endif
00371 }

void NLSOUND::CListenerDSound::setEnvironment uint  env,
float  size = 7.5f
[virtual]
 

Set DSPROPERTY_EAXLISTENER_ENVIRONMENT and DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE if EAX available (see EAX listener properties).

Implements NLSOUND::IListener.

Definition at line 334 of file listener_dsound.cpp.

References nlwarning, res, size, and uint.

00335 {
00336 #if EAX_AVAILABLE == 1
00337         if (_EAXListener == NULL)
00338         {
00339                 _EAXListener = CSoundDriverDSound::instance()->createPropertySet(NULL);
00340         }
00341         if ( _EAXListener != NULL )
00342         {
00343                 HRESULT res = _EAXListener->Set( DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENT, NULL, 0, &env, sizeof(unsigned long) );
00344                 if (res != S_OK)
00345                         nlwarning("Setting EAX environment #%u fail : %x", env, res);
00346                 res = _EAXListener->Set( DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE, NULL, 0, &size, sizeof(float) );
00347                 if (res != S_OK)
00348                         nlwarning("Setting EAX environment size %f fail : %x", size, res);
00349         }
00350 #endif
00351 }

void NLSOUND::CListenerDSound::setGain float  gain  )  [virtual]
 

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::IListener.

Definition at line 244 of file listener_dsound.cpp.

00245 {
00246         CSoundDriverDSound::instance()->setGain(gain);
00247 }

void NLSOUND::CListenerDSound::setOrientation const NLMISC::CVector front,
const NLMISC::CVector up
[virtual]
 

Set the orientation vectors (3D mode only) (default: (0,1,0), (0,0,1)).

Implements NLSOUND::IListener.

Definition at line 194 of file listener_dsound.cpp.

References nlwarning, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

00195 {
00196     if (_Listener != NULL)
00197     {
00198         if (FAILED(_Listener->SetOrientation(front.x, front.z, front.y, up.x, up.z, up.y, DS3D_DEFERRED)))
00199                 {
00200                         nlwarning("SetOrientation failed");
00201                 }
00202                 else
00203                 {
00204                         //nlwarning ("NLSOUND: set listener orientation NEL(f:%.2f/%.2f/%.2f up:%.2f/%.2f/%.2f) DS(f:%.2f/%.2f/%.2f up:%.2f/%.2f/%.2f)", front.x, front.y, front.z, up.x, up.y, up.z, front.x, front.z, front.y, up.x, up.z, up.y);
00205                 }
00206     }
00207 }

void NLSOUND::CListenerDSound::setPos const NLMISC::CVector pos  )  [virtual]
 

Set the position vector (default: (0,0,0)) (3D mode only).

Implements NLSOUND::IListener.

Definition at line 103 of file listener_dsound.cpp.

References nlwarning.

00104 {
00105 
00106         _Pos = pos;
00107         // Coordinate system: conversion from NeL to OpenAL/GL:
00108     if (_Listener != NULL)
00109     {
00110         if (FAILED(_Listener->SetPosition(pos.x, pos.z, pos.y, DS3D_DEFERRED)))
00111                 {
00112                         nlwarning("SetPosition failed");
00113                 }
00114                 else
00115                 {
00116                         //nlwarning ("set listener NEL(p:%.2f/%.2f/%.2f) DS(p:%.2f/%.2f/%.2f)", pos.x, pos.y, pos.z, pos.x, pos.z, pos.y);
00117                 }
00118         }
00119 }

void NLSOUND::CListenerDSound::setRolloffFactor float  f  )  [virtual]
 

Set the rolloff factor (default: 1) to scale the distance attenuation effect.

Implements NLSOUND::IListener.

Definition at line 286 of file listener_dsound.cpp.

References nlwarning.

Referenced by CListenerDSound().

00287 {
00288 #if MANUAL_ROLLOFF == 1
00289     if (_Listener != NULL)
00290     {
00291                 //clamp(f, DS3D_MINROLLOFFFACTOR, DS3D_MAXROLLOFFFACTOR);
00292 
00293                 // VOLUMETEST: Don't use the rolloff factor. We manage the
00294                 // volumes ourselves
00295                 f = DS3D_MINROLLOFFFACTOR;
00296 
00297         
00298                 if (FAILED(_Listener->SetRolloffFactor(f, DS3D_DEFERRED)))
00299                 {
00300                         nlwarning("SetRolloffFactor failed");
00301                 }
00302     }
00303 #endif
00304 }

void NLSOUND::CListenerDSound::setVelocity const NLMISC::CVector vel  )  [virtual]
 

Set the velocity vector (3D mode only) (default: (0,0,0)).

Implements NLSOUND::IListener.

Definition at line 154 of file listener_dsound.cpp.

References nlwarning, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

00155 {
00156     if (_Listener != NULL)
00157     {
00158         if (FAILED(_Listener->SetVelocity(vel.x, vel.z, vel.y, DS3D_DEFERRED)))
00159                 {
00160                         nlwarning("SetVelocity failed");
00161                 }
00162     }
00163 }


Friends And Related Function Documentation

friend class CSoundDriverDSound [friend]
 

Definition at line 58 of file listener_dsound.h.


Field Documentation

CListenerDSound * NLSOUND::CListenerDSound::_Instance = NULL [static, private]
 

The instance of the singleton.

Definition at line 44 of file listener_dsound.cpp.

LPDIRECTSOUND3DLISTENER8 NLSOUND::CListenerDSound::_Listener [private]
 

The DirectSound listener interface.

Definition at line 138 of file listener_dsound.h.

NLMISC::CVector NLSOUND::CListenerDSound::_Pos [private]
 

Definition at line 141 of file listener_dsound.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 14:39:22 2004 for NeL by doxygen 1.3.6