aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/coreaudio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alc/backends/coreaudio.cpp')
-rw-r--r--alc/backends/coreaudio.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp
index b9c95ff7..4ad7ab84 100644
--- a/alc/backends/coreaudio.cpp
+++ b/alc/backends/coreaudio.cpp
@@ -100,7 +100,8 @@ void CoreAudioPlayback::open(const ALCchar *name)
if(!name)
name = ca_device;
else if(strcmp(name, ca_device) != 0)
- throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name};
+ throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
+ name};
/* open the default output unit */
AudioComponentDescription desc{};
@@ -116,17 +117,18 @@ void CoreAudioPlayback::open(const ALCchar *name)
AudioComponent comp{AudioComponentFindNext(NULL, &desc)};
if(comp == nullptr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"};
+ throw al::backend_exception{al::backend_error::NoDevice, "Could not find audio component"};
OSStatus err{AudioComponentInstanceNew(comp, &mAudioUnit)};
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u",
- err};
+ throw al::backend_exception{al::backend_error::NoDevice,
+ "Could not create component instance: %u", err};
/* init and start the default audio unit... */
err = AudioUnitInitialize(mAudioUnit);
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Could not initialize audio unit: %u", err};
mDevice->DeviceName = name;
}
@@ -280,7 +282,8 @@ void CoreAudioPlayback::start()
{
const OSStatus err{AudioOutputUnitStart(mAudioUnit)};
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_DEVICE, "AudioOutputUnitStart failed: %d", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "AudioOutputUnitStart failed: %d", err};
}
void CoreAudioPlayback::stop()
@@ -394,7 +397,8 @@ void CoreAudioCapture::open(const ALCchar *name)
if(!name)
name = ca_device;
else if(strcmp(name, ca_device) != 0)
- throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name};
+ throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
+ name};
desc.componentType = kAudioUnitType_Output;
#if TARGET_OS_IOS
@@ -409,20 +413,20 @@ void CoreAudioCapture::open(const ALCchar *name)
// Search for component with given description
comp = AudioComponentFindNext(NULL, &desc);
if(comp == NULL)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"};
+ throw al::backend_exception{al::backend_error::NoDevice, "Could not find audio component"};
// Open the component
err = AudioComponentInstanceNew(comp, &mAudioUnit);
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u",
- err};
+ throw al::backend_exception{al::backend_error::NoDevice,
+ "Could not create component instance: %u", err};
// Turn off AudioUnit output
enableIO = 0;
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output, 0, &enableIO, sizeof(ALuint));
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE,
+ throw al::backend_exception{al::backend_error::DeviceError,
"Could not disable audio unit output property: %u", err};
// Turn on AudioUnit input
@@ -430,7 +434,7 @@ void CoreAudioCapture::open(const ALCchar *name)
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input, 1, &enableIO, sizeof(ALuint));
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE,
+ throw al::backend_exception{al::backend_error::DeviceError,
"Could not enable audio unit input property: %u", err};
#if !TARGET_OS_IOS
@@ -447,15 +451,17 @@ void CoreAudioCapture::open(const ALCchar *name)
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, nullptr,
&propertySize, &inputDevice);
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input device: %u", err};
+ throw al::backend_exception{al::backend_error::NoDevice,
+ "Could not get input device: %u", err};
if(inputDevice == kAudioDeviceUnknown)
- throw al::backend_exception{ALC_INVALID_VALUE, "Unknown input device"};
+ throw al::backend_exception{al::backend_error::NoDevice, "Unknown input device"};
// Track the input device
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global, 0, &inputDevice, sizeof(AudioDeviceID));
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input device: %u", err};
+ throw al::backend_exception{al::backend_error::NoDevice,
+ "Could not set input device: %u", err};
}
#endif
@@ -466,27 +472,30 @@ void CoreAudioCapture::open(const ALCchar *name)
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global, 0, &input, sizeof(AURenderCallbackStruct));
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not set capture callback: %u", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Could not set capture callback: %u", err};
// Disable buffer allocation for capture
UInt32 flag{0};
err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_ShouldAllocateBuffer,
kAudioUnitScope_Output, 1, &flag, sizeof(flag));
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE,
+ throw al::backend_exception{al::backend_error::DeviceError,
"Could not disable buffer allocation property: %u", err};
// Initialize the device
err = AudioUnitInitialize(mAudioUnit);
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Could not initialize audio unit: %u", err};
// Get the hardware format
propertySize = sizeof(AudioStreamBasicDescription);
err = AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
1, &hardwareFormat, &propertySize);
if(err != noErr || propertySize != sizeof(AudioStreamBasicDescription))
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input format: %u", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Could not get input format: %u", err};
// Set up the requested format description
switch(mDevice->FmtType)
@@ -536,7 +545,7 @@ void CoreAudioCapture::open(const ALCchar *name)
case DevFmtX61:
case DevFmtX71:
case DevFmtAmbi3D:
- throw al::backend_exception{ALC_INVALID_VALUE, "%s not supported",
+ throw al::backend_exception{al::backend_error::DeviceError, "%s not supported",
DevFmtChannelsString(mDevice->FmtChans)};
}
@@ -561,7 +570,8 @@ void CoreAudioCapture::open(const ALCchar *name)
err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
1, &outputFormat, sizeof(outputFormat));
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input format: %u", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Could not set input format: %u", err};
/* Calculate the minimum AudioUnit output format frame count for the pre-
* conversion ring buffer. Ensure at least 100ms for the total buffer.
@@ -571,7 +581,7 @@ void CoreAudioCapture::open(const ALCchar *name)
static_cast<UInt32>(outputFormat.mSampleRate)/10);
FrameCount64 += MaxResamplerPadding;
if(FrameCount64 > std::numeric_limits<int32_t>::max())
- throw al::backend_exception{ALC_INVALID_VALUE,
+ throw al::backend_exception{al::backend_error::DeviceError,
"Calculated frame count is too large: %" PRIu64, FrameCount64};
UInt32 outputFrameCount{};
@@ -579,8 +589,8 @@ void CoreAudioCapture::open(const ALCchar *name)
err = AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_MaximumFramesPerSlice,
kAudioUnitScope_Global, 0, &outputFrameCount, &propertySize);
if(err != noErr || propertySize != sizeof(outputFrameCount))
- throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input frame count: %u",
- err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Could not get input frame count: %u", err};
outputFrameCount = static_cast<UInt32>(maxu64(outputFrameCount, FrameCount64));
mRing = RingBuffer::Create(outputFrameCount, mFrameSize, false);
@@ -599,7 +609,8 @@ void CoreAudioCapture::start()
{
OSStatus err{AudioOutputUnitStart(mAudioUnit)};
if(err != noErr)
- throw al::backend_exception{ALC_INVALID_DEVICE, "AudioOutputUnitStart failed: %d", err};
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "AudioOutputUnitStart failed: %d", err};
}
void CoreAudioCapture::stop()