ref: fab854e3a169920ccd610717c50633fa11362db3
parent: 02ce1b0c415872da32c880c981ed3191f4233301
author: menno <menno>
date: Wed Nov 1 09:05:32 EST 2000
Code reorganisation
--- a/aac_se_enc.c
+++ b/aac_se_enc.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.14 $
- $Date: 2000/10/06 14:47:27 $ (check in)
+ $Revision: 1.15 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -341,8 +341,7 @@
{
int bit_count = 0;
- bit_count += ltp_encode (fixed_stream, quantInfo->block_type, quantInfo->nr_of_sfb,
- quantInfo->ltpInfo, writeFlag);
+ bit_count += ltp_encode (quantInfo, fixed_stream, writeFlag);
return (bit_count);
}
@@ -399,7 +398,7 @@
unsigned long unsignedIndex;
int w;
- TNS_INFO* tnsInfoPtr = quantInfo->tnsInfo;
+ TNS_INFO* tnsInfoPtr = &quantInfo->tnsInfo;
if (writeFlag) {
BsPutBit(fixed_stream,tnsInfoPtr->tnsDataPresent,LEN_TNS_PRES);
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.66 $
- $Date: 2000/10/31 14:48:41 $ (check in)
+ $Revision: 1.67 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -171,16 +171,9 @@
enum WINDOW_TYPE desired_block_type[MAX_TIME_CHANNELS];
enum WINDOW_TYPE next_desired_block_type[MAX_TIME_CHANNELS];
-/* Additional variables for AAC */
-TNS_INFO tnsInfo[MAX_TIME_CHANNELS];
-LT_PRED_STATUS ltp_status[MAX_TIME_CHANNELS];
-
AACQuantInfo quantInfo[MAX_TIME_CHANNELS]; /* Info structure for AAC quantization and coding */
-/* Channel information */
-Ch_Info channelInfo[MAX_TIME_CHANNELS];
-
/* EncTfFree() */
/* Free memory allocated by t/f-based encoder core. */
@@ -194,7 +187,7 @@
if (reconstructed_spectrum[chanNum]) free(reconstructed_spectrum[chanNum]);
if (overlap_buffer[chanNum]) free(overlap_buffer[chanNum]);
- if (ltp_status[chanNum].delay) free(ltp_status[chanNum].delay);
+ if (quantInfo[chanNum].ltpInfo.delay) free(quantInfo[chanNum].ltpInfo.delay);
if (tmp_DTimeSigBuf[chanNum]) free(tmp_DTimeSigBuf[chanNum]);
}
for (chanNum=0;chanNum<MAX_TIME_CHANNELS*2;chanNum++) {
@@ -254,7 +247,7 @@
overlap_buffer[chanNum] = (double*)malloc(sizeof(double)*BLOCK_LEN_LONG);
memset(overlap_buffer[chanNum],0,(BLOCK_LEN_LONG)*sizeof(double));
block_type[chanNum] = ONLY_LONG_WINDOW;
- ltp_status[chanNum].delay = (int*)malloc(MAX_SHORT_WINDOWS*sizeof(int));
+ quantInfo[chanNum].ltpInfo.delay = (int*)malloc(MAX_SHORT_WINDOWS*sizeof(int));
tmp_DTimeSigBuf[chanNum] = (double*)malloc(2*BLOCK_LEN_LONG*sizeof(double));
memset(tmp_DTimeSigBuf[chanNum],0,(2*BLOCK_LEN_LONG)*sizeof(double));
}
@@ -272,14 +265,12 @@
/* Init TNS */
for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
- TnsInit(as->out_sampling_rate,as->profile,&tnsInfo[chanNum]);
- quantInfo[chanNum].tnsInfo = &tnsInfo[chanNum]; /* Set pointer to TNS data */
+ TnsInit(as->out_sampling_rate,as->profile,&quantInfo[chanNum].tnsInfo);
}
/* Init LTP predictor */
for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
- init_lt_pred (<p_status[chanNum]);
- quantInfo[chanNum].ltpInfo = <p_status[chanNum]; /* Set pointer to LTP data */
+ init_lt_pred (&quantInfo[chanNum].ltpInfo);
quantInfo[chanNum].prev_window_shape = WS_SIN;
}
@@ -356,7 +347,7 @@
/***********************************************************************/
/* Determine channel elements */
/***********************************************************************/
- DetermineChInfo(channelInfo, max_ch, as->lfePresent);
+ DetermineChInfo(quantInfo, max_ch, as->lfePresent);
/***********************************************************************/
@@ -370,10 +361,10 @@
for (chanNum = 0; chanNum < max_ch; chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe) && (channelInfo[chanNum].ch_is_left)) { /* CPE */
+ if (quantInfo[chanNum].channelInfo.present) {
+ if ((quantInfo[chanNum].channelInfo.cpe) && (quantInfo[chanNum].channelInfo.ch_is_left)) { /* CPE */
int leftChan = chanNum;
- int rightChan = channelInfo[chanNum].paired_ch;
+ int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
if (as->use_MS == 1) {
for(i = 0; i < BLOCK_LEN_LONG; i++){
@@ -413,7 +404,6 @@
quantInfo,
as->out_sampling_rate,
max_ch,
- channelInfo,
DTimeSigLookAheadBuf,
next_desired_block_type,
as->use_MS,
@@ -578,10 +568,10 @@
}
MSPreprocess(p_ratio_long[!ps], p_ratio_short[!ps], chpo_long, chpo_short,
- channelInfo, block_type, quantInfo, as->use_MS, max_ch);
+ block_type, quantInfo, as->use_MS, max_ch);
MSEnergy(spectral_line_vector, energy, chpo_long, chpo_short, sfb_width_table,
- channelInfo, block_type, quantInfo, as->use_MS, max_ch);
+ block_type, quantInfo, as->use_MS, max_ch);
{
int chanNum;
@@ -604,7 +594,7 @@
{
int chanNum;
for (chanNum=0;chanNum<max_ch;chanNum++) {
- if (channelInfo[chanNum].lfe) {
+ if (quantInfo[chanNum].channelInfo.lfe) {
int i;
for (i = sfb_offset_table[chanNum][10];
i < sfb_offset_table[chanNum][nr_of_sfb[chanNum]]; i++)
@@ -638,18 +628,17 @@
/* Perform TNS analysis and filtering */
/******************************************/
for (chanNum=0;chanNum<max_ch;chanNum++) {
- if (!channelInfo[chanNum].lfe) {
- error = TnsEncode(nr_of_sfb[chanNum], /* Number of bands per window */
- quantInfo[chanNum].max_sfb, /* max_sfb */
- block_type[chanNum],
- sfb_offset_table[chanNum],
- spectral_line_vector[chanNum],
- &tnsInfo[chanNum],
- as->use_TNS);
+ if (!quantInfo[chanNum].channelInfo.lfe) {
+ error = TnsEncode(&quantInfo[chanNum],
+ nr_of_sfb[chanNum], /* Number of bands per window */
+ block_type[chanNum],
+ sfb_offset_table[chanNum],
+ spectral_line_vector[chanNum],
+ as->use_TNS);
if (error == FERROR)
return FERROR;
} else {
- tnsInfo[chanNum].tnsDataPresent=0; /* TNS not used for LFE */
+ quantInfo[chanNum].tnsInfo.tnsDataPresent=0; /* TNS not used for LFE */
}
}
@@ -657,13 +646,13 @@
/* If LTP prediction is used, compute LTP predictor info and residual spectrum */
/*******************************************************************************/
for(chanNum=0;chanNum<max_ch;chanNum++) {
- if(as->use_LTP && channelInfo[chanNum].present &&
- (!channelInfo[chanNum].lfe) && (block_type[chanNum] != ONLY_SHORT_WINDOW)) {
- if(channelInfo[chanNum].cpe) {
- if(channelInfo[chanNum].ch_is_left) {
+ if(as->use_LTP && quantInfo[chanNum].channelInfo.present &&
+ (!quantInfo[chanNum].channelInfo.lfe) && (block_type[chanNum] != ONLY_SHORT_WINDOW)) {
+ if(quantInfo[chanNum].channelInfo.cpe) {
+ if(quantInfo[chanNum].channelInfo.ch_is_left) {
int i;
int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
+ int rightChan=quantInfo[chanNum].channelInfo.paired_ch;
ltp_enc(spectral_line_vector[leftChan],
tmp_DTimeSigBuf[leftChan],
@@ -671,17 +660,17 @@
WS_SIN,
&sfb_offset_table[leftChan][0],
nr_of_sfb[leftChan],
- <p_status[leftChan]);
+ &quantInfo[leftChan].ltpInfo);
- ltp_status[rightChan].global_pred_flag = ltp_status[leftChan].global_pred_flag;
+ quantInfo[rightChan].ltpInfo.global_pred_flag = quantInfo[leftChan].ltpInfo.global_pred_flag;
for(i = 0; i < BLOCK_LEN_LONG; i++)
- ltp_status[rightChan].pred_mdct[i] = ltp_status[leftChan].pred_mdct[i];
+ quantInfo[rightChan].ltpInfo.pred_mdct[i] = quantInfo[leftChan].ltpInfo.pred_mdct[i];
for(i = 0; i < MAX_SCFAC_BANDS; i++)
- ltp_status[rightChan].sfb_prediction_used[i] = ltp_status[leftChan].sfb_prediction_used[i];
- ltp_status[rightChan].weight = ltp_status[leftChan].weight;
- ltp_status[rightChan].delay[0] = ltp_status[leftChan].delay[0];
+ quantInfo[rightChan].ltpInfo.sfb_prediction_used[i] = quantInfo[leftChan].ltpInfo.sfb_prediction_used[i];
+ quantInfo[rightChan].ltpInfo.weight = quantInfo[leftChan].ltpInfo.weight;
+ quantInfo[rightChan].ltpInfo.delay[0] = quantInfo[leftChan].ltpInfo.delay[0];
- if (!channelInfo[leftChan].common_window) {
+ if (!quantInfo[leftChan].channelInfo.common_window) {
ltp_enc(spectral_line_vector[rightChan],
tmp_DTimeSigBuf[rightChan],
block_type[rightChan],
@@ -688,7 +677,7 @@
WS_SIN,
&sfb_offset_table[rightChan][0],
nr_of_sfb[rightChan],
- <p_status[rightChan]);
+ &quantInfo[rightChan].ltpInfo);
}
} /* if(channelInfo[chanNum].ch_is_left) */
} /* if(channelInfo[chanNum].cpe) */
@@ -699,10 +688,10 @@
WS_SIN,
&sfb_offset_table[chanNum][0],
nr_of_sfb[chanNum],
- <p_status[chanNum]);
+ &quantInfo[chanNum].ltpInfo);
} /* if(channelInfo[chanNum].present... */
else
- quantInfo[chanNum].ltpInfo->global_pred_flag = 0;
+ quantInfo[chanNum].ltpInfo.global_pred_flag = 0;
} /* for(chanNum... */
/******************************************/
@@ -710,7 +699,6 @@
/******************************************/
if (as->use_MS == 1) {
MSEncode(spectral_line_vector,
- channelInfo,
sfb_offset_table,
block_type,
quantInfo,
@@ -718,12 +706,10 @@
}
else if (as->use_MS == 0) {
MSEncodeSwitch(spectral_line_vector,
- channelInfo,
sfb_offset_table,
-// block_type,
quantInfo,
max_ch
- );
+ );
}
/************************************************/
@@ -739,7 +725,7 @@
double lfeBitRatio = 0.14; /* ratio of LFE bits to bits of one SCE */
int lfeBits = max(200,(int)((average_bits - used_bits) * lfeBitRatio / (max_ch - 1))); /* number of bits for LFE */
- if (channelInfo[chanNum].lfe) {
+ if (quantInfo[chanNum].channelInfo.lfe) {
bitsToUse = lfeBits;
bitsToUse += (int)(0.2*available_bitreservoir_bits
* lfeBitRatio / (max_ch - 1));
@@ -751,26 +737,16 @@
}
error = tf_encode_spectrum_aac(&spectral_line_vector[chanNum],
- &p_ratio[chanNum],
- &allowed_distortion[chanNum],
- &energy[chanNum],
- &block_type[chanNum],
- &sfb_width_table[chanNum],
-// &nr_of_sfb[chanNum],
- bitsToUse,
-// available_bitreservoir_bits,
-// padding_limit,
- fixed_stream,
-// NULL,
-// 1, /* nr of audio channels */
- &reconstructed_spectrum[chanNum],
-// useShortWindows,
-// aacAllowScalefacs,
- &quantInfo[chanNum],
- &(channelInfo[chanNum])
-// ,0/*no vbr*/,
-// ,bit_rate
- );
+ &p_ratio[chanNum],
+ &allowed_distortion[chanNum],
+ &energy[chanNum],
+ &block_type[chanNum],
+ &sfb_width_table[chanNum],
+ bitsToUse,
+ fixed_stream,
+ &reconstructed_spectrum[chanNum],
+ &quantInfo[chanNum]
+ );
if (error == FERROR)
return error;
}
@@ -780,7 +756,6 @@
/**********************************************************/
if (as->use_MS != -1) {
MSReconstruct(reconstructed_spectrum,
- channelInfo,
sfb_offset_table,
// block_type,
quantInfo,
@@ -792,13 +767,13 @@
/**********************************************************/
if(as->use_LTP)
for (chanNum=0;chanNum<max_ch;chanNum++) {
- if (!channelInfo[chanNum].lfe) { /* no reconstruction needed for LFE channel*/
+ if (!quantInfo[chanNum].channelInfo.lfe) { /* no reconstruction needed for LFE channel*/
ltp_reconstruct(reconstructed_spectrum[chanNum],
block_type[chanNum],
WS_SIN,
&sfb_offset_table[chanNum][0],
nr_of_sfb[chanNum],
- <p_status[chanNum]);
+ &quantInfo[chanNum].ltpInfo);
}
}
@@ -811,31 +786,31 @@
used_bits += WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 0);
for (chanNum=0;chanNum<max_ch;chanNum++) {
- if (channelInfo[chanNum].present) {
+ if (quantInfo[chanNum].channelInfo.present) {
/* Write out a single_channel_element */
- if (!channelInfo[chanNum].cpe) {
- if (channelInfo[chanNum].lfe) {
+ if (!quantInfo[chanNum].channelInfo.cpe) {
+ if (quantInfo[chanNum].channelInfo.lfe) {
/* Write out lfe */
used_bits += WriteLFE(&quantInfo[chanNum], /* Quantization information */
- channelInfo[chanNum].tag,
+ quantInfo[chanNum].channelInfo.tag,
fixed_stream, /* Bitstream */
0); /* Write flag, 1 means write */
} else {
/* Write out sce */
used_bits += WriteSCE(&quantInfo[chanNum], /* Quantization information */
- channelInfo[chanNum].tag,
+ quantInfo[chanNum].channelInfo.tag,
fixed_stream, /* Bitstream */
0); /* Write flag, 1 means write */
}
}
else {
- if (channelInfo[chanNum].ch_is_left) {
+ if (quantInfo[chanNum].channelInfo.ch_is_left) {
/* Write out cpe */
used_bits += WriteCPE(&quantInfo[chanNum], /* Quantization information,left */
- &quantInfo[channelInfo[chanNum].paired_ch], /* Right */
- channelInfo[chanNum].tag,
- channelInfo[chanNum].common_window, /* common window */
- &(channelInfo[chanNum].ms_info),
+ &quantInfo[quantInfo[chanNum].channelInfo.paired_ch], /* Right */
+ quantInfo[chanNum].channelInfo.tag,
+ quantInfo[chanNum].channelInfo.common_window, /* common window */
+ &(quantInfo[chanNum].channelInfo.ms_info),
fixed_stream, /* Bitstream */
0); /* Write flag, 1 means write */
}
@@ -870,31 +845,31 @@
WriteADTSHeader(&quantInfo[0], fixed_stream, used_bits, 1);
for (chanNum=0;chanNum<max_ch;chanNum++) {
- if (channelInfo[chanNum].present) {
+ if (quantInfo[chanNum].channelInfo.present) {
/* Write out a single_channel_element */
- if (!channelInfo[chanNum].cpe) {
- if (channelInfo[chanNum].lfe) {
+ if (!quantInfo[chanNum].channelInfo.cpe) {
+ if (quantInfo[chanNum].channelInfo.lfe) {
/* Write out lfe */
WriteLFE(&quantInfo[chanNum], /* Quantization information */
- channelInfo[chanNum].tag,
+ quantInfo[chanNum].channelInfo.tag,
fixed_stream, /* Bitstream */
1); /* Write flag, 1 means write */
} else {
/* Write out sce */
WriteSCE(&quantInfo[chanNum], /* Quantization information */
- channelInfo[chanNum].tag,
+ quantInfo[chanNum].channelInfo.tag,
fixed_stream, /* Bitstream */
1); /* Write flag, 1 means write */
}
}
else {
- if (channelInfo[chanNum].ch_is_left) {
+ if (quantInfo[chanNum].channelInfo.ch_is_left) {
/* Write out cpe */
WriteCPE(&quantInfo[chanNum], /* Quantization information,left */
- &quantInfo[channelInfo[chanNum].paired_ch], /* Right */
- channelInfo[chanNum].tag,
- channelInfo[chanNum].common_window, /* common window */
- &(channelInfo[chanNum].ms_info),
+ &quantInfo[quantInfo[chanNum].channelInfo.paired_ch], /* Right */
+ quantInfo[chanNum].channelInfo.tag,
+ quantInfo[chanNum].channelInfo.common_window, /* common window */
+ &(quantInfo[chanNum].channelInfo.ms_info),
fixed_stream, /* Bitstream */
1); /* Write flag, 1 means write */
}
--- a/ltp_enc.c
+++ b/ltp_enc.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.1 $
- $Date: 2000/10/06 14:47:27 $ (check in)
+ $Revision: 1.2 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <math.h>
+#include "quant.h"
#include "interface.h"
#include "transfo.h"
#include "bitstream.h"
@@ -796,8 +797,7 @@
*************************************************************************/
int
-ltp_encode (BsBitStream *bs, enum WINDOW_TYPE win_type, int num_of_sfb,
- LT_PRED_STATUS *lt_status, int write_flag)
+ltp_encode (AACQuantInfo *quantInfo, BsBitStream *bs, int write_flag)
{
int i, last_band;
// int first_subblock;
@@ -807,12 +807,12 @@
bit_count += 1;
- if (lt_status->side_info > 1)
+ if (quantInfo->ltpInfo.side_info > 1)
{
if(write_flag)
BsPutBit (bs, 1, 1); /* LTP used */
- switch(win_type)
+ switch(quantInfo->block_type)
{
case ONLY_LONG_WINDOW:
case LONG_SHORT_WINDOW:
@@ -821,16 +821,16 @@
bit_count += LEN_LTP_COEF;
if(write_flag)
{
- BsPutBit (bs, lt_status->delay[0], LEN_LTP_LAG);
- BsPutBit (bs, lt_status->weight_idx, LEN_LTP_COEF);
+ BsPutBit (bs, quantInfo->ltpInfo.delay[0], LEN_LTP_LAG);
+ BsPutBit (bs, quantInfo->ltpInfo.weight_idx, LEN_LTP_COEF);
}
- last_band = (num_of_sfb < MAX_LT_PRED_LONG_SFB) ? num_of_sfb : MAX_LT_PRED_LONG_SFB;
+ last_band = (quantInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ? quantInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
bit_count += last_band;
if(write_flag)
{
for (i = 0; i < last_band; i++)
- BsPutBit (bs, lt_status->sfb_prediction_used[i], LEN_LTP_LONG_USED);
+ BsPutBit (bs, quantInfo->ltpInfo.sfb_prediction_used[i], LEN_LTP_LONG_USED);
}
break;
--- a/ltp_enc.h
+++ b/ltp_enc.h
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.1 $
- $Date: 2000/10/06 14:47:27 $ (check in)
+ $Revision: 1.2 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -31,6 +31,7 @@
#include "interface.h"
#include "bitstream.h"
+#include "quant.h"
/*
Macro: LT_BLEN
@@ -80,7 +81,7 @@
/* Type: LT_PRED_STATUS
Purpose: Type of the struct holding the LTP encoding parameters.
Explanation: - */
-typedef struct
+typedef struct _LT_PRED_STATUS
{
short buffer[LT_BLEN];
double pred_mdct[2 * BLOCK_LEN_LONG];
@@ -117,8 +118,7 @@
int *sfb_offset, int num_of_sfb,
LT_PRED_STATUS *lt_status);
-int ltp_encode (BsBitStream *bs, enum WINDOW_TYPE win_type, int num_of_sfb,
- LT_PRED_STATUS *lt_status, int write_flag);
+int ltp_encode (struct _AACQuantInfo *quantInfo, BsBitStream *bs, int write_flag);
#endif /* not defined _LTP_ENC_H */
--- a/mc_enc.c
+++ b/mc_enc.c
@@ -21,14 +21,15 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.4 $
- $Date: 2000/10/05 08:39:02 $ (check in)
+ $Revision: 1.5 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
#include "mc_enc.h"
+#include "quant.h"
-void DetermineChInfo(Ch_Info* chInfo, int numChannels, int lfePresent) {
+void DetermineChInfo(AACQuantInfo *quantInfo, int numChannels, int lfePresent) {
/* If LFE present */
/* Num channels # of SCE's # of CPE's #of LFE's */
@@ -63,10 +64,10 @@
/* First element is sce, except for 2 channel case */
if (numChannelsLeft!=2) {
- chInfo[numChannels-numChannelsLeft].present = 1;
- chInfo[numChannels-numChannelsLeft].tag=sceTag++;
- chInfo[numChannels-numChannelsLeft].cpe=0;
- chInfo[numChannels-numChannelsLeft].lfe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.tag=sceTag++;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;
numChannelsLeft--;
}
@@ -73,22 +74,22 @@
/* Next elements are cpe's */
while (numChannelsLeft>1) {
/* Left channel info */
- chInfo[numChannels-numChannelsLeft].present = 1;
- chInfo[numChannels-numChannelsLeft].tag=cpeTag++;
- chInfo[numChannels-numChannelsLeft].cpe=1;
- chInfo[numChannels-numChannelsLeft].common_window=0;
- chInfo[numChannels-numChannelsLeft].ch_is_left=1;
- chInfo[numChannels-numChannelsLeft].paired_ch=numChannels-numChannelsLeft+1;
- chInfo[numChannels-numChannelsLeft].lfe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.tag=cpeTag++;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.common_window=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.ch_is_left=1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.paired_ch=numChannels-numChannelsLeft+1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;
numChannelsLeft--;
/* Right channel info */
- chInfo[numChannels-numChannelsLeft].present = 1;
- chInfo[numChannels-numChannelsLeft].cpe=1;
- chInfo[numChannels-numChannelsLeft].common_window=0;
- chInfo[numChannels-numChannelsLeft].ch_is_left=0;
- chInfo[numChannels-numChannelsLeft].paired_ch=numChannels-numChannelsLeft-1;
- chInfo[numChannels-numChannelsLeft].lfe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.common_window=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.ch_is_left=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.paired_ch=numChannels-numChannelsLeft-1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;
numChannelsLeft--;
}
@@ -95,15 +96,15 @@
/* Is there another channel left ? */
if (numChannelsLeft) {
if (lfePresent) {
- chInfo[numChannels-numChannelsLeft].present = 1;
- chInfo[numChannels-numChannelsLeft].tag=lfeTag++;
- chInfo[numChannels-numChannelsLeft].cpe=0;
- chInfo[numChannels-numChannelsLeft].lfe=1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.tag=lfeTag++;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=1;
} else {
- chInfo[numChannels-numChannelsLeft].present = 1;
- chInfo[numChannels-numChannelsLeft].tag=sceTag++;
- chInfo[numChannels-numChannelsLeft].cpe=0;
- chInfo[numChannels-numChannelsLeft].lfe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.present = 1;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.tag=sceTag++;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.cpe=0;
+ quantInfo[numChannels-numChannelsLeft].channelInfo.lfe=0;
}
numChannelsLeft--;
}
--- a/mc_enc.h
+++ b/mc_enc.h
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.5 $
- $Date: 2000/10/05 13:04:05 $ (check in)
+ $Revision: 1.6 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -31,7 +31,7 @@
#include "interface.h"
-void DetermineChInfo(Ch_Info* chInfo, int numChannels, int lfePresent);
+void DetermineChInfo(struct _AACQuantInfo *quantInfo, int numChannels, int lfePresent);
#endif
--- a/ms.c
+++ b/ms.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.14 $
- $Date: 2000/10/05 08:39:02 $ (check in)
+ $Revision: 1.15 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -33,7 +33,6 @@
double p_ratio_short[][MAX_SCFAC_BANDS],
CH_PSYCH_OUTPUT_LONG p_chpo_long[],
CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int use_ms,
@@ -48,12 +47,12 @@
/* Look for channel_pair_elements */
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ if (quantInfo[chanNum].channelInfo.present) {
+ if ((quantInfo[chanNum].channelInfo.cpe)&&(quantInfo[chanNum].channelInfo.ch_is_left)) {
int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
- channelInfo[leftChan].ms_info.is_present=0;
- channelInfo[leftChan].common_window = 0;
+ int rightChan=quantInfo[chanNum].channelInfo.paired_ch;
+ quantInfo[leftChan].channelInfo.ms_info.is_present=0;
+ quantInfo[leftChan].channelInfo.common_window = 0;
/* Perform MS if block_types are the same */
if ((block_type[leftChan]==block_type[rightChan])&&(use_ms==0)) {
@@ -68,7 +67,7 @@
maxSfb = quantInfo[leftChan].max_sfb;
/* Determine which bands should be enabled */
- msInfo = &(channelInfo[leftChan].ms_info);
+ msInfo = &(quantInfo[leftChan].channelInfo.ms_info);
isBand = maxSfb;
for (g=0;g<numGroups;g++) {
@@ -131,10 +130,10 @@
}
if (realyused) {
- channelInfo[leftChan].common_window = 1; /* Use common window */
- channelInfo[leftChan].ms_info.is_present=1;
- channelInfo[rightChan].common_window = 1; /* Use common window */
- channelInfo[rightChan].ms_info.is_present=1;
+ quantInfo[leftChan].channelInfo.common_window = 1; /* Use common window */
+ quantInfo[leftChan].channelInfo.ms_info.is_present=1;
+ quantInfo[rightChan].channelInfo.common_window = 1; /* Use common window */
+ quantInfo[rightChan].channelInfo.ms_info.is_present=1;
}
}
else if ((block_type[leftChan]==block_type[rightChan])&&(use_ms == 1)) {
@@ -145,10 +144,10 @@
int g,b,j;
MS_Info *msInfo;
- channelInfo[leftChan].ms_info.is_present = 1;
- channelInfo[leftChan].common_window = 1;
- channelInfo[rightChan].ms_info.is_present = 1;
- channelInfo[rightChan].common_window = 1;
+ quantInfo[leftChan].channelInfo.ms_info.is_present = 1;
+ quantInfo[leftChan].channelInfo.common_window = 1;
+ quantInfo[rightChan].channelInfo.ms_info.is_present = 1;
+ quantInfo[rightChan].channelInfo.common_window = 1;
for (chan = 0; chan < 2; chan++) {
int chan2;
@@ -158,7 +157,7 @@
maxSfb = quantInfo[chan].max_sfb;
/* Determine which bands should be enabled */
- msInfo = &(channelInfo[leftChan].ms_info);
+ msInfo = &(quantInfo[leftChan].channelInfo.ms_info);
numGroups = quantInfo[chan2].num_window_groups;
for (g=0;g<numGroups;g++) {
@@ -199,7 +198,7 @@
maxSfb = quantInfo[chan].max_sfb;
/* Determine which bands should be enabled */
- msInfo = &(channelInfo[leftChan].ms_info);
+ msInfo = &(quantInfo[leftChan].channelInfo.ms_info);
numGroups = quantInfo[chan2].num_window_groups;
for (g=0;g<numGroups;g++) {
@@ -234,7 +233,6 @@
CH_PSYCH_OUTPUT_LONG p_chpo_long[],
CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int use_ms,
@@ -247,10 +245,10 @@
double dtmp;
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ if (quantInfo[chanNum].channelInfo.present) {
+ if ((quantInfo[chanNum].channelInfo.cpe)&&(quantInfo[chanNum].channelInfo.ch_is_left)) {
int leftChan = chanNum;
- int rightChan = channelInfo[chanNum].paired_ch;
+ int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
/* Compute energy in each scalefactor band of each window */
numWindows = (block_type[chanNum]==ONLY_SHORT_WINDOW) ? 8 : 1;
@@ -332,7 +330,6 @@
/* Perform MS encoding. Spectrum is non-interleaved. */
/* This would be a lot simpler on interleaved spectral data */
void MSEncode(double *spectrum[MAX_TIME_CHANNELS], /* array of pointers to spectral data */
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
int sfb_offset_table[][MAX_SCFAC_BANDS+1],
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
@@ -342,9 +339,12 @@
int sfbNum;
int lineNum;
double sum,diff;
+ Ch_Info *channelInfo;
/* Look for channel_pair_elements */
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ channelInfo = &quantInfo[chanNum].channelInfo;
+
if (channelInfo[chanNum].present) {
if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
int leftChan=chanNum;
@@ -408,9 +408,7 @@
/* Perform MS encoding. Spectrum is non-interleaved. */
/* This would be a lot simpler on interleaved spectral data */
void MSEncodeSwitch(double *spectrum[MAX_TIME_CHANNELS], /* array of pointers to spectral data */
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-// enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int numberOfChannels /* Number of channels */
)
@@ -419,9 +417,12 @@
int sfbNum;
int lineNum;
double sum,diff;
+ Ch_Info *channelInfo;
/* Look for channel_pair_elements */
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ channelInfo = &quantInfo[chanNum].channelInfo;
+
if (channelInfo[0].ms_info.is_present) {
if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
int leftChan=chanNum;
@@ -480,7 +481,6 @@
void MSReconstruct(double *spectrum[MAX_TIME_CHANNELS], /* array of pointers to spectral data */
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
int sfb_offset_table[][MAX_SCFAC_BANDS+1],
// enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
@@ -490,9 +490,12 @@
int sfbNum;
int lineNum;
double sum,diff;
+ Ch_Info *channelInfo;
/* Look for channel_pair_elements */
for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ channelInfo = &quantInfo[chanNum].channelInfo;
+
if (channelInfo[chanNum].present) {
if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
int leftChan=chanNum;
--- a/ms.h
+++ b/ms.h
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.10 $
- $Date: 2000/10/05 13:04:05 $ (check in)
+ $Revision: 1.11 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -36,7 +36,6 @@
double p_ratio_short[][MAX_SCFAC_BANDS],
CH_PSYCH_OUTPUT_LONG p_chpo_long[],
CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int use_ms,
@@ -48,7 +47,6 @@
CH_PSYCH_OUTPUT_LONG p_chpo_long[],
CH_PSYCH_OUTPUT_SHORT p_chpo_short[][MAX_SHORT_WINDOWS],
int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
int use_ms,
@@ -56,15 +54,12 @@
);
void MSEncodeSwitch(double *spectrum[MAX_TIME_CHANNELS], /* array of pointers to spectral data */
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
int sfb_offset_table[][MAX_SCFAC_BANDS+1],
-// enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo,
int numberOfChannels
); /* Number of channels */
void MSEncode(double *spectrum[MAX_TIME_CHANNELS], /* array of pointers to spectral data */
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
int sfb_offset_table[][MAX_SCFAC_BANDS+1],
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo,
@@ -71,7 +66,6 @@
int numberOfChannels); /* Number of channels */
void MSReconstruct(double *spectrum[MAX_TIME_CHANNELS], /* array of pointers to spectral data */
- Ch_Info *channelInfo, /* Pointer to Ch_Info */
int sfb_offset_table[][MAX_SCFAC_BANDS+1],
// enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
AACQuantInfo* quantInfo, /* Quant info */
--- a/psych.c
+++ b/psych.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.71 $
- $Date: 2000/10/31 14:48:41 $ (check in)
+ $Revision: 1.72 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -325,7 +325,6 @@
AACQuantInfo *quantInfo,
double sampling_rate,
int no_of_chan, /* no of audio channels */
- Ch_Info* channelInfo,
double *p_time_signal[],
enum WINDOW_TYPE block_type[],
int use_MS,
@@ -353,12 +352,12 @@
}
for (chanNum = 0; chanNum < no_of_chan; chanNum++) {
- if (channelInfo[chanNum].present) {
+ if (quantInfo[chanNum].channelInfo.present) {
p_sri = quantInfo[chanNum].sr_info;
- if ((channelInfo[chanNum].cpe) && (channelInfo[chanNum].ch_is_left)) { /* CPE */
+ if ((quantInfo[chanNum].channelInfo.cpe) && (quantInfo[chanNum].channelInfo.ch_is_left)) { /* CPE */
int leftChan = chanNum;
- int rightChan = channelInfo[chanNum].paired_ch;
+ int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
int midChan = chanNum + MAX_TIME_CHANNELS;
int sideChan = chanNum + MAX_TIME_CHANNELS;
@@ -486,7 +485,7 @@
memcpy(p_chpo_short[rightChan][i].use_ms, psy_stvar_short[rightChan].use_ms[i], NSFB_SHORT*sizeof(int));
}
- } else if (channelInfo[chanNum].lfe) { /* LFE */
+ } else if (quantInfo[chanNum].channelInfo.lfe) { /* LFE */
// LFE psych ratios are set to -24 dB for low frequencies
for (i = 0; i < 10; i++) {
--- a/psych.h
+++ b/psych.h
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.24 $
- $Date: 2000/10/31 14:48:41 $ (check in)
+ $Revision: 1.25 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -167,7 +167,6 @@
AACQuantInfo *quantInfo,
double sampling_rate,
int no_of_chan, /* no of audio channels */
- Ch_Info* chInfo,
double *p_time_signal[],
enum WINDOW_TYPE block_type[],
int use_MS,
--- a/quant.c
+++ b/quant.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.11 $
- $Date: 2000/10/06 14:47:27 $ (check in)
+ $Revision: 1.12 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -105,9 +105,9 @@
for (i=0;i<9000;i++){
pow_quant[i]=pow(i, ((double)4.0/(double)3.0));
}
- for (i=0;i<8999;i++){
+ for (i = 0; i < 8999; i++)
adj_quant[i] = (i + 1) - pow(0.5 * (pow_quant[i] + pow_quant[i + 1]), 0.75);
- }
+ adj_quant[i] = 0.5;
adj_quant_asm[0] = 0.0;
for (i = 1; i < 9000; i++) {
@@ -116,6 +116,70 @@
}
+#if 0
+
+#define XRPOW_FTOI(src,dest) ((dest) = (int)(src))
+#define QUANTFAC(rx) adj_quant[rx]
+#define ROUNDFAC 0.4054
+
+
+void quantize(AACQuantInfo *quantInfo,
+ double *pow_spectrum,
+ int *quant)
+{
+ int j, i;
+ double istep = pow(2.0,-((double)(quantInfo->common_scalefac)-210)*.1875);
+ double w = 8192 / pow(2.0,-((double)(quantInfo->common_scalefac)-210)*.1875);
+
+ for ( i = 0; i < 1024; i++ ) {
+ if (pow_spectrum[i] > w)
+ {
+ for (j = 0; j < 1024; j++)
+ quant[j] = 8192;
+ return;
+ }
+ }
+
+ for ( j = 1024/8; j > 0; --j) {
+ double x1, x2, x3, x4, x5, x6, x7, x8;
+ int rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8;
+ x1 = *pow_spectrum++ * istep;
+ x2 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x1, rx1);
+ x3 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x2, rx2);
+ x4 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x3, rx3);
+ x5 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x4, rx4);
+ x6 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x5, rx5);
+ x7 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x6, rx6);
+ x8 = *pow_spectrum++ * istep;
+ XRPOW_FTOI(x7, rx7);
+ x1 += QUANTFAC(rx1);
+ XRPOW_FTOI(x8, rx8);
+ x2 += QUANTFAC(rx2);
+ XRPOW_FTOI(x1,*quant++);
+ x3 += QUANTFAC(rx3);
+ XRPOW_FTOI(x2,*quant++);
+ x4 += QUANTFAC(rx4);
+ XRPOW_FTOI(x3,*quant++);
+ x5 += QUANTFAC(rx5);
+ XRPOW_FTOI(x4,*quant++);
+ x6 += QUANTFAC(rx6);
+ XRPOW_FTOI(x5,*quant++);
+ x7 += QUANTFAC(rx7);
+ XRPOW_FTOI(x6,*quant++);
+ x8 += QUANTFAC(rx8);
+ XRPOW_FTOI(x7,*quant++);
+ XRPOW_FTOI(x8,*quant++);
+ }
+}
+
+#else
+
#if (defined(__GNUC__) && defined(__i386__))
#define USE_GNUC_ASM
#endif
@@ -344,6 +408,7 @@
}
#endif
}
+#endif
int inner_loop(AACQuantInfo *quantInfo,
double *pow_spectrum,
@@ -578,21 +643,11 @@
double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-// int nr_of_sfb[MAX_TIME_CHANNELS],
int average_block_bits,
-// int available_bitreservoir_bits,
-// int padding_limit,
BsBitStream *fixed_stream,
-// BsBitStream *var_stream,
-// int nr_of_chan,
double *p_reconstructed_spectrum[MAX_TIME_CHANNELS],
-// int useShortWindows,
-// int aacAllowScalefacs,
- AACQuantInfo* quantInfo, /* AAC quantization information */
- Ch_Info* ch_info
-// ,int varBitRate
-// ,int bitRate
- )
+ AACQuantInfo* quantInfo /* AAC quantization information */
+ )
{
int quant[BLOCK_LEN_LONG];
int s_quant[BLOCK_LEN_LONG];
@@ -722,7 +777,7 @@
}
/* PNS prepare */
- ms_info=&(ch_info->ms_info);
+ ms_info=&(quantInfo->channelInfo.ms_info);
for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
quantInfo->pns_sfb_flag[sb] = 0;
@@ -1025,333 +1080,9 @@
return 0;
}
-
-#if 0 // VBR quantizer not finished yet
-
-#if (defined(__GNUC__) && defined(__i386__))
-#define USE_GNUC_ASM
-#endif
-#ifdef _MSC_VER
-#define USE_MSC_ASM
-#endif
-
-/*********************************************************************
- * XRPOW_FTOI is a macro to convert floats to ints.
- * if XRPOW_FTOI(x) = nearest_int(x), then QUANTFAC(x)=adj43asm[x]
- * ROUNDFAC= -0.0946
- *
- * if XRPOW_FTOI(x) = floor(x), then QUANTFAC(x)=asj43[x]
- * ROUNDFAC=0.4054
- *********************************************************************/
-#ifdef USE_GNUC_ASM
-# define ROUNDFAC -0.0946
-#elif defined (USE_MSC_ASM)
-# define ROUNDFAC -0.0946
-#else
-# define ROUNDFAC 0.4054
-#endif
-
-
-
-int compute_scalefacs(AACQuantInfo* quantInfo,
- int sf[MAX_SCFAC_BANDS],
- int scalefac[MAX_SCFAC_BANDS])
-{
- int sfb;
- int maxover;
- int ifqstep = 2;
-
-
-// if (cod_info->preflag)
-// for ( sfb = 11; sfb < SBPSY_l; sfb++ )
-// sf[sfb] += pretab[sfb]*ifqstep;
-
-
- maxover = 0;
- for (sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++) {
-
- if (sf[sfb]<0) {
- /* ifqstep*scalefac >= -sf[sfb], so round UP */
- scalefac[sfb]=-sf[sfb]/ifqstep + (-sf[sfb] % ifqstep != 0);
- if (scalefac[sfb] > /*max_range[sfb]*/10) scalefac[sfb]=10/*max_range[sfb]*/;
-
- /* sf[sfb] should now be positive: */
- if ( -(sf[sfb] + scalefac[sfb]*ifqstep) > maxover) {
- maxover = -(sf[sfb] + scalefac[sfb]*ifqstep);
- }
- }
- }
-
- return maxover;
-}
-
-
-
-double calc_sfb_noise_ave(double *p_spectrum, double *pow_spectrum, int bw,int sf)
-{
- int j;
- double xfsf=0, xfsf_p1=0, xfsf_m1=0;
- double sfpow34,sfpow34_p1,sfpow34_m1;
- double sfpow,sfpow_p1,sfpow_m1;
-
- sfpow = pow(2.0,((double)sf)*.25);
- sfpow34 = pow(2.0,-((double)sf)*.1875);
-
- sfpow_m1 = sfpow*.8408964153;
- sfpow34_m1 = sfpow34*1.13878863476;
-
- sfpow_p1 = sfpow*1.189207115;
- sfpow34_p1 = sfpow34*0.878126080187;
-
- for ( j=0; j < bw ; j++) {
- int ix;
- double temp,temp_p1,temp_m1;
-
- if (pow_quant[j]*sfpow34_m1 > 8191) return -1;
-
- temp = pow_quant[j]*sfpow34;
- XRPOW_FTOI(temp, ix);
- XRPOW_FTOI(temp + QUANTFAC(ix), ix);
- temp = fabs(p_spectrum[j])- pow_quant[ix]*sfpow;
- temp *= temp;
-
- temp_p1 = pow_quant[j]*sfpow34_p1;
- XRPOW_FTOI(temp_p1, ix);
- XRPOW_FTOI(temp_p1 + QUANTFAC(ix), ix);
- temp_p1 = fabs(p_spectrum[j])- pow_quant[ix]*sfpow_p1;
- temp_p1 *= temp_p1;
-
- temp_m1 = pow_quant[j]*sfpow34_m1;
- XRPOW_FTOI(temp_m1, ix);
- XRPOW_FTOI(temp_m1 + QUANTFAC(ix), ix);
- temp_m1 = fabs(p_spectrum[j])- pow_quant[ix]*sfpow_m1;
- temp_m1 *= temp_m1;
-
- xfsf += temp;
- xfsf_p1 += temp_p1;
- xfsf_m1 += temp_m1;
- }
- if (xfsf_p1>xfsf) xfsf = xfsf_p1;
- if (xfsf_m1>xfsf) xfsf = xfsf_m1;
- return xfsf/bw;
-}
-
-int find_scalefac(double *p_spectrum,double *pow_quant,int sfb,
- double l3_xmin,int bw)
-{
- double xfsf;
- int i,sf,sf_ok,delsf;
-
- /* search will range from sf: -209 -> 45 */
- sf = -82;
- delsf = 128;
-
- sf_ok=10000;
- for (i=0; i<7; i++) {
- delsf /= 2;
- xfsf = calc_sfb_noise_ave(p_spectrum,pow_quant,bw,sf);
-
- if (xfsf < 0) {
- /* scalefactors too small */
- sf += delsf;
- }else{
- if (sf_ok==10000) sf_ok=sf;
- if (xfsf > l3_xmin) {
- /* distortion. try a smaller scalefactor */
- sf -= delsf;
- }else{
- sf_ok = sf;
- sf += delsf;
- }
- }
- }
-// assert(sf_ok!=10000);
-
- return sf;
-}
-
-int
-VBR_quantize_granule(AACQuantInfo* quantInfo,
- double *pow_spectrum,
- int quant[1024]
- )
-{
- quantize(quantInfo, pow_spectrum, quant);
-
- return count_bits(quantInfo, quant);
-}
-
-int
-VBR_noise_shaping(AACQuantInfo* quantInfo,
- double p_spectrum[1024],
- double pow_quant_orig[1024],
- double allowed_dist[SFB_NUM_MAX],
- int quant[1024], int minbits, int maxbits,
- int scalefac[MAX_SCFAC_BANDS])
-{
- int start,end,bw,sfb,l, vbrmax;
- int bits_used;
- int vbrsf[MAX_SCFAC_BANDS];
- int save_sf[MAX_SCFAC_BANDS];
- int maxover0,maxover1,maxover,mover;
- int ifqstep;
- double pow_quant[1024];
-
-
-// for(i=0;i<1024;i++) {
-// double temp=fabs(p_spectrum[i]);
-// pow_quant[i]=sqrt(sqrt(temp)*temp);
-// }
- memcpy(pow_quant, pow_quant_orig, sizeof(pow_quant));
-
-
- vbrmax=-10000;
-
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ ) {
- start = quantInfo->sfb_offset[sfb];
- end = quantInfo->sfb_offset[sfb+1];
- bw = end - start;
- vbrsf[sfb] = find_scalefac(&p_spectrum[start],&pow_quant[start],sfb,
- allowed_dist[sfb],bw);
- }
-
-#define MAX_SF_DELTA 4
-
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ ) {
- if (sfb>0)
- vbrsf[sfb] = min(vbrsf[sfb-1]+MAX_SF_DELTA,vbrsf[sfb]);
- if (sfb< quantInfo->nr_of_sfb-1)
- vbrsf[sfb] = min(vbrsf[sfb+1]+MAX_SF_DELTA,vbrsf[sfb]);
- }
-
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ )
- if (vbrsf[sfb]>vbrmax) vbrmax = vbrsf[sfb];
-
-
- /* save a copy of vbrsf, incase we have to recomptue scalefacs */
- memcpy(&save_sf,&vbrsf,sizeof(int)*MAX_SCFAC_BANDS);
-
-
- do {
-
- memset(scalefac,0,sizeof(int)*MAX_SCFAC_BANDS);
-
- maxover0=0;
- maxover1=0;
-
-
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ ) {
- maxover0 = max(maxover0,(vbrmax - vbrsf[sfb]) - 2*/*max_range[sfb]*/10 );
- maxover1 = max(maxover1,(vbrmax - vbrsf[sfb]) - 4*/*max_range[sfb]*/10 );
- }
- mover = maxover0;
-
-
- vbrmax -= mover;
- maxover0 -= mover;
- maxover1 -= mover;
-
#if 0
- if (maxover0<=0) {
- cod_info->preflag=0;
- vbrmax -= maxover0;
- } else if (maxover0p<=0) {
- cod_info->preflag=1;
- vbrmax -= maxover0p;
- } else if (maxover1==0) {
- cod_info->preflag=0;
- } else if (maxover1p==0) {
- cod_info->preflag=1;
- }
-#endif
-
- quantInfo->common_scalefac = vbrmax +210;
-// assert(cod_info->global_gain < 256);
- if (quantInfo->common_scalefac>255) quantInfo->common_scalefac = 255;
-
-
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ )
- vbrsf[sfb] -= vbrmax;
-
-
- maxover = compute_scalefacs(quantInfo,vbrsf,scalefac);
-// assert(maxover <=0);
-
-
- /* quantize pow_quant[] based on computed scalefactors */
- ifqstep = 2;
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ ) {
- int ifac;
- double fac;
- ifac = ifqstep*scalefac[sfb];
-// if (cod_info->preflag)
-// ifac += ifqstep*pretab[sfb];
-
-// if (ifac+210<330)
-// fac = 1/pow(2.0,-((double)ifac)*.1875);
-// else
- fac = pow(2.0,.75*ifac/4.0);
-
- start = quantInfo->sfb_offset[sfb];
- end = quantInfo->sfb_offset[sfb+1];
- for ( l = start; l < end; l++ ) {
- pow_quant[l]*=fac;
- }
- }
-
- bits_used = VBR_quantize_granule(quantInfo, pow_quant, quant);
-
-
- if (bits_used < minbits) {
- /* decrease global gain, recompute scale factors */
-// if (digital_silence) break;
- if (vbrmax+210 ==0 ) break;
-
-
-
- --vbrmax;
- memcpy(&vbrsf,&save_sf,sizeof(int)*MAX_SCFAC_BANDS);
- memcpy(pow_quant, pow_quant_orig, sizeof(pow_quant));
- }
-
- } while ((bits_used < minbits));
-
-
- while (bits_used > min(maxbits,4095)) {
- /* increase global gain, keep exisiting scale factors */
- ++quantInfo->common_scalefac;
- bits_used = VBR_quantize_granule(quantInfo, pow_quant, quant);
- }
-
- return bits_used;
-}
-
-int calc_xmin(AACQuantInfo* quantInfo, double p_spectrum[1024], double ratio[MAX_SCFAC_BANDS],
- double allowed_dist[MAX_SCFAC_BANDS], double masking_lower)
-{
- int start, end, bw,l,ath_over=0;
- int sfb;
- double en0, ener;
-
- for ( sfb = 0; sfb < quantInfo->nr_of_sfb; sfb++ ){
- start = quantInfo->sfb_offset[sfb];
- end = quantInfo->sfb_offset[sfb+1];
- bw = end - start;
-
- for (en0 = 0.0, l = start; l < end; l++ ) {
- ener = p_spectrum[l] * p_spectrum[l];
- en0 += ener;
- }
- en0 /= bw;
-
- allowed_dist[sfb] = en0 * ratio[sfb] * masking_lower / en0;
- }
-
- return 0;
-}
-
-int tf_encode_spectrum_aac_VBR(
+int iteration_loop(
double *p_spectrum[MAX_TIME_CHANNELS],
double *PsySigMaskRatio[MAX_TIME_CHANNELS],
double allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
@@ -1366,9 +1097,12 @@
)
{
int quant[BLOCK_LEN_LONG];
+ int s_quant[BLOCK_LEN_LONG];
int i;
int k;
double max_dct_line = 0;
+ int store_common_scalefac;
+ int best_scale_factor[MAX_SCFAC_BANDS];
double pow_spectrum[BLOCK_LEN_LONG];
double requant[BLOCK_LEN_LONG];
int sb;
@@ -1378,12 +1112,15 @@
int *ptr_book_vector;
/* Set up local pointers to quantInfo elements for convenience */
- int* sfb_offset = quantInfo->sfb_offset;
- int* scale_factor = quantInfo->scale_factor;
+ int* sfb_offset = quantInfo -> sfb_offset;
+ int* scale_factor = quantInfo -> scale_factor;
int* common_scalefac = &(quantInfo -> common_scalefac);
- int outer_loop_count;
+ int outer_loop_count, notdone;
+ int over, better;
int best_over = 100;
+ int best_common_scalefac;
+ double noise_thresh;
double sfQuantFac;
double over_noise, tot_noise, max_noise;
double noise[MAX_SCFAC_BANDS];
@@ -1391,14 +1128,6 @@
double best_over_noise = 0;
double best_tot_noise = 0;
- int max_bits = 3 * average_block_bits;
- int min_bits = average_block_bits / 1;
- int totbits, bits_ok;
- double masking_lower_db = 0;
- double masking_lower = 0;
- double qadjust = 0;
- int used_bits;
-
/* Set block type in quantization info */
quantInfo -> block_type = block_type[0];
@@ -1486,24 +1215,31 @@
for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
quantInfo->pns_sfb_flag[sb] = 0;
- for(sb = pns_sfb_start; sb < quantInfo->nr_of_sfb; sb++ ) {
- /* Calc. pseudo scalefactor */
- if (energy[0][sb] == 0.0) {
- quantInfo->pns_sfb_flag[sb] = 0;
- continue;
- }
+// if (block_type[0] != ONLY_SHORT_WINDOW) { /* long blocks only */
+ for(sb = pns_sfb_start; sb < quantInfo->nr_of_sfb; sb++ ) {
+ /* Calc. pseudo scalefactor */
+ if (energy[0][sb] == 0.0) {
+ quantInfo->pns_sfb_flag[sb] = 0;
+ continue;
+ }
- if ((ms_info->is_present)&&(!ms_info->ms_used[sb])) {
- if ((10*log10(energy[0][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
- quantInfo->pns_sfb_flag[sb] = 1;
- quantInfo->pns_sfb_nrg[sb] = (int) (2.0 * log(energy[0][sb]*sfb_width_table[0][sb]+1e-60) / log(2.0) + 0.5) + PNS_SF_OFFSET;
+ if ((ms_info->is_present)&&(!ms_info->ms_used[sb])) {
+ if ((10*log10(energy[0][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
+ quantInfo->pns_sfb_flag[sb] = 1;
+ quantInfo->pns_sfb_nrg[sb] = (int) (2.0 * log(energy[0][sb]*sfb_width_table[0][sb]+1e-60) / log(2.0) + 0.5) + PNS_SF_OFFSET;
- /* Erase spectral lines */
- for( i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++ ) {
- p_spectrum[0][i] = 0.0;
+ /* Erase spectral lines */
+ for( i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++ ) {
+ p_spectrum[0][i] = 0.0;
+ }
}
}
}
+// }
+
+ /* Compute allowed distortion */
+ for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
+ allowed_dist[0][sb] = energy[0][sb] * SigMaskRatio[sb];
}
/** find the maximum spectral coefficient **/
@@ -1526,75 +1262,54 @@
}
outer_loop_count = 0;
- used_bits = max_bits + 1;
- calc_xmin(quantInfo, p_spectrum[0], SigMaskRatio, allowed_dist[0],
- masking_lower);
+ bit_rate = bitrate_table [gfc->gfp->version] [gfc->bitrate_index];
+ getframebits (gfc, &bitsPerFrame, &mean_bits);
+ ResvFrameBegin (gfc, l3_side, mean_bits, bitsPerFrame );
- do {
+ /* calculate needed bits
+ */
+ max_bits = on_pe (gfc, pe, l3_side, targ_bits, mean_bits, gr);
+
+ cod_info = &l3_side->gr[gr].ch[ch].tt;
- int shortblock;
- totbits=0;
-
- /* ENCODE this data first pass, and on future passes unless it uses
- * a very small percentage of the max_frame_bits */
- if (used_bits > max_bits) {
+ /* init_outer_loop sets up cod_info, scalefac and xrpow
+ */
+ if (!init_outer_loop (cod_info, &scalefac[gr][ch], xr[gr][ch],
+ xrpow )) {
+ /* xr contains no energy, l3_enc will be quantized to zero
+ */
+ memset (l3_enc[gr][ch], 0, sizeof(int)*576);
+ } else {
+ /* xr contains energy we will have to encode
+ * calculate the masking abilities
+ * find some good quantization in outer_loop
+ */
+ calc_xmin (gfc, xr[gr][ch], &ratio[gr][ch], cod_info,
+ &l3_xmin[ch]);
+ outer_loop (gfc, cod_info, xr[gr][ch], &l3_xmin[ch],
+ &scalefac[gr][ch], xrpow, l3_enc[gr][ch],
+ ch, targ_bits[ch]);
+ }
+ assert (cod_info->part2_3_length < 4096);
- shortblock = (quantInfo->block_type == ONLY_SHORT_WINDOW);
+ /* try some better scalefac storage
+ */
+ best_scalefac_store (gfc, gr, ch, l3_enc, l3_side, scalefac);
- if (qadjust!=0 /*|| shortblock*/) {
- /* Adjust allowed masking based on quality setting */
- masking_lower_db = /*dbQ[0]*/0 + qadjust;
+ /* best huffman_divide may save some bits too
+ */
+ if (gfc->use_best_huffman == 1)
+ best_huffman_divide (gfc, gr, ch, cod_info, l3_enc[gr][ch]);
-// if (pe[gr][ch]>750)
-// masking_lower_db -= 4*(pe[gr][ch]-750.)/750.;
-
- masking_lower = pow(10.0,masking_lower_db/10);
- calc_xmin(quantInfo, p_spectrum[0], SigMaskRatio, allowed_dist[0],
- masking_lower);
- }
-
- used_bits = VBR_noise_shaping(quantInfo, p_spectrum[0], pow_spectrum,
- allowed_dist[0], quant, min_bits, max_bits, scale_factor);
- }
- bits_ok=1;
- if (used_bits > max_bits) {
- qadjust += max(.25,(used_bits - max_bits)/300.0);
- min_bits = max(125,min_bits*0.975);
- max_bits = max(min_bits,max_bits*0.975);
- bits_ok=0;
- }
-
- } while (!bits_ok);
-
- calc_noise(quantInfo, p_spectrum[0], quant, requant, noise, allowed_dist[0],
- &over_noise, &tot_noise, &max_noise);
- count_bits(quantInfo, quant);
- if (quantInfo->block_type!=ONLY_SHORT_WINDOW)
- PulseDecoder(quantInfo, quant);
-
- /* offset the differenec of common_scalefac and scalefactors by SF_OFFSET */
- for (i=0; i<quantInfo->nr_of_sfb; i++){
- if ((ptr_book_vector[i]!=INTENSITY_HCB)&&(ptr_book_vector[i]!=INTENSITY_HCB2)) {
- scale_factor[i] = *common_scalefac - scale_factor[i] + SF_OFFSET;
- }
+ /* set the sign of l3_enc from the sign of xr
+ */
+ for (i = 0; i < 576; i++) {
+ if (xr[gr][ch][i] < 0) l3_enc[gr][ch][i] *= -1;
}
- *common_scalefac = scale_factor[0];
+
+ ResvFrameEnd (gfc, l3_side, mean_bits);
- /* place the codewords and their respective lengths in arrays data[] and len[] respectively */
- /* there are 'counter' elements in each array, and these are variable length arrays depending on the input */
-
- quantInfo -> spectralCount = 0;
- for(k=0;k< quantInfo -> nr_of_sfb; k++) {
- output_bits(
- quantInfo,
- quantInfo->book_vector[k],
- quant,
- quantInfo->sfb_offset[k],
- quantInfo->sfb_offset[k+1]-quantInfo->sfb_offset[k],
- 1);
- }
-
/* write the reconstructed spectrum to the output for use with prediction */
{
int i;
@@ -1613,4 +1328,5 @@
return FNO_ERROR;
}
+
#endif
--- a/quant.h
+++ b/quant.h
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.6 $
- $Date: 2000/10/31 14:48:41 $ (check in)
+ $Revision: 1.7 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -64,7 +64,7 @@
/*********************************************************/
/* AACQuantInfo, info for AAC quantization and coding. */
/*********************************************************/
-typedef struct {
+typedef struct _AACQuantInfo {
int max_sfb; /* max_sfb, should = nr_of_sfb/num_window_groups */
int nr_of_sfb; /* Number of scalefactor bands, interleaved */
int spectralCount; /* Number of spectral data coefficients */
@@ -83,10 +83,12 @@
short pred_global_flag; /* Global prediction enable flag */
int pred_sfb_flag[MAX_SCFAC_BANDS]; /* Prediction enable flag for each scalefactor band */
int reset_group_number; /* Prediction reset group number */
- TNS_INFO* tnsInfo; /* Ptr to tns data */
AACPulseInfo pulseInfo;
- LT_PRED_STATUS *ltpInfo; /* Ptr to LTP data */
SR_INFO *sr_info;
+ TNS_INFO tnsInfo;
+ struct _LT_PRED_STATUS ltpInfo;
+ Ch_Info channelInfo;
+
int pns_sfb_nrg[MAX_SCFAC_BANDS];
int pns_sfb_flag[MAX_SCFAC_BANDS];
int profile;
@@ -135,21 +137,11 @@
double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-// int nr_of_sfb[MAX_TIME_CHANNELS],
int average_block_bits,
-// int available_bitreservoir_bits,
-// int padding_limit,
BsBitStream *fixed_stream,
-// BsBitStream *var_stream,
-// int nr_of_chan,
double *p_reconstructed_spectrum[MAX_TIME_CHANNELS],
-// int useShortWindows,
-// int aacAllowScalefacs,
- AACQuantInfo* quantInfo, /* AAC quantization information */
- Ch_Info *ch_info
-// ,int varBitRate
-// ,int bitRate
- );
+ AACQuantInfo* quantInfo /* AAC quantization information */
+ );
--- a/tns.c
+++ b/tns.c
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.13 $
- $Date: 2000/10/06 14:47:27 $ (check in)
+ $Revision: 1.14 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include "tns.h"
#include "aacenc.h"
+#include "quant.h"
/***********************************************/
/* TNS Profile/Frequency Dependent Parameters */
@@ -115,12 +116,12 @@
/*****************************************************/
/* TnsEncode: */
/*****************************************************/
-int TnsEncode(int numberOfBands, /* Number of bands per window */
- int maxSfb, /* max_sfb */
- enum WINDOW_TYPE blockType, /* block type */
- int* sfbOffsetTable, /* Scalefactor band offset table */
- double* spec, /* Spectral data array */
- TNS_INFO* tnsInfo, int use_tns) /* TNS info */
+int TnsEncode(AACQuantInfo *quantInfo,
+ int numberOfBands, /* Number of bands per window */
+ enum WINDOW_TYPE blockType, /* block type */
+ int* sfbOffsetTable, /* Scalefactor band offset table */
+ double* spec, /* Spectral data array */
+ int use_tns)
{
int numberOfWindows,windowSize;
int startBand,stopBand,order; /* Bands over which to apply TNS */
@@ -128,6 +129,7 @@
int w, error;
int startIndex,length;
double gain;
+ TNS_INFO *tnsInfo = &quantInfo->tnsInfo;
switch( blockType ) {
case ONLY_SHORT_WINDOW :
@@ -155,8 +157,8 @@
/* Make sure that start and stop bands < maxSfb */
/* Make sure that start and stop bands >= 0 */
- startBand = min(startBand,maxSfb);
- stopBand = min(stopBand,maxSfb);
+ startBand = min(startBand,quantInfo->max_sfb);
+ stopBand = min(stopBand,quantInfo->max_sfb);
startBand = max(startBand,0);
stopBand = max(stopBand,0);
--- a/tns.h
+++ b/tns.h
@@ -21,8 +21,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.7 $
- $Date: 2000/10/06 14:47:27 $ (check in)
+ $Revision: 1.8 $
+ $Date: 2000/11/01 14:05:32 $ (check in)
$Author: menno $
*************************************************************************/
@@ -104,7 +104,7 @@
void TnsFilter(int length,double* spec,TNS_FILTER_DATA* filter);
int TnsInvFilter(int length,double* spec,TNS_FILTER_DATA* filter);
void TnsInit(long samplingRate,enum AAC_PROFILE profile,TNS_INFO* tnsInfo);
-int TnsEncode(int numberOfBands,int maxSfb,enum WINDOW_TYPE blockType,int* sfbOffsetTable,double* spec,TNS_INFO* tnsInfo,int use_tns);
+int TnsEncode(struct _AACQuantInfo *quantInfo,int numberOfBands,enum WINDOW_TYPE blockType,int* sfbOffsetTable,double* spec,int use_tns);
#endif