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
44 changes: 21 additions & 23 deletions src/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,6 @@ void CChannel::SetGain ( const int iChanID, const float fNewGain )
}
}

float CChannel::GetGain ( const int iChanID )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed

{
QMutexLocker locker ( &Mutex );

// get value (make sure channel ID is in range)
if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
{
return vecfGains[iChanID];
}
else
{
return 0;
}
}

void CChannel::SetPan ( const int iChanID, const float fNewPan )
{
QMutexLocker locker ( &Mutex );
Expand All @@ -342,18 +327,31 @@ void CChannel::SetPan ( const int iChanID, const float fNewPan )
}
}

float CChannel::GetPan ( const int iChanID )
/// @brief Copies a consistent snapshot of gain and panning settings for the requested channel IDs under Mutex.
/// @param vecChanIDs Channel IDs to read, in the order used for the output vectors.
/// @param iNumClients Number of leading entries to read and populate. All three vectors must contain at least this many entries.
/// @param vecGains Receives each requested channel's gain, or zero for an out-of-range channel ID.
/// @param vecPannings Receives each requested channel's panning, or zero for an out-of-range channel ID.
void CChannel::GetGainsAndPannings ( const CVector<int>& vecChanIDs, const int iNumClients, CVector<float>& vecGains, CVector<float>& vecPannings )
{
QMutexLocker locker ( &Mutex );

// get value (make sure channel ID is in range)
if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
// copy the gain and pan values of the connected channels
for ( int j = 0; j < iNumClients; j++ )
{
return vecfPannings[iChanID];
}
else
{
return 0;
const int iChanID = vecChanIDs[j];

if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
{
vecGains[j] = vecfGains[iChanID];
vecPannings[j] = vecfPannings[iChanID];
}
else
{
// should not happen
vecGains[j] = 0;
vecPannings[j] = 0;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ class CChannel : public QObject
void CreateMuteStateHasChangedMes ( const int iChanID, const bool bIsMuted ) { Protocol.CreateMuteStateHasChangedMes ( iChanID, bIsMuted ); }

void SetGain ( const int iChanID, const float fNewGain );
float GetGain ( const int iChanID );
float GetFadeInGain() { return static_cast<float> ( iFadeInCnt ) / iFadeInCntMax; }

void SetPan ( const int iChanID, const float fNewPan );
float GetPan ( const int iChanID );
void SetPan ( const int iChanID, const float fNewPan );

void GetGainsAndPannings ( const CVector<int>& vecChanIDs, const int iNumClients, CVector<float>& vecGains, CVector<float>& vecPannings );

void SetRemoteChanGain ( const int iId, const float fGain ) { Protocol.CreateChanGainMes ( iId, fGain ); }

Expand Down
18 changes: 8 additions & 10 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,15 +896,16 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
CurOpusDecoder = nullptr;
}

// get gains of all 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! Therefore we have to use
// "vecChanIDsCurConChan" to query the IDs of the currently
// connected channels
vecChannels[iCurChanID].GetGainsAndPannings ( vecChanIDsCurConChan, iNumClients, vecvecfGains[iChanCnt], vecvecfPannings[iChanCnt] );

for ( int j = 0; j < iNumClients; j++ )
Comment thread
pljones marked this conversation as resolved.
{
// The second index of "vecvecdGains" does not represent
// the channel ID! Therefore we have to use
// "vecChanIDsCurConChan" to query the IDs of the currently
// connected channels
vecvecfGains[iChanCnt][j] = vecChannels[iCurChanID].GetGain ( vecChanIDsCurConChan[j] );

// consider audio fade-in
vecvecfGains[iChanCnt][j] *= vecChannels[vecChanIDsCurConChan[j]].GetFadeInGain();

Expand All @@ -914,9 +915,6 @@ void CServer::DecodeReceiveData ( const int iChanCnt, const int iNumClients )
{
vecvecfGains[iChanCnt][j] *= vecChannels[iCurChanID].GetFadeInGain();
}

// panning
vecvecfPannings[iChanCnt][j] = vecChannels[iCurChanID].GetPan ( vecChanIDsCurConChan[j] );
}

// If the server frame size is smaller than the received OPUS frame size, we need a conversion
Expand Down
Loading