From 4cfd54b21b67333eec1026e8d687e51b1788ffc3 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sun, 29 Mar 2020 18:03:24 +0200 Subject: [PATCH] audio fade-in at the server if new client connects --- ChangeLog | 3 ++- src/channel.cpp | 10 ++++++++++ src/channel.h | 14 +++++++++++++- src/server.cpp | 15 +++++++-------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index c046813f..6eebf3ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,10 +4,11 @@ - changed the maximum number of clients from 20 to 40 +- audio fade-in at the server if new client connects + TODO add a QScrollArea to the mixer board to get a scroll bar if we have too many mixer faders -TODO slowly fade in the audio at the server for all inputs of client which new connects to the server and also if new other client enters the server diff --git a/src/channel.cpp b/src/channel.cpp index 8dcd597d..bebdf501 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -29,6 +29,7 @@ CChannel::CChannel ( const bool bNIsServer ) : vecdGains ( MAX_NUM_CHANNELS, 1.0 ), bDoAutoSockBufSize ( true ), + iFadeInCnt ( 0 ), bIsEnabled ( false ), bIsServer ( bNIsServer ) { @@ -461,6 +462,12 @@ EPutDataStat CChannel::PutAudioData ( const CVector& vecbyData, { eRet = PS_AUDIO_ERR; } + + // manage audio fade-in counter + if ( iFadeInCnt < FADE_IN_NUM_FRAMES ) + { + iFadeInCnt++; + } } else { @@ -481,6 +488,9 @@ EPutDataStat CChannel::PutAudioData ( const CVector& vecbyData, { // overwrite status eRet = PS_NEW_CONNECTION; + + // init audio fade-in counter + iFadeInCnt = 0; } // reset time-out counter (note that this must be done after the diff --git a/src/channel.h b/src/channel.h index 618c02f0..1f855877 100755 --- a/src/channel.h +++ b/src/channel.h @@ -36,11 +36,21 @@ /* Definitions ****************************************************************/ -// Set the time-out for the input buffer until the state changes from +// set the time-out for the input buffer until the state changes from // connected to not connected (the actual time depends on the way the error // correction is implemented) #define CON_TIME_OUT_SEC_MAX 30 // seconds +// number of frames for audio fade-in +#if ( SYSTEM_FRAME_SIZE_SAMPLES == 64 ) +// 48 kHz, 64 samples: 2 seconds / ( 64 samples / 48 kHz ) = 2250 +# define FADE_IN_NUM_FRAMES 1500 +#else +// 48 kHz, 128 samples: 2 seconds / ( 128 samples / 48 kHz ) = 1125 +# define FADE_IN_NUM_FRAMES 750 +#endif + + enum EPutDataStat { PS_GEN_ERROR, @@ -103,6 +113,7 @@ public: void SetGain ( const int iChanID, const double dNewGain ); double GetGain ( const int iChanID ); + double GetFadeInGain() { return static_cast ( iFadeInCnt ) / FADE_IN_NUM_FRAMES; } void SetRemoteChanGain ( const int iId, const double dGain ) { Protocol.CreateChanGainMes ( iId, dGain ); } @@ -190,6 +201,7 @@ protected: int iConTimeOut; int iConTimeOutStartVal; + int iFadeInCnt; bool bIsEnabled; bool bIsServer; diff --git a/src/server.cpp b/src/server.cpp index 5ddc2df3..fd8af258 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -833,10 +833,8 @@ JitterMeas.Measure(); const int iCurChanID = vecChanIDsCurConChan[i]; // get and store number of audio channels - const int iCurNumAudChan = - vecChannels[iCurChanID].GetNumAudioChannels(); - - vecNumAudioChannels[i] = iCurNumAudChan; + const int iCurNumAudChan = vecChannels[iCurChanID].GetNumAudioChannels(); + vecNumAudioChannels[i] = iCurNumAudChan; // get gains of all connected channels for ( j = 0; j < iNumClients; j++ ) @@ -845,13 +843,14 @@ JitterMeas.Measure(); // the channel ID! Therefore we have to use // "vecChanIDsCurConChan" to query the IDs of the currently // connected channels - vecvecdGains[i][j] = - vecChannels[iCurChanID].GetGain( vecChanIDsCurConChan[j] ); + vecvecdGains[i][j] = vecChannels[iCurChanID].GetGain ( vecChanIDsCurConChan[j] ); + + // consider audio fade-in + vecvecdGains[i][j] *= vecChannels[vecChanIDsCurConChan[j]].GetFadeInGain(); } // get current number of CELT coded bytes - const int iCeltNumCodedBytes = - vecChannels[iCurChanID].GetNetwFrameSize(); + const int iCeltNumCodedBytes = vecChannels[iCurChanID].GetNetwFrameSize(); // get data const EGetDataStat eGetStat =