the local pan middle position is no longer attenuated in Mono-in/Stereo-out mode (#353)

This commit is contained in:
Volker Fischer 2020-06-18 19:16:31 +02:00
parent ca60870a55
commit e73b198f92
4 changed files with 23 additions and 13 deletions

View File

@ -15,6 +15,7 @@
- add a headless build type which does not depend on QtGui/QtWidgets, coded by marcan (#322) - add a headless build type which does not depend on QtGui/QtWidgets, coded by marcan (#322)
- the local pan middle position is no longer attenuated in Mono-in/Stereo-out mode (#353)

View File

@ -991,8 +991,8 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
if ( eAudioChannelConf == CC_STEREO ) if ( eAudioChannelConf == CC_STEREO )
{ {
// for stereo only apply pan attenuation on one channel (same as pan in the server) // for stereo only apply pan attenuation on one channel (same as pan in the server)
const double dGainL = std::min ( 0.5, 1 - dPan ) * 2; const double dGainL = MathUtils::GetLeftPan ( dPan, false );
const double dGainR = std::min ( 0.5, dPan ) * 2; const double dGainR = MathUtils::GetRightPan ( dPan, false );
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 ) for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
{ {
@ -1004,12 +1004,14 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
} }
else else
{ {
// for mono implement a cross-fade between channels and mix them // for mono implement a cross-fade between channels and mix them, for
const double dGainL = 1 - dPan; // mono-in/stereo-out use no attenuation in pan center
const double dGainR = dPan; const double dGainL = MathUtils::GetLeftPan ( dPan, eAudioChannelConf != CC_MONO_IN_STEREO_OUT );
const double dGainR = MathUtils::GetRightPan ( dPan, eAudioChannelConf != CC_MONO_IN_STEREO_OUT );
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 ) for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
{ {
// note that we need the Double2Short for stereo pan mode
vecsStereoSndCrd[i] = Double2Short ( vecsStereoSndCrd[i] = Double2Short (
dGainL * vecsStereoSndCrd[j] + dGainR * vecsStereoSndCrd[j + 1] ); dGainL * vecsStereoSndCrd[j] + dGainR * vecsStereoSndCrd[j + 1] );
} }

View File

@ -1203,8 +1203,8 @@ void CServer::ProcessData ( const CVector<CVector<int16_t> >& vecvecsData,
// calculate combined gain/pan for each stereo channel where we define // calculate combined gain/pan for each stereo channel where we define
// the panning that center equals full gain for both channels // the panning that center equals full gain for both channels
const double dGainL = std::min ( 0.5, 1 - dPan ) * 2 * dGain; const double dGainL = MathUtils::GetLeftPan ( dPan, false ) * dGain;
const double dGainR = std::min ( 0.5, dPan ) * 2 * dGain; const double dGainR = MathUtils::GetRightPan ( dPan, false ) * dGain;
// if channel gain is 1, avoid multiplication for speed optimization // if channel gain is 1, avoid multiplication for speed optimization
if ( ( dGainL == static_cast<double> ( 1.0 ) ) && ( dGainR == static_cast<double> ( 1.0 ) ) ) if ( ( dGainL == static_cast<double> ( 1.0 ) ) && ( dGainR == static_cast<double> ( 1.0 ) ) )

View File

@ -508,8 +508,6 @@ private:
/******************************************************************************\ /******************************************************************************\
* Other Classes/Enums * * Other Classes/Enums *
\******************************************************************************/ \******************************************************************************/
// Audio channel configuration ------------------------------------------------- // Audio channel configuration -------------------------------------------------
enum EAudChanConf enum EAudChanConf
{ {
@ -1199,13 +1197,11 @@ public:
// different IIR weights for up and down direction // different IIR weights for up and down direction
if ( dNewValue < dOldValue ) if ( dNewValue < dOldValue )
{ {
dOldValue = dOldValue = dOldValue * dWeightDown + ( 1.0 - dWeightDown ) * dNewValue;
dOldValue * dWeightDown + ( 1.0 - dWeightDown ) * dNewValue;
} }
else else
{ {
dOldValue = dOldValue = dOldValue * dWeightUp + ( 1.0 - dWeightUp ) * dNewValue;
dOldValue * dWeightUp + ( 1.0 - dWeightUp ) * dNewValue;
} }
} }
@ -1223,6 +1219,17 @@ public:
return round ( dValue + dHysteresis ); return round ( dValue + dHysteresis );
} }
} }
// calculate pan gains: in cross fade mode the pan center is attenuated
// by 6 dB, otherwise the center equals full gain for both channels
static inline double GetLeftPan ( const double dPan, const bool bXFade)
{
return bXFade ? 1 - dPan : std::min ( 0.5, 1 - dPan ) * 2;
}
static inline double GetRightPan ( const double dPan, const bool bXFade)
{
return bXFade ? dPan : std::min ( 0.5, dPan ) * 2;
}
}; };