Il 14/04/2010 14:37, Randy Yates wrote:> > Usually a buffer is one frame of data, and a frame is 20 milliseconds. > Since the sample rate is typically 8 kHz in narrowband mode, this > corresponds to a buffer size of 160 samples.Hi Randy, thanks for the reply. So, suppose I encode an audio buffer (8000 kHz, MONO, float) of 640 PCM frames. In output I have 4 speex frame of 20 byte each that I put in a RPT payload of 80 bytes: UINT CSpeexCodec::Encode( float *inBuff, const char**outBuff, UINT BufferFrames ) { speex_encoder_ctl(spx_state_, SPEEX_GET_FRAME_SIZE, &spx_frame_size_); while (BufferFrames>0) { speex_bits_reset(&spx_bits_); speex_encode(spx_state_, inBuff, &spx_bits_); nbBytes += speex_bits_write(&spx_bits_, spx_enc_frame_, spx_frame_size_); inBuff+= spx_frame_size_; BufferFrames -= spx_frame_size_; } ..nbBytes is 80 bytes.. } Now I send this packet over the network and, into the receiving side, I need to recreate the original PCM buffer (640 frames). But how can I know the size of each speex frame into a multiframe payload? Daniele.
Daniele Barzotti <daniele.barzotti at eurocomtel.com> writes:> Il 14/04/2010 14:37, Randy Yates wrote: >> >> Usually a buffer is one frame of data, and a frame is 20 milliseconds. >> Since the sample rate is typically 8 kHz in narrowband mode, this >> corresponds to a buffer size of 160 samples. > > Hi Randy, thanks for the reply. > So, suppose I encode an audio buffer (8000 kHz, MONO, float) of 640 PCM > frames. > In output I have 4 speex frame of 20 byte each that I put in a RPT > payload of 80 bytes: > > UINT CSpeexCodec::Encode( float *inBuff, > const char**outBuff, > UINT BufferFrames ) > { > speex_encoder_ctl(spx_state_, > SPEEX_GET_FRAME_SIZE, > &spx_frame_size_); > > while (BufferFrames>0) > { > speex_bits_reset(&spx_bits_); > speex_encode(spx_state_, inBuff, &spx_bits_); > nbBytes += speex_bits_write(&spx_bits_, > spx_enc_frame_, > spx_frame_size_); > inBuff+= spx_frame_size_; > BufferFrames -= spx_frame_size_; > } > > ..nbBytes is 80 bytes.. > } > > > Now I send this packet over the network and, into the receiving side, I > need to recreate the original PCM buffer (640 frames). > But how can I know the size of each speex frame into a multiframe > payload?Apparently this information is carried by the ogg container format. See the speexdec() function that's provided as a reference example. ogg_stream_pagein(&os, &og); . . . ogg_stream_packetout(&os, &op); . . . speex_bits_read_from(&bits, (char*)op.packet, op.bytes); -- Randy Yates % "Maybe one day I'll feel her cold embrace, Digital Signal Labs % and kiss her interface, mailto://yates at ieee.org % til then, I'll leave her alone." http://www.digitalsignallabs.com % 'Yours Truly, 2095', *Time*, ELO
On 14 April 2010 23:50, Daniele Barzotti <daniele.barzotti at eurocomtel.com> wrote:> Il 14/04/2010 14:37, Randy Yates wrote: >> >> Usually a buffer is one frame of data, and a frame is 20 milliseconds. >> Since the sample rate is typically 8 kHz in narrowband mode, this >> corresponds to a buffer size of 160 samples. > > Hi Randy, thanks for the reply. > So, suppose I encode an audio buffer (8000 kHz, MONO, float) of 640 PCM > frames. > In output I have 4 speex frame of 20 byte each that I put in a RPT > payload of 80 bytes: > > UINT CSpeexCodec::Encode( float *inBuff, > ? ? ? ? ? ? ? ? ? ? ? ? ?const char**outBuff, > ? ? ? ? ? ? ? ? ? ? ? ? ?UINT BufferFrames ) > { > ?speex_encoder_ctl(spx_state_, > ? ? ? ? ? ? ? ? ? ?SPEEX_GET_FRAME_SIZE, > ? ? ? ? ? ? ? ? ? ?&spx_frame_size_); > > ?while (BufferFrames>0) > ?{ > ? ?speex_bits_reset(&spx_bits_); > ? ?speex_encode(spx_state_, inBuff, &spx_bits_); > ? ?nbBytes += speex_bits_write(&spx_bits_, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?spx_enc_frame_, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?spx_frame_size_); > ? ?inBuff+= spx_frame_size_; > ? ?BufferFrames -= spx_frame_size_; > ?} > > ?..nbBytes is 80 bytes.. > } > > > Now I send this packet over the network and, into the receiving side, I > need to recreate the original PCM buffer (640 frames). > But how can I know the size of each speex frame into a multiframe payload?use speex_bit_read_from() just once on the packet, then call speex_decode() once for each frame. Conrad.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 15/04/2010 01:30, Conrad Parker wrote:> >> But how can I know the size of each speex frame into a multiframe payload? > > use speex_bit_read_from() just once on the packet, then call > speex_decode() once for each frame. > > Conrad.Thanks for the reply, Conrad. What is not clear for me (and I didn't found it on the manual) is how to decode a multi-frame payload. Once have called speex_bits_read_from, I need a way to know how many speex frames there are, how can I do this? I try to use speex_bits_remaining, but after some cycles it returns always 4. UINT DecodePayload( char* payload, UINT payload_len ) { speex_bits_reset(&spx_bits_); speex_bits_read_from(&spx_bits_, payload, payload_len); UINT nbBytes = speex_bits_remaining(&spx_bits_); while (nbBytes>0) { speex_decode(spx_state_, &spx_bits_, spx_dec_frame_); nbBytes = speex_bits_remaining(&spx_bits_); // Save the speex frame into the buffer DecOutBuffer_.Write(spx_dec_frame_, spx_frame_size_); } } Any suggestion? Thanks, Daniele. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) iEYEARECAAYFAkvG1HUACgkQ/l+kMioSZwi/JgCfarhEpOljEFU3/zLrXO1BL+dq TqUAn2P1YMuqbNz3K80pvP0fJ0JTCFos =arZ0 -----END PGP SIGNATURE-----