Skip to content

Commit

Permalink
the local pan middle position is no longer attenuated in Mono-in/Ster…
Browse files Browse the repository at this point in the history
…eo-out mode (#353)
  • Loading branch information
corrados committed Jun 18, 2020
1 parent ca60870 commit e73b198
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- 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)



Expand Down
12 changes: 7 additions & 5 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
if ( eAudioChannelConf == CC_STEREO )
{
// 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 dGainR = std::min ( 0.5, dPan ) * 2;
const double dGainL = MathUtils::GetLeftPan ( dPan, false );
const double dGainR = MathUtils::GetRightPan ( dPan, false );

for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
{
Expand All @@ -1004,12 +1004,14 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
}
else
{
// for mono implement a cross-fade between channels and mix them
const double dGainL = 1 - dPan;
const double dGainR = dPan;
// for mono implement a cross-fade between channels and mix them, for
// mono-in/stereo-out use no attenuation in pan center
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 )
{
// note that we need the Double2Short for stereo pan mode
vecsStereoSndCrd[i] = Double2Short (
dGainL * vecsStereoSndCrd[j] + dGainR * vecsStereoSndCrd[j + 1] );
}
Expand Down
4 changes: 2 additions & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,8 @@ void CServer::ProcessData ( const CVector<CVector<int16_t> >& vecvecsData,

// calculate combined gain/pan for each stereo channel where we define
// the panning that center equals full gain for both channels
const double dGainL = std::min ( 0.5, 1 - dPan ) * 2 * dGain;
const double dGainR = std::min ( 0.5, dPan ) * 2 * dGain;
const double dGainL = MathUtils::GetLeftPan ( dPan, false ) * dGain;
const double dGainR = MathUtils::GetRightPan ( dPan, false ) * dGain;

// if channel gain is 1, avoid multiplication for speed optimization
if ( ( dGainL == static_cast<double> ( 1.0 ) ) && ( dGainR == static_cast<double> ( 1.0 ) ) )
Expand Down
19 changes: 13 additions & 6 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,6 @@ class ConsoleWriterFactory
/******************************************************************************\
* Other Classes/Enums *
\******************************************************************************/


// Audio channel configuration -------------------------------------------------
enum EAudChanConf
{
Expand Down Expand Up @@ -1199,13 +1197,11 @@ class MathUtils
// different IIR weights for up and down direction
if ( dNewValue < dOldValue )
{
dOldValue =
dOldValue * dWeightDown + ( 1.0 - dWeightDown ) * dNewValue;
dOldValue = dOldValue * dWeightDown + ( 1.0 - dWeightDown ) * dNewValue;
}
else
{
dOldValue =
dOldValue * dWeightUp + ( 1.0 - dWeightUp ) * dNewValue;
dOldValue = dOldValue * dWeightUp + ( 1.0 - dWeightUp ) * dNewValue;
}
}

Expand All @@ -1223,6 +1219,17 @@ class MathUtils
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;
}
};


Expand Down

0 comments on commit e73b198

Please sign in to comment.