ref: aba0b8bd63f902369011585e7dad29eaa1500717
parent: f30881d43ea98e160336f8ed7f56d3d98c457455
author: menno <menno>
date: Thu Feb 17 10:23:37 EST 2000
Bugfixes for bit counting
--- a/aac_qc.c
+++ b/aac_qc.c
@@ -1632,7 +1632,7 @@
/* then the scalefactors are written out the fixed_stream output bit */
/* stream. it returns k, the number of bits written to the bitstream*/
- int i,j,k=0;
+ int i,j,bit_count=0;
int diff,length,codeword;
int previous_scale_factor;
int previous_is_factor; /* Intensity stereo */
@@ -1669,7 +1669,7 @@
if ((diff < 60)&&(diff >= -60))
length = huff12[diff+60][FIRSTINTAB];
else length = 0;
- k+=length;
+ bit_count+=length;
previous_is_factor = scale_factors[index];
if (write_flag == 1 ) {
codeword = huff12[diff+60][LASTINTAB];
@@ -1690,7 +1690,7 @@
codeword = huff12[diff+60][LASTINTAB];
}
}
- k += length;
+ bit_count += length;
previous_noise_nrg = quantInfo->pns_sfb_nrg[index];
if (write_flag == 1 ) {
BsPutBit(fixed_stream,codeword,length);
@@ -1701,7 +1701,7 @@
if ((diff < 60)&&(diff >= -60))
length = huff12[diff+60][FIRSTINTAB];
else length = 0;
- k+=length;
+ bit_count+=length;
previous_scale_factor = scale_factors[index];
if (write_flag == 1 ) {
codeword = huff12[diff+60][LASTINTAB];
@@ -1711,6 +1711,6 @@
index++;
}
}
- return(k);
+ return(bit_count);
}
--- a/aac_se_enc.c
+++ b/aac_se_enc.c
@@ -105,6 +105,7 @@
BsPutBit(fixedStream, 0, 1); // copyr. id. bit
BsPutBit(fixedStream, 0, 1); // copyr. id. start
BsPutBit(fixedStream, bit2byte(used_bits), 13); // number of bits
+ printf("%d\t%d\t", used_bits, bit2byte(used_bits));
BsPutBit(fixedStream, 0x7FF, 11); // buffer fullness (0x7FF for VBR)
BsPutBit(fixedStream, 0, 2); // raw data blocks (0+1=1)
}
@@ -199,7 +200,7 @@
/* if common_window, write ics_info */
if (commonWindow) {
int numWindows,maxSfb;
- bit_count = WriteICSInfo(quantInfoL,fixedStream,writeFlag);
+ bit_count += WriteICSInfo(quantInfoL,fixedStream,writeFlag);
numWindows=quantInfoL->num_window_groups;
maxSfb = quantInfoL->max_sfb;
if (writeFlag) {
@@ -215,9 +216,10 @@
}
}
bit_count += LEN_MASK_PRES;
- bit_count += (ms_info->is_present==1)*numWindows*maxSfb*LEN_MASK;
+ if (ms_info->is_present==1)
+ bit_count += (numWindows*maxSfb*LEN_MASK);
}
-
+
/* Write individual_channel_stream elements */
bit_count += WriteICS(quantInfoL,commonWindow,fixedStream,writeFlag);
bit_count += WriteICS(quantInfoR,commonWindow,fixedStream,writeFlag);
@@ -357,7 +359,7 @@
BsPutBit(fixed_stream,quantInfo->pulseInfo.number_pulse,LEN_NEC_NPULSE); /* no pulse_data_present */
BsPutBit(fixed_stream,quantInfo->pulseInfo.pulse_start_sfb,LEN_NEC_ST_SFB); /* no pulse_data_present */
}
- bit_count += LEN_NEC_NPULSE + LEN_NEC_ST_SFB;
+ bit_count += (LEN_NEC_NPULSE + LEN_NEC_ST_SFB);
for (i = 0; i < quantInfo->pulseInfo.number_pulse+1; i++) {
if (writeFlag) {
@@ -364,7 +366,7 @@
BsPutBit(fixed_stream,quantInfo->pulseInfo.pulse_offset[i],LEN_NEC_POFF);
BsPutBit(fixed_stream,quantInfo->pulseInfo.pulse_amp[i],LEN_NEC_PAMP);
}
- bit_count += LEN_NEC_POFF + LEN_NEC_PAMP;
+ bit_count += (LEN_NEC_POFF + LEN_NEC_PAMP);
}
} else {
if (writeFlag) {
@@ -419,47 +421,48 @@
}
/* Write TNS data */
- bit_count += numWindows * len_tns_nfilt;
+ bit_count += (numWindows * len_tns_nfilt);
for (w=0;w<numWindows;w++) {
- TNS_WINDOW_DATA* windowDataPtr = &tnsInfoPtr->windowData[w];
- int numFilters = windowDataPtr->numFilters;
- if (writeFlag) {
- BsPutBit(fixed_stream,numFilters,len_tns_nfilt); /* n_filt[] = 0 */
- }
- if (numFilters) {
- bit_count += LEN_TNS_COEFF_RES;
- resInBits = windowDataPtr->coefResolution;
- resInBits = windowDataPtr->coefResolution;
- if (writeFlag) {
- BsPutBit(fixed_stream,resInBits-DEF_TNS_RES_OFFSET,LEN_TNS_COEFF_RES);
- }
- bit_count += numFilters * (len_tns_length+len_tns_order);
- for (filtNumber=0;filtNumber<numFilters;filtNumber++) {
- TNS_FILTER_DATA* tnsFilterPtr=&windowDataPtr->tnsFilter[filtNumber];
- int order = tnsFilterPtr->order;
- if (writeFlag) {
- BsPutBit(fixed_stream,tnsFilterPtr->length,len_tns_length);
- BsPutBit(fixed_stream,order,len_tns_order);
- }
- if (order) {
- bit_count += (LEN_TNS_DIRECTION + LEN_TNS_COMPRESS);
+ TNS_WINDOW_DATA* windowDataPtr = &tnsInfoPtr->windowData[w];
+ int numFilters = windowDataPtr->numFilters;
if (writeFlag) {
- BsPutBit(fixed_stream,tnsFilterPtr->direction,LEN_TNS_DIRECTION);
- BsPutBit(fixed_stream,tnsFilterPtr->coefCompress,LEN_TNS_COMPRESS);
+ BsPutBit(fixed_stream,numFilters,len_tns_nfilt); /* n_filt[] = 0 */
}
- bitsToTransmit = resInBits - tnsFilterPtr->coefCompress;
- bit_count += order * bitsToTransmit;
- if (writeFlag) {
- int i;
- for (i=1;i<=order;i++) {
- unsignedIndex = (unsigned long) (tnsFilterPtr->index[i])&(~(~0<<bitsToTransmit));
- BsPutBit(fixed_stream,unsignedIndex,bitsToTransmit);
- }
+ if (numFilters) {
+ bit_count += LEN_TNS_COEFF_RES;
+ resInBits = windowDataPtr->coefResolution;
+ resInBits = windowDataPtr->coefResolution;
+ if (writeFlag) {
+ BsPutBit(fixed_stream,resInBits-DEF_TNS_RES_OFFSET,LEN_TNS_COEFF_RES);
+ }
+ bit_count += numFilters * (len_tns_length+len_tns_order);
+ for (filtNumber=0;filtNumber<numFilters;filtNumber++) {
+ TNS_FILTER_DATA* tnsFilterPtr=&windowDataPtr->tnsFilter[filtNumber];
+ int order = tnsFilterPtr->order;
+ if (writeFlag) {
+ BsPutBit(fixed_stream,tnsFilterPtr->length,len_tns_length);
+ BsPutBit(fixed_stream,order,len_tns_order);
+ }
+ if (order) {
+ bit_count += (LEN_TNS_DIRECTION + LEN_TNS_COMPRESS);
+ if (writeFlag) {
+ BsPutBit(fixed_stream,tnsFilterPtr->direction,LEN_TNS_DIRECTION);
+ BsPutBit(fixed_stream,tnsFilterPtr->coefCompress,LEN_TNS_COMPRESS);
+ }
+ bitsToTransmit = resInBits - tnsFilterPtr->coefCompress;
+ bit_count += order * bitsToTransmit;
+ if (writeFlag) {
+ int i;
+ for (i=1;i<=order;i++) {
+ unsignedIndex = (unsigned long) (tnsFilterPtr->index[i])&(~(~0<<bitsToTransmit));
+ BsPutBit(fixed_stream,unsignedIndex,bitsToTransmit);
+ }
+ }
+ }
+ }
}
- }
- }
- }
}
+
return bit_count;
}
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -746,22 +746,24 @@
/* Update LTP history buffer */
/**********************************************************/
if(as->use_LTP)
- for (chanNum=0;chanNum<max_ch;chanNum++) {
- nok_ltp_reconstruct(reconstructed_spectrum[chanNum],
- block_type[chanNum],
- WS_SIN, block_size_samples,
- block_size_samples/2,
- block_size_samples/short_win_in_long,
- &sfb_offset_table[chanNum][0],
- nr_of_sfb[chanNum],
- &nok_lt_status[chanNum]);
- }
+ for (chanNum=0;chanNum<max_ch;chanNum++) {
+ nok_ltp_reconstruct(reconstructed_spectrum[chanNum],
+ block_type[chanNum],
+ WS_SIN, block_size_samples,
+ block_size_samples/2,
+ block_size_samples/short_win_in_long,
+ &sfb_offset_table[chanNum][0],
+ nr_of_sfb[chanNum],
+ &nok_lt_status[chanNum]);
+ }
+
/**********************************/
/* Write out all encoded channels */
/**********************************/
- if (as->header_type==ADTS_HEADER)
- used_bits = WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 0);
+ used_bits = 0;
+ if (as->header_type==ADTS_HEADER)
+ used_bits += WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 0);
for (chanNum=0;chanNum<max_ch;chanNum++) {
if (channelInfo[chanNum].present) {
@@ -796,7 +798,7 @@
} else {
numFillBits = 0;
}
-
+
/* Write AAC fill_elements, smallest fill element is 7 bits. */
/* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
numFillBits += 6;
@@ -809,8 +811,8 @@
/* Now byte align the bitstream */
used_bits += ByteAlign(fixed_stream, 0);
- if (as->header_type==ADTS_HEADER)
- WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 1);
+ if (as->header_type==ADTS_HEADER)
+ WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 1);
for (chanNum=0;chanNum<max_ch;chanNum++) {
if (channelInfo[chanNum].present) {
--- a/nok_ltp_enc.c
+++ b/nok_ltp_enc.c
@@ -34,9 +34,9 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.5 $
- $Date: 2000/02/07 07:45:00 $ (check in)
- $Author: lenox $
+ $Revision: 1.6 $
+ $Date: 2000/02/17 15:23:37 $ (check in)
+ $Author: menno $
*************************************************************************/
@@ -400,6 +400,7 @@
break;
case ONLY_SHORT_WINDOW:
+#if 0
for(i=0; i < MAX_SHORT_WINDOWS; i++)
{
if(lt_status->sbk_prediction_used[i])
@@ -451,7 +452,7 @@
}
}
break;
-
+#endif
default:
// CommonExit(1, "nok_ltp_encode : unsupported window sequence %i", win_type);
break;