Browse Source

Get rid of dsound.h

Darryl Pogue 14 years ago
parent
commit
3fc884e5ad
  1. 54
      Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp
  2. 6
      Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.h

54
Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.cpp

@ -46,8 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plStatusLog/plStatusLog.h" #include "plStatusLog/plStatusLog.h"
#include <dsound.h>
UInt32 plDSoundBuffer::fNumBuffers = 0; UInt32 plDSoundBuffer::fNumBuffers = 0;
plProfile_CreateCounterNoReset( "Playing", "Sound", SoundPlaying ); plProfile_CreateCounterNoReset( "Playing", "Sound", SoundPlaying );
plProfile_CreateCounterNoReset( "Allocated", "Sound", NumAllocated ); plProfile_CreateCounterNoReset( "Allocated", "Sound", NumAllocated );
@ -89,20 +87,10 @@ plDSoundBuffer::~plDSoundBuffer()
void plDSoundBuffer::IAllocate( UInt32 size, plWAVHeader &bufferDesc, hsBool enable3D, hsBool tryStatic ) void plDSoundBuffer::IAllocate( UInt32 size, plWAVHeader &bufferDesc, hsBool enable3D, hsBool tryStatic )
{ {
// Create a DSound buffer description // Create a DSound buffer description
fBufferDesc = TRACKED_NEW DSBUFFERDESC; fBufferDesc = TRACKED_NEW plWAVHeader;
fBufferDesc->dwSize = sizeof( DSBUFFERDESC ); *fBufferDesc = bufferDesc;
fBufferDesc->dwBufferBytes = size;
fBufferDesc->dwReserved = 0;
fBufferDesc->lpwfxFormat = TRACKED_NEW WAVEFORMATEX; fBufferSize = size;
fBufferDesc->lpwfxFormat->cbSize = 0;
fBufferDesc->lpwfxFormat->nAvgBytesPerSec = bufferDesc.fAvgBytesPerSec;
fBufferDesc->lpwfxFormat->nBlockAlign = bufferDesc.fBlockAlign;
fBufferDesc->lpwfxFormat->nChannels = bufferDesc.fNumChannels;
fBufferDesc->lpwfxFormat->nSamplesPerSec = bufferDesc.fNumSamplesPerSec;
fBufferDesc->lpwfxFormat->wBitsPerSample = bufferDesc.fBitsPerSample;
fBufferDesc->lpwfxFormat->wFormatTag = bufferDesc.fFormatTag;
// Do we want to try EAX? // Do we want to try EAX?
if( plgAudioSys::UsingEAX() ) if( plgAudioSys::UsingEAX() )
@ -133,14 +121,10 @@ void plDSoundBuffer::IRelease( void )
alGetError(); alGetError();
memset(streamingBuffers, 0, STREAMING_BUFFERS * sizeof(unsigned)); memset(streamingBuffers, 0, STREAMING_BUFFERS * sizeof(unsigned));
if( fBufferDesc != nil )
{
delete fBufferDesc->lpwfxFormat;
fBufferDesc->lpwfxFormat = nil;
}
delete fBufferDesc; delete fBufferDesc;
fBufferDesc = nil; fBufferDesc = nil;
fBufferSize = 0;
fValid = false; fValid = false;
plProfile_Dec( NumAllocated ); plProfile_Dec( NumAllocated );
@ -181,7 +165,7 @@ bool plDSoundBuffer::FillBuffer(void *data, unsigned bytes, plWAVHeader *header)
source = 0; source = 0;
buffer = 0; buffer = 0;
ALenum format = IGetALFormat(fBufferDesc->lpwfxFormat->wBitsPerSample, fBufferDesc->lpwfxFormat->nChannels); ALenum format = IGetALFormat(fBufferDesc->fBitsPerSample, fBufferDesc->fNumChannels);
ALenum error = alGetError(); ALenum error = alGetError();
alGenBuffers(1, &buffer); alGenBuffers(1, &buffer);
error = alGetError(); error = alGetError();
@ -264,8 +248,8 @@ bool plDSoundBuffer::SetupStreamingSource(plAudioFileReader *stream)
return false; return false;
} }
ALenum format = IGetALFormat(fBufferDesc->lpwfxFormat->wBitsPerSample, fBufferDesc->lpwfxFormat->nChannels); ALenum format = IGetALFormat(fBufferDesc->fBitsPerSample, fBufferDesc->fNumChannels);
alBufferData( streamingBuffers[i], format, data, size, fBufferDesc->lpwfxFormat->nSamplesPerSec ); alBufferData( streamingBuffers[i], format, data, size, fBufferDesc->fNumSamplesPerSec );
if( (error = alGetError()) != AL_NO_ERROR ) if( (error = alGetError()) != AL_NO_ERROR )
plStatusLog::AddLineS("audio.log", "alBufferData"); plStatusLog::AddLineS("audio.log", "alBufferData");
} }
@ -330,8 +314,8 @@ bool plDSoundBuffer::SetupStreamingSource(void *data, unsigned bytes)
return false; return false;
} }
ALenum format = IGetALFormat(fBufferDesc->lpwfxFormat->wBitsPerSample, fBufferDesc->lpwfxFormat->nChannels); ALenum format = IGetALFormat(fBufferDesc->fBitsPerSample, fBufferDesc->fNumChannels);
alBufferData( streamingBuffers[i], format, bufferData, size, fBufferDesc->lpwfxFormat->nSamplesPerSec ); alBufferData( streamingBuffers[i], format, bufferData, size, fBufferDesc->fNumSamplesPerSec );
if( (error = alGetError()) != AL_NO_ERROR ) if( (error = alGetError()) != AL_NO_ERROR )
plStatusLog::AddLineS("audio.log", "alBufferData"); plStatusLog::AddLineS("audio.log", "alBufferData");
} }
@ -434,8 +418,8 @@ bool plDSoundBuffer::StreamingFillBuffer(plAudioFileReader *stream)
{ unsigned int size = stream->NumBytesLeft() < STREAM_BUFFER_SIZE ? stream->NumBytesLeft() : STREAM_BUFFER_SIZE; { unsigned int size = stream->NumBytesLeft() < STREAM_BUFFER_SIZE ? stream->NumBytesLeft() : STREAM_BUFFER_SIZE;
stream->Read(size, data); stream->Read(size, data);
ALenum format = IGetALFormat(fBufferDesc->lpwfxFormat->wBitsPerSample, fBufferDesc->lpwfxFormat->nChannels); ALenum format = IGetALFormat(fBufferDesc->fBitsPerSample, fBufferDesc->fNumChannels);
alBufferData( bufferId, format, data, size, fBufferDesc->lpwfxFormat->nSamplesPerSec ); alBufferData( bufferId, format, data, size, fBufferDesc->fNumSamplesPerSec );
if( (error = alGetError()) != AL_NO_ERROR ) if( (error = alGetError()) != AL_NO_ERROR )
{ {
plStatusLog::AddLineS("audio.log", "Failed to copy data to sound buffer %d", error); plStatusLog::AddLineS("audio.log", "Failed to copy data to sound buffer %d", error);
@ -550,8 +534,8 @@ bool plDSoundBuffer::VoiceFillBuffer(void *data, unsigned bytes, unsigned buffer
ALenum error; ALenum error;
unsigned int size = bytes < STREAM_BUFFER_SIZE ? bytes : STREAM_BUFFER_SIZE; unsigned int size = bytes < STREAM_BUFFER_SIZE ? bytes : STREAM_BUFFER_SIZE;
ALenum format = IGetALFormat(fBufferDesc->lpwfxFormat->wBitsPerSample, fBufferDesc->lpwfxFormat->nChannels); ALenum format = IGetALFormat(fBufferDesc->fBitsPerSample, fBufferDesc->fNumChannels);
alBufferData( bufferId, format, data, size, fBufferDesc->lpwfxFormat->nSamplesPerSec ); alBufferData( bufferId, format, data, size, fBufferDesc->fNumSamplesPerSec );
if( (error = alGetError()) != AL_NO_ERROR ) if( (error = alGetError()) != AL_NO_ERROR )
{ {
plStatusLog::AddLineS("audio.log", "Failed to copy data to sound buffer %d", error); plStatusLog::AddLineS("audio.log", "Failed to copy data to sound buffer %d", error);
@ -703,17 +687,17 @@ hsBool plDSoundBuffer::IsEAXAccelerated( void ) const
UInt32 plDSoundBuffer::BytePosToMSecs( UInt32 bytePos ) const UInt32 plDSoundBuffer::BytePosToMSecs( UInt32 bytePos ) const
{ {
return (UInt32)(bytePos * 1000 / (hsScalar)fBufferDesc->lpwfxFormat->nAvgBytesPerSec); return (UInt32)(bytePos * 1000 / (hsScalar)fBufferDesc->fAvgBytesPerSec);
} }
//// GetBufferBytePos //////////////////////////////////////////////////////// //// GetBufferBytePos ////////////////////////////////////////////////////////
UInt32 plDSoundBuffer::GetBufferBytePos( hsScalar timeInSecs ) const UInt32 plDSoundBuffer::GetBufferBytePos( hsScalar timeInSecs ) const
{ {
hsAssert( fBufferDesc != nil && fBufferDesc->lpwfxFormat != nil, "Nil buffer description when calling GetBufferBytePos()" ); hsAssert( fBufferDesc != nil, "Nil buffer description when calling GetBufferBytePos()" );
UInt32 byte = (UInt32)( timeInSecs * (hsScalar)fBufferDesc->lpwfxFormat->nSamplesPerSec ); UInt32 byte = (UInt32)( timeInSecs * (hsScalar)fBufferDesc->fNumSamplesPerSec );
byte *= fBufferDesc->lpwfxFormat->nBlockAlign; byte *= fBufferDesc->fBlockAlign;
return byte; return byte;
} }
@ -722,7 +706,7 @@ UInt32 plDSoundBuffer::GetBufferBytePos( hsScalar timeInSecs ) const
UInt32 plDSoundBuffer::GetLengthInBytes( void ) const UInt32 plDSoundBuffer::GetLengthInBytes( void ) const
{ {
return (UInt32)fBufferDesc->dwBufferBytes; return fBufferSize;
} }
//// SetEAXSettings ////////////////////////////////////////////////////////// //// SetEAXSettings //////////////////////////////////////////////////////////
@ -736,7 +720,7 @@ void plDSoundBuffer::SetEAXSettings( plEAXSourceSettings *settings, hsBool f
UInt8 plDSoundBuffer::GetBlockAlign( void ) const UInt8 plDSoundBuffer::GetBlockAlign( void ) const
{ {
return ( fBufferDesc != nil && fBufferDesc->lpwfxFormat != nil ) ? fBufferDesc->lpwfxFormat->nBlockAlign : 0; return ( fBufferDesc != nil ) ? fBufferDesc->fBlockAlign : 0;
} }
//// SetScalarVolume ///////////////////////////////////////////////////////// //// SetScalarVolume /////////////////////////////////////////////////////////

6
Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.h

@ -46,9 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plWAVHeader; class plWAVHeader;
class plAudioFileReader; class plAudioFileReader;
typedef struct tWAVEFORMATEX WAVEFORMATEX;
typedef struct _DSBUFFERDESC DSBUFFERDESC;
// Ported to OpenAL from DirectSound May 2006. Idealy the openal sources would be seperate from this class. // Ported to OpenAL from DirectSound May 2006. Idealy the openal sources would be seperate from this class.
// OpenAl sound buffer, and source. // OpenAl sound buffer, and source.
@ -127,7 +124,8 @@ protected:
hsTArray<UInt32> fPosNotifys; hsTArray<UInt32> fPosNotifys;
bool fStreaming; bool fStreaming;
DSBUFFERDESC* fBufferDesc; plWAVHeader* fBufferDesc;
UInt32 fBufferSize;
unsigned buffer; // used if this is not a streaming buffer unsigned buffer; // used if this is not a streaming buffer
unsigned streamingBuffers[STREAMING_BUFFERS]; // used if this is a streaming buffer unsigned streamingBuffers[STREAMING_BUFFERS]; // used if this is a streaming buffer

Loading…
Cancel
Save