@@ -118,6 +118,9 @@ typedef struct ao_coreaudio_s
118
118
119
119
static ao_coreaudio_t * ao = NULL ;
120
120
121
+ /* variable to store the volume when changing between audio units */
122
+ static Float32 temp_vol = -1.0 ;
123
+
121
124
/**
122
125
* \brief add data to ringbuffer
123
126
*/
@@ -581,6 +584,14 @@ int device_id, display_help = 0;
581
584
goto err_out1 ;
582
585
}
583
586
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
+
584
595
size = sizeof (AudioStreamBasicDescription );
585
596
err = AudioUnitSetProperty (ao -> theOutputUnit , kAudioUnitProperty_StreamFormat , kAudioUnitScope_Input , 0 , & inDesc , size );
586
597
@@ -1137,6 +1148,12 @@ static void uninit(int immed)
1137
1148
{
1138
1149
OSStatus err = noErr ;
1139
1150
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
+
1140
1157
if (!immed ) {
1141
1158
long long timeleft = (1000000LL * av_fifo_size (ao -> buffer ))/ao_data .bps ;
1142
1159
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