fixes for big block sizes, still not finished

This commit is contained in:
Volker Fischer 2009-08-13 06:43:42 +00:00
parent 2f794eeee0
commit 3f6cfbbaeb
2 changed files with 56 additions and 38 deletions

View file

@ -38,6 +38,15 @@ CClient::CClient ( const quint16 iPortNumber ) :
bDoAutoSockBufSize ( true ), bDoAutoSockBufSize ( true ),
iSndCrdPrefMonoFrameSizeFactor ( FRAME_SIZE_FACTOR_DEFAULT ) iSndCrdPrefMonoFrameSizeFactor ( FRAME_SIZE_FACTOR_DEFAULT )
{ {
// init audio endocder/decoder (mono)
CeltMode = celt_mode_create (
SYSTEM_SAMPLE_RATE, 1, SYSTEM_BLOCK_FRAME_SAMPLES, NULL );
CeltEncoder = celt_encoder_create ( CeltMode );
CeltDecoder = celt_decoder_create ( CeltMode );
// connections -------------------------------------------------------------
// connection for protocol // connection for protocol
QObject::connect ( &Channel, QObject::connect ( &Channel,
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
@ -152,8 +161,6 @@ void CClient::SetSndCrdPrefMonoFrameSizeFactor ( const int iNewFactor )
( iNewFactor == FRAME_SIZE_FACTOR_DEFAULT ) || ( iNewFactor == FRAME_SIZE_FACTOR_DEFAULT ) ||
( iNewFactor == FRAME_SIZE_FACTOR_SAFE ) ) ( iNewFactor == FRAME_SIZE_FACTOR_SAFE ) )
{ {
iSndCrdPrefMonoFrameSizeFactor = iNewFactor;
// init with new parameter, if client was running then first // init with new parameter, if client was running then first
// stop it and restart again after new initialization // stop it and restart again after new initialization
const bool bWasRunning = Sound.IsRunning(); const bool bWasRunning = Sound.IsRunning();
@ -162,6 +169,9 @@ void CClient::SetSndCrdPrefMonoFrameSizeFactor ( const int iNewFactor )
Sound.Stop(); Sound.Stop();
} }
// set new parameter
iSndCrdPrefMonoFrameSizeFactor = iNewFactor;
// init with new block size index parameter // init with new block size index parameter
Init(); Init();
@ -268,8 +278,8 @@ void CClient::Init()
iMonoBlockSizeSam = Sound.Init ( iPrefMonoFrameSize ); iMonoBlockSizeSam = Sound.Init ( iPrefMonoFrameSize );
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam; iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
vecsAudioSndCrdMono.Init ( iMonoBlockSizeSam );
vecsAudioSndCrdStereo.Init ( iStereoBlockSizeSam ); vecsAudioSndCrdStereo.Init ( iStereoBlockSizeSam );
vecdAudioStereo.Init ( iStereoBlockSizeSam ); vecdAudioStereo.Init ( iStereoBlockSizeSam );
// init response time evaluation // init response time evaluation
@ -281,13 +291,6 @@ void CClient::Init()
// init reverberation // init reverberation
AudioReverb.Init ( SYSTEM_SAMPLE_RATE ); AudioReverb.Init ( SYSTEM_SAMPLE_RATE );
// init audio endocder/decoder (mono)
CeltMode = celt_mode_create (
SYSTEM_SAMPLE_RATE, 1, iMonoBlockSizeSam, NULL );
CeltEncoder = celt_encoder_create ( CeltMode );
CeltDecoder = celt_decoder_create ( CeltMode );
// 22: low/normal quality 150 kbsp (128) / 108 kbps (256) // 22: low/normal quality 150 kbsp (128) / 108 kbps (256)
// 44: high quality 216 kbps (128) / 174 kbps (256) // 44: high quality 216 kbps (128) / 174 kbps (256)
iCeltNumCodedBytes = 22; iCeltNumCodedBytes = 22;
@ -299,6 +302,9 @@ void CClient::Init()
vecbyNetwData.Init ( iCeltNumCodedBytes ); vecbyNetwData.Init ( iCeltNumCodedBytes );
// set the channel network properties // set the channel network properties
// TODO use the actual frame size factor if possible...
Channel.SetNetwFrameSizeAndFact ( iCeltNumCodedBytes, Channel.SetNetwFrameSizeAndFact ( iCeltNumCodedBytes,
iSndCrdPrefMonoFrameSizeFactor ); iSndCrdPrefMonoFrameSizeFactor );
} }
@ -307,6 +313,7 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
{ {
int i, j; int i, j;
// Transmit signal ---------------------------------------------------------
// update stereo signal level meter // update stereo signal level meter
SignalLevelMeter.Update ( vecsStereoSndCrd ); SignalLevelMeter.Update ( vecsStereoSndCrd );
@ -382,9 +389,13 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
} }
} }
// TEST
// TODO use actual frame size factor, not preferred one!!!!
for ( i = 0; i < iSndCrdPrefMonoFrameSizeFactor; i++ )
{
// encode current audio frame with CELT encoder // encode current audio frame with CELT encoder
celt_encode ( CeltEncoder, celt_encode ( CeltEncoder,
&vecsNetwork[0], &vecsNetwork[i * SYSTEM_BLOCK_FRAME_SAMPLES],
NULL, NULL,
&vecCeltData[0], &vecCeltData[0],
iCeltNumCodedBytes ); iCeltNumCodedBytes );
@ -392,8 +403,15 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
// send coded audio through the network // send coded audio through the network
Socket.SendPacket ( Channel.PrepSendPacket ( vecCeltData ), Socket.SendPacket ( Channel.PrepSendPacket ( vecCeltData ),
Channel.GetAddress() ); Channel.GetAddress() );
}
// Receive signal ----------------------------------------------------------
// TEST
// TODO use actual frame size factor, not preferred one!!!!
for ( i = 0; i < iSndCrdPrefMonoFrameSizeFactor; i++ )
{
// receive a new block // receive a new block
const bool bReceiveDataOk = const bool bReceiveDataOk =
( Channel.GetData ( vecbyNetwData ) == GS_BUFFER_OK ); ( Channel.GetData ( vecbyNetwData ) == GS_BUFFER_OK );
@ -407,18 +425,13 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_RED ); PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_RED );
} }
// check if channel is connected
if ( Channel.IsConnected() )
{
CVector<short> vecsAudioSndCrdMono ( iMonoBlockSizeSam );
// CELT decoding // CELT decoding
if ( bReceiveDataOk ) if ( bReceiveDataOk )
{ {
celt_decode ( CeltDecoder, celt_decode ( CeltDecoder,
&vecbyNetwData[0], &vecbyNetwData[0],
iCeltNumCodedBytes, iCeltNumCodedBytes,
&vecsAudioSndCrdMono[0] ); &vecsAudioSndCrdMono[i * SYSTEM_BLOCK_FRAME_SAMPLES] );
} }
else else
{ {
@ -426,9 +439,13 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
celt_decode ( CeltDecoder, celt_decode ( CeltDecoder,
NULL, NULL,
iCeltNumCodedBytes, iCeltNumCodedBytes,
&vecsAudioSndCrdMono[0] ); &vecsAudioSndCrdMono[i * SYSTEM_BLOCK_FRAME_SAMPLES] );
}
} }
// check if channel is connected
if ( Channel.IsConnected() )
{
// copy mono data in stereo sound card buffer // copy mono data in stereo sound card buffer
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 ) for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
{ {

View file

@ -179,6 +179,7 @@ protected:
bool bOpenChatOnNewMessage; bool bOpenChatOnNewMessage;
CVector<int16_t> vecsAudioSndCrdMono;
CVector<int16_t> vecsAudioSndCrdStereo; CVector<int16_t> vecsAudioSndCrdStereo;
CVector<double> vecdAudioStereo; CVector<double> vecdAudioStereo;
CVector<int16_t> vecsNetwork; CVector<int16_t> vecsNetwork;