From eaf68a42713b204091d07736e17b6e4f86c260da Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 1 Dec 2004 00:31:44 +0000 Subject: [PATCH] exceptions (untested) --- .../src/arch/Sound/RageSoundDriver_CA.cpp | 44 +++++++++---------- stepmania/src/arch/Sound/RageSoundDriver_CA.h | 1 + .../src/arch/Sound/RageSoundDriver_QT1.cpp | 17 ++++--- .../src/arch/Sound/RageSoundDriver_QT1.h | 1 + 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/stepmania/src/arch/Sound/RageSoundDriver_CA.cpp b/stepmania/src/arch/Sound/RageSoundDriver_CA.cpp index 90e5141473..912a73de7f 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_CA.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_CA.cpp @@ -50,17 +50,21 @@ static CString FormatToString( int fmt ) } RageSound_CA::RageSound_CA() +{ + mOutputDevice = NULL; + mConverter = NULL; +} + +CString RageSound_OSS::Init() { try { - AudioDeviceID dID; - - dID = CAAudioHardwareSystem::GetDefaultDevice(false, false); + AudioDeviceID dID = CAAudioHardwareSystem::GetDefaultDevice( false, false ); mOutputDevice = new CAAudioHardwareDevice(dID); } catch (const CAException& e) { - RageException::ThrowNonfatal("Couldn't create default output device."); + return "Couldn't create default output device."; } try @@ -69,20 +73,16 @@ RageSound_CA::RageSound_CA() } catch (const CAException& e) { - RageException::ThrowNonfatal("Couldn't set the nominal sample rate."); + return "Couldn't set the nominal sample rate."; } - AudioStreamID sID; - - sID = mOutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 ); + AudioStreamID sID = mOutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 ); CAAudioHardwareStream stream( sID ); try { mOutputDevice->AddPropertyListener(kAudioPropertyWildcardChannel, - kAudioPropertyWildcardSection, - kAudioDeviceProcessorOverload, - OverloadListener, this); - } + kAudioPropertyWildcardSection, kAudioDeviceProcessorOverload, OverloadListener, this); + } catch (const CAException& e) { LOG->Warn("Could not install the overload listener."); @@ -97,10 +97,7 @@ RageSound_CA::RageSound_CA() stream.SetCurrentIOProcFormat(CanonicalFormat); if (AudioConverterNew(&SMFormat, &CanonicalFormat, &mConverter)) - { - delete mOutputDevice; - RageException::ThrowNonfatal("Couldn't create the audio converter"); - } + return "Couldn't create the audio converter"; try { @@ -131,9 +128,7 @@ RageSound_CA::RageSound_CA() } catch (const CAException& e) { - delete mOutputDevice; - AudioConverterDispose(mConverter); - RageException::ThrowNonfatal("Couldn't get Latency."); + return "Couldn't get latency."; } StartDecodeThread(); @@ -145,17 +140,18 @@ RageSound_CA::RageSound_CA() } catch(const CAException& e) { - delete mOutputDevice; - AudioConverterDispose(mConverter); - RageException::Throw("Couldn't start the IOProc."); + return "Couldn't start the IOProc."; } } RageSound_CA::~RageSound_CA() { - mOutputDevice->StopIOProc(GetData); + if( mOutputDevice != NULL ) + mOutputDevice->StopIOProc( GetData ); delete mOutputDevice; - AudioConverterDispose(mConverter); + + if( mConverter != NULL ) + AudioConverterDispose( mConverter ); } int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const diff --git a/stepmania/src/arch/Sound/RageSoundDriver_CA.h b/stepmania/src/arch/Sound/RageSoundDriver_CA.h index 4b07719a47..a6820952cb 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_CA.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_CA.h @@ -39,6 +39,7 @@ private: public: RageSound_CA(); + CString Init(); ~RageSound_CA(); float GetPlayLatency() const { return mLatency; } int64_t GetPosition(const RageSoundBase *sound) const; diff --git a/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp b/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp index 0dbe724824..2ed40d3d53 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp @@ -32,6 +32,13 @@ namespace } RageSound_QT1::RageSound_QT1() +{ + channel = NULL; + buffer[0] = NULL; + buffer[1] = NULL; +} + +CString RageSound_QT1::Init() { SndCallBackUPP callback; callback = NewSndCallBackUPP(GetData); @@ -59,11 +66,7 @@ RageSound_QT1::RageSound_QT1() OSErr err = SndNewChannel(&channel, sampledSynth, initStereo, callback); if (err != noErr) - { - delete channel; - channel = NULL; - RageException::ThrowNonfatal("Unable to create audio channel"); - } + return "Unable to create audio channel"; SndCommand cmd; cmd.cmd = clockComponentCmd; @@ -87,9 +90,9 @@ RageSound_QT1::RageSound_QT1() err |= SndDoCommand(channel, &cmd, false); if (err != noErr) - RageException::ThrowNonfatal("Unable to create audio channel"); + return "Unable to create audio channel"; } - + RageSound_QT1::~RageSound_QT1() { if (channel) diff --git a/stepmania/src/arch/Sound/RageSoundDriver_QT1.h b/stepmania/src/arch/Sound/RageSoundDriver_QT1.h index db7248901a..eb642fa3ce 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_QT1.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_QT1.h @@ -33,6 +33,7 @@ protected: public: RageSound_QT1(); + CString Init(); virtual ~RageSound_QT1(); static void GetData(QT::SndChannel *chan, QT::SndCommand *cmd_passed); };