[Speex-dev] A question about speex_bits_write function

Jean-Marc Valin jean-marc.valin at usherbrooke.ca
Sun Dec 10 02:24:46 PST 2006


The last argument should simply be the size of your own buffer, i.e.
it's there to make sure there's no buffer overflow and that's it. If you
know that at the bit rate you're using the output is 20 bytes, then you
can choose to allocate a 20-byte buffer and let speex_bits_write() know
that. Same idea as e.g. strncpy(), which is safer than strcpy().

	Jean-Marc

yaseminyilmaz wrote:
> Hi everybody,
> 
> I need clarification about speex_bits_write function usage. There is an
> example usage of it.
> 
> nbBytes = speex_bits_write(&bits, cbits, MAX_FRAME_BYTES);
> 
> I examine the content of this function and which value should I set to
> MAX_FRAME_BYTE. In speexenc project, it is 2000 and in manual it is 200.
> For example, I set it to 200 but the length of bits->chars is 250
> (bits->nbBits is 2000), is this right? If so, max_nchars gets 200 value
> because following statement in speex_bits_write and the condition of if
> statement does not achieve. (in my environment, BYTES_PER_CHAR=1,
> speex_nb_mode, 8 kHz, 15 kbps)
> 
> int max_nchars = max_nbytes/BYTES_PER_CHAR;
> 
> if (max_nchars > ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR))
> 
> max_nchars = ((bits->nbBits+BITS_PER_CHAR-1)>>LOG2_BITS_PER_CHAR);
> 
>  
> 
> Excuse me if I make longer my question. Which value should I set to
> MAX_FRAME_BYTES and why?
> 
> Can you please help me?
> 
> Thanks in advance
> 
> Sincerely
> 
> Yasemin
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev


More information about the Speex-dev mailing list