ref: 7d9f87f6814836eab130bfe340828ec84d16f329
parent: bb0e703f2bd279b28c4d9ee6b2a21eacefbf945f
author: lenox <lenox>
date: Mon Feb 28 11:47:07 EST 2000
improved readability of the code
--- a/ms.c
+++ b/ms.c
@@ -37,343 +37,338 @@
#include "is.h"
void MSPreprocess(double p_ratio_long[][MAX_SCFAC_BANDS],
- 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, int use_is,
- int numberOfChannels
- )
+ 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, int use_is,
+ int numberOfChannels
+ )
{
- int chanNum;
- int sfbNum;
+ int chanNum;
+ int sfbNum;
-// static int block = 0;
- int used = 0, notused = 0;
- int realyused = 0;
+// static int block = 0;
+ int used = 0, notused = 0;
+ int realyused = 0;
- /* Look for channel_pair_elements */
- for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
- int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
- channelInfo[leftChan].ms_info.is_present=0;
- channelInfo[leftChan].common_window = 0;
+ /* Look for channel_pair_elements */
+ for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ if (channelInfo[chanNum].present) {
+ if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ int leftChan=chanNum;
+ int rightChan=channelInfo[chanNum].paired_ch;
+ channelInfo[leftChan].ms_info.is_present=0;
+ channelInfo[leftChan].common_window = 0;
- /* Perform MS if block_types are the same */
- if ((block_type[leftChan]==block_type[rightChan])&&(use_ms==0)) {
+ /* Perform MS if block_types are the same */
+ if ((block_type[leftChan]==block_type[rightChan])&&(use_ms==0)) {
+ int numGroups;
+ int groupIndex = 0;
+ int maxSfb, isBand;
+ int g,b,j;
+ int use_ms_short;
+ MS_Info *msInfo;
- int numGroups;
- int groupIndex = 0;
- int maxSfb, isBand;
- int g,b,j;
- int use_ms_short;
- MS_Info *msInfo;
+ numGroups = quantInfo[leftChan].num_window_groups;
+ maxSfb = quantInfo[leftChan].max_sfb;
- numGroups = quantInfo[leftChan].num_window_groups;
- maxSfb = quantInfo[leftChan].max_sfb;
+ /* Determine which bands should be enabled */
+ msInfo = &(channelInfo[leftChan].ms_info);
+ if (use_is) {
+ isBand = (block_type[rightChan]==ONLY_SHORT_WINDOW) ? IS_MIN_BAND_S : IS_MIN_BAND_L;
+ isBand = (isBand>maxSfb) ? maxSfb : isBand;
+ }
+ else {
+ isBand = maxSfb;
+ }
- /* Determine which bands should be enabled */
- msInfo = &(channelInfo[leftChan].ms_info);
- if (use_is) {
- isBand = (block_type[rightChan]==ONLY_SHORT_WINDOW) ? IS_MIN_BAND_S : IS_MIN_BAND_L;
- isBand = (isBand>maxSfb) ? maxSfb : isBand;
- } else {
- isBand = maxSfb;
- }
+ for (g=0;g<numGroups;g++) {
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ use_ms_short = 1;
+ b = g*maxSfb+sfbNum;
- for (g=0;g<numGroups;g++) {
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- use_ms_short = 1;
- b = g*maxSfb+sfbNum;
+ if (block_type[leftChan] == ONLY_SHORT_WINDOW) {
+ for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
+ use_ms_short = min(use_ms_short, p_chpo_short[1][j].use_ms[sfbNum]);
+ }
+ if (sfbNum < isBand) {
+ msInfo->ms_used[b] = use_ms_short;
+ }
+ else {
+ msInfo->ms_used[b] = 0;
+ use_ms_short = 0;
+ }
- if (block_type[leftChan] == ONLY_SHORT_WINDOW) {
+ if (msInfo->ms_used[b]) {
+ realyused = 1;
+ used++;
+ for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
+ p_ratio_short[0][(g*maxSfb)+sfbNum] = p_chpo_short[2][j].p_ratio[sfbNum];
+ p_ratio_short[1][(g*maxSfb)+sfbNum] = p_chpo_short[3][j].p_ratio[sfbNum];
+ p_chpo_short[1][j].use_ms[sfbNum] = use_ms_short;
+ }
+ }
+ else {
+ notused++;
+ for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
+ p_ratio_short[0][(g*maxSfb)+sfbNum] = p_chpo_short[0][j].p_ratio[sfbNum];
+ p_ratio_short[1][(g*maxSfb)+sfbNum] = p_chpo_short[1][j].p_ratio[sfbNum];
+ p_chpo_short[1][j].use_ms[sfbNum] = use_ms_short;
+ }
+ }
+ }
+ else {
+ if (sfbNum < isBand) {
+ msInfo->ms_used[b] = p_chpo_long[1].use_ms[sfbNum];
+ }
+ else {
+ msInfo->ms_used[b] = 0;
+ p_chpo_long[1].use_ms[sfbNum] = 0;
+ }
+ if (msInfo->ms_used[b]) {
+ realyused = 1;
+ used++;
+ p_ratio_long[0][sfbNum] = p_chpo_long[2].p_ratio[sfbNum];
+ p_ratio_long[1][sfbNum] = p_chpo_long[3].p_ratio[sfbNum];
+ }
+ else {
+ notused++;
+ p_ratio_long[0][sfbNum] = p_chpo_long[0].p_ratio[sfbNum];
+ p_ratio_long[1][sfbNum] = p_chpo_long[1].p_ratio[sfbNum];
+ }
+ }
+ }
+ groupIndex+=quantInfo[leftChan].window_group_length[g];
+ }
- for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
- use_ms_short = min(use_ms_short, p_chpo_short[1][j].use_ms[sfbNum]);
- }
- if (sfbNum < isBand) {
- msInfo->ms_used[b] = use_ms_short;
- } else {
- msInfo->ms_used[b] = 0;
- use_ms_short = 0;
- }
+ if (realyused) {
+ channelInfo[leftChan].common_window = 1; /* Use common window */
+ channelInfo[leftChan].ms_info.is_present=1;
+ }
+ }
+ else if ((block_type[leftChan]==block_type[rightChan])&&(use_ms == 1)) {
+ int chan;
+ int numGroups;
+ int groupIndex;
+ int maxSfb;
+ int g,b,j;
+ MS_Info *msInfo;
- if (msInfo->ms_used[b]) {
- realyused = 1;
- used++;
- for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
- p_ratio_short[0][(g*maxSfb)+sfbNum] = p_chpo_short[2][j].p_ratio[sfbNum];
- p_ratio_short[1][(g*maxSfb)+sfbNum] = p_chpo_short[3][j].p_ratio[sfbNum];
- p_chpo_short[1][j].use_ms[sfbNum] = use_ms_short;
- }
- } else {
- notused++;
- for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
- p_ratio_short[0][(g*maxSfb)+sfbNum] = p_chpo_short[0][j].p_ratio[sfbNum];
- p_ratio_short[1][(g*maxSfb)+sfbNum] = p_chpo_short[1][j].p_ratio[sfbNum];
- p_chpo_short[1][j].use_ms[sfbNum] = use_ms_short;
- }
- }
+ channelInfo[0].ms_info.is_present = 1;
+ channelInfo[0].common_window = 1;
- } else {
+ for (chan = 0; chan < 2; chan++) {
+ maxSfb = quantInfo[chan].max_sfb;
- if (sfbNum < isBand) {
- msInfo->ms_used[b] = p_chpo_long[1].use_ms[sfbNum];
- } else {
- msInfo->ms_used[b] = 0;
- p_chpo_long[1].use_ms[sfbNum] = 0;
- }
- if (msInfo->ms_used[b]) {
- realyused = 1;
- used++;
- p_ratio_long[0][sfbNum] = p_chpo_long[2].p_ratio[sfbNum];
- p_ratio_long[1][sfbNum] = p_chpo_long[3].p_ratio[sfbNum];
- } else {
- notused++;
- p_ratio_long[0][sfbNum] = p_chpo_long[0].p_ratio[sfbNum];
- p_ratio_long[1][sfbNum] = p_chpo_long[1].p_ratio[sfbNum];
- }
+ /* Determine which bands should be enabled */
+ msInfo = &(channelInfo[leftChan].ms_info);
+ numGroups = quantInfo[chan].num_window_groups;
- }
- }
- groupIndex+=quantInfo[leftChan].window_group_length[g];
- }
+ for (g=0;g<numGroups;g++) {
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ b = g*maxSfb+sfbNum;
+ groupIndex = 0;
- if (realyused) {
- channelInfo[leftChan].common_window = 1; /* Use common window */
- channelInfo[leftChan].ms_info.is_present=1;
- }
- } else if ((block_type[leftChan]==block_type[rightChan])&&(use_ms == 1)) {
- int chan;
- int numGroups;
- int groupIndex;
- int maxSfb;
- int g,b,j;
- MS_Info *msInfo;
+ if (block_type[chan] == ONLY_SHORT_WINDOW) {
+ msInfo->ms_used[b] = 1;
+ for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
+ p_ratio_short[chan][(g*maxSfb)+sfbNum] = p_chpo_short[chan][j].p_ratio[sfbNum];
+ p_chpo_short[1][j].use_ms[sfbNum] = 1;
+ }
+ }
+ else {
+ msInfo->ms_used[b] = 1;
+ p_ratio_long[chan][sfbNum] = p_chpo_long[chan].p_ratio[sfbNum];
+ p_chpo_long[1].use_ms[sfbNum] = 1;
+ }
+ }
+// groupIndex+=quantInfo[chan].window_group_length[g];
+ }
+ }
+ }
+ else {
+ int chan;
+ int numGroups;
+ int groupIndex;
+ int maxSfb;
+ int g,b,j;
+ MS_Info *msInfo;
- channelInfo[0].ms_info.is_present = 1;
- channelInfo[0].common_window = 1;
+ for (chan = 0; chan < 2; chan++) {
+ maxSfb = quantInfo[chan].max_sfb;
- for (chan = 0; chan < 2; chan++) {
- maxSfb = quantInfo[chan].max_sfb;
+ /* Determine which bands should be enabled */
+ msInfo = &(channelInfo[leftChan].ms_info);
+ numGroups = quantInfo[chan].num_window_groups;
- /* Determine which bands should be enabled */
- msInfo = &(channelInfo[leftChan].ms_info);
- numGroups = quantInfo[chan].num_window_groups;
+ for (g=0;g<numGroups;g++) {
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ b = g*maxSfb+sfbNum;
+ groupIndex = 0;
- for (g=0;g<numGroups;g++) {
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- b = g*maxSfb+sfbNum;
- groupIndex = 0;
+ if (block_type[chan] == ONLY_SHORT_WINDOW) {
+ msInfo->ms_used[b] = 0;
+ for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
+ p_ratio_short[chan][(g*maxSfb)+sfbNum] = p_chpo_short[chan][j].p_ratio[sfbNum];
+ p_chpo_short[1][j].use_ms[sfbNum] = 0;
+ }
+ }
+ else {
+ msInfo->ms_used[b] = 0;
+ p_ratio_long[chan][sfbNum] = p_chpo_long[chan].p_ratio[sfbNum];
+ p_chpo_long[1].use_ms[sfbNum] = 0;
+ }
+ }
+// groupIndex+=quantInfo[chan].window_group_length[g];
+ }
+ }
+ }
+ }
+ }
+ }
- if (block_type[chan] == ONLY_SHORT_WINDOW) {
-
- msInfo->ms_used[b] = 1;
- for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
- p_ratio_short[chan][(g*maxSfb)+sfbNum] = p_chpo_short[chan][j].p_ratio[sfbNum];
- p_chpo_short[1][j].use_ms[sfbNum] = 1;
- }
-
- } else {
-
- msInfo->ms_used[b] = 1;
- p_ratio_long[chan][sfbNum] = p_chpo_long[chan].p_ratio[sfbNum];
- p_chpo_long[1].use_ms[sfbNum] = 1;
-
- }
- }
-// groupIndex+=quantInfo[chan].window_group_length[g];
- }
- }
- } else {
- int chan;
- int numGroups;
- int groupIndex;
- int maxSfb;
- int g,b,j;
- MS_Info *msInfo;
-
- for (chan = 0; chan < 2; chan++) {
- maxSfb = quantInfo[chan].max_sfb;
-
- /* Determine which bands should be enabled */
- msInfo = &(channelInfo[leftChan].ms_info);
- numGroups = quantInfo[chan].num_window_groups;
-
- for (g=0;g<numGroups;g++) {
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- b = g*maxSfb+sfbNum;
- groupIndex = 0;
-
- if (block_type[chan] == ONLY_SHORT_WINDOW) {
-
- msInfo->ms_used[b] = 0;
- for (j = groupIndex; j < quantInfo[chan].window_group_length[g]+groupIndex; j++) {
- p_ratio_short[chan][(g*maxSfb)+sfbNum] = p_chpo_short[chan][j].p_ratio[sfbNum];
- p_chpo_short[1][j].use_ms[sfbNum] = 0;
- }
-
- } else {
-
- msInfo->ms_used[b] = 0;
- p_ratio_long[chan][sfbNum] = p_chpo_long[chan].p_ratio[sfbNum];
- p_chpo_long[1].use_ms[sfbNum] = 0;
-
- }
- }
-// groupIndex+=quantInfo[chan].window_group_length[g];
- }
- }
- }
- }
- }
- }
-
// printf("%d used: %d, notused: %d\n", block++, used, notused);
}
void MSEnergy(double *spectral_line_vector[MAX_TIME_CHANNELS],
- double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
- 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,
- int numberOfChannels
- )
+ double energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+ 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,
+ int numberOfChannels
+ )
{
- int chanNum, numWindows, bandNumber;
- int windowLength, w, j;
- int *p_use_ms;
+ int chanNum, numWindows, bandNumber;
+ int windowLength, w, j;
+ int *p_use_ms;
- for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- double dtmp;
+ for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ double dtmp;
- /* Compute energy in each scalefactor band of each window */
- numWindows = (block_type[chanNum]==ONLY_SHORT_WINDOW) ? 8 : 1;
- windowLength = 1024/8;
- bandNumber=0;
- for (w=0;w<numWindows;w++) {
- int offset=0;
- int sfb;
+ /* Compute energy in each scalefactor band of each window */
+ numWindows = (block_type[chanNum]==ONLY_SHORT_WINDOW) ? 8 : 1;
+ windowLength = 1024/8;
+ bandNumber=0;
+ for (w=0;w<numWindows;w++) {
+ int offset=0;
+ int sfb;
- if (block_type[chanNum] == ONLY_SHORT_WINDOW) {
- p_use_ms = p_chpo_short[1][w].use_ms;
- } else {
- p_use_ms = p_chpo_long[1].use_ms;
- }
+ if (block_type[chanNum] == ONLY_SHORT_WINDOW) {
+ p_use_ms = p_chpo_short[1][w].use_ms;
+ }
+ else {
+ p_use_ms = p_chpo_long[1].use_ms;
+ }
- j = w*windowLength;
+ j = w*windowLength;
- /* Only compute energy up to max_sfb */
- for(sfb=0; sfb< quantInfo[chanNum].max_sfb; sfb++ ) {
- /* calculate scale factor band energy */
- int width,i;
- energy[chanNum][bandNumber] = 0.0;
- width=sfb_width_table[chanNum][sfb];
- for(i=offset; i<(offset+width); i++ ) {
- if (((p_use_ms[sfb]||(use_ms==1)) && (chanNum == 0))&&(use_ms!=-1))
- dtmp = (spectral_line_vector[0][j]+spectral_line_vector[1][j])*0.5;
- else if (((p_use_ms[sfb]||(use_ms==1)) && (chanNum == 1))&&(use_ms!=-1))
- dtmp = (spectral_line_vector[0][j]-spectral_line_vector[1][j])*0.5;
- else
- dtmp = spectral_line_vector[chanNum][j];
- j++;
- energy[chanNum][bandNumber] += dtmp*dtmp;
- }
- energy[chanNum][bandNumber] = energy[chanNum][bandNumber] / width;
- bandNumber++;
- offset+=width;
- }
- }
- } /* for (chanNum... */
+ /* Only compute energy up to max_sfb */
+ for(sfb=0; sfb< quantInfo[chanNum].max_sfb; sfb++ ) {
+ /* calculate scale factor band energy */
+ int width,i;
+ energy[chanNum][bandNumber] = 0.0;
+ width=sfb_width_table[chanNum][sfb];
+ for(i=offset; i<(offset+width); i++ ) {
+ if (((p_use_ms[sfb]||(use_ms==1)) && (chanNum == 0))&&(use_ms!=-1))
+ dtmp = (spectral_line_vector[0][j]+spectral_line_vector[1][j])*0.5;
+ else if (((p_use_ms[sfb]||(use_ms==1)) && (chanNum == 1))&&(use_ms!=-1))
+ dtmp = (spectral_line_vector[0][j]-spectral_line_vector[1][j])*0.5;
+ else
+ dtmp = spectral_line_vector[chanNum][j];
+ j++;
+ energy[chanNum][bandNumber] += dtmp*dtmp;
+ }
+ energy[chanNum][bandNumber] = energy[chanNum][bandNumber] / width;
+ bandNumber++;
+ offset+=width;
+ }
+ }
+ } /* for (chanNum... */
}
/* 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 */
- int numberOfChannels) { /* Number of channels */
+ 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 */
+{
+ int chanNum;
+ int sfbNum;
+ int lineNum;
+ double sum,diff;
- int chanNum;
- int sfbNum;
- int lineNum;
- double sum,diff;
+ /* Look for channel_pair_elements */
+ for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ if (channelInfo[chanNum].present) {
+ if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ int leftChan=chanNum;
+ int rightChan=channelInfo[chanNum].paired_ch;
+ channelInfo[leftChan].ms_info.is_present=0;
- /* Look for channel_pair_elements */
- for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
- int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
- channelInfo[leftChan].ms_info.is_present=0;
+ /* Perform MS if block_types are the same */
+ if (block_type[leftChan]==block_type[rightChan]) {
+ int numGroups;
+ int maxSfb;
+ int g,b,w,line_offset;
+ int startWindow,stopWindow;
+ IS_Info *isInfo;
+ MS_Info *msInfo;
- /* Perform MS if block_types are the same */
- if (block_type[leftChan]==block_type[rightChan]) {
-
- int numGroups;
- int maxSfb;
- int g,b,w,line_offset;
- int startWindow,stopWindow;
- IS_Info *isInfo;
- MS_Info *msInfo;
-
- channelInfo[leftChan].common_window = 1; /* Use common window */
- channelInfo[leftChan].ms_info.is_present=1;
-// w = 0;
+ channelInfo[leftChan].common_window = 1; /* Use common window */
+ channelInfo[leftChan].ms_info.is_present=1;
+// w = 0;
- numGroups = quantInfo[leftChan].num_window_groups;
- maxSfb = quantInfo[leftChan].max_sfb;
+ numGroups = quantInfo[leftChan].num_window_groups;
+ maxSfb = quantInfo[leftChan].max_sfb;
- /* Determine which bands should be enabled */
- /* Right now, simply enable bands which do not use intensity stereo */
- isInfo = &(channelInfo[rightChan].is_info);
- msInfo = &(channelInfo[leftChan].ms_info);
- for (g=0;g<numGroups;g++) {
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- b = g*maxSfb+sfbNum;
- msInfo->ms_used[b] = ( (!isInfo->is_used[b])||(!isInfo->is_present) );
- }
- }
+ /* Determine which bands should be enabled */
+ /* Right now, simply enable bands which do not use intensity stereo */
+ isInfo = &(channelInfo[rightChan].is_info);
+ msInfo = &(channelInfo[leftChan].ms_info);
+ for (g=0;g<numGroups;g++) {
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ b = g*maxSfb+sfbNum;
+ msInfo->ms_used[b] = ( (!isInfo->is_used[b])||(!isInfo->is_present) );
+ }
+ }
- /* Perform sum and differencing on bands in which ms_used flag */
- /* has been set. */
-// line_offset=0;
- startWindow = 0;
- for (g=0;g<numGroups;g++) {
- int numWindows = quantInfo[leftChan].window_group_length[g];
- stopWindow = startWindow + numWindows;
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- /* Enable MS mask */
- if (msInfo->ms_used[g*maxSfb+sfbNum]) {
- for (w=startWindow;w<stopWindow;w++) {
- for (lineNum=sfb_offset_table[leftChan][sfbNum];
- lineNum<sfb_offset_table[leftChan][sfbNum+1];
- lineNum++) {
- line_offset = w*BLOCK_LEN_SHORT;
- sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
- diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
- spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
- spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
- } /* for (lineNum... */
- } /* for (w=... */
- }
- } /* for (sfbNum... */
- startWindow = stopWindow;
- } /* for (g... */
- } /* if (block_type... */
- }
- } /* if (channelInfo[chanNum].present */
- } /* for (chanNum... */
+ /* Perform sum and differencing on bands in which ms_used flag */
+ /* has been set. */
+// line_offset=0;
+ startWindow = 0;
+ for (g=0;g<numGroups;g++) {
+ int numWindows = quantInfo[leftChan].window_group_length[g];
+ stopWindow = startWindow + numWindows;
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ /* Enable MS mask */
+ if (msInfo->ms_used[g*maxSfb+sfbNum]) {
+ for (w=startWindow;w<stopWindow;w++) {
+ for (lineNum=sfb_offset_table[leftChan][sfbNum]; lineNum<sfb_offset_table[leftChan][sfbNum+1]; lineNum++) {
+ line_offset = w*BLOCK_LEN_SHORT;
+ sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
+ diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
+ spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
+ spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
+ } /* for (lineNum... */
+ } /* for (w=... */
+ }
+ } /* for (sfbNum... */
+ startWindow = stopWindow;
+ } /* for (g... */
+ } /* if (block_type... */
+ }
+ } /* if (channelInfo[chanNum].present */
+ } /* for (chanNum... */
}
/* Perform MS encoding. Spectrum is non-interleaved. */
@@ -386,72 +381,68 @@
// ,int numberOfChannels /* Number of channels */
)
{
- int chanNum;
- int sfbNum;
- int lineNum;
- double sum,diff;
+ int chanNum;
+ int sfbNum;
+ int lineNum;
+ double sum,diff;
- /* Look for channel_pair_elements */
-// for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- chanNum = 0;
- if (channelInfo[0].ms_info.is_present) {
- int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
+ /* Look for channel_pair_elements */
+//for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ chanNum = 0;
+ if (channelInfo[0].ms_info.is_present) {
+ int leftChan=chanNum;
+ int rightChan=channelInfo[chanNum].paired_ch;
+ int numGroups;
+ int maxSfb;
+ int g,b,w,line_offset;
+ int startWindow,stopWindow;
+ IS_Info *isInfo;
+ MS_Info *msInfo;
+ channelInfo[leftChan].common_window = 1; /* Use common window */
+ channelInfo[leftChan].ms_info.is_present=1;
- int numGroups;
- int maxSfb;
- int g,b,w,line_offset;
- int startWindow,stopWindow;
- IS_Info *isInfo;
- MS_Info *msInfo;
+ numGroups = quantInfo[leftChan].num_window_groups;
+ maxSfb = quantInfo[leftChan].max_sfb;
+// w=0;
- channelInfo[leftChan].common_window = 1; /* Use common window */
- channelInfo[leftChan].ms_info.is_present=1;
-
- numGroups = quantInfo[leftChan].num_window_groups;
- maxSfb = quantInfo[leftChan].max_sfb;
-// w=0;
-
- /* Determine which bands should be enabled */
- /* Right now, simply enable bands which do not use intensity stereo */
- isInfo = &(channelInfo[rightChan].is_info);
- msInfo = &(channelInfo[leftChan].ms_info);
+ /* Determine which bands should be enabled */
+ /* Right now, simply enable bands which do not use intensity stereo */
+ isInfo = &(channelInfo[rightChan].is_info);
+ msInfo = &(channelInfo[leftChan].ms_info);
#if 1
- for (g=0;g<numGroups;g++) {
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- b = g*maxSfb+sfbNum;
- msInfo->ms_used[b] = (((!isInfo->is_used[b])||(!isInfo->is_present))&&msInfo->ms_used[b]);
- }
- }
+ for (g=0;g<numGroups;g++) {
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ b = g*maxSfb+sfbNum;
+ msInfo->ms_used[b] = (((!isInfo->is_used[b])||(!isInfo->is_present))&&msInfo->ms_used[b]);
+ }
+ }
#endif
- /* Perform sum and differencing on bands in which ms_used flag */
- /* has been set. */
-// line_offset=0;
- startWindow = 0;
- for (g=0;g<numGroups;g++) {
- int numWindows = quantInfo[leftChan].window_group_length[g];
- stopWindow = startWindow + numWindows;
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- /* Enable MS mask */
- if (msInfo->ms_used[g*maxSfb+sfbNum]) {
- for (w=startWindow;w<stopWindow;w++) {
- for (lineNum=sfb_offset_table[leftChan][sfbNum];
- lineNum<sfb_offset_table[leftChan][sfbNum+1];
- lineNum++) {
- line_offset = w*BLOCK_LEN_SHORT;
- sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
- diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
- spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
- spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
- } /* for (lineNum... */
- } /* for (w=... */
- }
- } /* for (sfbNum... */
- startWindow = stopWindow;
- } /* for (g... */
- } /* if (block_type... */
-// } /* for (chanNum... */
+ /* Perform sum and differencing on bands in which ms_used flag */
+ /* has been set. */
+// line_offset=0;
+ startWindow = 0;
+ for (g=0;g<numGroups;g++) {
+ int numWindows = quantInfo[leftChan].window_group_length[g];
+ stopWindow = startWindow + numWindows;
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ /* Enable MS mask */
+ if (msInfo->ms_used[g*maxSfb+sfbNum]) {
+ for (w=startWindow;w<stopWindow;w++) {
+ for (lineNum=sfb_offset_table[leftChan][sfbNum];lineNum<sfb_offset_table[leftChan][sfbNum+1];lineNum++) {
+ line_offset = w*BLOCK_LEN_SHORT;
+ sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
+ diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
+ spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
+ spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
+ } /* for (lineNum... */
+ } /* for (w=... */
+ }
+ } /* for (sfbNum... */
+ startWindow = stopWindow;
+ } /* for (g... */
+ } /* if (block_type... */
+//} /* for (chanNum... */
}
@@ -462,55 +453,53 @@
AACQuantInfo* quantInfo, /* Quant info */
int numberOfChannels) /* Number of channels */
{
- int chanNum;
- int sfbNum;
- int lineNum;
- double sum,diff;
+ int chanNum;
+ int sfbNum;
+ int lineNum;
+ double sum,diff;
- /* Look for channel_pair_elements */
- for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
- int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
+ /* Look for channel_pair_elements */
+ for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ if (channelInfo[chanNum].present) {
+ if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ int leftChan=chanNum;
+ int rightChan=channelInfo[chanNum].paired_ch;
- MS_Info *msInfo;
- msInfo = &(channelInfo[leftChan].ms_info);
- if (msInfo->is_present) {
- int numGroups = quantInfo[leftChan].num_window_groups;
- int maxSfb = quantInfo[leftChan].max_sfb;
- int g,w,line_offset;
- int startWindow,stopWindow;
-// w=0;
+ MS_Info *msInfo;
+ msInfo = &(channelInfo[leftChan].ms_info);
+ if (msInfo->is_present) {
+ int numGroups = quantInfo[leftChan].num_window_groups;
+ int maxSfb = quantInfo[leftChan].max_sfb;
+ int g,w,line_offset;
+ int startWindow,stopWindow;
+// w=0;
- /* Perform sum and differencing on bands in which ms_used flag */
- /* has been set. */
+ /* Perform sum and differencing on bands in which ms_used flag */
+ /* has been set. */
// line_offset=0;
- startWindow = 0;
- for (g=0;g<numGroups;g++) {
- int numWindows = quantInfo[leftChan].window_group_length[g];
- stopWindow = startWindow + numWindows;
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- /* Enable MS mask */
- if ((msInfo->ms_used[g*maxSfb+sfbNum]) || (msInfo->is_present==2)) {
- for (w=startWindow;w<stopWindow;w++) {
- line_offset = w*BLOCK_LEN_SHORT;
- for (lineNum=sfb_offset_table[leftChan][sfbNum];
- lineNum<sfb_offset_table[leftChan][sfbNum+1];
- lineNum++) {
- sum=spectrum[leftChan][line_offset+lineNum];
- diff=spectrum[rightChan][line_offset+lineNum];
- spectrum[leftChan][line_offset+lineNum] = (sum+diff);
- spectrum[rightChan][line_offset+lineNum] = (sum-diff);
- } /* for (lineNum... */
- } /* for (w=start... */
- } /* if (msInfo... */
- } /* for (sfbNum... */
- startWindow = stopWindow;
- } /* for (g... */
- } /* if (ms_info.is_present... */
- } /* if (channelInfo... */
- } /* if (channelInfo[chanNum].present */
- } /* for (chanNum... */
+ startWindow = 0;
+ for (g=0;g<numGroups;g++) {
+ int numWindows = quantInfo[leftChan].window_group_length[g];
+ stopWindow = startWindow + numWindows;
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ /* Enable MS mask */
+ if ((msInfo->ms_used[g*maxSfb+sfbNum]) || (msInfo->is_present==2)) {
+ for (w=startWindow;w<stopWindow;w++) {
+ line_offset = w*BLOCK_LEN_SHORT;
+ for (lineNum=sfb_offset_table[leftChan][sfbNum];lineNum<sfb_offset_table[leftChan][sfbNum+1];lineNum++) {
+ sum=spectrum[leftChan][line_offset+lineNum];
+ diff=spectrum[rightChan][line_offset+lineNum];
+ spectrum[leftChan][line_offset+lineNum] = (sum+diff);
+ spectrum[rightChan][line_offset+lineNum] = (sum-diff);
+ } /* for (lineNum... */
+ } /* for (w=start... */
+ } /* if (msInfo... */
+ } /* for (sfbNum... */
+ startWindow = stopWindow;
+ } /* for (g... */
+ } /* if (ms_info.is_present... */
+ } /* if (channelInfo... */
+ } /* if (channelInfo[chanNum].present */
+ } /* for (chanNum... */
}
--- a/transfo.c
+++ b/transfo.c
@@ -23,189 +23,187 @@
*******************************************************************************/
void MDCT (double *data, int N)
{
- double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
- double freq = 2.0 * M_PI / N;
- double fac,cosfreq8,sinfreq8;
- int i, n;
- int b = N >> 1;
- int N4 = N >> 2;
- int N2 = N >> 1;
- int a = N - b;
- int a2 = a >> 1;
- int a4 = a >> 2;
- int b4 = b >> 2;
- int unscambled;
+ double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
+ double freq = 2.0 * M_PI / N;
+ double fac,cosfreq8,sinfreq8;
+ int i, n;
+ int b = N >> 1;
+ int N4 = N >> 2;
+ int N2 = N >> 1;
+ int a = N - b;
+ int a2 = a >> 1;
+ int a4 = a >> 2;
+ int b4 = b >> 2;
+ int unscambled;
- /* Choosing to allocate 2/N factor to Inverse Xform! */
- fac = 2.; /* 2 from MDCT inverse to forward */
+ /* Choosing to allocate 2/N factor to Inverse Xform! */
+ fac = 2.; /* 2 from MDCT inverse to forward */
- /* prepare for recurrence relation in pre-twiddle */
- cfreq = cos (freq);
- sfreq = sin (freq);
- cosfreq8 = cos (freq * 0.125);
- sinfreq8 = sin (freq * 0.125);
- c = cosfreq8;
- s = sinfreq8;
+ /* prepare for recurrence relation in pre-twiddle */
+ cfreq = cos (freq);
+ sfreq = sin (freq);
+ cosfreq8 = cos (freq * 0.125);
+ sinfreq8 = sin (freq * 0.125);
+ c = cosfreq8;
+ s = sinfreq8;
- for (i = 0; i < N4; i++) {
- /* calculate real and imaginary parts of g(n) or G(p) */
+ for (i = 0; i < N4; i++) {
+ /* calculate real and imaginary parts of g(n) or G(p) */
+ n = N / 2 - 1 - 2 * i;
- n = N / 2 - 1 - 2 * i;
- if (i < b4) {
- tempr = data [a2 + n] + data [N + a2 - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */
- } else {
- tempr = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */
- }
- n = 2 * i;
- if (i < a4) {
- tempi = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n=2i */
- } else {
- tempi = data [a2 + n] + data [N + a2 - 1 - n]; /* use second form of e(n) for n=2i*/
- }
+ if (i < b4)
+ tempr = data [a2 + n] + data [N + a2 - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */
+ else
+ tempr = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */
- /* calculate pre-twiddled FFT input */
- FFTarray [i].re = tempr * c + tempi * s;
- FFTarray [i].im = tempi * c - tempr * s;
+ n = 2 * i;
+ if (i < a4)
+ tempi = data [a2 + n] - data [a2 - 1 - n]; /* use first form of e(n) for n=2i */
+ else
+ tempi = data [a2 + n] + data [N + a2 - 1 - n]; /* use second form of e(n) for n=2i*/
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
+ /* calculate pre-twiddled FFT input */
+ FFTarray [i].re = tempr * c + tempi * s;
+ FFTarray [i].im = tempi * c - tempr * s;
- /* Perform in-place complex FFT of length N/4 */
- switch (N) {
- case 256: pfftw_64(FFTarray);
- break;
- case 2048:pfftw_512(FFTarray);
- }
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
- /* prepare for recurrence relations in post-twiddle */
- c = cosfreq8;
- s = sinfreq8;
+ /* Perform in-place complex FFT of length N/4 */
+ switch (N) {
+ case 256:
+ pfftw_64(FFTarray);
+ break;
+ case 2048:
+ pfftw_512(FFTarray);
+ }
- /* post-twiddle FFT output and then get output data */
- for (i = 0; i < N4; i++) {
+ /* prepare for recurrence relations in post-twiddle */
+ c = cosfreq8;
+ s = sinfreq8;
- /* get post-twiddled FFT output */
- /* Note: fac allocates 4/N factor from IFFT to forward and inverse */
- switch (N) {
- case 256:
- unscambled = unscambled64[i];
- break;
- case 2048:
- unscambled = unscambled512[i];
- }
- tempr = fac * (FFTarray [unscambled].re * c + FFTarray [unscambled].im * s);
- tempi = fac * (FFTarray [unscambled].im * c - FFTarray [unscambled].re * s);
+ /* post-twiddle FFT output and then get output data */
+ for (i = 0; i < N4; i++) {
+ /* get post-twiddled FFT output */
+ /* Note: fac allocates 4/N factor from IFFT to forward and inverse */
+ switch (N) {
+ case 256:
+ unscambled = unscambled64[i];
+ break;
+ case 2048:
+ unscambled = unscambled512[i];
+ }
+ tempr = fac * (FFTarray [unscambled].re * c + FFTarray [unscambled].im * s);
+ tempi = fac * (FFTarray [unscambled].im * c - FFTarray [unscambled].re * s);
+ /* fill in output values */
+ data [2 * i] = -tempr; /* first half even */
+ data [N2 - 1 - 2 * i] = tempi; /* first half odd */
+ data [N2 + 2 * i] = -tempi; /* second half even */
+ data [N - 1 - 2 * i] = tempr; /* second half odd */
- /* fill in output values */
- data [2 * i] = -tempr; /* first half even */
- data [N2 - 1 - 2 * i] = tempi; /* first half odd */
- data [N2 + 2 * i] = -tempi; /* second half even */
- data [N - 1 - 2 * i] = tempr; /* second half odd */
-
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
}
void IMDCT(double *data, int N)
{
- double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
- double freq = 2.0 * M_PI / N;
- double fac, cosfreq8, sinfreq8;
- int i;
- int Nd2 = N >> 1;
- int Nd4 = N >> 2;
- int Nd8 = N >> 3;
- int unscambled;
+ double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
+ double freq = 2.0 * M_PI / N;
+ double fac, cosfreq8, sinfreq8;
+ int i;
+ int Nd2 = N >> 1;
+ int Nd4 = N >> 2;
+ int Nd8 = N >> 3;
+ int unscambled;
- /* Choosing to allocate 2/N factor to Inverse Xform! */
- fac = 2. / N; /* remaining 2/N from 4/N IFFT factor */
+ /* Choosing to allocate 2/N factor to Inverse Xform! */
+ fac = 2. / N; /* remaining 2/N from 4/N IFFT factor */
- /* prepare for recurrence relation in pre-twiddle */
- cfreq = cos (freq);
- sfreq = sin (freq);
- cosfreq8 = cos (freq * 0.125);
- sinfreq8 = sin (freq * 0.125);
- c = cosfreq8;
- s = sinfreq8;
+ /* prepare for recurrence relation in pre-twiddle */
+ cfreq = cos (freq);
+ sfreq = sin (freq);
+ cosfreq8 = cos (freq * 0.125);
+ sinfreq8 = sin (freq * 0.125);
+ c = cosfreq8;
+ s = sinfreq8;
- for (i = 0; i < Nd4; i++) {
+ for (i = 0; i < Nd4; i++) {
+ /* calculate real and imaginary parts of g(n) or G(p) */
+ tempr = -data [2 * i];
+ tempi = data [Nd2 - 1 - 2 * i];
- /* calculate real and imaginary parts of g(n) or G(p) */
- tempr = -data [2 * i];
- tempi = data [Nd2 - 1 - 2 * i];
+ /* calculate pre-twiddled FFT input */
+ switch (N) {
+ case 256:
+ unscambled = unscambled64[i];
+ break;
+ case 2048:
+ unscambled = unscambled512[i];
+ }
- /* calculate pre-twiddled FFT input */
- switch (N) {
- case 256:
- unscambled = unscambled64[i];
- break;
- case 2048:
- unscambled = unscambled512[i];
- }
- FFTarray [unscambled].re = tempr * c - tempi * s;
- FFTarray [unscambled].im = tempi * c + tempr * s;
+ FFTarray [unscambled].re = tempr * c - tempi * s;
+ FFTarray [unscambled].im = tempi * c + tempr * s;
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
}
- /* Perform in-place complex IFFT of length N/4 */
+ /* Perform in-place complex IFFT of length N/4 */
switch (N) {
- case 256: pfftwi_64(FFTarray);
- break;
- case 2048:pfftwi_512(FFTarray);
- }
+ case 256:
+ pfftwi_64(FFTarray);
+ break;
+ case 2048:pfftwi_512(FFTarray);
+ }
+ /* prepare for recurrence relations in post-twiddle */
+ c = cosfreq8;
+ s = sinfreq8;
- /* prepare for recurrence relations in post-twiddle */
- c = cosfreq8;
- s = sinfreq8;
+ /* post-twiddle FFT output and then get output data */
+ for (i = 0; i < Nd4; i++) {
- /* post-twiddle FFT output and then get output data */
- for (i = 0; i < Nd4; i++) {
+ /* get post-twiddled FFT output */
+ tempr = fac * (FFTarray[i].re * c - FFTarray[i].im * s);
+ tempi = fac * (FFTarray[i].im * c + FFTarray[i].re * s);
- /* get post-twiddled FFT output */
- tempr = fac * (FFTarray[i].re * c - FFTarray[i].im * s);
- tempi = fac * (FFTarray[i].im * c + FFTarray[i].re * s);
+ /* fill in output values */
+ data [Nd2 + Nd4 - 1 - 2 * i] = tempr;
+ if (i < Nd8)
+ data [Nd2 + Nd4 + 2 * i] = tempr;
+ else
+ data [2 * i - Nd4] = -tempr;
- /* fill in output values */
- data [Nd2 + Nd4 - 1 - 2 * i] = tempr;
- if (i < Nd8) {
- data [Nd2 + Nd4 + 2 * i] = tempr;
- } else {
- data [2 * i - Nd4] = -tempr;
- }
- data [Nd4 + 2 * i] = tempi;
- if (i < Nd8) {
- data [Nd4 - 1 - 2 * i] = -tempi;
- } else {
- data [Nd4 + N - 1 - 2*i] = tempi;
- }
+ data [Nd4 + 2 * i] = tempi;
+ if (i < Nd8)
+ data [Nd4 - 1 - 2 * i] = -tempi;
+ else
+ data [Nd4 + N - 1 - 2*i] = tempi;
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
}
void make_MDCT_windows(void)
{
-int i;
-for( i=0; i<BLOCK_LEN_LONG; i++ )
- sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
-for( i=0; i<BLOCK_LEN_SHORT; i++ )
- sin_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
-sizedouble = sizeof (double);
+ int i;
+ for( i=0; i<BLOCK_LEN_LONG; i++ )
+ sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
+ for( i=0; i<BLOCK_LEN_SHORT; i++ )
+ sin_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
+ sizedouble = sizeof (double);
}
/*******************************************************************************
T/F mapping
@@ -219,114 +217,119 @@
Mdct_in overlap_select
)
{
- double transf_buf[ 2*BLOCK_LEN_LONG ];
- double *p_o_buf, *first_window, *second_window;
- int k,i;
+ double transf_buf[ 2*BLOCK_LEN_LONG ];
+ double *p_o_buf, *first_window, *second_window;
+ int k,i;
- static int firstTime=1;
+ static int firstTime=1;
- /* create / shift old values */
- /* We use p_overlap here as buffer holding the last frame time signal*/
- if(overlap_select != MNON_OVERLAPPED){
- if (firstTime){
- firstTime=0;
- memset(transf_buf,0,BLOCK_LEN_LONG*sizedouble);
- }
- else
- memcpy(transf_buf,p_overlap,BLOCK_LEN_LONG*sizedouble);
- memcpy(transf_buf+BLOCK_LEN_LONG,p_in_data,BLOCK_LEN_LONG*sizedouble);
- memcpy(p_overlap,p_in_data,BLOCK_LEN_LONG*sizedouble);
- }
- else{
- memcpy(transf_buf,p_in_data,2*BLOCK_LEN_LONG*sizedouble);
- }
+ /* create / shift old values */
+ /* We use p_overlap here as buffer holding the last frame time signal*/
+ if(overlap_select != MNON_OVERLAPPED){
+ if (firstTime){
+ firstTime=0;
+ memset(transf_buf,0,BLOCK_LEN_LONG*sizedouble);
+ }
+ else
+ memcpy(transf_buf,p_overlap,BLOCK_LEN_LONG*sizedouble);
+ memcpy(transf_buf+BLOCK_LEN_LONG,p_in_data,BLOCK_LEN_LONG*sizedouble);
+ memcpy(p_overlap,p_in_data,BLOCK_LEN_LONG*sizedouble);
+ }
+ else {
+ memcpy(transf_buf,p_in_data,2*BLOCK_LEN_LONG*sizedouble);
+ }
- /* Window shape processing */
- switch (wfun_select_prev){
- case WS_SIN: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = sin_window_long;
- else
- first_window = sin_window_short;
- break;
- case WS_KBD: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = kbd_window_long;
- else
- first_window = kbd_window_short;
- break;
- }
+ /* Window shape processing */
+ switch (wfun_select_prev){
+ case WS_SIN:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = sin_window_long;
+ else
+ first_window = sin_window_short;
+ break;
+ case WS_KBD:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = kbd_window_long;
+ else
+ first_window = kbd_window_short;
+ break;
+ }
- switch (wfun_select){
- case WS_SIN: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = sin_window_long;
- else
- second_window = sin_window_short;
- break;
- case WS_KBD: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = kbd_window_long;
- else
- second_window = kbd_window_short;
- break;
- }
+ switch (wfun_select){
+ case WS_SIN:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = sin_window_long;
+ else
+ second_window = sin_window_short;
+ break;
+ case WS_KBD:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = kbd_window_long;
+ else
+ second_window = kbd_window_short;
+ break;
+ }
- /* Set ptr to transf-Buffer */
- p_o_buf = transf_buf;
+ /* Set ptr to transf-Buffer */
+ p_o_buf = transf_buf;
- /* Separate action for each Block Type */
- switch( block_type ) {
- case ONLY_LONG_WINDOW :
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++){
- p_out_mdct[i] = p_o_buf[i] * first_window[i];
- p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- }
- MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
- break;
+ /* Separate action for each Block Type */
+ switch( block_type ) {
+ case ONLY_LONG_WINDOW :
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++){
+ p_out_mdct[i] = p_o_buf[i] * first_window[i];
+ p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ }
+ MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+ break;
- case LONG_SHORT_WINDOW :
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- p_out_mdct[i] = p_o_buf[i] * first_window[i];
- memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
-// for ( ; i < NFLAT_LS + BLOCK_LEN_LONG; i++){
-// p_out_mdct[i] = 1.0;
-// p_out_mdct[i+NFLAT_LS+BLOCK_LEN_SHORT] = 0.0;
-// }
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
- memset(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
- MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
- break;
+ case LONG_SHORT_WINDOW :
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ p_out_mdct[i] = p_o_buf[i] * first_window[i];
+ memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
+// for ( ; i < NFLAT_LS + BLOCK_LEN_LONG; i++){
+// p_out_mdct[i] = 1.0;
+// p_out_mdct[i+NFLAT_LS+BLOCK_LEN_SHORT] = 0.0;
+// }
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
+ memset(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
+ MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+ break;
- case SHORT_LONG_WINDOW :
- memset(p_out_mdct,0,NFLAT_LS*sizedouble);
-// for ( i = 0 ; i < NFLAT_LS ; i++){
-// p_out_mdct[i] = 0.0;
-// p_out_mdct[i+NFLAT_LS+BLOCK_LEN_SHORT] = 1.0;
-// }
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
- memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizedouble);
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
- break;
+ case SHORT_LONG_WINDOW :
+ memset(p_out_mdct,0,NFLAT_LS*sizedouble);
+// for ( i = 0 ; i < NFLAT_LS ; i++){
+// p_out_mdct[i] = 0.0;
+// p_out_mdct[i+NFLAT_LS+BLOCK_LEN_SHORT] = 1.0;
+// }
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
+ memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizedouble);
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+ break;
- case ONLY_SHORT_WINDOW :
- if(overlap_select != MNON_OVERLAPPED){ /* YT 970615 for sonPP */
- p_o_buf += NFLAT_LS;
- }
- for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++ ){
- p_out_mdct[i] = p_o_buf[i] * first_window[i];
- p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
- }
- MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
-
- p_out_mdct += BLOCK_LEN_SHORT;
- if(overlap_select != MNON_OVERLAPPED) p_o_buf += BLOCK_LEN_SHORT;
- else p_o_buf += 2*BLOCK_LEN_SHORT;
- first_window = second_window;
- }
- break;
- }
+ case ONLY_SHORT_WINDOW :
+ if(overlap_select != MNON_OVERLAPPED){ /* YT 970615 for sonPP */
+ p_o_buf += NFLAT_LS;
+ }
+ for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++ ){
+ p_out_mdct[i] = p_o_buf[i] * first_window[i];
+ p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
+ }
+ MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
+ p_out_mdct += BLOCK_LEN_SHORT;
+ if(overlap_select != MNON_OVERLAPPED)
+ p_o_buf += BLOCK_LEN_SHORT;
+ else
+ p_o_buf += 2*BLOCK_LEN_SHORT;
+ first_window = second_window;
+ }
+ break;
+ }
}
void freq2buffer(double p_in_data[],
@@ -338,142 +341,144 @@
Mdct_in overlap_select
)
{
- double *o_buf, transf_buf[ 2*BLOCK_LEN_LONG ];
- double overlap_buf[ 2*BLOCK_LEN_LONG ], *first_window, *second_window;
+ double *o_buf, transf_buf[ 2*BLOCK_LEN_LONG ];
+ double overlap_buf[ 2*BLOCK_LEN_LONG ], *first_window, *second_window;
- double *fp;
- int k,i;
+ double *fp;
+ int k,i;
- /* Window shape processing */
- switch (wfun_select_prev){
- case WS_SIN: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = sin_window_long;
- else
- first_window = sin_window_short;
- break;
- case WS_KBD: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = kbd_window_long;
- else
- first_window = kbd_window_short;
- break;
- }
+ /* Window shape processing */
+ switch (wfun_select_prev){
+ case WS_SIN:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = sin_window_long;
+ else
+ first_window = sin_window_short;
+ break;
+ case WS_KBD:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = kbd_window_long;
+ else
+ first_window = kbd_window_short;
+ break;
+ }
- switch (wfun_select){
- case WS_SIN: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = sin_window_long;
- else
- second_window = sin_window_short;
- break;
- case WS_KBD: if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = kbd_window_long;
- else
- second_window = kbd_window_short;
- break;
- }
+ switch (wfun_select){
+ case WS_SIN:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = sin_window_long;
+ else
+ second_window = sin_window_short;
+ break;
+ case WS_KBD:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = kbd_window_long;
+ else
+ second_window = kbd_window_short;
+ break;
+ }
- /* Assemble overlap buffer */
- memcpy(overlap_buf,p_overlap,BLOCK_LEN_LONG*sizedouble);
- o_buf = overlap_buf;
+ /* Assemble overlap buffer */
+ memcpy(overlap_buf,p_overlap,BLOCK_LEN_LONG*sizedouble);
+ o_buf = overlap_buf;
- /* Separate action for each Block Type */
- switch( block_type ) {
- case ONLY_LONG_WINDOW :
- memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
- IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- transf_buf[i] *= first_window[i];
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_LONG; i++ ){
- o_buf[i] += transf_buf[i];
- o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- }
- }
- else { /* overlap_select == NON_OVERLAPPED */
- for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
- transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
- }
- break;
+ /* Separate action for each Block Type */
+ switch( block_type ) {
+ case ONLY_LONG_WINDOW :
+ memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
+ IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ transf_buf[i] *= first_window[i];
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ ){
+ o_buf[i] += transf_buf[i];
+ o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ }
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
+ transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
+ }
+ break;
- case LONG_SHORT_WINDOW :
- memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
- IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- transf_buf[i] *= first_window[i];
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
- o_buf[i] += transf_buf[i];
- memcpy(o_buf+BLOCK_LEN_LONG,transf_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] = transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
- memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
- }
- else { /* overlap_select == NON_OVERLAPPED */
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] *= second_window[BLOCK_LEN_SHORT-i-1];
- memset(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
- }
- break;
+ case LONG_SHORT_WINDOW :
+ memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
+ IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ transf_buf[i] *= first_window[i];
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
+ o_buf[i] += transf_buf[i];
+ memcpy(o_buf+BLOCK_LEN_LONG,transf_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] = transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
+ memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] *= second_window[BLOCK_LEN_SHORT-i-1];
+ memset(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
+ }
+ break;
- case SHORT_LONG_WINDOW :
- memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
- IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- transf_buf[i+NFLAT_LS] *= first_window[i];
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_SHORT; i++ )
- o_buf[i+NFLAT_LS] += transf_buf[i+NFLAT_LS];
- memcpy(o_buf+BLOCK_LEN_SHORT+NFLAT_LS,transf_buf+BLOCK_LEN_SHORT+NFLAT_LS,NFLAT_LS*sizedouble);
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- }
- else { /* overlap_select == NON_OVERLAPPED */
- memset(transf_buf,0,NFLAT_LS*sizedouble);
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
- }
- break;
+ case SHORT_LONG_WINDOW :
+ memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizedouble);
+ IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ transf_buf[i+NFLAT_LS] *= first_window[i];
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_SHORT; i++ )
+ o_buf[i+NFLAT_LS] += transf_buf[i+NFLAT_LS];
+ memcpy(o_buf+BLOCK_LEN_SHORT+NFLAT_LS,transf_buf+BLOCK_LEN_SHORT+NFLAT_LS,NFLAT_LS*sizedouble);
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ memset(transf_buf,0,NFLAT_LS*sizedouble);
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
+ }
+ break;
- case ONLY_SHORT_WINDOW :
- if (overlap_select != MNON_OVERLAPPED) {
- fp = o_buf + NFLAT_LS;
- }
- else { /* overlap_select == NON_OVERLAPPED */
- fp = transf_buf;
- }
- for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
- memcpy(transf_buf,p_in_data,BLOCK_LEN_SHORT*sizedouble);
- IMDCT( transf_buf, 2*BLOCK_LEN_SHORT );
- p_in_data += BLOCK_LEN_SHORT;
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
- transf_buf[i] *= first_window[i];
- fp[i] += transf_buf[i];
- fp[i+BLOCK_LEN_SHORT] = transf_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
- }
- fp += BLOCK_LEN_SHORT;
- }
- else { /* overlap_select == NON_OVERLAPPED */
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
- fp[i] *= first_window[i];
- fp[i+BLOCK_LEN_SHORT] *= second_window[BLOCK_LEN_SHORT-i-1];
- }
- fp += 2*BLOCK_LEN_SHORT;
- }
- first_window = second_window;
- }
- memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
- break;
- }
+ case ONLY_SHORT_WINDOW :
+ if (overlap_select != MNON_OVERLAPPED) {
+ fp = o_buf + NFLAT_LS;
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ fp = transf_buf;
+ }
+ for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
+ memcpy(transf_buf,p_in_data,BLOCK_LEN_SHORT*sizedouble);
+ IMDCT( transf_buf, 2*BLOCK_LEN_SHORT );
+ p_in_data += BLOCK_LEN_SHORT;
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
+ transf_buf[i] *= first_window[i];
+ fp[i] += transf_buf[i];
+ fp[i+BLOCK_LEN_SHORT] = transf_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
+ }
+ fp += BLOCK_LEN_SHORT;
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
+ fp[i] *= first_window[i];
+ fp[i+BLOCK_LEN_SHORT] *= second_window[BLOCK_LEN_SHORT-i-1];
+ }
+ fp += 2*BLOCK_LEN_SHORT;
+ }
+ first_window = second_window;
+ }
+ memset(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizedouble);
+ break;
+ }
- if (overlap_select != MNON_OVERLAPPED) {
- memcpy(p_out_data,o_buf,BLOCK_LEN_LONG*sizedouble);
- }
- else { /* overlap_select == NON_OVERLAPPED */
- memcpy(p_out_data,transf_buf,2*BLOCK_LEN_LONG*sizedouble);
- }
+ if (overlap_select != MNON_OVERLAPPED)
+ memcpy(p_out_data,o_buf,BLOCK_LEN_LONG*sizedouble);
+ else /* overlap_select == NON_OVERLAPPED */
+ memcpy(p_out_data,transf_buf,2*BLOCK_LEN_LONG*sizedouble);
- /* save unused output data */
- memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizedouble);
+ /* save unused output data */
+ memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizedouble);
}
/******************************************************************************/
@@ -485,102 +490,103 @@
int specLen
)
{
- int lowpass,xlowpass;
+ int lowpass,xlowpass;
- /* calculate the last line which is not zero */
- lowpass = (lowpass_freq * specLen) / (samp_rate>>1) + 1;
- xlowpass = (lowpass < specLen) ? lowpass : specLen ;
+ /* calculate the last line which is not zero */
+ lowpass = (lowpass_freq * specLen) / (samp_rate>>1) + 1;
+ xlowpass = (lowpass < specLen) ? lowpass : specLen ;
- if( p_out != p_in ) memcpy(p_out,p_in,specLen*sizedouble);
- memset(p_out+xlowpass,0,(specLen-xlowpass)*sizedouble);
+ if( p_out != p_in )
+ memcpy(p_out,p_in,specLen*sizedouble);
+ memset(p_out+xlowpass,0,(specLen-xlowpass)*sizedouble);
}
void initrft(void)
{
-double theta,wtemp;
+ double theta,wtemp;
-theta = -M_PI/128.0;
-wpi256 = sin(theta);
-wtemp = sin(0.5*theta);
-wpr256 = -2.0*wtemp*wtemp;
+ theta = -M_PI/128.0;
+ wpi256 = sin(theta);
+ wtemp = sin(0.5*theta);
+ wpr256 = -2.0*wtemp*wtemp;
-theta = -M_PI/1024.0;
-wpi2048 = sin(theta);
-wtemp = sin(0.5*theta);
-wpr2048 = -2.0*wtemp*wtemp;
+ theta = -M_PI/1024.0;
+ wpi2048 = sin(theta);
+ wtemp = sin(0.5*theta);
+ wpr2048 = -2.0*wtemp*wtemp;
}
void realft256(double *data)
{
- int i,i1,i2,i3,i4;
- double h1r,h1i,h2r,h2i,t1,t2,t3;
- double wr,wi,wtemp;
+ int i,i1,i2,i3,i4;
+ double h1r,h1i,h2r,h2i,t1,t2,t3;
+ double wr,wi,wtemp;
- pfftw_128(FFTarray);
- for (i = 0; i < 128; i++){
- data[(i<<1)] = FFTarray[unscambled128[i]].re;
- data[(i<<1)+1]= FFTarray[unscambled128[i]].im;
- }
+ pfftw_128(FFTarray);
+ for (i = 0; i < 128; i++){
+ data[(i<<1)] = FFTarray[unscambled128[i]].re;
+ data[(i<<1)+1]= FFTarray[unscambled128[i]].im;
+ }
- wr=1.0+wpr256;
- wi=wpi256;
- for (i=1;i<64;i++) {
- i4=1+(i3=257-(i2=1+(i1=i+i)));
- h1r=0.5*(data[i1]+data[i3]);
- h1i=0.5*(data[i2]-data[i4]);
- h2r=0.5*(data[i2]+data[i4]);
- h2i=-0.5*(data[i1]-data[i3]);
- t1=wr*h2r;
- t2=wi*h2i;
- t3=wr*h2i+wi*h2r;
+ wr=1.0+wpr256;
+ wi=wpi256;
+ for (i=1;i<64;i++) {
+ i4=1+(i3=257-(i2=1+(i1=i+i)));
+ h1r=0.5*(data[i1]+data[i3]);
+ h1i=0.5*(data[i2]-data[i4]);
+ h2r=0.5*(data[i2]+data[i4]);
+ h2i=-0.5*(data[i1]-data[i3]);
+ t1=wr*h2r;
+ t2=wi*h2i;
+ t3=wr*h2i+wi*h2r;
- data[i1]=h1r+t1-t2;
- data[i2]=h1i+t3;
- data[i3]=h1r-t1+t2;
- data[i4]=-h1i+t3;
- wtemp=wr;
- wr=wtemp*wpr256-wi*wpi256+wr;
- wi=wi*wpr256+wtemp*wpi256+wi;
- }
- data[0] = data[0]+data[1];
- data[1] = 0;
- data[129] = -data[129]; // hack to emulate complex FFT
+ data[i1]=h1r+t1-t2;
+ data[i2]=h1i+t3;
+ data[i3]=h1r-t1+t2;
+ data[i4]=-h1i+t3;
+ wtemp=wr;
+ wr=wtemp*wpr256-wi*wpi256+wr;
+ wi=wi*wpr256+wtemp*wpi256+wi;
+ }
+ data[0] = data[0]+data[1];
+ data[1] = 0;
+ data[129] = -data[129]; // hack to emulate complex FFT
}
void realft2048(double *data)
{
- int i,i1,i2,i3,i4;
- double h1r,h1i,h2r,h2i,t1,t2,t3;
- double wr,wi,wtemp;
+ int i,i1,i2,i3,i4;
+ double h1r,h1i,h2r,h2i,t1,t2,t3;
+ double wr,wi,wtemp;
- pfftw_1024(FFTarray);
- for (i = 0; i < 1024; i++){
- data[(i<<1)] = FFTarray[unscambled1024[i]].re;
- data[(i<<1)+1]= FFTarray[unscambled1024[i]].im;
- }
+ pfftw_1024(FFTarray);
+ for (i = 0; i < 1024; i++){
+ data[(i<<1)] = FFTarray[unscambled1024[i]].re;
+ data[(i<<1)+1]= FFTarray[unscambled1024[i]].im;
+ }
- wr=1.0+wpr2048;
- wi=wpi2048;
- for (i=1;i<512;i++) {
- i4=1+(i3=2049-(i2=1+(i1=i+i)));
- h1r=0.5*(data[i1]+data[i3]);
- h1i=0.5*(data[i2]-data[i4]);
- h2r=0.5*(data[i2]+data[i4]);
- h2i=-0.5*(data[i1]-data[i3]);
- t1=wr*h2r;
- t2=wi*h2i;
- t3=wr*h2i+wi*h2r;
+ wr=1.0+wpr2048;
+ wi=wpi2048;
+ for (i=1;i<512;i++) {
+ i4=1+(i3=2049-(i2=1+(i1=i+i)));
+ h1r=0.5*(data[i1]+data[i3]);
+ h1i=0.5*(data[i2]-data[i4]);
+ h2r=0.5*(data[i2]+data[i4]);
+ h2i=-0.5*(data[i1]-data[i3]);
+ t1=wr*h2r;
+ t2=wi*h2i;
+ t3=wr*h2i+wi*h2r;
- data[i1]=h1r+t1-t2;
- data[i2]=h1i+t3;
- data[i3]=h1r-t1+t2;
- data[i4]=-h1i+t3;
- wtemp=wr;
- wr=wtemp*wpr2048-wi*wpi2048+wr;
- wi=wi*wpr2048+wtemp*wpi2048+wi;
- }
- data[0] = data[0]+data[1];
- data[1] = 0;
- data[1025] = -data[1025]; // hack to emulate complex FFT
+ data[i1]=h1r+t1-t2;
+ data[i2]=h1i+t3;
+ data[i3]=h1r-t1+t2;
+ data[i4]=-h1i+t3;
+ wtemp=wr;
+ wr=wtemp*wpr2048-wi*wpi2048+wr;
+ wi=wi*wpr2048+wtemp*wpi2048+wi;
+ }
+ data[0] = data[0]+data[1];
+ data[1] = 0;
+ data[1025] = -data[1025]; // hack to emulate complex FFT
}