@@ -468,6 +468,7 @@ SIMDALIGNEDSTRUCT ALsource
468468 ALfloat cone_inner_angle ;
469469 ALfloat cone_outer_angle ;
470470 ALfloat cone_outer_gain ;
471+ ALfloat EXT_balance ; /* stereo linear balance extension */
471472 ALbuffer * buffer ;
472473 SDL_AudioStream * stream ; /* for resampling. */
473474 BufferQueue buffer_queue ;
@@ -1706,7 +1707,12 @@ static void calculate_channel_gains(const ALCcontext *ctx, const ALsource *src,
17061707
17071708 /* this goes through the steps the AL spec dictates for gain and distance attenuation... */
17081709
1709- if (!spatialize ) {
1710+ if (src -> queue_channels == 2 ) {
1711+ gain = SDL_min (SDL_max (src -> gain , src -> min_gain ), src -> max_gain ) * ctx -> listener .gain ;
1712+ gains [0 ] = gain * SDL_min (1.f , 1.f - src -> EXT_balance ); // left channel
1713+ gains [1 ] = gain * SDL_min (1.f , 1.f + src -> EXT_balance ); // right channel
1714+ return ;
1715+ } else if (!spatialize ) {
17101716 /* simpler path through the same AL spec details if not spatializing. */
17111717 gain = SDL_min (SDL_max (src -> gain , src -> min_gain ), src -> max_gain ) * ctx -> listener .gain ;
17121718 gains [0 ] = gains [1 ] = gain ; /* no spatialization, but AL_GAIN (etc) is still applied. */
@@ -3712,6 +3718,8 @@ static void _alSourcefv(const ALuint name, const ALenum param, const ALfloat *va
37123718 source_set_offset (src , param , * values );
37133719 break ;
37143720
3721+ case AL_EXT_BALANCE : src -> EXT_balance = * values ; break ;
3722+
37153723 default : set_al_error (ctx , AL_INVALID_ENUM ); return ;
37163724
37173725 }
@@ -3736,6 +3744,7 @@ static void _alSourcef(const ALuint name, const ALenum param, const ALfloat valu
37363744 case AL_SEC_OFFSET :
37373745 case AL_SAMPLE_OFFSET :
37383746 case AL_BYTE_OFFSET :
3747+ case AL_EXT_BALANCE :
37393748 _alSourcefv (name , param , & value );
37403749 break ;
37413750
@@ -3917,6 +3926,8 @@ static void _alGetSourcefv(const ALuint name, const ALenum param, ALfloat *value
39173926 * values = source_get_offset (src , param );
39183927 break ;
39193928
3929+ case AL_EXT_BALANCE : * values = src -> EXT_balance ; break ;
3930+
39203931 default : set_al_error (ctx , AL_INVALID_ENUM ); break ;
39213932 }
39223933}
@@ -3938,6 +3949,7 @@ static void _alGetSourcef(const ALuint name, const ALenum param, ALfloat *value)
39383949 case AL_SEC_OFFSET :
39393950 case AL_SAMPLE_OFFSET :
39403951 case AL_BYTE_OFFSET :
3952+ case AL_EXT_BALANCE :
39413953 _alGetSourcefv (name , param , value );
39423954 break ;
39433955 default : set_al_error (get_current_context (), AL_INVALID_ENUM ); break ;
0 commit comments