📄 aac_se_enc.c
字号:
BsPutBit(fixed_stream,0,LEN_ICS_RESERV); /* reserved Bit*/
/* Write out window sequence */
BsPutBit(fixed_stream,quantInfo->block_type,LEN_WIN_SEQ); /* short window */
/* Write out window shape */
BsPutBit(fixed_stream,quantInfo->window_shape,LEN_WIN_SH); /* window shape */
}
bit_count += LEN_ICS_RESERV;
bit_count += LEN_WIN_SEQ;
bit_count += LEN_WIN_SH;
/* For short windows, write out max_sfb and scale_factor_grouping */
if (quantInfo -> block_type == ONLY_SHORT_WINDOW){
if (writeFlag) {
BsPutBit(fixed_stream,max_sfb,LEN_MAX_SFBS);
grouping_bits = find_grouping_bits(quantInfo->window_group_length,quantInfo->num_window_groups);
BsPutBit(fixed_stream,grouping_bits,MAX_SHORT_IN_LONG_BLOCK - 1); /* the grouping bits */
}
bit_count += LEN_MAX_SFBS;
bit_count += MAX_SHORT_IN_LONG_BLOCK - 1;
}
/* Otherwise, write out max_sfb and predictor data */
else { /* block type is either start, stop, or long */
if (writeFlag) {
BsPutBit(fixed_stream,max_sfb,LEN_MAX_SFBL);
}
bit_count += LEN_MAX_SFBL;
bit_count += WritePredictorData(quantInfo,fixed_stream,writeFlag);
}
return bit_count;
}
/*****************************************************************************/
/* WritePredictorData(...), write predictor data. */
/*****************************************************************************/
int WritePredictorData(AACQuantInfo* quantInfo, /* AACQuantInfo structure */
BsBitStream* fixed_stream, /* Pointer to bitstream */
int writeFlag) /* 1 means write, 0 means count only */
{
int bit_count = 0;
/* Write global predictor data present */
short predictorDataPresent = quantInfo->pred_global_flag;
int numBands = min(max_pred_sfb,quantInfo->nr_of_sfb);
if (writeFlag) {
BsPutBit(fixed_stream,predictorDataPresent,LEN_PRED_PRES); /* predictor_data_present */
if (predictorDataPresent) {
int b;
/* Code segment added by JB */
if (quantInfo->reset_group_number == -1)
BsPutBit(fixed_stream,0,LEN_PRED_RST); /* No prediction reset */
else
{
BsPutBit(fixed_stream,1,LEN_PRED_RST);
BsPutBit(fixed_stream,(unsigned long)quantInfo->reset_group_number,
LEN_PRED_RSTGRP);
}
/* End of code segment */
for (b=0;b<numBands;b++) {
BsPutBit(fixed_stream,quantInfo->pred_sfb_flag[b],LEN_PRED_ENAB);
}
}
}
bit_count = LEN_PRED_PRES;
bit_count += (predictorDataPresent) ?
(LEN_PRED_RST +
((quantInfo->reset_group_number)!=-1)*LEN_PRED_RSTGRP +
numBands*LEN_PRED_ENAB) : 0;
return bit_count;
}
/*****************************************************************************/
/* WritePulseData(...), write pulse data. */
/*****************************************************************************/
int WritePulseData(AACQuantInfo* quantInfo, /* AACQuantInfo structure */
BsBitStream* fixed_stream, /* Pointer to bitstream */
int writeFlag) /* 1 means write, 0 means count only */
{
int bit_count = 0;
/* Currently write no pulse data present */
if (writeFlag) {
BsPutBit(fixed_stream,0,LEN_PULSE_PRES); /* no prediction_data_present */
}
bit_count = LEN_PULSE_PRES;
return bit_count;
}
/*****************************************************************************/
/* WriteTNSData(...), write TNS data. */
/*****************************************************************************/
int WriteTNSData(AACQuantInfo* quantInfo, /* AACQuantInfo structure */
BsBitStream* fixed_stream, /* Pointer to bitstream */
int writeFlag) /* 1 means write, 0 means count only */
{
int bit_count = 0;
int numWindows = 1;
int len_tns_nfilt;
int len_tns_length;
int len_tns_order;
int filtNumber;
int resInBits;
int bitsToTransmit;
unsigned long unsignedIndex;
int w;
TNS_INFO* tnsInfoPtr = quantInfo->tnsInfo;
if (writeFlag) {
BsPutBit(fixed_stream,tnsInfoPtr->tnsDataPresent,LEN_TNS_PRES);
}
bit_count += LEN_TNS_PRES;
/* If TNS is not present, bail */
if (!tnsInfoPtr->tnsDataPresent) {
return bit_count;
}
/* Set window-dependent TNS parameters */
if (quantInfo->block_type == ONLY_SHORT_WINDOW) {
numWindows = MAX_SHORT_IN_LONG_BLOCK;
len_tns_nfilt = LEN_TNS_NFILTS;
len_tns_length = LEN_TNS_LENGTHS;
len_tns_order = LEN_TNS_ORDERS;
} else {
numWindows = 1;
len_tns_nfilt = LEN_TNS_NFILTL;
len_tns_length = LEN_TNS_LENGTHL;
len_tns_order = LEN_TNS_ORDERL;
}
/* Write TNS data */
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);
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;
}
/*****************************************************************************/
/* WriteGainControlData(...), write gain control data. */
/*****************************************************************************/
int WriteGainControlData(AACQuantInfo* quantInfo, /* AACQuantInfo structure */
BsBitStream* fixed_stream, /* Pointer to bitstream */
int writeFlag) /* 1 means write, 0 means count only */
{
int bit_count = 0;
bit_count += LEN_GAIN_PRES;
if (writeFlag) {
BsPutBit(fixed_stream,0,LEN_GAIN_PRES);
}
return bit_count;
}
/*****************************************************************************/
/* WriteSpectralData(...), write spectral data. */
/*****************************************************************************/
int WriteSpectralData(AACQuantInfo* quantInfo, /* AACQuantInfo structure */
BsBitStream* fixed_stream, /* Pointer to bitstream */
int writeFlag) /* 1 means write, 0 means count only */
{
int bit_count = 0;
int numSpectral = quantInfo->spectralCount;
/* set up local pointers to data and len */
/* data array contains data to be written */
/* len array contains lengths of data words */
int* data = quantInfo -> data;
int* len = quantInfo -> len;
if (writeFlag) {
int i;
for(i=0;i<numSpectral;i++) {
if (len[i] > 0) { /* only send out non-zero codebook data */
BsPutBit(fixed_stream,data[i],len[i]); /* write data */
bit_count += len[i]; /* update bit_count */
}
}
} else {
int i;
for(i=0;i<numSpectral;i++) {
bit_count += len[i]; /* update bit_count */
}
}
return bit_count;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -