yaseminyilmaz
2006-Dec-09 20:23 UTC
[Speex-dev] A question about speex_bits_write function
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20061209/68cecd1b/attachment.htm
Jean-Marc Valin
2006-Dec-10 02:45 UTC
[Speex-dev] A question about speex_bits_write function
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@xiph.org > http://lists.xiph.org/mailman/listinfo/speex-dev