diff --git a/src/buffer.cpp b/src/buffer.cpp index a067d7b6..578d5f1f 100755 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -97,7 +97,9 @@ CNetBufWithStats::CNetBufWithStats() : dAutoFilt_WightUpNormal ( IIR_WEIGTH_UP_NORMAL ), dAutoFilt_WightDownNormal ( IIR_WEIGTH_DOWN_NORMAL ), dAutoFilt_WightUpFast ( IIR_WEIGTH_UP_FAST ), - dAutoFilt_WightDownFast ( IIR_WEIGTH_DOWN_FAST ) + dAutoFilt_WightDownFast ( IIR_WEIGTH_DOWN_FAST ), + dErrorRateBound ( ERROR_RATE_BOUND ), + dUpMaxErrorBound ( UP_MAX_ERROR_BOUND ) { // Define the sizes of the simulation buffers, // must be NUM_STAT_SIMULATION_BUFFERS elements! @@ -135,8 +137,8 @@ void CNetBufWithStats::GetErrorRates ( CVector& vecErrRates, } // get the limits for the decisions - dLimit = ERROR_RATE_BOUND; - dMaxUpLimit = UP_MAX_ERROR_BOUND; + dLimit = dErrorRateBound; + dMaxUpLimit = dUpMaxErrorBound; } void CNetBufWithStats::Init ( const int iNewBlockSize, @@ -157,6 +159,8 @@ void CNetBufWithStats::Init ( const int iNewBlockSize, dAutoFilt_WightUpFast = IIR_WEIGTH_UP_FAST_DOUBLE_FRAME_SIZE; dAutoFilt_WightDownFast = IIR_WEIGTH_DOWN_FAST_DOUBLE_FRAME_SIZE; iMaxStatisticCount = MAX_STATISTIC_COUNT_DOUBLE_FRAME_SIZE; + dErrorRateBound = ERROR_RATE_BOUND_DOUBLE_FRAME_SIZE; + dUpMaxErrorBound = UP_MAX_ERROR_BOUND_DOUBLE_FRAME_SIZE; } else { @@ -165,6 +169,8 @@ void CNetBufWithStats::Init ( const int iNewBlockSize, dAutoFilt_WightUpFast = IIR_WEIGTH_UP_FAST; dAutoFilt_WightDownFast = IIR_WEIGTH_DOWN_FAST; iMaxStatisticCount = MAX_STATISTIC_COUNT; + dErrorRateBound = ERROR_RATE_BOUND; + dUpMaxErrorBound = UP_MAX_ERROR_BOUND; } for ( int i = 0; i < NUM_STAT_SIMULATION_BUFFERS; i++ ) @@ -248,7 +254,7 @@ void CNetBufWithStats::UpdateAutoSetting() for ( int i = 0; i < NUM_STAT_SIMULATION_BUFFERS - 1; i++ ) { if ( ( !bDecisionFound ) && - ( ErrorRateStatistic[i].GetAverage() <= ERROR_RATE_BOUND ) ) + ( ErrorRateStatistic[i].GetAverage() <= dErrorRateBound ) ) { iCurDecision = viBufSizesForSim[i]; bDecisionFound = true; @@ -272,7 +278,7 @@ void CNetBufWithStats::UpdateAutoSetting() for ( int i = 0; i < NUM_STAT_SIMULATION_BUFFERS - 1; i++ ) { if ( ( !bDecisionFound ) && - ( ErrorRateStatistic[i].GetAverage() <= UP_MAX_ERROR_BOUND ) ) + ( ErrorRateStatistic[i].GetAverage() <= dUpMaxErrorBound ) ) { iCurMaxUpDecision = viBufSizesForSim[i]; bDecisionFound = true; @@ -369,7 +375,7 @@ else { // check error rate of the largest buffer as the indicator if ( ErrorRateStatistic[NUM_STAT_SIMULATION_BUFFERS - 1]. - GetAverage() > ERROR_RATE_BOUND ) + GetAverage() > dErrorRateBound ) { for ( int i = 0; i < NUM_STAT_SIMULATION_BUFFERS; i++ ) { diff --git a/src/buffer.h b/src/buffer.h index 4890130e..a57a0563 100755 --- a/src/buffer.h +++ b/src/buffer.h @@ -37,17 +37,23 @@ #define FILTER_DECISION_HYSTERESIS 0.1 // definition of the upper error bound of the jitter buffers -#define ERROR_RATE_BOUND 0.001 +#define ERROR_RATE_BOUND_DOUBLE_FRAME_SIZE 0.001 +#define ERROR_RATE_BOUND ( ERROR_RATE_BOUND_DOUBLE_FRAME_SIZE / 2 ) // definition of the upper jitter buffer error bound, if that one is reached we // have to speed up the filtering to quickly get out of a incorrect buffer // size state -#define UP_MAX_ERROR_BOUND 0.01 +#define UP_MAX_ERROR_BOUND_DOUBLE_FRAME_SIZE 0.01 +#define UP_MAX_ERROR_BOUND ( UP_MAX_ERROR_BOUND_DOUBLE_FRAME_SIZE / 2 ) // each regular buffer access lead to a count for put and get, assuming 2.66 ms // blocks we have 15 s / 2.66 ms * 2 = approx. 11000 #define MAX_STATISTIC_COUNT_DOUBLE_FRAME_SIZE 11000 +// each regular buffer access lead to a count for put and get, assuming 1.33 ms +// blocks we have 15 s / 1.33 ms * 2 = approx. 22500 +#define MAX_STATISTIC_COUNT 22500 + // Note that the following definitions of the weigh constants assume a block // size of 128 samples at a sampling rate of 48 kHz. #define IIR_WEIGTH_UP_NORMAL_DOUBLE_FRAME_SIZE 0.999995 @@ -55,10 +61,6 @@ #define IIR_WEIGTH_UP_FAST_DOUBLE_FRAME_SIZE 0.9995 #define IIR_WEIGTH_DOWN_FAST_DOUBLE_FRAME_SIZE 0.999 -// each regular buffer access lead to a count for put and get, assuming 1.33 ms -// blocks we have 15 s / 1.33 ms * 2 = approx. 22500 -#define MAX_STATISTIC_COUNT 22500 - // convert numbers from 128 samples case using http://www.tsdconseil.fr/tutos/tuto-iir1-en.pdf // and https://octave-online.net: // gamma = exp(-Ts/tau), after some calculations we get: x=0.999995;exp(64/128*log(x)) @@ -459,6 +461,8 @@ protected: double dAutoFilt_WightDownNormal; double dAutoFilt_WightUpFast; double dAutoFilt_WightDownFast; + double dErrorRateBound; + double dUpMaxErrorBound; };