exceptions
This commit is contained in:
@@ -98,15 +98,18 @@ void DSound::SetPrimaryBufferMode()
|
|||||||
|
|
||||||
DSound::DSound()
|
DSound::DSound()
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
// Initialize COM
|
// Initialize COM
|
||||||
|
HRESULT hr;
|
||||||
if( FAILED( hr = CoInitialize( NULL ) ) )
|
if( FAILED( hr = CoInitialize( NULL ) ) )
|
||||||
RageException::ThrowNonfatal(hr_ssprintf(hr, "CoInitialize"));
|
RageException::Throw(hr_ssprintf(hr, "CoInitialize"));
|
||||||
|
}
|
||||||
|
|
||||||
|
CString DSound::Init()
|
||||||
|
{
|
||||||
// Create IDirectSound using the primary sound device
|
// Create IDirectSound using the primary sound device
|
||||||
|
HRESULT hr;
|
||||||
if( FAILED( hr = DirectSoundCreate( NULL, &ds, NULL ) ) )
|
if( FAILED( hr = DirectSoundCreate( NULL, &ds, NULL ) ) )
|
||||||
RageException::ThrowNonfatal(hr_ssprintf(hr, "DirectSoundCreate"));
|
return hr_ssprintf( hr, "DirectSoundCreate" );
|
||||||
|
|
||||||
#ifndef _XBOX
|
#ifndef _XBOX
|
||||||
static bool bShownInfo = false;
|
static bool bShownInfo = false;
|
||||||
@@ -134,6 +137,8 @@ DSound::DSound()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SetPrimaryBufferMode();
|
SetPrimaryBufferMode();
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
DSound::~DSound()
|
DSound::~DSound()
|
||||||
@@ -163,9 +168,16 @@ bool DSound::IsEmulated() const
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
DSoundBuf::DSoundBuf( DSound &ds, DSoundBuf::hw hardware,
|
DSoundBuf::DSoundBuf()
|
||||||
|
{
|
||||||
|
buf = NULL;
|
||||||
|
temp_buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString DSoundBuf::Init( DSound &ds, DSoundBuf::hw hardware,
|
||||||
int channels_, int samplerate_, int samplebits_, int writeahead_ )
|
int channels_, int samplerate_, int samplebits_, int writeahead_ )
|
||||||
{
|
{
|
||||||
|
|
||||||
channels = channels_;
|
channels = channels_;
|
||||||
samplerate = samplerate_;
|
samplerate = samplerate_;
|
||||||
samplebits = samplebits_;
|
samplebits = samplebits_;
|
||||||
@@ -250,7 +262,7 @@ DSoundBuf::DSoundBuf( DSound &ds, DSoundBuf::hw hardware,
|
|||||||
|
|
||||||
HRESULT hr = ds.GetDS()->CreateSoundBuffer( &format, &buf, NULL );
|
HRESULT hr = ds.GetDS()->CreateSoundBuffer( &format, &buf, NULL );
|
||||||
if( FAILED(hr) )
|
if( FAILED(hr) )
|
||||||
RageException::ThrowNonfatal( hr_ssprintf(hr, "CreateSoundBuffer failed") );
|
return hr_ssprintf( hr, "CreateSoundBuffer failed" );
|
||||||
|
|
||||||
#ifndef _XBOX
|
#ifndef _XBOX
|
||||||
/* I'm not sure this should ever be needed, but ... */
|
/* I'm not sure this should ever be needed, but ... */
|
||||||
@@ -258,7 +270,7 @@ DSoundBuf::DSoundBuf( DSound &ds, DSoundBuf::hw hardware,
|
|||||||
bcaps.dwSize=sizeof(bcaps);
|
bcaps.dwSize=sizeof(bcaps);
|
||||||
hr = buf->GetCaps(&bcaps);
|
hr = buf->GetCaps(&bcaps);
|
||||||
if( FAILED(hr) )
|
if( FAILED(hr) )
|
||||||
RageException::Throw(hr_ssprintf(hr, "buf->GetCaps"));
|
return hr_ssprintf( hr, "buf->GetCaps" );
|
||||||
if( int(bcaps.dwBufferBytes) != buffersize )
|
if( int(bcaps.dwBufferBytes) != buffersize )
|
||||||
{
|
{
|
||||||
LOG->Warn( "bcaps.dwBufferBytes (%i) != buffersize(%i); adjusting", bcaps.dwBufferBytes, buffersize );
|
LOG->Warn( "bcaps.dwBufferBytes (%i) != buffersize(%i); adjusting", bcaps.dwBufferBytes, buffersize );
|
||||||
@@ -280,6 +292,8 @@ DSoundBuf::DSoundBuf( DSound &ds, DSoundBuf::hw hardware,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
temp_buffer = new char[buffersize];
|
temp_buffer = new char[buffersize];
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSoundBuf::SetSampleRate(int hz)
|
void DSoundBuf::SetSampleRate(int hz)
|
||||||
@@ -331,6 +345,7 @@ static bool contained( int start, int end, int pos )
|
|||||||
|
|
||||||
DSoundBuf::~DSoundBuf()
|
DSoundBuf::~DSoundBuf()
|
||||||
{
|
{
|
||||||
|
if( buf != NULL )
|
||||||
buf->Release();
|
buf->Release();
|
||||||
delete [] temp_buffer;
|
delete [] temp_buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public:
|
|||||||
|
|
||||||
DSound();
|
DSound();
|
||||||
~DSound();
|
~DSound();
|
||||||
|
CString Init();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DSoundBuf
|
class DSoundBuf
|
||||||
@@ -33,7 +34,8 @@ public:
|
|||||||
* you use the sample. */
|
* you use the sample. */
|
||||||
enum { DYNAMIC_SAMPLERATE = -1 };
|
enum { DYNAMIC_SAMPLERATE = -1 };
|
||||||
|
|
||||||
DSoundBuf(DSound &ds, hw hardware,
|
DSoundBuf();
|
||||||
|
CString Init( DSound &ds, hw hardware,
|
||||||
int channels, int samplerate, int samplebits, int writeahead );
|
int channels, int samplerate, int samplebits, int writeahead );
|
||||||
|
|
||||||
bool get_output_buf(char **buffer, unsigned *bufsiz, int chunksize);
|
bool get_output_buf(char **buffer, unsigned *bufsiz, int chunksize);
|
||||||
|
|||||||
@@ -198,34 +198,42 @@ RageSound_DSound::RageSound_DSound():
|
|||||||
m_InactiveSoundMutex("InactiveSoundMutex")
|
m_InactiveSoundMutex("InactiveSoundMutex")
|
||||||
{
|
{
|
||||||
shutdown = false;
|
shutdown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString RageSound_DSound::Init()
|
||||||
|
{
|
||||||
|
CString sError = ds.Init();
|
||||||
|
if( sError != "" )
|
||||||
|
return sError;
|
||||||
|
|
||||||
/* Don't bother wasting time trying to create buffers if we're
|
/* Don't bother wasting time trying to create buffers if we're
|
||||||
* emulated. This also gives us better diagnostic information. */
|
* emulated. This also gives us better diagnostic information. */
|
||||||
if( ds.IsEmulated() )
|
if( ds.IsEmulated() )
|
||||||
RageException::ThrowNonfatal("Driver unusable (emulated device)");
|
return "Driver unusable (emulated device)";
|
||||||
|
|
||||||
/* Create a bunch of streams and put them into the stream pool. */
|
/* Create a bunch of streams and put them into the stream pool. */
|
||||||
for(int i = 0; i < 32; ++i) {
|
for( int i = 0; i < 32; ++i )
|
||||||
DSoundBuf *newbuf;
|
{
|
||||||
try {
|
DSoundBuf *newbuf = new DSoundBuf;
|
||||||
newbuf = new DSoundBuf(ds,
|
CString sError = newbuf->Init( ds, DSoundBuf::HW_HARDWARE,
|
||||||
DSoundBuf::HW_HARDWARE,
|
|
||||||
channels, DSoundBuf::DYNAMIC_SAMPLERATE, 16, buffersize );
|
channels, DSoundBuf::DYNAMIC_SAMPLERATE, 16, buffersize );
|
||||||
} catch(const RageException &e) {
|
if( sError != "" )
|
||||||
/* If we didn't get at least 8, fail. */
|
{
|
||||||
if(i >= 8) break; /* OK */
|
/* The channel failed to create. We may be out of hardware streams, or we
|
||||||
|
* may not have hardware mixing at all. If we didn't get at least 8, fail. */
|
||||||
|
delete newbuf;
|
||||||
|
|
||||||
/* Clean up; the dtor won't be called. */
|
if( i >= 8 )
|
||||||
for(int n = 0; n < i; ++n)
|
break; /* OK */
|
||||||
delete stream_pool[n];
|
|
||||||
|
|
||||||
if( i )
|
if( i )
|
||||||
{
|
{
|
||||||
/* We created at least one hardware buffer. */
|
/* We created at least one hardware buffer. */
|
||||||
LOG->Trace("Could only create %i buffers; need at least 8 (failed with %s). DirectSound driver can't be used.", i, e.what());
|
LOG->Trace( "Could only create %i buffers; need at least 8 (failed with %s). Hardware DirectSound driver can't be used.", i, sError.c_str() );
|
||||||
RageException::ThrowNonfatal( "not enough hardware buffers available" );
|
return "not enough hardware buffers available";
|
||||||
}
|
}
|
||||||
RageException::ThrowNonfatal( "no hardware buffers available" );
|
|
||||||
|
return "no hardware buffers available";
|
||||||
}
|
}
|
||||||
|
|
||||||
stream *s = new stream;
|
stream *s = new stream;
|
||||||
@@ -237,6 +245,8 @@ RageSound_DSound::RageSound_DSound():
|
|||||||
|
|
||||||
MixingThread.SetName("Mixer thread");
|
MixingThread.SetName("Mixer thread");
|
||||||
MixingThread.Create( MixerThread_start, this );
|
MixingThread.Create( MixerThread_start, this );
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound_DSound::~RageSound_DSound()
|
RageSound_DSound::~RageSound_DSound()
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class RageSound_DSound: public RageSoundDriver
|
|||||||
public:
|
public:
|
||||||
RageSound_DSound();
|
RageSound_DSound();
|
||||||
~RageSound_DSound();
|
~RageSound_DSound();
|
||||||
|
CString Init();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ RageSound_DSound_Software::RageSound_DSound_Software()
|
|||||||
|
|
||||||
CString RageSound_DSound_Software::Init()
|
CString RageSound_DSound_Software::Init()
|
||||||
{
|
{
|
||||||
|
CString sError = ds.Init();
|
||||||
|
if( sError != "" )
|
||||||
|
return sError;
|
||||||
|
|
||||||
/* If we're emulated, we're better off with the WaveOut driver; DS
|
/* If we're emulated, we're better off with the WaveOut driver; DS
|
||||||
* emulation tends to be desynced. */
|
* emulation tends to be desynced. */
|
||||||
if( ds.IsEmulated() )
|
if( ds.IsEmulated() )
|
||||||
@@ -76,7 +80,10 @@ CString RageSound_DSound_Software::Init()
|
|||||||
max_writeahead = PREFSMAN->m_iSoundWriteAhead;
|
max_writeahead = PREFSMAN->m_iSoundWriteAhead;
|
||||||
|
|
||||||
/* Create a DirectSound stream, but don't force it into hardware. */
|
/* Create a DirectSound stream, but don't force it into hardware. */
|
||||||
pcm = new DSoundBuf( ds, DSoundBuf::HW_DONT_CARE, channels, samplerate, 16, max_writeahead );
|
pcm = new DSoundBuf;
|
||||||
|
sError = pcm->Init( ds, DSoundBuf::HW_DONT_CARE, channels, samplerate, 16, max_writeahead );
|
||||||
|
if( sError != "" )
|
||||||
|
return sError;
|
||||||
|
|
||||||
/* Fill a buffer before we start playing, so we don't play whatever junk is
|
/* Fill a buffer before we start playing, so we don't play whatever junk is
|
||||||
* in the buffer. */
|
* in the buffer. */
|
||||||
|
|||||||
Reference in New Issue
Block a user