[Speex-dev] More frames in one packet
Peter Soxberger
Peter.Soxberger at gmx.net
Tue Jul 26 13:31:09 PDT 2011
Hi,
I read in the documentation something about how to realize packing more than one encoded frame into a packet. Before I read this, I always encoded every frame seperate and packet them as following together:
[encoded length][encoded frame][encoded length][encoded frame]...
But if I understood the docu correct, it should be easier:
I call speex_encode_int() for every frame until the whole recorded buffer has been encoded. After that I call only once speex_bits_write() and send this data over the network.
The receiver then calls speex_decode_int() (only once I guess, but this isn't mentioned in the manual).
It works if I encode only one frame, but with multiple frames I get strange results (sounds like parts are lost or something like that).
What am I doing wrong? Do I have to call speex_decode_int() for every frame inside the packet? And how can I get the number of bytes speex_decode_int() wrote into the destination buffer?
Here small code snippets of my implementation:
//**********************************************
// Encoding:
short* Frame = (short*)malloc(speex_frame_size);
speex_bits_reset(enc_bits);
for(unsigned int i = 0; RecBufferLen > speex_frame_size * i; i++)
{
memcpy(Frame, RecBuffer + speex_frame_size * i, speex_frame_size);
speex_encode_int(enc_state, Frame, enc_bits);
}
free((void*)Frame);
return speex_bits_write(enc_bits, SendBuffer, SendBufferLen);
//**********************************************
//Decoding:
speex_bits_reset(dec_bits);
speex_bits_read_from(dec_bits, RcvBuffer, RcvBufferLen);
return speex_decode_int(dec_state, dec_bits, (spx_int16_t*)DestBuffer);
//**********************************************
Is this correct what I'm doing here?
Thanks for your help!
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
More information about the Speex-dev
mailing list