/**************************************************************** * Window the samples then, * Fast Fourier transform of the input samples. * * ( call the FHT-based fft() in fft.c ) * * ****************************************************************/ static void psycho_1_hann_fft_pickmax(FLOAT sample[FFT_SIZE], mask power[HAN_SIZE], FLOAT spike[SBLIMIT], FLOAT energy[FFT_SIZE]) { FLOAT x_real[FFT_SIZE]; register int i, j; register FLOAT sqrt_8_over_3; static int init = 0; static FLOAT window[FFT_SIZE]; FLOAT sum; if (!init) { /* calculate window function for the Fourier transform */ /* These values need only be initiliased once, regardless of the caller */ sqrt_8_over_3 = pow(8.0 / 3.0, 0.5); for (i = 0; i < FFT_SIZE; i++) { /* Hann window formula */ window[i] = sqrt_8_over_3 * 0.5 * (1 - cos(2.0 * PI * i / (FFT_SIZE))) / FFT_SIZE; } init = 1; } for (i = 0; i < FFT_SIZE; i++) x_real[i] = (FLOAT) (sample[i] * window[i]); psycho_1_fft(x_real, energy, FFT_SIZE); for (i = 0; i < HAN_SIZE; i++) { /* calculate power density spectrum */ if (energy[i] < 1E-20) power[i].x = -200.0 + POWERNORM; else power[i].x = 10 * log10(energy[i]) + POWERNORM; power[i].next = STOP; power[i].type = FALSE; } /* Calculate the sum of spectral component in each subband from bound 4-16 */ #define CF 1073741824 /* pow(10, 0.1*POWERNORM) */ #define DBM 1E-20 /* pow(10.0, 0.1*DBMIN */ for (i = 0; i < HAN_SIZE; spike[i >> 4] = 10.0 * log10(sum), i += 16) { for (j = 0, sum = DBM; j < 16; j++) sum += CF * energy[i + j]; } }
/* ISO11172 Sec D.1 Step 1 - Window with HANN and then perform the FFT */ static void psycho_3_fft(FLOAT sample[BLKSIZE], FLOAT energy[BLKSIZE]) { FLOAT x_real[BLKSIZE]; int i; static int init = 0; static FLOAT window[FFT_SIZE]; if (!init) { /* calculate window function for the Fourier transform */ FLOAT sqrt_8_over_3 = pow(8.0 / 3.0, 0.5); for (i = 0; i < BLKSIZE; i++) { window[i] = sqrt_8_over_3 * 0.5 * (1 - cos(2.0 * PI * i / (BLKSIZE))) / BLKSIZE; } init++; } /* convolve the samples with the hann window */ for (i = 0; i < BLKSIZE; i++) x_real[i] = (FLOAT) (sample[i] * window[i]); /* do the FFT */ psycho_1_fft(x_real, energy, BLKSIZE); }