Commit 2d4b5b6a authored by jm's avatar jm
Browse files

implemented new speex_bits_insert_terminator call so that the number of

frames in a packet can be automatically determined.


git-svn-id: http://svn.xiph.org/trunk/speex@4847 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent a74f2ca0
......@@ -342,3 +342,11 @@ int speex_bits_nbytes(SpeexBits *bits)
{
return ((bits->nbBits+7)>>3);
}
void speex_bits_insert_terminator(SpeexBits *bits)
{
if (bits->bitPtr<7)
speex_bits_pack(bits, 0, 1);
while (bits->bitPtr<7)
speex_bits_pack(bits, 1, 1);
}
......@@ -1158,6 +1158,8 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
/* Search for next narrowband block (handle requests, skip wideband blocks) */
do {
if (speex_bits_remaining(bits)<5)
return -1;
wideband = speex_bits_unpack_unsigned(bits, 1);
if (wideband) /* Skip wideband block (for compatibility) */
{
......@@ -1172,6 +1174,9 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
}
advance -= (SB_SUBMODE_BITS+1);
speex_bits_advance(bits, advance);
if (speex_bits_remaining(bits)<5)
return -1;
wideband = speex_bits_unpack_unsigned(bits, 1);
if (wideband)
{
......@@ -1193,7 +1198,8 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
}
}
if (speex_bits_remaining(bits)<4)
return -1;
/* FIXME: Check for overflow */
m = speex_bits_unpack_unsigned(bits, 4);
if (m==15) /* We found a terminator */
......
......@@ -140,6 +140,13 @@ void speex_bits_advance(SpeexBits *bits, int n);
*/
int speex_bits_remaining(SpeexBits *bits);
/** Insert a terminator so that the data can be sent as a packet while auto-detecting
* the number of frames in each packet
*
* @param bits Bit-stream to operate on
*/
void speex_bits_insert_terminator(SpeexBits *bits);
#ifdef __cplusplus
}
#endif
......
......@@ -571,7 +571,7 @@ int main(int argc, char **argv)
/*Copy Ogg packet to Speex bitstream*/
speex_bits_read_from(&bits, (char*)op.packet, op.bytes);
for (j=0;j<nframes;j++)
for (j=0;j!=nframes;j++)
{
int ret;
/*Decode frame*/
......
......@@ -672,6 +672,7 @@ int main(int argc, char **argv)
if ((id+1)%nframes!=0)
continue;
speex_bits_insert_terminator(&bits);
nbBytes = speex_bits_write(&bits, cbits, MAX_FRAME_BYTES);
speex_bits_reset(&bits);
op.packet = (unsigned char *)cbits;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment