exceptions (untested)

This commit is contained in:
Glenn Maynard
2004-12-01 00:31:44 +00:00
parent d60eb0306e
commit eaf68a4271
4 changed files with 32 additions and 31 deletions
+19 -23
View File
@@ -50,17 +50,21 @@ static CString FormatToString( int fmt )
} }
RageSound_CA::RageSound_CA() RageSound_CA::RageSound_CA()
{
mOutputDevice = NULL;
mConverter = NULL;
}
CString RageSound_OSS::Init()
{ {
try try
{ {
AudioDeviceID dID; AudioDeviceID dID = CAAudioHardwareSystem::GetDefaultDevice( false, false );
dID = CAAudioHardwareSystem::GetDefaultDevice(false, false);
mOutputDevice = new CAAudioHardwareDevice(dID); mOutputDevice = new CAAudioHardwareDevice(dID);
} }
catch (const CAException& e) catch (const CAException& e)
{ {
RageException::ThrowNonfatal("Couldn't create default output device."); return "Couldn't create default output device.";
} }
try try
@@ -69,19 +73,15 @@ RageSound_CA::RageSound_CA()
} }
catch (const CAException& e) catch (const CAException& e)
{ {
RageException::ThrowNonfatal("Couldn't set the nominal sample rate."); return "Couldn't set the nominal sample rate.";
} }
AudioStreamID sID; AudioStreamID sID = mOutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 );
sID = mOutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 );
CAAudioHardwareStream stream( sID ); CAAudioHardwareStream stream( sID );
try try
{ {
mOutputDevice->AddPropertyListener(kAudioPropertyWildcardChannel, mOutputDevice->AddPropertyListener(kAudioPropertyWildcardChannel,
kAudioPropertyWildcardSection, kAudioPropertyWildcardSection, kAudioDeviceProcessorOverload, OverloadListener, this);
kAudioDeviceProcessorOverload,
OverloadListener, this);
} }
catch (const CAException& e) catch (const CAException& e)
{ {
@@ -97,10 +97,7 @@ RageSound_CA::RageSound_CA()
stream.SetCurrentIOProcFormat(CanonicalFormat); stream.SetCurrentIOProcFormat(CanonicalFormat);
if (AudioConverterNew(&SMFormat, &CanonicalFormat, &mConverter)) if (AudioConverterNew(&SMFormat, &CanonicalFormat, &mConverter))
{ return "Couldn't create the audio converter";
delete mOutputDevice;
RageException::ThrowNonfatal("Couldn't create the audio converter");
}
try try
{ {
@@ -131,9 +128,7 @@ RageSound_CA::RageSound_CA()
} }
catch (const CAException& e) catch (const CAException& e)
{ {
delete mOutputDevice; return "Couldn't get latency.";
AudioConverterDispose(mConverter);
RageException::ThrowNonfatal("Couldn't get Latency.");
} }
StartDecodeThread(); StartDecodeThread();
@@ -145,17 +140,18 @@ RageSound_CA::RageSound_CA()
} }
catch(const CAException& e) catch(const CAException& e)
{ {
delete mOutputDevice; return "Couldn't start the IOProc.";
AudioConverterDispose(mConverter);
RageException::Throw("Couldn't start the IOProc.");
} }
} }
RageSound_CA::~RageSound_CA() RageSound_CA::~RageSound_CA()
{ {
mOutputDevice->StopIOProc(GetData); if( mOutputDevice != NULL )
mOutputDevice->StopIOProc( GetData );
delete mOutputDevice; delete mOutputDevice;
AudioConverterDispose(mConverter);
if( mConverter != NULL )
AudioConverterDispose( mConverter );
} }
int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const
@@ -39,6 +39,7 @@ private:
public: public:
RageSound_CA(); RageSound_CA();
CString Init();
~RageSound_CA(); ~RageSound_CA();
float GetPlayLatency() const { return mLatency; } float GetPlayLatency() const { return mLatency; }
int64_t GetPosition(const RageSoundBase *sound) const; int64_t GetPosition(const RageSoundBase *sound) const;
@@ -32,6 +32,13 @@ namespace
} }
RageSound_QT1::RageSound_QT1() RageSound_QT1::RageSound_QT1()
{
channel = NULL;
buffer[0] = NULL;
buffer[1] = NULL;
}
CString RageSound_QT1::Init()
{ {
SndCallBackUPP callback; SndCallBackUPP callback;
callback = NewSndCallBackUPP(GetData); callback = NewSndCallBackUPP(GetData);
@@ -59,11 +66,7 @@ RageSound_QT1::RageSound_QT1()
OSErr err = SndNewChannel(&channel, sampledSynth, initStereo, callback); OSErr err = SndNewChannel(&channel, sampledSynth, initStereo, callback);
if (err != noErr) if (err != noErr)
{ return "Unable to create audio channel";
delete channel;
channel = NULL;
RageException::ThrowNonfatal("Unable to create audio channel");
}
SndCommand cmd; SndCommand cmd;
cmd.cmd = clockComponentCmd; cmd.cmd = clockComponentCmd;
@@ -87,7 +90,7 @@ RageSound_QT1::RageSound_QT1()
err |= SndDoCommand(channel, &cmd, false); err |= SndDoCommand(channel, &cmd, false);
if (err != noErr) if (err != noErr)
RageException::ThrowNonfatal("Unable to create audio channel"); return "Unable to create audio channel";
} }
RageSound_QT1::~RageSound_QT1() RageSound_QT1::~RageSound_QT1()
@@ -33,6 +33,7 @@ protected:
public: public:
RageSound_QT1(); RageSound_QT1();
CString Init();
virtual ~RageSound_QT1(); virtual ~RageSound_QT1();
static void GetData(QT::SndChannel *chan, QT::SndCommand *cmd_passed); static void GetData(QT::SndChannel *chan, QT::SndCommand *cmd_passed);
}; };