exceptions
This commit is contained in:
@@ -6,6 +6,10 @@ class RageSoundDriver
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class RageSoundManager;
|
friend class RageSoundManager;
|
||||||
|
|
||||||
|
/* Initialize. On failure, an error message is returned. */
|
||||||
|
virtual CString Init() { return ""; }
|
||||||
|
|
||||||
/* A RageSound calls this to request to be played.
|
/* A RageSound calls this to request to be played.
|
||||||
* XXX: define what we should do when it can't be played (eg. out of
|
* XXX: define what we should do when it can't be played (eg. out of
|
||||||
* channels) */
|
* channels) */
|
||||||
|
|||||||
@@ -100,8 +100,12 @@ RageSound_WaveOut::RageSound_WaveOut()
|
|||||||
|
|
||||||
sound_event = CreateEvent(NULL, false, true, NULL);
|
sound_event = CreateEvent(NULL, false, true, NULL);
|
||||||
|
|
||||||
WAVEFORMATEX fmt;
|
wo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString RageSound_WaveOut::Init()
|
||||||
|
{
|
||||||
|
WAVEFORMATEX fmt;
|
||||||
fmt.wFormatTag = WAVE_FORMAT_PCM;
|
fmt.wFormatTag = WAVE_FORMAT_PCM;
|
||||||
fmt.nChannels = channels;
|
fmt.nChannels = channels;
|
||||||
fmt.cbSize = 0;
|
fmt.cbSize = 0;
|
||||||
@@ -110,20 +114,18 @@ RageSound_WaveOut::RageSound_WaveOut()
|
|||||||
fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8;
|
fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8;
|
||||||
fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign;
|
fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign;
|
||||||
|
|
||||||
MMRESULT ret = waveOutOpen(&wo, WAVE_MAPPER, &fmt,
|
MMRESULT ret = waveOutOpen( &wo, WAVE_MAPPER, &fmt, (DWORD_PTR) sound_event, NULL, CALLBACK_EVENT );
|
||||||
(DWORD_PTR) sound_event, NULL, CALLBACK_EVENT);
|
if( ret != MMSYSERR_NOERROR )
|
||||||
|
return wo_ssprintf( ret, "waveOutOpen failed" );
|
||||||
if(ret != MMSYSERR_NOERROR)
|
|
||||||
RageException::ThrowNonfatal(wo_ssprintf(ret, "waveOutOpen failed"));
|
|
||||||
|
|
||||||
|
ZERO( buffers );
|
||||||
for(int b = 0; b < num_chunks; ++b)
|
for(int b = 0; b < num_chunks; ++b)
|
||||||
{
|
{
|
||||||
memset(&buffers[b], 0, sizeof(buffers[b]));
|
|
||||||
buffers[b].dwBufferLength = chunksize;
|
buffers[b].dwBufferLength = chunksize;
|
||||||
buffers[b].lpData = new char[chunksize];
|
buffers[b].lpData = new char[chunksize];
|
||||||
ret = waveOutPrepareHeader(wo, &buffers[b], sizeof(buffers[b]));
|
ret = waveOutPrepareHeader(wo, &buffers[b], sizeof(buffers[b]));
|
||||||
if(ret != MMSYSERR_NOERROR)
|
if( ret != MMSYSERR_NOERROR )
|
||||||
RageException::ThrowNonfatal(wo_ssprintf(ret, "waveOutPrepareHeader failed"));
|
return wo_ssprintf( ret, "waveOutPrepareHeader failed" );
|
||||||
buffers[b].dwFlags |= WHDR_DONE;
|
buffers[b].dwFlags |= WHDR_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,25 +136,34 @@ RageSound_WaveOut::RageSound_WaveOut()
|
|||||||
|
|
||||||
MixingThread.SetName("Mixer thread");
|
MixingThread.SetName("Mixer thread");
|
||||||
MixingThread.Create( MixerThread_start, this );
|
MixingThread.Create( MixerThread_start, this );
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound_WaveOut::~RageSound_WaveOut()
|
RageSound_WaveOut::~RageSound_WaveOut()
|
||||||
{
|
{
|
||||||
/* Signal the mixing thread to quit. */
|
/* Signal the mixing thread to quit. */
|
||||||
|
if( MixingThread.IsCreated() )
|
||||||
|
{
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
SetEvent( sound_event );
|
SetEvent( sound_event );
|
||||||
LOG->Trace("Shutting down mixer thread ...");
|
LOG->Trace("Shutting down mixer thread ...");
|
||||||
MixingThread.Wait();
|
MixingThread.Wait();
|
||||||
LOG->Trace("Mixer thread shut down.");
|
LOG->Trace("Mixer thread shut down.");
|
||||||
|
}
|
||||||
|
|
||||||
CloseHandle(sound_event);
|
if( wo != NULL )
|
||||||
waveOutClose(wo);
|
{
|
||||||
|
for( int b = 0; b < num_chunks && buffers[b].lpData != NULL; ++b )
|
||||||
for(int b = 0; b < num_chunks; ++b)
|
|
||||||
{
|
{
|
||||||
waveOutUnprepareHeader( wo, &buffers[b], sizeof(buffers[b]) );
|
waveOutUnprepareHeader( wo, &buffers[b], sizeof(buffers[b]) );
|
||||||
delete [] buffers[b].lpData;
|
delete [] buffers[b].lpData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waveOutClose( wo );
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(sound_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
float RageSound_WaveOut::GetPlayLatency() const
|
float RageSound_WaveOut::GetPlayLatency() const
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public:
|
|||||||
|
|
||||||
RageSound_WaveOut();
|
RageSound_WaveOut();
|
||||||
~RageSound_WaveOut();
|
~RageSound_WaveOut();
|
||||||
|
CString Init();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -137,8 +137,19 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers)
|
|||||||
if(!DriversToTry[i].CompareNoCase("QT1")) ret = new RageSound_QT1;
|
if(!DriversToTry[i].CompareNoCase("QT1")) ret = new RageSound_QT1;
|
||||||
#endif
|
#endif
|
||||||
if(!DriversToTry[i].CompareNoCase("Null")) ret = new RageSound_Null;
|
if(!DriversToTry[i].CompareNoCase("Null")) ret = new RageSound_Null;
|
||||||
if( !ret )
|
|
||||||
LOG->Warn("Unknown sound driver name: %s", DriversToTry[i].c_str());
|
if( ret == NULL )
|
||||||
|
{
|
||||||
|
LOG->Warn( "Unknown sound driver name: %s", DriversToTry[i].c_str() );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString sError = ret->Init();
|
||||||
|
if( sError != "" )
|
||||||
|
{
|
||||||
|
LOG->Info( "Couldn't load driver %s: %s", DriversToTry[i].c_str(), sError.c_str() );
|
||||||
|
SAFE_DELETE( ret );
|
||||||
|
}
|
||||||
} catch(const RageException &e) {
|
} catch(const RageException &e) {
|
||||||
LOG->Info("Couldn't load driver %s: %s", DriversToTry[i].c_str(), e.what());
|
LOG->Info("Couldn't load driver %s: %s", DriversToTry[i].c_str(), e.what());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user