Skip to content

Commit 33893ca

Browse files
pigozastiob
authored andcommitted
ao_coreaudio: remember volume between chapters
1 parent 2c378c7 commit 33893ca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libao2/ao_coreaudio.c

+17
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ typedef struct ao_coreaudio_s
118118

119119
static ao_coreaudio_t *ao = NULL;
120120

121+
/* variable to store the volume when changing between audio units */
122+
static Float32 temp_vol = -1.0;
123+
121124
/**
122125
* \brief add data to ringbuffer
123126
*/
@@ -581,6 +584,14 @@ int device_id, display_help = 0;
581584
goto err_out1;
582585
}
583586

587+
if (temp_vol >= 0) {
588+
err = AudioUnitSetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, temp_vol, 0);
589+
if (err) {
590+
ao_msg(MSGT_AO, MSGL_WARN, "could not restore the HAL output volume: [%4.4s]\n", (char *)&err);
591+
goto err_out2;
592+
}
593+
}
594+
584595
size = sizeof(AudioStreamBasicDescription);
585596
err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);
586597

@@ -1137,6 +1148,12 @@ static void uninit(int immed)
11371148
{
11381149
OSStatus err = noErr;
11391150

1151+
err = AudioUnitGetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, &temp_vol);
1152+
if(err) {
1153+
temp_vol = -1.0; // backing off to standard volume
1154+
ao_msg(MSGT_AO, MSGL_WARN, "could not save HAL output volume: [%4.4s]\n", (char *)&err);
1155+
}
1156+
11401157
if (!immed) {
11411158
long long timeleft=(1000000LL*av_fifo_size(ao->buffer))/ao_data.bps;
11421159
ao_msg(MSGT_AO,MSGL_DBG2, "%d bytes left @%d bps (%d usec)\n", av_fifo_size(ao->buffer), ao_data.bps, (int)timeleft);

0 commit comments

Comments
 (0)