summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/fft.hcc
diff options
context:
space:
mode:
authorMarcel Lauwerijssen <paranoya@morphcore.com>2004-11-22 15:10:48 (GMT)
committerMarcel Lauwerijssen <paranoya@morphcore.com>2004-11-22 15:10:48 (GMT)
commitf80c80233a37323881fa5fd66e25d973aca5e386 (patch)
tree61f33f4b26ec628d4200a575edd145ff3fa7a6e8 /Graphic_Equalizer/src/fft.hcc
parent517918c3d47593858f638406f6dbc7b00df74e72 (diff)
downloadTASS-f80c80233a37323881fa5fd66e25d973aca5e386.zip
TASS-f80c80233a37323881fa5fd66e25d973aca5e386.tar.gz
TASS-f80c80233a37323881fa5fd66e25d973aca5e386.tar.bz2
Added comment throughout the entire FFT.hcc file
Optimized the equalize_audio function.
Diffstat (limited to 'Graphic_Equalizer/src/fft.hcc')
-rw-r--r--Graphic_Equalizer/src/fft.hcc127
1 files changed, 96 insertions, 31 deletions
diff --git a/Graphic_Equalizer/src/fft.hcc b/Graphic_Equalizer/src/fft.hcc
index d12ab01..34103ed 100644
--- a/Graphic_Equalizer/src/fft.hcc
+++ b/Graphic_Equalizer/src/fft.hcc
@@ -66,17 +66,18 @@ macro proc multiply(result, op_a, op_b)
-/*******************************************************************
-* Function: calculate_fft *
-* *
-* Arguments *
-* select_inverse Boolean that indicates FFT or iFFT calculation *
-* *
-* Description *
-* This routine performs the Fast Fourier Transform for *
-* calculation of the frequency spectrum *
-* *
-*******************************************************************/
+/************************************************************************
+* Function: calculate_fft *
+* *
+* Arguments *
+* select_inverse Boolean that indicates FFT or iFFT calculation *
+* *
+* Description *
+* This routine performs the Fast Fourier Transform for *
+* calculation of the frequency spectrum *
+* *
+* Cost: 259 cycles (excl. the calculate FFT function) *
+************************************************************************/
void calculate_fft(unsigned 1 select_inverse)
{
unsigned 4 level;
@@ -218,7 +219,20 @@ void calculate_fft(unsigned 1 select_inverse)
}
-/********************************************************************/
+/*******************************************************************
+* Function: perform_fft *
+* *
+* Arguments *
+* pcm_audio Pointer to the array containing the audio data *
+* *
+* Description *
+* This routine obtains the audio data from the audio I/O *
+* component and copies this data to local arrays for *
+* calculating purposes, and calls the FFT algorithm. *
+* *
+* Cost: 259 cycles (excl. the calculate FFT function) *
+* *
+*******************************************************************/
#if HARDWARE_MULTIPLY
void perform_fft(signed 18 *pcm_audio)
#else
@@ -226,8 +240,6 @@ void perform_fft(signed 16 *pcm_audio)
#endif
{
unsigned 8 k;
-
-
#if HARDWARE_MULTIPLY
signed 18 sample;
k=0;
@@ -273,7 +285,27 @@ void perform_fft(signed 16 *pcm_audio)
}
-/********************************************************************/
+/*******************************************************************
+* Function: perform_ifft *
+* *
+* Arguments *
+* modified_audio Pointer to the array containing the audio data *
+* *
+* ifft_info Pointer to the ifft_info array containing the *
+* modified waveform data for display purposes*
+* *
+* *
+* Description *
+* This routine calls the ifft algorithm and after completing that*
+* it obtains the modified audio data and copies that to the *
+* output arrays of the audio I/O component. Besides that it *
+* also fills the array used by the display routine for *
+* displaying the waveform . *
+* *
+* *
+* Cost: 259 cycles (excl. the calculate FFT function) *
+* *
+*******************************************************************/
#if HARDWARE_MULTIPLY
void perform_ifft(signed 18 *modified_audio, unsigned 6 *ifft_info)
#else
@@ -310,27 +342,54 @@ void perform_ifft(signed 16 *modified_audio, unsigned 6 *ifft_info)
//determined by the sampling rate of 44,1 Khz
par
{
+ /*
+ * Before copying the modified audio from the local real-array
+ * to the output array of the audio I/O component, compensate
+ * for the FFT calculation by shifting the values.
+ * 95 is added to start the output from the middle of the sliding
+ * window, this is done to get a better sound quality.
+ */
#if PERFORM_FFT_CALCULATION
#if HARDWARE_MULTIPLY
- p = (real.read[(0@k)+95] << NUMBER_OF_COLUMNS);
+ p = (real.read[(0@k)+95] << NUMBER_OF_COLUMNS);
#else
- p = (real.read[(0@k)+95] >> NUMBER_OF_COLUMNS);
+ p = (real.read[(0@k)+95] >> NUMBER_OF_COLUMNS);
#endif
#else
- p = (real.read[(0@k)+95]);
+ p = (real.read[(0@k)+95]);
#endif
+ //Copy the modified audio from the local real array to the output array of the audio I/O component.
#if HARDWARE_MULTIPLY
modified_audio[k] = p ;
#else
modified_audio[k] = (p<-16);
#endif
+ //Fill the array for displaying the waveform, only the 6 MSB are needed.
ifft_info[k] = (unsigned 6)(32+(p[17:12]));
+
+ ifft_info[k] = (p[17:12]);
k++;
}
} while(k);
}
-/********************************************************************/
+/*******************************************************************
+* Function: equalize_audio *
+* *
+* Arguments *
+* audiodata Pointer to the audiodata structure *
+* *
+* *
+* *
+* Description *
+* This routine equalizes the frequencies derived by the FFT *
+* calculation, according to the settings of the equalizer *
+* bars. *
+* *
+* *
+* Cost: 3844 cycles (Maximum) *
+* *
+*******************************************************************/
void equalize_audio(audiodata_t *audiodata)
{
#if HARDWARE_MULTIPLY
@@ -358,17 +417,19 @@ void equalize_audio(audiodata_t *audiodata)
p = real.read[0] - DC_COMPONENT; // remove DC component for calculations
real.rwrite[0] = p;
-// imaginary.rwrite[0] = 0; // remove DC component
-
for(i=0;i!=NUMBER_OF_FREQUENCIES;i++)
{
- // set multiplication factor (0..64) for current frequency bar, The first frequency band must be equalized at 100% (63) since there is no DC-component taken into account.
- a = (i==0) ? 63 : adjs(eq_settings[audiodata->equalizer_levels_ptr[i <- 7]],18);
+
+ par
+ {
+ // set multiplication factor (0..64) for current frequency bar, The first frequency band must be equalized at 100% (63) since there is no DC-component taken into account.
+ a = (i==0) ? 63 : adjs(eq_settings[audiodata->equalizer_levels_ptr[i <- 7]],18);
- // multiply frequency with this factor and divide by 64 (drop 6 LSB's)
- q = real.read[i];
+ // multiply frequency with this factor and divide by 64 (drop 6 LSB's)
+ q = real.read[i];
+ }
equalize_bar(p);
real.rwrite[i] = p;
@@ -394,15 +455,18 @@ void equalize_audio(audiodata_t *audiodata)
//write data to fft_info for display purposes
for(i=0;i<NUMBER_OF_FREQUENCIES;i++)
{
- p = real.read[i];
- q = imaginary.read[i];
+ par
+ {
+ p = real.read[i];
+ q = imaginary.read[i];
#if HARDWARE_MULTIPLY
- if (p[17] == 1) p = -p; else delay;
- if (q[17] == 1) q = -q; else delay;
+ if (p[17] == 1) p = -p; else delay;
+ if (q[17] == 1) q = -q; else delay;
#else
- if (p[23] == 1) p = -p; else delay;
- if (q[23] == 1) q = -q; else delay;
+ if (p[23] == 1) p = -p; else delay;
+ if (q[23] == 1) q = -q; else delay;
#endif
+ }
p = (p<q) ? q : p; // This is done to get the best visual frequency result
if (!audiodata->display_log)
@@ -439,3 +503,4 @@ void equalize_audio(audiodata_t *audiodata)
p = real.read[0] + DC_COMPONENT;
real.rwrite[0] = p;
}
+