ref: db4f5b7c07c0a1d67d8b62eb191efe96e7dc5a16
parent: d378fcfb11437762dc639711322a58212caf8148
author: lenox <lenox>
date: Sat Jan 29 12:11:25 EST 2000
changed T/F transformation
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -118,9 +118,9 @@
int SampleRates[] = {
96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,0
};
- int BitRates[] = {
- 64000,80000,96000,112000,128000,160000,192000,224000,256000,0
- };
+// int BitRates[] = {
+// 64000,80000,96000,112000,128000,160000,192000,224000,256000,0
+// };
sampling_rate = ac->out_sampling_rate;
bit_rate = ac->bit_rate;
@@ -188,6 +188,7 @@
nok_init_lt_pred (&nok_lt_status[chanNum]);
quantInfo[chanNum].ltpInfo = &nok_lt_status[chanNum]; /* Set pointer to LTP data */
}
+ make_MDCT_windows();
}
/*****************************************************************************************
@@ -236,7 +237,7 @@
int nr_of_sfb[MAX_TIME_CHANNELS], sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS];
int sfb_offset_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS+1];
- int no_sub_win, sub_win_size;
+// int no_sub_win, sub_win_size;
/* structures holding the output of the psychoacoustic model */
CH_PSYCH_OUTPUT_LONG chpo_long[MAX_TIME_CHANNELS+2];
@@ -388,8 +389,8 @@
switch( block_type[chanNum] ) {
case ONLY_SHORT_WINDOW :
- no_sub_win = short_win_in_long;
- sub_win_size = block_size_samples/short_win_in_long;
+// no_sub_win = short_win_in_long;
+// sub_win_size = block_size_samples/short_win_in_long;
quantInfo[chanNum].max_sfb = max_sfb_s[srate_idx];
#if 0
quantInfo[chanNum].num_window_groups = 4;
@@ -411,8 +412,8 @@
break;
default:
- no_sub_win = 1;
- sub_win_size = block_size_samples;
+// no_sub_win = 1;
+// sub_win_size = block_size_samples;
quantInfo[chanNum].max_sfb = max_sfb_l[srate_idx];
quantInfo[chanNum].num_window_groups = 1;
quantInfo[chanNum].window_group_length[0]=1;
@@ -448,10 +449,10 @@
spectral_line_vector[chanNum],
overlap_buffer[chanNum],
block_type[chanNum],
- quantInfo[chanNum].window_shape,
- block_size_samples,
- block_size_samples/2,
- block_size_samples/short_win_in_long,
+// quantInfo[chanNum].window_shape,
+// block_size_samples,
+// block_size_samples/2,
+// block_size_samples/short_win_in_long,
MOVERLAPPED
);
--- a/nok_ltp_enc.c
+++ b/nok_ltp_enc.c
@@ -34,8 +34,8 @@
/**************************************************************************
Version Control Information Method: CVS
Identifiers:
- $Revision: 1.3 $
- $Date: 2000/01/08 13:31:28 $ (check in)
+ $Revision: 1.4 $
+ $Date: 2000/01/29 17:11:25 $ (check in)
$Author: lenox $
*************************************************************************/
@@ -202,9 +202,10 @@
<_status->weight_idx, lt_status->delay[0], 2 * block_size_long);
/* Transform prediction to frequency domain and save it for subsequent use. */
- buffer2freq (predicted_samples, lt_status->pred_mdct, NULL, win_type,
- win_shape, block_size_long, block_size_medium,
- block_size_short, MNON_OVERLAPPED);
+// buffer2freq (predicted_samples, lt_status->pred_mdct, NULL, win_type,
+// win_shape, block_size_long, block_size_medium,
+// block_size_short, MNON_OVERLAPPED);
+ buffer2freq (predicted_samples, lt_status->pred_mdct, NULL, win_type, MNON_OVERLAPPED);
lt_status->side_info = LEN_LTP_DATA_PRESENT + last_band + LEN_LTP_LAG + LEN_LTP_COEF;
@@ -286,10 +287,11 @@
p_spectrum[i] += lt_status->pred_mdct[i];
/* Finally update the time domain history buffer. */
- freq2buffer (p_spectrum, predicted_samples, overlap_buffer, win_type,
- block_size_long, block_size_medium, block_size_short,
- win_shape, MNON_OVERLAPPED);
-
+// freq2buffer (p_spectrum, predicted_samples, overlap_buffer, win_type,
+// block_size_long, block_size_medium, block_size_short,
+// win_shape, MNON_OVERLAPPED);
+ freq2buffer (p_spectrum, predicted_samples, overlap_buffer, win_type, MNON_OVERLAPPED);
+
for (i = 0; i < NOK_LT_BLEN - block_size_long; i++)
lt_status->buffer[i] = lt_status->buffer[i + block_size_long];
--- a/tf_main.h
+++ b/tf_main.h
@@ -105,7 +105,7 @@
#define MAX_SHORT_WINDOWS 8
-/* if static memory allocation is used, this value tells the max. nr of
+/* if static memory allocation is used, this value tells the max. nr of
audio channels to be supported */
/*#define MAX_TIME_CHANNELS (MAX_CHANNELS)*/
#define MAX_TIME_CHANNELS 2 //6
@@ -114,14 +114,11 @@
#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_IN_LONG_BLOCK)
void freq2buffer(
- double p_in_data[],
+ double p_in_data[],
double p_out_data[],
double p_overlap[],
enum WINDOW_TYPE block_type,
- int nlong, /* shift length for long windows */
- int nmed, /* shift length for medium windows */
- int nshort, /* shift length for short windows */
- Window_shape wfun_select, /* offers the possibility to select different window functions */
+// int nlong, /* shift length for long windows */
Mdct_in overlap_select); /* select imdct output *TK* */
void buffer2freq( /* Input: Time signal */
@@ -129,14 +126,11 @@
double p_out_mdct[],
double p_overlap[],
enum WINDOW_TYPE block_type,
- Window_shape wfun_select, /* offers the possibility to select different window functions */
- int nlong, /* shift length for long windows */
- int nmed, /* shift length for medium windows */
- int nshort, /* shift length for short windows */
+// Window_shape wfun_select, /* offers the possibility to select different window functions */
Mdct_in overlap_select /* YT 970615 for Son_PP */
);
-void imdct(double in_data[], double out_data[], int len);
+void make_MDCT_windows(void);
void specFilter (double p_in[],
double p_out[],
--- a/transfo.c
+++ b/transfo.c
@@ -1,4 +1,5 @@
#include <math.h>
+#include <string.h>
#include "all.h"
#include "transfo.h"
@@ -10,11 +11,16 @@
#define M_PI_2 1.57079632679489661923
#endif
+#define NFLAT_LS 448 // (BLOCK_LEN_LONG - BLOCK_LEN_SHORT) / 2
+
+double fhg_window_long[BLOCK_LEN_LONG];
+double fhg_window_short[BLOCK_LEN_SHORT];
+
/*****************************
Fast MDCT & IMDCT Code
*****************************/
-void MDCT (fftw_real *data, int N) {
-
+void MDCT (fftw_real *data, int N)
+{
fftw_real tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
fftw_real freq = 2.0 * M_PI / N;
fftw_real fac,cosfreq8,sinfreq8;
@@ -189,3 +195,246 @@
s = s * cfreq + cold * sfreq;
}
}
+
+void make_MDCT_windows(void)
+{
+int i;
+for( i=0; i<BLOCK_LEN_LONG; i++ )
+ fhg_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
+for( i=0; i<BLOCK_LEN_SHORT; i++ )
+ fhg_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
+}
+
+void buffer2freq(double p_in_data[],
+ double p_out_mdct[],
+ double p_overlap[],
+ enum WINDOW_TYPE block_type,
+// Window_shape wfun_select, /* offers the possibility to select different window functions */
+ Mdct_in overlap_select /* YT 970615 for son_PP */
+ )
+{
+ double transf_buf[ 2*BLOCK_LEN_LONG ];
+ double *p_o_buf;
+ int k,i;
+ int sizedouble = sizeof(double);
+
+ static int firstTime=1;
+
+ /* create / shift old values */
+ /* We use p_overlap here as buffer holding the last frame time signal*/
+ /* YT 970615 for son_pp */
+ 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);
+ }
+
+ /* 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] * fhg_window_long[i];
+ p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * fhg_window_long[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] * fhg_window_long[i];
+ memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizedouble);
+ 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] * fhg_window_short[BLOCK_LEN_SHORT-i-1];
+ memset(p_out_mdct+2*BLOCK_LEN_LONG-1-NFLAT_LS,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 < BLOCK_LEN_SHORT ; i++)
+ p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * fhg_window_short[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] * fhg_window_long[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] * fhg_window_short[i];
+ p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * fhg_window_short[BLOCK_LEN_SHORT-i-1];
+ }
+ MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
+
+ p_out_mdct += BLOCK_LEN_SHORT;
+ /* YT 970615 for sonPP*/
+ if(overlap_select != MNON_OVERLAPPED) p_o_buf += BLOCK_LEN_SHORT;
+ else p_o_buf += 2*BLOCK_LEN_SHORT;
+ }
+ break;
+ }
+}
+
+void freq2buffer(double p_in_data[],
+ double p_out_data[],
+ double p_overlap[],
+ enum WINDOW_TYPE block_type,
+// Window_shape wfun_select, /* offers the possibility to select different window functions */
+ Mdct_in overlap_select /* select imdct output *TK* */
+ )
+{
+ double *o_buf, transf_buf[ 2*BLOCK_LEN_LONG ];
+ double overlap_buf[ 2*BLOCK_LEN_LONG ];
+
+ double *fp;
+ int k,i;
+ int sizedouble = sizeof(double);
+
+ /* 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] *= fhg_window_long[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] * fhg_window_long[BLOCK_LEN_LONG-i-1];
+ }
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
+ transf_buf[i+BLOCK_LEN_LONG] *= fhg_window_long[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] *= fhg_window_long[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] * fhg_window_short[BLOCK_LEN_SHORT-i-1];
+ memset(o_buf+2*BLOCK_LEN_LONG-1-NFLAT_LS,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] *= fhg_window_short[BLOCK_LEN_SHORT-i-1];
+ memset(transf_buf+2*BLOCK_LEN_LONG-1-NFLAT_LS,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] *= fhg_window_short[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] * fhg_window_long[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] *= fhg_window_long[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] *= fhg_window_short[i];
+ fp[i] += transf_buf[i];
+ fp[i+BLOCK_LEN_SHORT] = transf_buf[i+BLOCK_LEN_SHORT] * fhg_window_short[BLOCK_LEN_SHORT-i-1];
+ }
+ fp += BLOCK_LEN_SHORT;
+ }
+ else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
+ fp[i] *= fhg_window_short[i];
+ fp[i+BLOCK_LEN_SHORT] *= fhg_window_short[BLOCK_LEN_SHORT-i-1];
+ }
+ fp += 2*BLOCK_LEN_SHORT;
+ }
+ }
+ memset(o_buf+2*BLOCK_LEN_LONG-1-NFLAT_LS,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);
+ }
+
+ /* save unused output data */
+ memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizedouble);
+}
+
+/***********************************************************************************************/
+
+void specFilter (double p_in[],
+ double p_out[],
+ int samp_rate,
+ int lowpass_freq,
+ int specLen
+ )
+{
+ float lowpass;
+ int xlowpass,i;
+
+ /* calculate the last line which is not zero */
+ lowpass = (float)lowpass_freq * (float)specLen;
+ lowpass /= (samp_rate>>1);
+ lowpass += 1.0; /* round up to ensure that the desired upper frequency limit is correct */
+ xlowpass = ((int)lowpass < specLen) ? (int)lowpass : specLen ;
+
+ if( p_out != p_in ) {
+ for (i = 0; i < specLen; i++ ) {
+ p_out[i] = p_in[i];
+ }
+ }
+ for (i = xlowpass; i <specLen ; i++ ) {
+ p_out[i] = 0;
+ }
+}
+