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
+20 -24
View File
@@ -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
@@ -39,6 +39,7 @@ private:
public:
RageSound_CA();
CString Init();
~RageSound_CA();
float GetPlayLatency() const { return mLatency; }
int64_t GetPosition(const RageSoundBase *sound) const;
@@ -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)
@@ -33,6 +33,7 @@ protected:
public:
RageSound_QT1();
CString Init();
virtual ~RageSound_QT1();
static void GetData(QT::SndChannel *chan, QT::SndCommand *cmd_passed);
};