#include <source_dsound.h>
Inheritance diagram for NLSOUND::CSourceDSound:
For arguments as 3D vectors, use the NeL vector coordinate system
Nevrax France
Definition at line 99 of file source_dsound.h.
Public Member Functions | |
CSourceDSound (uint sourcename=0) | |
Constructor. | |
IBuffer * | getBuffer () |
Returns the buffer associated with this source. | |
void | init (LPDIRECTSOUND8 directSound, bool useEax) |
Initialize the DirectSound buffers. Called by the sound driver only. | |
void | reset () |
virtual void | setAlpha (double a) |
uint | sourceName () |
Return the OpenAL source name. | |
void | updateVolume (const NLMISC::CVector &listener) |
virtual | ~CSourceDSound () |
Destructor. | |
Initialization | |
virtual void | setStreamLoader (ILoader *loader) |
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. | |
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 deferred) |
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 uint32 | getTime () |
Returns the number of milliseconds the source has been playing. | |
virtual bool | isPaused () const |
Return the paused 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). | |
Initialization | |
virtual IBuffer * | getStaticBuffer () |
Return the buffer, or NULL if streaming is used. | |
virtual void | setStaticBuffer (IBuffer *buffer) |
Initialization | |
virtual void | setStreamLoader (ILoader *loader) |
Protected Attributes | |
ILoader * | _Loader |
Private Types | |
enum | TSourceState { source_stoped, source_playing, source_silencing, source_swap_pending } |
Private Member Functions | |
void | advanceFill (TLockedBufferInfo &lbi, uint nbSample) |
uint32 | checkFillCursor () |
void | copySampleTo16BitsTrack (void *dst, void *src, uint nbSample, TSampleFormat sourceFormat) |
void | crossFade () |
void | fadeIn () |
void | fadeIn (const TLockedBufferInfo &lbi) |
void | fadeOut () |
void | fadeOut (const TLockedBufferInfo &lbi) |
bool | fill () |
void | fillData (sint16 *dst, uint nbSample) |
void | fillData (const TLockedBufferInfo &lbi, int nbSample) |
void | fillSilence (const TLockedBufferInfo &lbi, int nbSample) |
void | getCursors (TCursors &cursors) |
bool | lock (uint32 writePos, uint32 size, TLockedBufferInfo &lockedInfo) |
bool | needsUpdate () |
Check whether the play position has advanced enough to require an update. | |
void | release () |
Release all DirectSound resources. | |
bool | silence () |
void | swap () |
bool | unlock (const TLockedBufferInfo &lockedInfo) |
void | xfade (const TLockedBufferInfo &lbi, sint16 *src) |
Private Attributes | |
LPDIRECTSOUND3DBUFFER | _3DBuffer |
IBuffer::TADPCMState | _ADPCMState |
double | _Alpha |
CRITICAL_SECTION | _CriticalSection |
uint32 | _FillOffset |
TSampleFormat | _Format |
float | _Freq |
float | _Gain |
uint32 | _LastPlayPos |
bool | _Loop |
IBuffer * | _NextSample |
uint32 | _PlayOffset |
NLMISC::CVector | _Pos |
IBuffer * | _Sample |
uint | _SampleFreq |
uint | _SampleOffset |
uint32 | _SampleRate |
uint | _SampleSize |
LPDIRECTSOUNDBUFFER | _SecondaryBuffer |
uint32 | _SilenceWriten |
uint | _SourceName |
TSourceState | _State |
sint32 | _Volume |
Static Private Attributes | |
const uint | _DefaultChannels = 1 |
const uint | _DefaultSampleRate = 22050 |
const uint | _DefaultSampleSize = 16 |
const uint32 | _SecondaryBufferSize = 0x10000 |
const uint32 | _SizeMask = 0xffff |
const uint32 | _SwapCopySize = 0x8000 |
const uint32 | _UpdateCopySize = 0x4000 |
const uint32 | _XFadeSize = 64 |
Friends | |
class | CSoundDriverDSound |
|
Definition at line 271 of file source_dsound.h.
00272 { 00273 source_stoped, 00274 source_playing, 00275 source_silencing, 00276 source_swap_pending 00277 }; |
|
Constructor.
Definition at line 111 of file source_dsound.cpp. References _3DBuffer, _Alpha, _CriticalSection, _DefaultSampleRate, _FillOffset, _LastPlayPos, _Loop, _PlayOffset, _Sample, _SampleFreq, _SampleOffset, _SampleRate, _SampleSize, _SecondaryBuffer, _State, NLSOUND::Mono8, source_stoped, and uint.
00112 : ISource(), 00113 _SourceName(sourcename) 00114 { 00115 #if EAX_AVAILABLE == 1 00116 _EAXSource = 0; 00117 #endif 00118 _Sample = 0; 00119 _SampleSize = 0; 00120 _SampleOffset = 0; 00121 _Format = Mono8; 00122 _SampleFreq = _DefaultSampleRate; 00123 _FillOffset = 0; 00124 _State = source_stoped; 00125 _PlayOffset = 0; 00126 _LastPlayPos = 0; 00127 00128 // _BufferSize = 0; 00129 // _SwapBuffer = 0; 00130 _SecondaryBuffer = 0; 00131 // _SecondaryBufferState = NL_DSOUND_SILENCED; 00132 _3DBuffer = 0; 00133 // _NextWritePos = 0; 00134 // _BytesWritten = 0; 00135 // _SilenceWritten = 0; 00136 _Loop = false; 00137 // _EndPosition = 0; 00138 // _EndState = NL_DSOUND_TAIL1; 00139 // _UserState = NL_DSOUND_STOPPED; 00140 _Freq = 1.0f; 00141 _SampleRate = _DefaultSampleRate; 00142 // _IsUsed = false; 00143 _Gain = 1.0f; 00144 _Volume = 0; 00145 _Alpha = 0.0; 00146 InitializeCriticalSection(&_CriticalSection); 00147 } |
|
Destructor.
Definition at line 152 of file source_dsound.cpp. References _CriticalSection, nldebug, and release().
00153 { 00154 nldebug("Destroying DirectSound source"); 00155 00156 CSoundDriverDSound::instance()->removeSource(this); 00157 00158 EnterCriticalSection(&_CriticalSection); 00159 00160 // Release the DirectSound buffer within the critical zone 00161 // to avoid a call to update during deconstruction 00162 release(); 00163 00164 LeaveCriticalSection(&_CriticalSection); 00165 DeleteCriticalSection(&_CriticalSection); 00166 } |
|
Definition at line 662 of file source_dsound.cpp. References _FillOffset, _SecondaryBufferSize, _SizeMask, nlassert, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, size, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, uint, and uint32. Referenced by play(), stop(), and update().
00663 { 00664 uint32 size = nbSample * 2; 00665 if (lbi.Size1 < size) 00666 { 00667 size -= lbi.Size1; 00668 lbi.Size1 = lbi.Size2; 00669 lbi.Size2 = 0; 00670 lbi.Ptr1 = lbi.Ptr2; 00671 lbi.Ptr2 = 0; 00672 } 00673 00674 nlassert(lbi.Size1 >= size); 00675 lbi.Size1 -= size; 00676 lbi.Ptr1 += size/2; 00677 00678 _FillOffset += nbSample*2; 00679 nlassert(_FillOffset == (_FillOffset & 0xfffffffC)); 00680 _FillOffset &= _SizeMask; 00681 // if (_FillOffset >= _SecondaryBufferSize) 00682 // _FillOffset -= _SecondaryBufferSize; 00683 nlassert(_FillOffset < _SecondaryBufferSize); 00684 } |
|
|
|
|
|
|
|
Referenced by play(). |
|
Definition at line 627 of file source_dsound.cpp. References _XFadeSize, alpha, count, nlassert, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, sint, sint16, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, and uint.
00628 { 00629 // do the XFade in integer fixed point arithmetic 00630 00631 nlassert((_XFadeSize & 0x1) == 0); 00632 uint fade = _XFadeSize; 00633 sint16 *ptr = lbi.Ptr1; 00634 uint count = lbi.Size1 /2; 00635 sint alpha, invAlpha; 00636 00637 while (fade && count) 00638 { 00639 alpha = (fade<<16) / _XFadeSize; 00640 invAlpha = 0x10000 - alpha; 00641 *ptr = (*ptr*invAlpha) >> 16; 00642 ++ptr; 00643 --count; 00644 --fade; 00645 } 00646 00647 ptr = lbi.Ptr2; 00648 count = lbi.Size2 /2; 00649 00650 while (fade && count) 00651 { 00652 alpha = (fade<<16) / _XFadeSize; 00653 invAlpha = 0x10000 - alpha; 00654 *ptr = (*ptr*invAlpha) >> 16; 00655 ++ptr; 00656 --count; 00657 --fade; 00658 } 00659 } |
|
|
|
Definition at line 598 of file source_dsound.cpp. References _XFadeSize, alpha, count, nlassert, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, sint, sint16, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, and uint.
00599 { 00600 nlassert((_XFadeSize & 0x1) == 0); 00601 uint fade = _XFadeSize; 00602 sint16 *ptr = lbi.Ptr1; 00603 uint count = lbi.Size1/2; 00604 sint alpha; 00605 00606 while (fade && count) 00607 { 00608 alpha = (fade<<16) / _XFadeSize; 00609 *ptr = (*ptr*alpha) >> 16; 00610 ++ptr; 00611 --count; 00612 --fade; 00613 } 00614 00615 ptr = lbi.Ptr2; 00616 count = lbi.Size2/2; 00617 00618 while (fade && count) 00619 { 00620 alpha = (fade<<16) / _XFadeSize; 00621 *ptr = (*ptr*alpha) >> 16; 00622 ++ptr; 00623 --count; 00624 --fade; 00625 } 00626 } |
|
|
|
Definition at line 432 of file source_dsound.cpp. References _ADPCMState, _Sample, _SampleOffset, _SampleSize, data, NLSOUND::Mono16, NLSOUND::Mono16ADPCM, NLSOUND::Mono8, nlassert, nldebug, sint16, sint8, NLSOUND::Stereo16, NLSOUND::Stereo8, uint, and uint8.
00433 { 00434 nlassert((nbSample & 0xfffffffe) == nbSample); 00435 if (_Sample != 0) 00436 { 00437 void *data = ((CBufferDSound*) _Sample)->getData(); 00438 sint8 *data8; 00439 uint8 *dataAdpcm; 00440 sint16 *data16; 00441 uint i; 00442 00443 //nldebug("Filling from %p to %p (%p sample, %p bytes)", dst, dst+nbSample, nbSample, nbSample*2); 00444 00445 00446 switch(_Format) 00447 { 00448 case Mono8: 00449 data8 = (sint8*) data; 00450 data8 += _SampleOffset; 00451 // nldebug(" with data (Mono8) from %p to %p (sample : base = %p, size = %p)", data8, data8+nbSample, data, _SampleSize); 00452 for (i=0; i<nbSample; ++i) 00453 { 00454 dst[i] = sint16(data8[i])*256; 00455 } 00456 _SampleOffset += nbSample; 00457 break; 00458 case Mono16ADPCM: 00459 dataAdpcm = (uint8*) data; 00460 dataAdpcm += _SampleOffset/2; 00461 //nldebug("Filling ADPCM : %p => %p with %p to %p", dst, dst+nbSample, dataAdpcm - (uint8*)data, dataAdpcm + (nbSample/2)-(uint8*)data); 00462 //nldebug(" with data (Mono16ADPCM) from %p to %p (sample : base = %p, size = %p)", dataAdpcm, dataAdpcm+(nbSample/2), data, _SampleSize*2); 00463 IBuffer::decodeADPCM(dataAdpcm, dst, nbSample, _ADPCMState); 00464 _SampleOffset += nbSample; 00465 break; 00466 case Mono16: 00467 data16 = (sint16*)data; 00468 data16 += _SampleOffset; 00469 //nldebug("Filling Mono16 : %p => %p with %p to %p", dst, dst+nbSample, data16 - (sint16*)data, data16 + (nbSample)-(sint16*)data); 00470 // nldebug(" with data (Mono16) from %p to %p (sample : base = %p, size = %p)", data16, data16+nbSample, data, _SampleSize/2); 00471 CFastMem::memcpy(dst, data16, nbSample*2); 00472 _SampleOffset += nbSample; 00473 break; 00474 case Stereo8: 00475 data8 = (sint8*) data; 00476 data8 += _SampleOffset*2; 00477 for (i=0; i<nbSample; ++i) 00478 { 00479 dst[i] = (sint16(data8[i*2])*128) + (sint16(data8[i*2+1])*128); 00480 } 00481 _SampleOffset += nbSample*2; 00482 break; 00483 case Stereo16: 00484 data16 = (sint16*) data; 00485 data16 += _SampleOffset*2; 00486 for (i=0; i<nbSample; ++i) 00487 { 00488 dst[i] = (data16[i*2]>>1) + (data16[i*2+1]>>1); 00489 } 00490 _SampleOffset += nbSample*2; 00491 break; 00492 } 00493 00494 /* if (_SampleOffset == _SampleSize) 00495 { 00496 _SampleOffset = 0; 00497 _ADPCMState.PreviousSample = 0; 00498 _ADPCMState.StepIndex = 0; 00499 } 00500 */ 00501 00502 nlassert(_SampleOffset <= _SampleSize); 00503 } 00504 else 00505 { 00506 nldebug("Filling : NO DATA from %p to %p (%p sample, %p bytes)", dst, dst+nbSample, nbSample, nbSample*2); 00507 00508 // write silence in the dst. 00509 while (nbSample) 00510 { 00511 *dst++ = 0; 00512 --nbSample; 00513 } 00514 } 00515 } |
|
Definition at line 517 of file source_dsound.cpp. References min, nlassert, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, size, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, uint, and uint32. Referenced by play(), and update().
00518 { 00519 nlassert((nbSample & 0x1) == 0); 00520 /* nlassert(lbi.Size1 != 0); 00521 nlassert(lbi.Ptr1 != NULL); 00522 */ uint size = std::min(uint32(nbSample), lbi.Size1>>1); 00523 fillData(lbi.Ptr1, size); 00524 nbSample -= size; 00525 00526 if (nbSample) 00527 { 00528 /* nlassert(lbi.Size2 != 0); 00529 nlassert(lbi.Ptr2 != NULL); 00530 */ size = min(uint32(nbSample), lbi.Size2>>1); 00531 fillData(lbi.Ptr2, size); 00532 nbSample -= size; 00533 } 00534 nlassert(nbSample == 0); 00535 } |
|
Definition at line 537 of file source_dsound.cpp. References min, nlassert, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, sint16, size, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, uint, and uint32. Referenced by play(), stop(), and update().
00538 { 00539 uint size = min(uint32(nbSample), lbi.Size1>>1); 00540 uint tmp = size; 00541 sint16 *ptr = lbi.Ptr1; 00542 // nldebug("Silencing from %p to %p (%p sample, %p bytes)", ptr, ptr+size, size, size*2); 00543 00544 for (; size != 0; --size) 00545 *ptr++ = 0; 00546 nbSample -= tmp; 00547 00548 if (nbSample) 00549 { 00550 size = std::min(uint32(nbSample), lbi.Size2>>1); 00551 tmp = size; 00552 ptr = lbi.Ptr2; 00553 // nldebug("Silencing from %p to %p (%p sample, %p bytes)", ptr, ptr+size, size, size*2); 00554 for (; size != 0; --size) 00555 *ptr++ = 0; 00556 nbSample -= tmp; 00557 } 00558 nlassert(nbSample == 0); 00559 00560 } |
|
Returns the buffer associated with this source.
Definition at line 1803 of file source_dsound.cpp. References _Sample.
01804 { 01805 return _Sample; 01806 } |
|
Get the cone angles (in radian).
Implements NLSOUND::ISource. Definition at line 1745 of file source_dsound.cpp. References _3DBuffer, nlwarning, and NLMISC::Pi.
01746 { 01747 if (_3DBuffer != 0) 01748 { 01749 DWORD inner, outer; 01750 LONG volume; 01751 01752 if (_3DBuffer->GetConeAngles(&inner, &outer) != DS_OK) 01753 { 01754 nlwarning("GetConeAngles failed"); 01755 innerAngle = outerAngle = (float)(2.0 * Pi); 01756 } 01757 else 01758 { 01759 innerAngle = (float)(Pi * inner / 180.0); 01760 outerAngle = (float)(Pi * outer / 180.0); 01761 } 01762 01763 if (_3DBuffer->GetConeOutsideVolume(&volume) != DS_OK) 01764 { 01765 nlwarning("GetConeOutsideVolume failed"); 01766 outerGain = 0.0f; 01767 } 01768 else 01769 { 01770 outerGain = (float) pow(10, (double) volume / 20.0 / 100.0); 01771 } 01772 } 01773 else 01774 { 01775 nlwarning("Requested getCone on a non-3D source"); 01776 } 01777 } |
|
Definition at line 419 of file source_dsound.cpp. References _SecondaryBuffer, _SizeMask, _UpdateCopySize, min, NLSOUND::CSourceDSound::TCursors::PlayCursor, NLSOUND::CSourceDSound::TCursors::WriteCursor, and NLSOUND::CSourceDSound::TCursors::WriteSize. Referenced by play(), stop(), and update().
00420 { 00421 _SecondaryBuffer->GetCurrentPosition((DWORD*)&cursors.PlayCursor, (DWORD*)&cursors.WriteCursor); 00422 // add a security margin to the write cursor 00423 /* cursors.WriteCursor += _UpdateCopySize; 00424 if (cursors.WriteCursor > _SecondaryBufferSize) 00425 cursors.WriteCursor -= _SecondaryBufferSize; 00426 */ 00427 // compute the available write size 00428 // cursors.WriteSize = std::min(_UpdateCopySize, cursors.PlayCursor + _SecondaryBufferSize - cursors.WriteCursor); 00429 cursors.WriteSize = std::min(_UpdateCopySize, (cursors.PlayCursor - cursors.WriteCursor) & _SizeMask); 00430 } |
|
Get the direction vector.
Implements NLSOUND::ISource. Definition at line 1398 of file source_dsound.cpp. References _3DBuffer, nlwarning, NLMISC::CVector::set(), and v.
01399 { 01400 if (_3DBuffer != NULL) 01401 { 01402 D3DVECTOR v; 01403 01404 if (_3DBuffer->GetConeOrientation(&v) != DS_OK) 01405 { 01406 nlwarning("GetConeOrientation failed"); 01407 dir.set(0, 0, 1); 01408 } 01409 else 01410 { 01411 dir.set(v.x, v.z, v.y); 01412 } 01413 } 01414 else 01415 { 01416 dir.set(0, 0, 1); 01417 } 01418 } |
|
Get the gain.
Implements NLSOUND::ISource. Definition at line 1446 of file source_dsound.cpp.
01447 { 01448 return _Gain; 01449 } |
|
Return the looping state.
Implements NLSOUND::ISource. Definition at line 874 of file source_dsound.cpp. References _Loop.
00875 { 00876 return _Loop; 00877 } |
|
Get the min and max distances.
Implements NLSOUND::ISource. Definition at line 1580 of file source_dsound.cpp. References _3DBuffer, min, and nlwarning. Referenced by updateVolume().
01581 { 01582 if (_3DBuffer != 0) 01583 { 01584 D3DVALUE min, max; 01585 01586 if ((_3DBuffer->GetMinDistance(&min) != DS_OK) 01587 || (_3DBuffer->GetMaxDistance(&max) != DS_OK)) 01588 { 01589 mindist = 0.0f; 01590 maxdist = 0.0f; 01591 nlwarning("GetMinDistance or GetMaxDistance failed"); 01592 } 01593 else 01594 { 01595 mindist = min; 01596 maxdist = max; 01597 } 01598 } 01599 else 01600 { 01601 mindist = 0.0f; 01602 maxdist = 0.0f; 01603 nlwarning("Requested getMinMaxDistances on a non-3D source"); 01604 } 01605 } |
|
Get the pitch.
Implements NLSOUND::ISource. Definition at line 1480 of file source_dsound.cpp. References _Sample, _SecondaryBuffer, format, NLSOUND::IBuffer::getFormat(), nlwarning, NLSOUND::TSampleFormat, and uint.
01481 { 01482 if ((_Sample != 0) && (_SecondaryBuffer != 0)) 01483 { 01484 TSampleFormat format; 01485 uint freq0; 01486 DWORD freq; 01487 01488 _Sample->getFormat(format, freq0); 01489 01490 if (_SecondaryBuffer->GetFrequency(&freq) != DS_OK) 01491 { 01492 nlwarning("GetFrequency failed"); 01493 return 1.0; 01494 } 01495 01496 return ((float) freq / (float) freq0); 01497 } 01498 01499 return 1.0; 01500 } |
|
Get the position vector. See setPos() for details. Implements NLSOUND::ISource. Definition at line 1333 of file source_dsound.cpp. Referenced by updateVolume().
01334 { 01335 return _Pos; 01336 } |
|
Get the source relative mode.
Implements NLSOUND::ISource. Definition at line 1534 of file source_dsound.cpp. References _3DBuffer, and nlwarning.
01535 { 01536 if (_3DBuffer != 0) 01537 { 01538 DWORD mode; 01539 01540 if (_3DBuffer->GetMode(&mode) != DS_OK) 01541 { 01542 nlwarning("GetMode failed"); 01543 return false; 01544 } 01545 01546 return (mode == DS3DMODE_HEADRELATIVE); 01547 } 01548 else 01549 { 01550 nlwarning("Requested setSourceRelativeMode on a non-3D source"); 01551 return false; 01552 } 01553 } |
|
Return the buffer, or NULL if streaming is used.
Implements NLSOUND::ISource. Definition at line 409 of file source_dsound.cpp. References _NextSample, _Sample, _State, and source_swap_pending.
00410 { 00411 if (_State == source_swap_pending) 00412 return _NextSample; 00413 else 00414 return _Sample; 00415 00416 } |
|
Returns the number of milliseconds the source has been playing. Update the source (e.g. continue to stream the data in) Returns an indication whether the source actually streamed data or not. Reimplemented from NLSOUND::ISource. Definition at line 203 of file source_dsound.cpp. References _PlayOffset, _Sample, format, NLSOUND::IBuffer::getFormat(), NLSOUND::TSampleFormat, uint, and uint32.
|
|
Get the velocity vector.
Implements NLSOUND::ISource. Definition at line 1355 of file source_dsound.cpp. References _3DBuffer, nlwarning, NLMISC::CVector::set(), and v.
01356 { 01357 if (_3DBuffer != NULL) 01358 { 01359 D3DVECTOR v; 01360 01361 if (_3DBuffer->GetVelocity(&v) != DS_OK) 01362 { 01363 nlwarning ("GetVelocity failed"); 01364 vel.set(0, 0, 0); 01365 } 01366 else 01367 { 01368 vel.set(v.x, v.z, v.y); 01369 } 01370 } 01371 else 01372 { 01373 vel.set(0, 0, 0); 01374 } 01375 } |
|
Initialize the DirectSound buffers. Called by the sound driver only.
Definition at line 218 of file source_dsound.cpp. References _3DBuffer, _DefaultChannels, _DefaultSampleRate, _DefaultSampleSize, _SecondaryBuffer, _SecondaryBufferSize, NLSOUND::CSoundDriverDSound::countHw2DBuffers(), NLSOUND::CSoundDriverDSound::countHw3DBuffers(), format, nldebug, and nlwarning.
00219 { 00220 00221 // Initialize the buffer format 00222 WAVEFORMATEX format; 00223 00224 format.cbSize = sizeof(WAVEFORMATEX); 00225 format.nChannels = _DefaultChannels; 00226 format.wBitsPerSample = _DefaultSampleSize; 00227 format.nSamplesPerSec = _DefaultSampleRate; 00228 format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8; 00229 format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; 00230 format.wFormatTag = WAVE_FORMAT_PCM; 00231 00232 00233 // Initialize the buffer description 00234 00235 DSBUFFERDESC desc; 00236 00237 CSoundDriverDSound* driver = CSoundDriverDSound::instance(); 00238 00239 00240 ZeroMemory(&desc, sizeof(DSBUFFERDESC)); 00241 desc.dwSize = sizeof(DSBUFFERDESC); 00242 desc.lpwfxFormat = &format; 00243 desc.dwBufferBytes = _SecondaryBufferSize; 00244 desc.dwReserved = 0; 00245 00246 if (driver->countHw3DBuffers() > 0) 00247 { 00248 //nldebug("Source: Allocating 3D buffer in hardware"); 00249 desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCHARDWARE | DSBCAPS_GETCURRENTPOSITION2 00250 | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE; 00251 } 00252 else 00253 { 00254 if (useEax) 00255 { 00256 throw ESoundDriver("No 3d hardware sound buffer, but EAX support requested"); 00257 } 00258 //nldebug("Source: Allocating 3D buffer in software"); 00259 desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 00260 | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE; 00261 desc.guid3DAlgorithm = DS3DALG_NO_VIRTUALIZATION; 00262 //desc.guid3DAlgorithm = DS3DALG_HRTF_FULL; 00263 } 00264 00265 00266 // Allocate the secondary buffer 00267 00268 if (FAILED(directSound->CreateSoundBuffer(&desc, &_SecondaryBuffer, NULL))) 00269 { 00270 if (useEax) 00271 { 00272 throw ESoundDriver("Failed to create a 3d hardware sound buffer, but EAX support requested"); 00273 } 00274 nlwarning("Source: Failed to create a buffer with 3D capabilities."); 00275 00276 ZeroMemory(&desc, sizeof(DSBUFFERDESC)); 00277 desc.dwSize = sizeof(DSBUFFERDESC); 00278 desc.lpwfxFormat = &format; 00279 desc.dwBufferBytes = _SecondaryBufferSize; 00280 desc.dwReserved = 0; 00281 00282 if (driver->countHw2DBuffers() > 0) 00283 { 00284 //nldebug("Source: Allocating 2D buffer in hardware"); 00285 desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCHARDWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; 00286 } 00287 else 00288 { 00289 //nldebug("Source: Allocating 2D buffer in software"); 00290 desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; 00291 } 00292 00293 if (FAILED(directSound->CreateSoundBuffer(&desc, &_SecondaryBuffer, NULL))) 00294 { 00295 throw ESoundDriver("Failed to allocate the DirectSound secondary buffer"); 00296 } 00297 } 00298 00299 00300 nldebug("Created DirectX secondary buffer @ %p", _SecondaryBuffer); 00301 00302 // Fill the buffer with silence 00303 LPVOID ptr; 00304 DWORD bytes; 00305 00306 if (FAILED(_SecondaryBuffer->Lock(0, 0, &ptr, &bytes, NULL, NULL, DSBLOCK_ENTIREBUFFER))) 00307 { 00308 throw ESoundDriver("Failed to lock the DirectSound secondary buffer"); 00309 } 00310 00311 memset(ptr, 0, bytes); 00312 00313 _SecondaryBuffer->Unlock(ptr, bytes, 0, 0); 00314 00315 // Allocate the 3D interface, if necessary 00316 00317 if (FAILED(_SecondaryBuffer->QueryInterface(IID_IDirectSound3DBuffer, (LPVOID *) &_3DBuffer))) 00318 { 00319 throw ESoundDriver("Failed to allocate the DirectSound 3D buffer"); 00320 } 00321 00322 00323 if (FAILED(_SecondaryBuffer->Play(0, 0, DSBPLAY_LOOPING))) 00324 { 00325 throw ESoundDriver("Play failed"); 00326 } 00327 00328 } |
|
Return the paused state.
Definition at line 1030 of file source_dsound.cpp. References nlassert.
01031 { 01032 // TODO 01033 nlassert(false); 01034 return false; 01035 // return (_UserState == NL_DSOUND_PAUSED); 01036 } |
|
Return the playing state.
Implements NLSOUND::ISource. Definition at line 1021 of file source_dsound.cpp. References _State, source_playing, and source_swap_pending.
01022 { 01023 // return (_UserState == NL_DSOUND_PLAYING); 01024 return _State == source_playing || _State == source_swap_pending; 01025 } |
|
Return true if playing is finished or stop() has been called.
Implements NLSOUND::ISource. Definition at line 1041 of file source_dsound.cpp. References _State, source_silencing, and source_stoped.
01042 { 01043 return _State == source_silencing || _State == source_stoped; 01044 // return (_UserState == NL_DSOUND_STOPPED); 01045 } |
|
Definition at line 1811 of file source_dsound.cpp. References _SecondaryBuffer, nlwarning, offset, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, size, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, and uint32. Referenced by play(), stop(), and update().
01812 { 01813 HRESULT hr = _SecondaryBuffer->Lock(offset, size, (LPVOID*) &lbi.Ptr1, (DWORD*) &lbi.Size1, (LPVOID*) &lbi.Ptr2, (DWORD*) &lbi.Size2, 0); 01814 01815 if (hr == DSERR_BUFFERLOST) 01816 { 01817 // If the buffer got lost somehow, try to restore it. 01818 if (FAILED(_SecondaryBuffer->Restore())) 01819 { 01820 nlwarning("Lock failed (1)"); 01821 return false; 01822 } 01823 if (FAILED(_SecondaryBuffer->Lock(offset, size, (LPVOID*) &lbi.Ptr1, (DWORD*)&lbi.Size1, (LPVOID*) &lbi.Ptr2, (DWORD*)&lbi.Size2, 0))) 01824 { 01825 nlwarning("Lock failed (2)"); 01826 return false; 01827 } 01828 } 01829 else if (hr != DS_OK) 01830 { 01831 nlwarning("Lock failed (3)"); 01832 return false; 01833 } 01834 01835 return true; 01836 } |
|
Check whether the play position has advanced enough to require an update.
Definition at line 1050 of file source_dsound.cpp. References _State, source_playing, source_silencing, and source_swap_pending.
01051 { 01052 return _State == source_silencing || _State == source_playing || _State == source_swap_pending; 01053 } |
|
Pause. Call play() to resume.
Implements NLSOUND::ISource. Definition at line 997 of file source_dsound.cpp. References nlassert.
00998 { 00999 // TODO : recode this ! 01000 nlassert(false); 01001 /* EnterCriticalSection(&_CriticalSection); 01002 01003 TSourceDSoundUserState old = _UserState; 01004 01005 _UserState = NL_DSOUND_PAUSED; 01006 DBGPOS(("[%p] PAUZ: PAUSED", this)); 01007 01008 //nldebug ("NLOUND: pause %p", this); 01009 01010 if (old == NL_DSOUND_PLAYING) 01011 { 01012 fadeOut(); 01013 } 01014 01015 LeaveCriticalSection(&_CriticalSection); 01016 */ 01017 } |
|
Play the static buffer (or stream in and play).
Implements NLSOUND::ISource. Definition at line 688 of file source_dsound.cpp. References _ADPCMState, _CriticalSection, _FillOffset, _LastPlayPos, _Loop, _NextSample, _PlayOffset, _Sample, _SampleFreq, _SampleOffset, _SampleSize, _SilenceWriten, _State, _XFadeSize, advanceFill(), fadeIn(), fillData(), fillSilence(), getCursors(), NLSOUND::IBuffer::getFormat(), NLSOUND::CListenerDSound::getPos(), NLSOUND::IBuffer::getSize(), lock(), min, NLSOUND::Mono16, NLSOUND::Mono16ADPCM, NLSOUND::Mono8, nlassert, nlwarning, NLSOUND::CSourceDSound::TCursors::PlayCursor, NLSOUND::IBuffer::TADPCMState::PreviousSample, sint16, source_playing, source_silencing, source_swap_pending, NLSOUND::IBuffer::TADPCMState::StepIndex, NLSOUND::Stereo16, NLSOUND::Stereo8, uint, unlock(), updateVolume(), NLSOUND::CSourceDSound::TCursors::WriteCursor, NLSOUND::CSourceDSound::TCursors::WriteSize, and xfade().
00689 { 00690 // nldebug("Play"); 00691 EnterCriticalSection(&_CriticalSection); 00692 00693 _SilenceWriten = 0; 00694 00695 // uint32 writeSize = checkFillCursor(); 00696 TCursors cursors; 00697 getCursors(cursors); 00698 00699 // set a new filling point 00700 _FillOffset = cursors.WriteCursor; 00701 _FillOffset = (_FillOffset+3) & 0xfffffffC; 00702 cursors.WriteCursor = _FillOffset; 00703 00704 TLockedBufferInfo lbi; 00705 if (lock(_FillOffset, cursors.WriteSize, lbi)) 00706 { 00707 TLockedBufferInfo unlockInfo(lbi); 00708 // ok, the buffer is locked, write data 00709 if (_State == source_swap_pending) 00710 { 00711 // we swap the buffer. 00712 _Sample = _NextSample; 00713 _NextSample = 0; 00714 if (_Sample != 0) 00715 { 00716 _Sample->getFormat(_Format, _SampleFreq); 00717 switch(_Format) 00718 { 00719 case Mono8: 00720 _SampleSize = _Sample->getSize(); 00721 break; 00722 case Mono16: 00723 _SampleSize = _Sample->getSize() / 2; 00724 break; 00725 case Mono16ADPCM: 00726 _SampleSize = _Sample->getSize() * 2; 00727 break; 00728 case Stereo8: 00729 _SampleSize = _Sample->getSize() / 2; 00730 break; 00731 case Stereo16: 00732 _SampleSize = _Sample->getSize() / 4; 00733 break; 00734 } 00735 _State = source_playing; 00736 } 00737 else 00738 { 00739 _SampleSize = 0; 00740 _State = source_silencing; 00741 } 00742 } 00743 _LastPlayPos = cursors.PlayCursor; 00744 _SampleOffset = 0; 00745 _PlayOffset = 0; 00746 _ADPCMState.PreviousSample = 0; 00747 _ADPCMState.StepIndex = 0; 00748 // Compute the size of data to write. 00749 uint dataToFill = std::min(uint(cursors.WriteSize / 2), _SampleSize - _SampleOffset); 00750 dataToFill &= 0xfffffffe; 00751 // ok, the buffer is locked, write data 00752 if (_State == source_playing || _State == source_silencing) 00753 { 00754 // we need a little XFade 00755 sint16 fadeBuffer[_XFadeSize]; 00756 fillData(fadeBuffer, _XFadeSize); 00757 xfade(lbi, fadeBuffer); 00758 advanceFill(lbi, _XFadeSize); 00759 cursors.WriteSize -= _XFadeSize*2; 00760 dataToFill -= _XFadeSize; 00761 } 00762 else 00763 { 00764 // we need a little FadeIn 00765 fillData(lbi, _XFadeSize); 00766 fadeIn(lbi); 00767 advanceFill(lbi, _XFadeSize); 00768 cursors.WriteSize -= _XFadeSize*2; 00769 dataToFill -= _XFadeSize; 00770 } 00771 fillData(lbi, dataToFill); 00772 cursors.WriteSize -= dataToFill * 2; 00773 advanceFill(lbi, dataToFill); 00774 _State = source_playing; 00775 if (_Loop) 00776 { 00777 while (cursors.WriteSize >= 4) 00778 { 00779 if (_SampleOffset == _SampleSize) 00780 { 00781 // rewind the sample 00782 _SampleOffset = 0; 00783 _ADPCMState.PreviousSample = 0; 00784 _ADPCMState.StepIndex = 0; 00785 } 00786 nlassert(_SampleOffset < _SampleSize); 00787 dataToFill = std::min(uint(cursors.WriteSize / 2), _SampleSize - _SampleOffset); 00788 dataToFill &= 0xfffffffe; 00789 fillData(lbi, dataToFill); 00790 advanceFill(lbi, dataToFill); 00791 cursors.WriteSize -= dataToFill*2; 00792 } 00793 } 00794 else 00795 { 00796 if (_SampleOffset == _SampleSize) 00797 { 00798 // begin to write silence, but stil in play state until all sample are played 00799 // _State = source_silencing; 00800 fillSilence(lbi, cursors.WriteSize/2); 00801 advanceFill(lbi, cursors.WriteSize/2); 00802 _SilenceWriten = cursors.WriteSize; 00803 cursors.WriteSize = 0; 00804 } 00805 // else 00806 // _State = source_playing; 00807 } 00808 00809 00810 unlock(unlockInfo); 00811 } 00812 else 00813 { 00814 nlwarning("Couldn't lock the sound buffer for %u bytes", cursors.WriteSize); 00815 } 00816 00817 // set the volume NOW 00818 CListenerDSound* listener = CListenerDSound::instance(); 00819 00820 updateVolume(listener->getPos()); 00821 00822 LeaveCriticalSection(&_CriticalSection); 00823 00824 return true; 00825 } |
|
Release all DirectSound resources.
Definition at line 171 of file source_dsound.cpp. References _3DBuffer, and _SecondaryBuffer. Referenced by ~CSourceDSound().
00172 { 00173 // _Buffer = 0; 00174 00175 #if EAX_AVAILABLE == 1 00176 if (_EAXSource != 0) 00177 { 00178 _EAXSource->Release(); 00179 _EAXSource = 0; 00180 } 00181 #endif 00182 00183 if (_SecondaryBuffer != 0) 00184 { 00185 _SecondaryBuffer->Stop(); 00186 } 00187 00188 if (_3DBuffer != 0) 00189 { 00190 _3DBuffer->Release(); 00191 _3DBuffer = 0; 00192 } 00193 00194 if (_SecondaryBuffer != 0) 00195 { 00196 _SecondaryBuffer->Release(); 00197 _SecondaryBuffer = 0; 00198 } 00199 00200 } |
|
Definition at line 332 of file source_dsound.cpp. References setGain(), setLooping(), and setPitch().
00333 { 00334 setPitch(1.0f); 00335 setLooping(false); 00336 setGain(1.0f); 00337 } |
|
Set the alpha value for the volume-distance curve alpha = 0.0: the volume will decrease linearly between 0dB and -100 dB alpha = 1.0: the volume will decrease linearly between 1.0 and 0.0 (linear scale) alpha = -1.0: the volume will decrease inversely with the distance (1/dist). This is the default used by DirectSound/OpenAL For any other value of alpha, an interpolation is be done between the two adjacent curves. For example, if alpha equals 0.5, the volume will be halfway between the linear dB curve and the linear amplitude curve. Reimplemented from NLSOUND::ISource. Definition at line 265 of file source_dsound.h. References _Alpha.
00265 { _Alpha = a; } |
|
Set the cone angles (in radian) and gain (in [0 , 1]) (default: 2PI, 2PI, 0) (3D mode only).
Implements NLSOUND::ISource. Definition at line 1671 of file source_dsound.cpp. References _3DBuffer, nlwarning, and NLMISC::Pi.
01672 { 01673 if (_3DBuffer != 0) 01674 { 01675 // Set the cone angles 01676 01677 // Convert from radians to degrees 01678 DWORD inner = (DWORD)(180.0 * innerAngle / Pi); 01679 DWORD outer = (DWORD)(180.0 * outerAngle / Pi); 01680 01681 01682 // Sanity check: wrap the angles in the [0,360] interval 01683 if (outer < inner) 01684 { 01685 outer = inner; 01686 } 01687 01688 while (inner < DS3D_MINCONEANGLE) 01689 { 01690 inner += 360; 01691 } 01692 01693 while (inner > DS3D_MAXCONEANGLE) 01694 { 01695 inner -= 360; 01696 } 01697 01698 while (outer < DS3D_MINCONEANGLE) 01699 { 01700 outer += 360; 01701 } 01702 01703 while (outer > DS3D_MAXCONEANGLE) 01704 { 01705 outer -= 360; 01706 } 01707 01708 if (_3DBuffer->SetConeAngles(inner, outer, DS3D_DEFERRED) != DS_OK) 01709 { 01710 nlwarning("SetConeAngles failed"); 01711 } 01712 01713 // Set the outside volume 01714 if (outerGain < 0.00001f) 01715 { 01716 outerGain = 0.00001f; 01717 } 01718 01719 // convert from linear amplitude to hundredths of decibels 01720 LONG volume = (LONG)(100.0 * 20.0 * log10(outerGain)); 01721 01722 if (volume < DSBVOLUME_MIN) 01723 { 01724 volume = DSBVOLUME_MIN; 01725 } 01726 else if (volume > DSBVOLUME_MAX) 01727 { 01728 volume = DSBVOLUME_MAX; 01729 } 01730 01731 if (_3DBuffer->SetConeOutsideVolume(volume, DS3D_DEFERRED) != DS_OK) 01732 { 01733 nlwarning("SetConeOutsideVolume failed"); 01734 } 01735 01736 } 01737 else 01738 { 01739 nlwarning("Requested setCone on a non-3D source"); 01740 } 01741 } |
|
Set the direction vector (3D mode only) (default: (0,0,0) as non-directional).
Implements NLSOUND::ISource. Definition at line 1380 of file source_dsound.cpp. References _3DBuffer, nlwarning, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.
01381 { 01382 if (_3DBuffer != 0) 01383 { 01384 if (_3DBuffer->SetConeOrientation(dir.x, dir.z, dir.y, DS3D_DEFERRED) != DS_OK) 01385 { 01386 nlwarning ("SetConeOrientation failed (x=%.2f, y=%.2f, z=%.2f)", dir.x, dir.y, dir.z); 01387 } 01388 else 01389 { 01390 //nlwarning ("NLSOUND: %p set source direction NEL(p:%.2f/%.2f/%.2f) DS(p:%.2f/%.2f/%.2f)", this, dir.x, dir.y, dir.z, dir.x, dir.z, dir.y); 01391 } 01392 } 01393 } |
|
Set any EAX source property if EAX available.
Implements NLSOUND::ISource. Definition at line 1781 of file source_dsound.cpp. References H_AUTO, res, uint, and value.
01782 { 01783 #if EAX_AVAILABLE == 1 01784 if (_EAXSource == 0) 01785 { 01786 _EAXSource = CSoundDriverDSound::instance()->createPropertySet(this); 01787 } 01788 if ( _EAXSource != NULL ) 01789 { 01790 H_AUTO(NLSOUND_EAXPropertySet_Set) 01791 HRESULT res = _EAXSource->Set( DSPROPSETID_EAX_BufferProperties, prop, NULL, 0, value, valuesize ); 01792 if (res != S_OK) 01793 { 01794 // nlwarning("Setting EAX Param #%u fail : %x", prop, res); 01795 } 01796 } 01797 #endif 01798 } |
|
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 1423 of file source_dsound.cpp. References NLMISC::clamp(), and uint32. Referenced by reset().
01424 { 01425 clamp(gain, 0.00001f, 1.0f); 01426 _Gain = gain; 01427 01428 /* convert from linear amplitude to hundredths of decibels */ 01429 _Volume = (uint32)(100.0 * 20.0 * log10(gain)); 01430 clamp(_Volume, DSBVOLUME_MIN, DSBVOLUME_MAX); 01431 01432 //nlwarning ("set gain %f vol %d", gain, _Volume); 01433 01434 /* 01435 if ((_SecondaryBuffer != 0) && (_SecondaryBuffer->SetVolume(_Volume) != DS_OK)) 01436 { 01437 nlwarning("SetVolume failed"); 01438 } 01439 */ 01440 } |
|
Set looping on/off for future playbacks (default: off).
Implements NLSOUND::ISource. Definition at line 866 of file source_dsound.cpp. References _Loop. Referenced by reset().
|
|
Set the min and max distances (default: 1, MAX_FLOAT) (3D mode only).
Implements NLSOUND::ISource. Definition at line 1558 of file source_dsound.cpp. References _3DBuffer, and nlwarning.
01559 { 01560 if (_3DBuffer != 0) 01561 { 01562 if (_3DBuffer->SetMinDistance(std::max(DS3D_DEFAULTMINDISTANCE, mindist), deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK) 01563 { 01564 nlwarning("SetMinDistance (%f) failed", mindist); 01565 } 01566 if (_3DBuffer->SetMaxDistance(std::min(DS3D_DEFAULTMAXDISTANCE, maxdist), deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK) 01567 { 01568 nlwarning("SetMaxDistance (%f) failed", maxdist); 01569 } 01570 } 01571 else 01572 { 01573 nlwarning("Requested setMinMaxDistances on a non-3D source"); 01574 } 01575 } |
|
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 1454 of file source_dsound.cpp. References _Sample, _SampleRate, _SecondaryBuffer, format, NLSOUND::IBuffer::getFormat(), nlwarning, NLSOUND::TSampleFormat, uint, and uint32. Referenced by reset().
01455 { 01456 // _Freq = coeff; 01457 01458 if ((_Sample != 0) && (_SecondaryBuffer != 0)) 01459 { 01460 TSampleFormat format; 01461 uint freq; 01462 01463 _Sample->getFormat(format, freq); 01464 01465 _SampleRate = (uint32) (coeff * (float) freq); 01466 01467 //nlwarning("Freq=%d", newfreq); 01468 01469 if (_SecondaryBuffer->SetFrequency(_SampleRate) != DS_OK) 01470 { 01471 // nlwarning("SetFrequency failed (buffer freq=%d, NeL freq=%.5f, DSound freq=%d)", freq, coeff, newfreq); 01472 nlwarning("SetFrequency"); 01473 } 01474 } 01475 } |
|
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 1313 of file source_dsound.cpp. References _3DBuffer, and nlwarning.
01314 { 01315 _Pos = pos; 01316 // Coordinate system: conversion from NeL to OpenAL/GL: 01317 if (_3DBuffer != NULL) 01318 { 01319 if (_3DBuffer->SetPosition(pos.x, pos.z, pos.y, deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK) 01320 { 01321 nlwarning ("SetPosition failed"); 01322 } 01323 else 01324 { 01325 //nlwarning ("%p set source NEL(p:%.2f/%.2f/%.2f) DS(p:%.2f/%.2f/%.2f)", this, pos.x, pos.y, pos.z, pos.x, pos.z, pos.y); 01326 } 01327 } 01328 } |
|
Set the source relative mode. If true, positions are interpreted relative to the listener position (default: false).
Implements NLSOUND::ISource. Definition at line 1505 of file source_dsound.cpp. References _3DBuffer, and nlwarning.
01506 { 01507 if (_3DBuffer != 0) 01508 { 01509 HRESULT hr; 01510 01511 if (mode) 01512 { 01513 hr = _3DBuffer->SetMode(DS3DMODE_HEADRELATIVE, DS3D_IMMEDIATE); 01514 } 01515 else 01516 { 01517 hr = _3DBuffer->SetMode(DS3DMODE_NORMAL, DS3D_IMMEDIATE); 01518 } 01519 01520 if (hr != DS_OK) 01521 { 01522 nlwarning("SetMode failed"); 01523 } 01524 } 01525 else 01526 { 01527 nlwarning("Requested setSourceRelativeMode on a non-3D source"); 01528 } 01529 } |
|
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 342 of file source_dsound.cpp. References _ADPCMState, _CriticalSection, _NextSample, _PlayOffset, _Sample, _SampleFreq, _SampleOffset, _SampleSize, _State, buffer, NLSOUND::Mono16, NLSOUND::Mono16ADPCM, NLSOUND::Mono8, NLSOUND::IBuffer::TADPCMState::PreviousSample, source_playing, source_swap_pending, NLSOUND::IBuffer::TADPCMState::StepIndex, NLSOUND::Stereo16, and NLSOUND::Stereo8.
00343 { 00344 EnterCriticalSection(&_CriticalSection); 00345 00346 if (_State == source_playing) 00347 { 00348 _State = source_swap_pending; 00349 _Sample = 0; 00350 _NextSample = buffer; 00351 _SampleOffset = 0; 00352 _PlayOffset = 0; 00353 } 00354 else 00355 { 00356 _Sample = buffer; 00357 _NextSample = 0; 00358 _SampleOffset = 0; 00359 _PlayOffset = 0; 00360 _ADPCMState.PreviousSample = 0; 00361 _ADPCMState.StepIndex = 0; 00362 if (buffer) 00363 { 00364 // _SampleSize = buffer->getSize(); 00365 buffer->getFormat(_Format, _SampleFreq); 00366 switch(_Format) 00367 { 00368 case Mono8: 00369 _SampleSize = buffer->getSize(); 00370 break; 00371 case Mono16: 00372 _SampleSize = buffer->getSize() / 2; 00373 break; 00374 case Mono16ADPCM: 00375 _SampleSize = buffer->getSize() * 2; 00376 break; 00377 case Stereo8: 00378 _SampleSize = buffer->getSize() / 2; 00379 break; 00380 case Stereo16: 00381 _SampleSize = buffer->getSize() / 4; 00382 break; 00383 } 00384 } 00385 } 00386 00387 /* 00388 // If the user calls setStaticBuffer with a null buffer, 00389 // stop the currently playing buffer and set it to null. 00390 // Otherwise, store the buffer in the swap buffer variable. 00391 // A crossfade between the current buffer and the swap buffer 00392 // will be done when the user calls play. 00393 if (buffer == 0) 00394 { 00395 stop(); 00396 _Buffer = 0; 00397 _BufferSize = 0; 00398 _BytesWritten = 0; 00399 } 00400 00401 _SwapBuffer = _Buffer = buffer; 00402 00403 _ADPCMState.PreviousSample = 0; 00404 _ADPCMState.StepIndex = 0; 00405 */ 00406 LeaveCriticalSection(&_CriticalSection); 00407 } |
|
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 1341 of file source_dsound.cpp. References _3DBuffer, nlwarning, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.
|
|
|
|
Return the OpenAL source name.
Definition at line 242 of file source_dsound.h. References _SourceName, and uint.
00242 { return _SourceName; } |
|
Stop playing.
Implements NLSOUND::ISource. Definition at line 827 of file source_dsound.cpp. References _CriticalSection, _FillOffset, _SilenceWriten, _State, _XFadeSize, advanceFill(), fadeOut(), fillSilence(), getCursors(), lock(), source_silencing, source_stoped, unlock(), NLSOUND::CSourceDSound::TCursors::WriteCursor, and NLSOUND::CSourceDSound::TCursors::WriteSize.
00828 { 00829 // nldebug("Stop"); 00830 EnterCriticalSection(&_CriticalSection); 00831 00832 if (_State != source_stoped && _State != source_silencing) 00833 { 00834 // retreive the cursors; 00835 TCursors cursors; 00836 getCursors(cursors); 00837 00838 _FillOffset = cursors.WriteCursor; 00839 _FillOffset = (_FillOffset+3) & 0xfffffffC; 00840 00841 TLockedBufferInfo lbi; 00842 if (lock(_FillOffset, cursors.WriteSize, lbi)) 00843 { 00844 TLockedBufferInfo unlockInfo(lbi); 00845 00846 fadeOut(lbi); 00847 advanceFill(lbi, _XFadeSize); 00848 cursors.WriteSize -= _XFadeSize*2; 00849 fillSilence(lbi, cursors.WriteSize/2); 00850 advanceFill(lbi, cursors.WriteSize/2); 00851 _SilenceWriten = cursors.WriteSize; 00852 00853 _State = source_silencing; 00854 00855 unlock(unlockInfo); 00856 } 00857 } 00858 00859 LeaveCriticalSection(&_CriticalSection); 00860 } |
|
|
|
Definition at line 1868 of file source_dsound.cpp. References _SecondaryBuffer, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, and NLSOUND::CSourceDSound::TLockedBufferInfo::Size2. Referenced by play(), stop(), and update().
01869 { 01870 _SecondaryBuffer->Unlock(lbi.Ptr1, lbi.Size1, lbi.Ptr2, lbi.Size2); 01871 return true; 01872 } |
|
Update the source (e.g. continue to stream the data in).
Implements NLSOUND::ISource. Definition at line 1059 of file source_dsound.cpp. References _ADPCMState, _CriticalSection, _FillOffset, _LastPlayPos, _Loop, _PlayOffset, _SampleOffset, _SampleSize, _SecondaryBufferSize, _SilenceWriten, _SizeMask, _State, _UpdateCopySize, _XFadeSize, advanceFill(), fadeOut(), fillData(), fillSilence(), getCursors(), H_AUTO, lock(), min, nlassert, nlwarning, NLSOUND::CSourceDSound::TCursors::PlayCursor, NLSOUND::IBuffer::TADPCMState::PreviousSample, source_playing, source_silencing, source_stoped, source_swap_pending, NLSOUND::IBuffer::TADPCMState::StepIndex, uint, uint32, unlock(), NLSOUND::CSourceDSound::TCursors::WriteCursor, and NLSOUND::CSourceDSound::TCursors::WriteSize.
01060 { 01061 H_AUTO(NLSOUND_SourceDSoundUpdate) 01062 bool updateDone = false; 01063 01064 EnterCriticalSection(&_CriticalSection); 01065 01066 // fill some data into the buffer 01067 TCursors cursors; 01068 getCursors(cursors); 01069 uint32 writeSize; 01070 01071 // The total size available for fill (between fillOffset and play cusors) 01072 uint32 fillSize = (cursors.PlayCursor - _FillOffset) & _SizeMask; 01073 // The play margin (between play and write cursor) 01074 uint32 margin = (cursors.WriteCursor - cursors.PlayCursor) & _SizeMask; 01075 // The number of sample played since previous update 01076 uint32 samplePlayed = ((cursors.PlayCursor - _LastPlayPos) & _SizeMask) / 2; 01077 _LastPlayPos = cursors.PlayCursor; 01078 01079 01080 // if (_FillOffset < cursors.WriteCursor && _FillOffset >cursors.PlayCursor) 01081 if (fillSize + margin > _SecondaryBufferSize) 01082 { 01083 // arg ! 01084 nlwarning("FillOffset is between play and write cursor (P = %p F = %p W = %p!", cursors.PlayCursor, _FillOffset, cursors.WriteCursor); 01085 _FillOffset = cursors.WriteCursor; 01086 _FillOffset = (_FillOffset+3) & 0xfffffffC; 01087 _SilenceWriten = 0; 01088 nlassert(_FillOffset < _SecondaryBufferSize); 01089 } 01090 01091 // advance of the fill offset over the write cursor 01092 uint32 advance = (_FillOffset - cursors.WriteCursor) & _SizeMask; 01093 01094 /* nldebug("Play = %p, Write = %p, Fill = %p, FillSize = %p, Margin = %p, Advance = %p", 01095 cursors.PlayCursor, cursors.WriteCursor, _FillOffset, fillSize, margin, advance); 01096 */ 01097 if (advance > _UpdateCopySize) 01098 { 01099 // enougth data wrote, wait until next update 01100 cursors.WriteSize = 0; 01101 } 01102 /* if (cursors.WriteSize) 01103 { 01104 if (_FillOffset < cursors.WriteCursor) 01105 { 01106 if (_FillOffset > cursors.WriteCursor + _UpdateCopySize - _SecondaryBufferSize ) 01107 { 01108 // nlwarning("Enougth data wrote"); 01109 // already fill enough data 01110 cursors.WriteSize = 0; 01111 } 01112 } 01113 else 01114 { 01115 if (_FillOffset > cursors.WriteCursor + _UpdateCopySize) 01116 { 01117 // nlwarning("Enougth data wrote"); 01118 // already fill enough data 01119 cursors.WriteSize = 0; 01120 } 01121 } 01122 } 01123 */ 01124 // nldebug("Cursors : Play = %p, Write = %p, Fill = %p", cursors.PlayCursor, cursors.WriteCursor, _FillOffset); 01125 01126 cursors.WriteCursor = _FillOffset; 01127 writeSize = cursors.WriteSize; // compute the real played sample offset 01128 01129 // update the real number of played sample 01130 if (_State == source_playing) 01131 _PlayOffset += samplePlayed; 01132 01133 if (writeSize >= _UpdateCopySize) 01134 { 01135 // nldebug("Update %p bytes", _UpdateCopySize); 01136 writeSize = _UpdateCopySize; 01137 updateDone = true; 01138 TLockedBufferInfo lbi; 01139 if (lock(_FillOffset, writeSize, lbi)) 01140 { 01141 TLockedBufferInfo unlockInfo(lbi); 01142 if (_State == source_playing) 01143 { 01144 nlassert(_SampleOffset <= _SampleSize); 01145 uint32 updateSize = min(_SampleSize - _SampleOffset, uint(writeSize/2)); 01146 updateSize &= 0xfffffffe; 01147 fillData(lbi, updateSize); 01148 advanceFill(lbi, updateSize); 01149 writeSize -= updateSize*2; 01150 01151 if (_Loop) 01152 { 01153 while (_PlayOffset >= _SampleSize) 01154 _PlayOffset -= _SampleSize; 01155 01156 // repeat until we have at least 2 sample to write 01157 while (writeSize >= 4) 01158 { 01159 if (_SampleOffset == _SampleSize) 01160 { 01161 // rewind the sample 01162 _SampleOffset = 0; 01163 _ADPCMState.PreviousSample = 0; 01164 _ADPCMState.StepIndex = 0; 01165 } 01166 01167 updateSize = min(_SampleSize - _SampleOffset, uint(writeSize/2)); 01168 updateSize &= 0xfffffffe; 01169 fillData(lbi, updateSize); 01170 advanceFill(lbi, updateSize); 01171 writeSize -= updateSize*2; 01172 } 01173 } 01174 else 01175 { 01176 if (_SampleOffset == _SampleSize) 01177 { 01178 fillSilence(lbi, writeSize/2); 01179 advanceFill(lbi, writeSize/2); 01180 _SilenceWriten += writeSize; 01181 } 01182 if (_PlayOffset >= _SampleSize) 01183 { 01184 // all the sample is played, no we are in silencing state ! 01185 _PlayOffset = _SampleSize; 01186 _State = source_silencing; 01187 } 01188 } 01189 01190 } 01191 else if (_State == source_swap_pending) 01192 { 01193 // the sample has been changed but not replayed yet ? so we 'stop' the old buffer 01194 01195 fadeOut(lbi); 01196 advanceFill(lbi, _XFadeSize); 01197 writeSize -= _XFadeSize*2; 01198 fillSilence(lbi, writeSize/2); 01199 advanceFill(lbi, writeSize/2); 01200 _SilenceWriten = writeSize; 01201 _State = source_silencing; 01202 } 01203 else if (_State == source_silencing) 01204 { 01205 // write silence into the buffer. 01206 uint32 updateSize = min(writeSize, _SecondaryBufferSize - _SilenceWriten); 01207 updateSize &= 0xfffffffC; 01208 fillSilence(lbi, updateSize/2); 01209 advanceFill(lbi, updateSize/2); 01210 _SilenceWriten += updateSize; 01211 01212 if (_SilenceWriten == _SecondaryBufferSize) 01213 _State = source_stoped; 01214 } 01215 else 01216 { 01217 nlwarning("Update not needed !"); 01218 } 01219 01220 unlock(unlockInfo); 01221 } 01222 } 01223 01224 LeaveCriticalSection(&_CriticalSection); 01225 01226 return updateDone; 01227 } |
|
Update the source's volume according to its distance and fade out curve. It takes the current position of the listener as argument. Definition at line 1608 of file source_dsound.cpp. References _Alpha, _SecondaryBuffer, NLMISC::clamp(), getMinMaxDistances(), getPos(), min, sint32, and NLMISC::CVector::sqrnorm(). Referenced by play().
01609 { 01610 #if MANUAL_ROLLOFF == 1 01611 _SecondaryBuffer->SetVolume(_Volume); 01612 return; 01613 #endif 01614 01615 CVector pos = getPos(); 01616 pos -= listener; 01617 01618 float sqrdist = pos.sqrnorm(); 01619 float min, max; 01620 01621 getMinMaxDistances(min, max); 01622 01623 if (sqrdist < min * min) 01624 { 01625 _SecondaryBuffer->SetVolume(_Volume); 01626 //nlwarning("VOLUME = %ddB, rolloff = %0.2f", _Volume/100, CListenerDSound::instance()->getRolloffFactor()); 01627 } 01628 else if (sqrdist > max * max) 01629 { 01630 _SecondaryBuffer->SetVolume(DSBVOLUME_MIN); 01631 //nlwarning("VOLUME = %ddB, rolloff = %0.2f", DSBVOLUME_MIN/100, CListenerDSound::instance()->getRolloffFactor()); 01632 } 01633 else 01634 { 01635 sint32 db = _Volume; 01636 01637 double dist = (double) sqrt(sqrdist); 01638 01639 // linearly descending volume on a dB scale 01640 double db1 = DSBVOLUME_MIN * (dist - min) / (max - min); 01641 01642 if (_Alpha == 0.0) { 01643 db += (sint32) db1; 01644 01645 } else if (_Alpha > 0.0) { 01646 double amp2 = 0.0001 + 0.9999 * (max - dist) / (max - min); // linear amp between 0.00001 and 1.0 01647 double db2 = 2000.0 * log10(amp2); // covert to 1/100th decibels 01648 db += (sint32) ((1.0 - _Alpha) * db1 + _Alpha * db2); 01649 01650 } else if (_Alpha < 0.0) { 01651 double amp3 = min / dist; // linear amplitude is 1/distance 01652 double db3 = 2000.0 * log10(amp3); // covert to 1/100th decibels 01653 db += (sint32) ((1.0 + _Alpha) * db1 - _Alpha * db3); 01654 } 01655 01656 clamp(db, DSBVOLUME_MIN, DSBVOLUME_MAX); 01657 01658 _SecondaryBuffer->SetVolume(db); 01659 01660 /* LONG tmp; 01661 _SecondaryBuffer->GetVolume(&tmp); 01662 */ 01663 01664 //nlwarning("VOLUME = %d dB, rolloff = %0.2f", db/100, CListenerDSound::instance()->getRolloffFactor()); 01665 } 01666 01667 } |
|
Definition at line 562 of file source_dsound.cpp. References _XFadeSize, alpha, count, nlassert, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr1, NLSOUND::CSourceDSound::TLockedBufferInfo::Ptr2, sint, sint16, NLSOUND::CSourceDSound::TLockedBufferInfo::Size1, NLSOUND::CSourceDSound::TLockedBufferInfo::Size2, src, and uint. Referenced by play().
00563 { 00564 // do the XFade in integer fixed point arithmetic 00565 00566 nlassert((_XFadeSize & 0x1) == 0); 00567 uint fade = _XFadeSize; 00568 sint16 *ptr = lbi.Ptr1; 00569 uint count = lbi.Size1 /2; 00570 sint alpha, invAlpha; 00571 00572 while (fade && count) 00573 { 00574 alpha = (fade<<16) / _XFadeSize; 00575 invAlpha = 0x10000 - alpha; 00576 *ptr = (sint(*ptr)*alpha + sint(*src) * invAlpha) >> 16; 00577 ++src; 00578 ++ptr; 00579 --count; 00580 --fade; 00581 } 00582 00583 ptr = lbi.Ptr2; 00584 count = lbi.Size2 /2; 00585 00586 while (fade && count) 00587 { 00588 alpha = (fade<<16) / _XFadeSize; 00589 invAlpha = 0x10000 - alpha; 00590 *ptr = (sint(*ptr)*alpha + sint(*src) * invAlpha) >> 16; 00591 ++src; 00592 ++ptr; 00593 --count; 00594 --fade; 00595 } 00596 } |
|
Definition at line 102 of file source_dsound.h. |
|
Definition at line 413 of file source_dsound.h. Referenced by CSourceDSound(), getCone(), getDirection(), getMinMaxDistances(), getSourceRelativeMode(), getVelocity(), init(), release(), setCone(), setDirection(), setMinMaxDistances(), setPos(), setSourceRelativeMode(), and setVelocity(). |
|
Definition at line 418 of file source_dsound.h. Referenced by fillData(), play(), setStaticBuffer(), and update(). |
|
Definition at line 458 of file source_dsound.h. Referenced by CSourceDSound(), setAlpha(), and updateVolume(). |
|
Definition at line 415 of file source_dsound.h. Referenced by CSourceDSound(), play(), setStaticBuffer(), stop(), update(), and ~CSourceDSound(). |
|
Definition at line 75 of file source_dsound.cpp. Referenced by init(). |
|
Definition at line 76 of file source_dsound.cpp. Referenced by CSourceDSound(), and init(). |
|
Definition at line 77 of file source_dsound.cpp. Referenced by init(). |
|
Definition at line 394 of file source_dsound.h. Referenced by advanceFill(), CSourceDSound(), play(), stop(), and update(). |
|
Definition at line 381 of file source_dsound.h. |
|
Definition at line 386 of file source_dsound.h. |
|
Definition at line 457 of file source_dsound.h. |
|
Definition at line 393 of file source_dsound.h. Referenced by CSourceDSound(), play(), and update(). |
|
Definition at line 170 of file source.h. Referenced by NLSOUND::ISource::ISource(), NLSOUND::ISource::setStreamLoader(), and NLSOUND::ISource::~ISource(). |
|
Definition at line 401 of file source_dsound.h. Referenced by CSourceDSound(), getLooping(), play(), setLooping(), and update(). |
|
Definition at line 391 of file source_dsound.h. Referenced by getStaticBuffer(), play(), and setStaticBuffer(). |
|
Definition at line 380 of file source_dsound.h. Referenced by CSourceDSound(), getTime(), play(), setStaticBuffer(), and update(). |
|
Definition at line 459 of file source_dsound.h. |
|
Definition at line 374 of file source_dsound.h. Referenced by CSourceDSound(), fillData(), getBuffer(), getPitch(), getStaticBuffer(), getTime(), play(), setPitch(), and setStaticBuffer(). |
|
Definition at line 382 of file source_dsound.h. Referenced by CSourceDSound(), play(), and setStaticBuffer(). |
|
Definition at line 378 of file source_dsound.h. Referenced by CSourceDSound(), fillData(), play(), setStaticBuffer(), and update(). |
|
Definition at line 388 of file source_dsound.h. Referenced by CSourceDSound(), and setPitch(). |
|
Definition at line 376 of file source_dsound.h. Referenced by CSourceDSound(), fillData(), play(), setStaticBuffer(), and update(). |
|
Definition at line 407 of file source_dsound.h. Referenced by CSourceDSound(), getCursors(), getPitch(), init(), lock(), release(), setPitch(), unlock(), and updateVolume(). |
|
Definition at line 70 of file source_dsound.cpp. Referenced by advanceFill(), init(), and update(). |
|
Definition at line 395 of file source_dsound.h. |
|
Definition at line 71 of file source_dsound.cpp. Referenced by advanceFill(), getCursors(), and update(). |
|
Definition at line 365 of file source_dsound.h. Referenced by sourceName(). |
|
Definition at line 368 of file source_dsound.h. Referenced by CSourceDSound(), getStaticBuffer(), isPlaying(), isStopped(), needsUpdate(), play(), setStaticBuffer(), stop(), and update(). |
|
Definition at line 72 of file source_dsound.cpp. |
|
Definition at line 73 of file source_dsound.cpp. Referenced by getCursors(), and update(). |
|
Definition at line 456 of file source_dsound.h. |
|
Definition at line 74 of file source_dsound.cpp. Referenced by fadeIn(), fadeOut(), play(), stop(), update(), and xfade(). |