speed optimzation: avoid some unnecessary conversions from short to double
This commit is contained in:
parent
9a2efd25fe
commit
379a3e9f9d
4 changed files with 40 additions and 61 deletions
|
@ -743,7 +743,6 @@ void CClient::Init()
|
||||||
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
|
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
|
||||||
|
|
||||||
vecsAudioSndCrdMono.Init ( iMonoBlockSizeSam );
|
vecsAudioSndCrdMono.Init ( iMonoBlockSizeSam );
|
||||||
vecdAudioStereo.Init ( iStereoBlockSizeSam );
|
|
||||||
|
|
||||||
// init reverberation
|
// init reverberation
|
||||||
AudioReverbL.Init ( SYSTEM_SAMPLE_RATE_HZ );
|
AudioReverbL.Init ( SYSTEM_SAMPLE_RATE_HZ );
|
||||||
|
@ -833,8 +832,6 @@ void CClient::Init()
|
||||||
vecbyNetwData.Init ( iCeltNumCodedBytes );
|
vecbyNetwData.Init ( iCeltNumCodedBytes );
|
||||||
if ( bUseStereo )
|
if ( bUseStereo )
|
||||||
{
|
{
|
||||||
vecsNetwork.Init ( iStereoBlockSizeSam );
|
|
||||||
|
|
||||||
// set the channel network properties
|
// set the channel network properties
|
||||||
Channel.SetAudioStreamProperties ( eAudioCompressionType,
|
Channel.SetAudioStreamProperties ( eAudioCompressionType,
|
||||||
iCeltNumCodedBytes,
|
iCeltNumCodedBytes,
|
||||||
|
@ -843,8 +840,6 @@ void CClient::Init()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vecsNetwork.Init ( iMonoBlockSizeSam );
|
|
||||||
|
|
||||||
// set the channel network properties
|
// set the channel network properties
|
||||||
Channel.SetAudioStreamProperties ( eAudioCompressionType,
|
Channel.SetAudioStreamProperties ( eAudioCompressionType,
|
||||||
iCeltNumCodedBytes,
|
iCeltNumCodedBytes,
|
||||||
|
@ -904,12 +899,6 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
// update stereo signal level meter
|
// update stereo signal level meter
|
||||||
SignalLevelMeter.Update ( vecsStereoSndCrd );
|
SignalLevelMeter.Update ( vecsStereoSndCrd );
|
||||||
|
|
||||||
// convert data from short to double
|
|
||||||
for ( i = 0; i < iStereoBlockSizeSam; i++ )
|
|
||||||
{
|
|
||||||
vecdAudioStereo[i] = static_cast<double> ( vecsStereoSndCrd[i] );
|
|
||||||
}
|
|
||||||
|
|
||||||
// add reverberation effect if activated
|
// add reverberation effect if activated
|
||||||
if ( iReverbLevel != 0 )
|
if ( iReverbLevel != 0 )
|
||||||
{
|
{
|
||||||
|
@ -923,12 +912,10 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
for ( i = 0; i < iStereoBlockSizeSam; i += 2 )
|
for ( i = 0; i < iStereoBlockSizeSam; i += 2 )
|
||||||
{
|
{
|
||||||
// left channel
|
// left channel
|
||||||
vecdAudioStereo[i] +=
|
AudioReverbL.ProcessSample ( vecsStereoSndCrd[i], dRevLev );
|
||||||
dRevLev * AudioReverbL.ProcessSample ( vecdAudioStereo[i] );
|
|
||||||
|
|
||||||
// right channel
|
// right channel
|
||||||
vecdAudioStereo[i + 1] +=
|
AudioReverbR.ProcessSample ( vecsStereoSndCrd[i + 1], dRevLev );
|
||||||
dRevLev * AudioReverbR.ProcessSample ( vecdAudioStereo[i + 1] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -938,8 +925,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
for ( i = 0; i < iStereoBlockSizeSam; i += 2 )
|
for ( i = 0; i < iStereoBlockSizeSam; i += 2 )
|
||||||
{
|
{
|
||||||
// left channel
|
// left channel
|
||||||
vecdAudioStereo[i] +=
|
AudioReverbL.ProcessSample ( vecsStereoSndCrd[i], dRevLev );
|
||||||
dRevLev * AudioReverbL.ProcessSample ( vecdAudioStereo[i] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -947,8 +933,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
for ( i = 1; i < iStereoBlockSizeSam; i += 2 )
|
for ( i = 1; i < iStereoBlockSizeSam; i += 2 )
|
||||||
{
|
{
|
||||||
// right channel
|
// right channel
|
||||||
vecdAudioStereo[i] +=
|
AudioReverbR.ProcessSample ( vecsStereoSndCrd[i], dRevLev );
|
||||||
dRevLev * AudioReverbR.ProcessSample ( vecdAudioStereo[i] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -958,22 +943,18 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
// from double to short
|
// from double to short
|
||||||
if ( iAudioInFader == AUD_FADER_IN_MIDDLE )
|
if ( iAudioInFader == AUD_FADER_IN_MIDDLE )
|
||||||
{
|
{
|
||||||
if ( bUseStereo )
|
// no action require if fader is in the middle and stereo is used
|
||||||
|
if ( !bUseStereo )
|
||||||
{
|
{
|
||||||
// perform type conversion
|
// mix channels together (store result in first half of the vector)
|
||||||
for ( i = 0; i < iStereoBlockSizeSam; i++ )
|
|
||||||
{
|
|
||||||
vecsNetwork[i] = Double2Short ( vecdAudioStereo[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// mix channels together
|
|
||||||
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
{
|
{
|
||||||
vecsNetwork[i] =
|
// for the sum make sure we have more bits available (cast to
|
||||||
Double2Short ( ( vecdAudioStereo[j] +
|
// int32), after the normalization by 2, the result will fit
|
||||||
vecdAudioStereo[j + 1] ) / 2 );
|
// into the old size so that cast to int16 is safe
|
||||||
|
vecsStereoSndCrd[i] = static_cast<int16_t> (
|
||||||
|
( static_cast<int32_t> ( vecsStereoSndCrd[j] ) +
|
||||||
|
vecsStereoSndCrd[j + 1] ) / 2 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -991,11 +972,8 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
{
|
{
|
||||||
// attenuation on right channel
|
// attenuation on right channel
|
||||||
vecsNetwork[j] = Double2Short (
|
vecsStereoSndCrd[j + 1] = Double2Short (
|
||||||
vecdAudioStereo[j] );
|
dAttFactStereo * vecsStereoSndCrd[j + 1] );
|
||||||
|
|
||||||
vecsNetwork[j + 1] = Double2Short (
|
|
||||||
dAttFactStereo * vecdAudioStereo[j + 1] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1003,11 +981,8 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
{
|
{
|
||||||
// attenuation on left channel
|
// attenuation on left channel
|
||||||
vecsNetwork[j] = Double2Short (
|
vecsStereoSndCrd[j] = Double2Short (
|
||||||
dAttFactStereo * vecdAudioStereo[j] );
|
dAttFactStereo * vecsStereoSndCrd[j] );
|
||||||
|
|
||||||
vecsNetwork[j + 1] = Double2Short (
|
|
||||||
vecdAudioStereo[j + 1] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1029,20 +1004,22 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
{
|
{
|
||||||
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
{
|
{
|
||||||
// attenuation on right channel
|
// attenuation on right channel (store result in first half
|
||||||
vecsNetwork[i] = Double2Short (
|
// of the vector)
|
||||||
dAmplFactMono * vecdAudioStereo[j] +
|
vecsStereoSndCrd[i] = Double2Short (
|
||||||
dAttFactMono * vecdAudioStereo[j + 1] );
|
dAmplFactMono * vecsStereoSndCrd[j] +
|
||||||
|
dAttFactMono * vecsStereoSndCrd[j + 1] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
{
|
{
|
||||||
// attenuation on left channel
|
// attenuation on left channel (store result in first half
|
||||||
vecsNetwork[i] = Double2Short (
|
// of the vector)
|
||||||
dAmplFactMono * vecdAudioStereo[j + 1] +
|
vecsStereoSndCrd[i] = Double2Short (
|
||||||
dAttFactMono * vecdAudioStereo[j] );
|
dAmplFactMono * vecsStereoSndCrd[j + 1] +
|
||||||
|
dAttFactMono * vecsStereoSndCrd[j] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1056,7 +1033,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
if ( eAudioCompressionType == CT_CELT )
|
if ( eAudioCompressionType == CT_CELT )
|
||||||
{
|
{
|
||||||
cc6_celt_encode ( CeltEncoderStereo,
|
cc6_celt_encode ( CeltEncoderStereo,
|
||||||
&vecsNetwork[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES],
|
&vecsStereoSndCrd[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES],
|
||||||
NULL,
|
NULL,
|
||||||
&vecCeltData[0],
|
&vecCeltData[0],
|
||||||
iCeltNumCodedBytes );
|
iCeltNumCodedBytes );
|
||||||
|
@ -1064,7 +1041,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opus_custom_encode ( OpusEncoderStereo,
|
opus_custom_encode ( OpusEncoderStereo,
|
||||||
&vecsNetwork[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES],
|
&vecsStereoSndCrd[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES],
|
||||||
SYSTEM_FRAME_SIZE_SAMPLES,
|
SYSTEM_FRAME_SIZE_SAMPLES,
|
||||||
&vecCeltData[0],
|
&vecCeltData[0],
|
||||||
iCeltNumCodedBytes );
|
iCeltNumCodedBytes );
|
||||||
|
@ -1076,7 +1053,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
if ( eAudioCompressionType == CT_CELT )
|
if ( eAudioCompressionType == CT_CELT )
|
||||||
{
|
{
|
||||||
cc6_celt_encode ( CeltEncoderMono,
|
cc6_celt_encode ( CeltEncoderMono,
|
||||||
&vecsNetwork[i * SYSTEM_FRAME_SIZE_SAMPLES],
|
&vecsStereoSndCrd[i * SYSTEM_FRAME_SIZE_SAMPLES],
|
||||||
NULL,
|
NULL,
|
||||||
&vecCeltData[0],
|
&vecCeltData[0],
|
||||||
iCeltNumCodedBytes );
|
iCeltNumCodedBytes );
|
||||||
|
@ -1084,7 +1061,7 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opus_custom_encode ( OpusEncoderMono,
|
opus_custom_encode ( OpusEncoderMono,
|
||||||
&vecsNetwork[i * SYSTEM_FRAME_SIZE_SAMPLES],
|
&vecsStereoSndCrd[i * SYSTEM_FRAME_SIZE_SAMPLES],
|
||||||
SYSTEM_FRAME_SIZE_SAMPLES,
|
SYSTEM_FRAME_SIZE_SAMPLES,
|
||||||
&vecCeltData[0],
|
&vecCeltData[0],
|
||||||
iCeltNumCodedBytes );
|
iCeltNumCodedBytes );
|
||||||
|
|
|
@ -357,8 +357,6 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType );
|
||||||
bool bUseDefaultCentralServerAddress;
|
bool bUseDefaultCentralServerAddress;
|
||||||
|
|
||||||
CVector<int16_t> vecsAudioSndCrdMono;
|
CVector<int16_t> vecsAudioSndCrdMono;
|
||||||
CVector<double> vecdAudioStereo;
|
|
||||||
CVector<int16_t> vecsNetwork;
|
|
||||||
|
|
||||||
// server settings
|
// server settings
|
||||||
int iServerSockBufNumFrames;
|
int iServerSockBufNumFrames;
|
||||||
|
|
|
@ -263,7 +263,8 @@ void CAudioReverb::setT60 ( const double rT60,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double CAudioReverb::ProcessSample ( const double input )
|
void CAudioReverb::ProcessSample ( int16_t& input,
|
||||||
|
const double dAttenuation )
|
||||||
{
|
{
|
||||||
// compute one output sample
|
// compute one output sample
|
||||||
double temp, temp0, temp1, temp2;
|
double temp, temp0, temp1, temp2;
|
||||||
|
@ -296,7 +297,9 @@ double CAudioReverb::ProcessSample ( const double input )
|
||||||
combDelays_[2].Add ( (int) temp5 );
|
combDelays_[2].Add ( (int) temp5 );
|
||||||
combDelays_[3].Add ( (int) temp6 );
|
combDelays_[3].Add ( (int) temp6 );
|
||||||
|
|
||||||
return ( temp3 + temp4 + temp5 + temp6 ) * (double) 0.5;
|
// inplace apply the attenuated reverb signal
|
||||||
|
input = Double2Short ( input +
|
||||||
|
( temp3 + temp4 + temp5 + temp6 ) * (double) 0.5 * dAttenuation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -892,7 +892,8 @@ public:
|
||||||
|
|
||||||
void Init ( const int iSampleRate, const double rT60 = (double) 1.1 );
|
void Init ( const int iSampleRate, const double rT60 = (double) 1.1 );
|
||||||
void Clear();
|
void Clear();
|
||||||
double ProcessSample ( const double input );
|
void ProcessSample ( int16_t& input,
|
||||||
|
const double dAttenuation );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setT60 ( const double rT60, const int iSampleRate );
|
void setT60 ( const double rT60, const int iSampleRate );
|
||||||
|
|
Loading…
Reference in a new issue