@@ -471,6 +471,7 @@ SIMDALIGNEDSTRUCT ALsource
471471 ALfloat cone_inner_angle ;
472472 ALfloat cone_outer_angle ;
473473 ALfloat cone_outer_gain ;
474+ ALfloat EXT_balance ; /* stereo linear balance extension */
474475 ALbuffer * buffer ;
475476 SDL_AudioStream * stream ; /* for resampling. */
476477 SDL_atomic_t total_queued_buffers ; /* everything queued, playing and processed. AL_BUFFERS_QUEUED value. */
@@ -1710,7 +1711,12 @@ static void calculate_channel_gains(const ALCcontext *ctx, const ALsource *src,
17101711
17111712 /* this goes through the steps the AL spec dictates for gain and distance attenuation... */
17121713
1713- if (!spatialize ) {
1714+ if (src -> queue_channels == 2 ) {
1715+ gain = SDL_min (SDL_max (src -> gain , src -> min_gain ), src -> max_gain ) * ctx -> listener .gain ;
1716+ gains [0 ] = gain * SDL_min (1.f , 1.f - src -> EXT_balance ); // left channel
1717+ gains [1 ] = gain * SDL_min (1.f , 1.f + src -> EXT_balance ); // right channel
1718+ return ;
1719+ } else if (!spatialize ) {
17141720 /* simpler path through the same AL spec details if not spatializing. */
17151721 gain = SDL_min (SDL_max (src -> gain , src -> min_gain ), src -> max_gain ) * ctx -> listener .gain ;
17161722 gains [0 ] = gains [1 ] = gain ; /* no spatialization, but AL_GAIN (etc) is still applied. */
@@ -3727,6 +3733,8 @@ static void _alSourcefv(const ALuint name, const ALenum param, const ALfloat *va
37273733 source_set_offset (src , param , * values );
37283734 break ;
37293735
3736+ case AL_EXT_BALANCE : src -> EXT_balance = * values ; break ;
3737+
37303738 default : set_al_error (ctx , AL_INVALID_ENUM ); return ;
37313739
37323740 }
@@ -3751,6 +3759,7 @@ static void _alSourcef(const ALuint name, const ALenum param, const ALfloat valu
37513759 case AL_SEC_OFFSET :
37523760 case AL_SAMPLE_OFFSET :
37533761 case AL_BYTE_OFFSET :
3762+ case AL_EXT_BALANCE :
37543763 _alSourcefv (name , param , & value );
37553764 break ;
37563765
@@ -3932,6 +3941,8 @@ static void _alGetSourcefv(const ALuint name, const ALenum param, ALfloat *value
39323941 * values = source_get_offset (src , param );
39333942 break ;
39343943
3944+ case AL_EXT_BALANCE : * values = src -> EXT_balance ; break ;
3945+
39353946 default : set_al_error (ctx , AL_INVALID_ENUM ); break ;
39363947 }
39373948}
@@ -3953,6 +3964,7 @@ static void _alGetSourcef(const ALuint name, const ALenum param, ALfloat *value)
39533964 case AL_SEC_OFFSET :
39543965 case AL_SAMPLE_OFFSET :
39553966 case AL_BYTE_OFFSET :
3967+ case AL_EXT_BALANCE :
39563968 _alGetSourcefv (name , param , value );
39573969 break ;
39583970 default : set_al_error (get_current_context (), AL_INVALID_ENUM ); break ;
0 commit comments