From fa85bfde6943e5d2955830cd5e51f24210022719 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 1 Jul 2014 19:14:55 +0200 Subject: ao_coreaudio: split control to helper functions --- audio/out/ao_coreaudio.c | 53 +++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index 35baf6ebf9..615bb41fa0 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -68,34 +68,41 @@ static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags, return noErr; } +static int get_volume(struct ao *ao, struct ao_control_vol *vol) { + struct priv *p = ao->priv; + float auvol; + OSStatus err = + AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume, + kAudioUnitScope_Global, 0, &auvol); + + CHECK_CA_ERROR("could not get HAL output volume"); + vol->left = vol->right = auvol * 100.0; + return CONTROL_TRUE; +coreaudio_error: + return CONTROL_ERROR; +} + +static int set_volume(struct ao *ao, struct ao_control_vol *vol) { + struct priv *p = ao->priv; + float auvol = (vol->left + vol->right) / 200.0; + OSStatus err = + AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume, + kAudioUnitScope_Global, 0, auvol, 0); + CHECK_CA_ERROR("could not set HAL output volume"); + return CONTROL_TRUE; +coreaudio_error: + return CONTROL_ERROR; +} + static int control(struct ao *ao, enum aocontrol cmd, void *arg) { - struct priv *p = ao->priv; switch (cmd) { - case AOCONTROL_GET_VOLUME: { - ao_control_vol_t *control_vol = (ao_control_vol_t *)arg; - float vol; - OSStatus err = - AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume, - kAudioUnitScope_Global, 0, &vol); - CHECK_CA_ERROR("could not get HAL output volume"); - control_vol->left = control_vol->right = vol * 100.0; - return CONTROL_TRUE; - } - case AOCONTROL_SET_VOLUME: { - ao_control_vol_t *control_vol = (ao_control_vol_t *)arg; - float vol = (control_vol->left + control_vol->right) / 200.0; - OSStatus err = - AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume, - kAudioUnitScope_Global, 0, vol, 0); - CHECK_CA_ERROR("could not set HAL output volume"); - return CONTROL_TRUE; - } + case AOCONTROL_GET_VOLUME: + return get_volume(ao, arg); + case AOCONTROL_SET_VOLUME: + return set_volume(ao, arg); } // end switch return CONTROL_UNKNOWN; - -coreaudio_error: - return CONTROL_ERROR; } static bool init_chmap(struct ao *ao); -- cgit v1.2.3