static OSStatus init_out_device(CoreaudioVoiceOut *core)
{
+ AudioDeviceID device_id;
+ AudioDeviceIOProcID ioprocid;
AudioValueRange value_range;
OSStatus status;
+ UInt32 device_frame_size;
AudioStreamBasicDescription stream_basic_description = {
.mBitsPerChannel = audio_format_bits(core->hw.info.af),
.mSampleRate = core->hw.info.freq
};
- status = coreaudio_get_voice_out(&core->device_id);
+ status = coreaudio_get_voice_out(&device_id);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr(status,
"Could not get default output device");
return status;
}
- if (core->device_id == kAudioDeviceUnknown) {
+ if (device_id == kAudioDeviceUnknown) {
error_report("coreaudio: Could not initialize playback: "
"Unknown audio device");
return status;
}
/* get minimum and maximum buffer frame sizes */
- status = coreaudio_get_out_framesizerange(core->device_id, &value_range);
+ status = coreaudio_get_out_framesizerange(device_id, &value_range);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
}
if (value_range.mMinimum > core->frame_size_setting) {
- core->device_frame_size = value_range.mMinimum;
+ device_frame_size = value_range.mMinimum;
warn_report("coreaudio: Upsizing buffer frames to %f",
value_range.mMinimum);
} else if (value_range.mMaximum < core->frame_size_setting) {
- core->device_frame_size = value_range.mMaximum;
+ device_frame_size = value_range.mMaximum;
warn_report("coreaudio: Downsizing buffer frames to %f",
value_range.mMaximum);
} else {
- core->device_frame_size = core->frame_size_setting;
+ device_frame_size = core->frame_size_setting;
}
/* set Buffer Frame Size */
- status = coreaudio_set_out_framesize(core->device_id,
- &core->device_frame_size);
+ status = coreaudio_set_out_framesize(device_id, &device_frame_size);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr(status,
"Could not set device buffer frame size %" PRIu32,
- (uint32_t)core->device_frame_size);
+ (uint32_t)device_frame_size);
return status;
}
/* get Buffer Frame Size */
- status = coreaudio_get_out_framesize(core->device_id,
- &core->device_frame_size);
+ status = coreaudio_get_out_framesize(device_id, &device_frame_size);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
"Could not get device buffer frame size");
return status;
}
- core->hw.samples = core->buffer_count * core->device_frame_size;
/* set Samplerate */
- status = coreaudio_set_out_streamformat(core->device_id,
+ status = coreaudio_set_out_streamformat(device_id,
&stream_basic_description);
if (status == kAudioHardwareBadObjectError) {
return 0;
coreaudio_playback_logerr(status,
"Could not set samplerate %lf",
stream_basic_description.mSampleRate);
- core->device_id = kAudioDeviceUnknown;
return status;
}
* Therefore, the specified callback must be designed to avoid a deadlock
* with the callers of AudioObjectGetPropertyData.
*/
- core->ioprocid = NULL;
- status = AudioDeviceCreateIOProcID(core->device_id,
+ ioprocid = NULL;
+ status = AudioDeviceCreateIOProcID(device_id,
out_device_ioproc,
&core->hw,
- &core->ioprocid);
+ &ioprocid);
if (status == kAudioHardwareBadDeviceError) {
return 0;
}
- if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
+ if (status != kAudioHardwareNoError || ioprocid == NULL) {
coreaudio_playback_logerr(status, "Could not set IOProc");
- core->device_id = kAudioDeviceUnknown;
return status;
}
+ core->device_id = device_id;
+ core->device_frame_size = device_frame_size;
+ core->hw.samples = core->buffer_count * core->device_frame_size;
+ core->ioprocid = ioprocid;
+
return 0;
}
fini_out_device(core);
}
- if (!init_out_device(core)) {
+ init_out_device(core);
+
+ if (core->device_id) {
update_out_device_playback_state(core);
}
k->max_voices_out = 1;
k->max_voices_in = 0;
- k->voice_size_out = sizeof(coreaudioVoiceOut);
+ k->voice_size_out = sizeof(CoreaudioVoiceOut);
k->voice_size_in = 0;
k->init_out = coreaudio_init_out;