Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ CServer::CServer ( const int iNewMaxNumChan,

// allocate worst case memory for the temporary vectors
vecChanIDsCurConChan.Init ( iMaxNumChannels );
vecfFadeInGains.Init ( iMaxNumChannels );
vecvecfGains.Init ( iMaxNumChannels );
vecvecfPannings.Init ( iMaxNumChannels );
vecvecsData.Init ( iMaxNumChannels );
Expand Down Expand Up @@ -678,6 +679,12 @@ void CServer::OnTimer()
// connected clients is less, only a subset of elements of this
// vector are actually used and the others are dummy elements)
vecChanIDsCurConChan[iNumClients] = i;

// read the fade-in gain of the channel once per frame for use in
// DecodeReceiveData() (the fade-in counters are only written under
// the server mutex, which is held here and for the whole decode phase)
vecfFadeInGains[iNumClients] = vecChannels[i].GetFadeInGain();

iNumClients++;
}
}
Expand Down Expand Up @@ -896,24 +903,24 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
CurOpusDecoder = nullptr;
}

// get gains and pannings of all connected channels, compacted to the
// order of "vecChanIDsCurConChan".
// The second index of "vecvecfGains" does not represent
// the channel ID! Therefore we have to use
// "vecChanIDsCurConChan" to query the IDs of the currently
// connected channels
// get gains and pannings of all connected channels, compacted to the order of
// "vecChanIDsCurConChan" (the second index of "vecvecfGains" does not represent the
// channel ID but the position in "vecChanIDsCurConChan")
vecChannels[iCurChanID].GetGainsAndPannings ( vecChanIDsCurConChan, iNumClients, vecvecfGains[iChanCnt], vecvecfPannings[iChanCnt] );

// apply the audio fade-in: each connected channel fades in with its own fade-in gain,
// and the fade-in gain of the current channel is applied to all other channels as well
// to avoid the client volumes being at 100% when joining a server (#628); the fade-in
// gains were read once per frame into "vecfFadeInGains" in the same order
const float fCurChanFadeInGain = vecfFadeInGains[iChanCnt];

for ( int j = 0; j < iNumClients; j++ )
{
// consider audio fade-in
vecvecfGains[iChanCnt][j] *= vecChannels[vecChanIDsCurConChan[j]].GetFadeInGain();
vecvecfGains[iChanCnt][j] *= vecfFadeInGains[j];

// use the fade in of the current channel for all other connected clients
// as well to avoid the client volumes are at 100% when joining a server (#628)
if ( j != iChanCnt )
{
vecvecfGains[iChanCnt][j] *= vecChannels[iCurChanID].GetFadeInGain();
vecvecfGains[iChanCnt][j] *= fCurChanFadeInGain;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>

CVector<QString> vstrChatColors;
CVector<int> vecChanIDsCurConChan;
CVector<float> vecfFadeInGains;

CVector<CVector<float>> vecvecfGains;
CVector<CVector<float>> vecvecfPannings;
Expand Down
Loading