summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/fft.hcc
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2004-11-16 09:07:49 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2004-11-16 09:07:49 (GMT)
commit0a9c7d08968e20efbbded3dc2a0e9081823610be (patch)
treead77076cff584e9ec20e61092bf3209950b0bc61 /Graphic_Equalizer/src/fft.hcc
parent2550e155ac6b08475039b24d44f4e08d1d1c53fc (diff)
downloadTASS-0a9c7d08968e20efbbded3dc2a0e9081823610be.zip
TASS-0a9c7d08968e20efbbded3dc2a0e9081823610be.tar.gz
TASS-0a9c7d08968e20efbbded3dc2a0e9081823610be.tar.bz2
Merged FFT into Graphic Equalizer.
Diffstat (limited to 'Graphic_Equalizer/src/fft.hcc')
-rw-r--r--Graphic_Equalizer/src/fft.hcc93
1 files changed, 40 insertions, 53 deletions
diff --git a/Graphic_Equalizer/src/fft.hcc b/Graphic_Equalizer/src/fft.hcc
index 7c3fa94..92468a8 100644
--- a/Graphic_Equalizer/src/fft.hcc
+++ b/Graphic_Equalizer/src/fft.hcc
@@ -1,13 +1,12 @@
-#include <pal_master.hch>
#include <stdlib.hch>
-#include "weights256.hch"
-#include "config.hch"
+#include "pal_master.hch"
+
+#include "audio.hch"
+#include "weights_256.hch"
+#include "configuration.hch"
#include "debug.hch"
#include "xilinxmult.hch"
-#define PERFORM_FFT_CALCULATION 1
-#define USE_UNSIGNED_AUDIO 0
-#define PRINT_DEBUG 0
/* Define two multi-port RAMs for FFT calculation; one for real and one for imaginary values
* Extra block RAM settings are defined to make sure read and write actions can be performed
* within one clock-cycle.
@@ -60,24 +59,10 @@ macro proc multiply(result, op_a, op_b)
#if HARDWARE_MULTIPLY
xilinxmult(result, op_a, adjs(op_b,18));
#else
- macro expr mul_width = (width(op_a) + width(op_b));
- result = adjs(op_a, mul_width) * adjs(op_b, mul_width);
+ result = (adjs(op_a,38))*(adjs(op_a,38));
#endif
-/* signed result;
-
- fixed_mul(result,x,y);
- return result;*/
-}
-/*macro proc multiply(result, x,y)
-{
-#if HARDWARE_MULTIPLY
- xilinxmult(result, adjs(x,18), adjs(y,18));
-#else
- result = ((adjs(x,36))*(adjs(y,36)));
-#endif
-
}
-*/
+
@@ -105,12 +90,21 @@ void calculate_fft(unsigned 1 select_inverse)
#endif
signed a,b;
+#if HARDWARE_MULTIPLY
+ // Macro to provide rescaling of 36-bit result of fixed point multiply
+ // down to an 18-bit result. The range of bits selected depends on the
+ // number that represents the value of "1" in the trig function lookup
+ // tables. (Eg. for 16384 == 1, the lowest bit selected should be [14]).
macro expr rescale (x) = (x[35] @ x[30:14]);
+#else
+ //Macro to rescale the multiply result down to a 24-bit value.
+ macro expr rescale (x) = ((x>>FRACBITS)<-24);
+#endif
for(level=1;level<=NUMBER_OF_COLUMNS;level++) // count all the columns
{
e=1<<(NUMBER_OF_COLUMNS-level+1); // number of points in each block in this column
- f=(e>>1)<-8; // number of butterflies in each block in this column
+ f=(e>>1)<-8; // number of butterflies in each block in this column
for(j=1;j<=f;j++) // count all the butterflies in each block
{
@@ -281,9 +275,9 @@ void perform_fft(signed 16 *pcm_audio)
/********************************************************************/
#if HARDWARE_MULTIPLY
-void perform_ifft(signed 18 *modified_audio/*, unsigned 6 *ifft_info*/)
+void perform_ifft(signed 18 *modified_audio, signed 6 *ifft_info)
#else
-void perform_ifft(signed 16 *modified_audio/*, unsigned 6 *ifft_info*/)
+void perform_ifft(signed 16 *modified_audio, signed 6 *ifft_info)
#endif
{
unsigned 6 k;
@@ -330,51 +324,48 @@ void perform_ifft(signed 16 *modified_audio/*, unsigned 6 *ifft_info*/)
#else
modified_audio[k] = (p<-16);
#endif
- //ifft_info[k] = (unsigned)(p[15:10]);
+ ifft_info[k] = (p[17:12]);
k++;
}
} while(k);
}
/********************************************************************/
-void equalize_audio(unsigned 4 *eq_level, unsigned 7 *fft_info)
+void equalize_audio(audiodata_t *audiodata)
{
-#if 1
#if HARDWARE_MULTIPLY
signed 18 p,q;
#else
signed 24 p,q;
#endif
- signed 16 a;
+ signed 18 a;
unsigned 8 i, mirror_i, bit, m, n;
unsigned 7 old_value;
unsigned 9 tmp;
//macro expr equalize_bar = multiply(q,a)[29:6];
- macro proc equalize_bar(result)
+ macro proc equalize_bar(retval)
{
signed result;
multiply(result, q,a);
#if HARDWARE_MULTIPLY
- result = result[29:12];
+ retval = result[23:6]; //drop last 6 bit to compensate the maximum multiplication with 64 from the eq_settings array
#else
- result = result[29:6];
+ retval = result[29:6]; //drop last 6 bit to compensate the maximum multiplication with 64 from the eq_settings array
#endif
}
-#if HARDWARE_MULTIPLY
- p = real.read[0] - 10;
-#else
+
p = real.read[0] - DC_COMPONENT; // remove DC component for calculations
-#endif
real.rwrite[0] = p;
// imaginary.rwrite[0] = 0; // remove DC component
- for(i=0;i<=NUMBER_OF_FREQUENCIES;i++)
+ for(i=0;i!=NUMBER_OF_FREQUENCIES;i++)
{
- // set multiplication factor (0..64) for current frequency bar
- a = adjs(eq_settings[eq_level[i<-7]],16);
+ // 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.write[0 @ (i <- 7)]],18);
+
// multiply frequency with this factor and divide by 64 (drop 6 LSB's)
q = real.read[i];
@@ -409,46 +400,42 @@ void equalize_audio(unsigned 4 *eq_level, unsigned 7 *fft_info)
if (p[17] == 1) p = -p; else delay;
if (q[17] == 1) q = -q; else delay;
#else
- if (p[17] == 1) p = -p; else delay;
- if (q[17] == 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 (display_log)
+ if (audiodata->display_log)
{
bit=126;
#if HARDWARE_MULTIPLY
while ((p[15] == 0) && (bit != 0))
#else
- while ((p[15] == 0) && (bit != 0))
+ while ((p[21] == 0) && (bit != 0))
#endif
par
{
p = p<<1;
bit = bit - 18;
}
- old_value = fft_info[i<-7];
+ old_value = audiodata->fft_info.write[0 @ (i <- 7)];
tmp = ((0@old_value) + (0@bit))>>1;
- fft_info[i<-7] = (old_value <= (tmp<-7)) ? (tmp<-7) : old_value-1;
+ audiodata->fft_info.write[0 @ (i <- 7)] = (old_value <= (tmp<-7)) ? (tmp<-7) : old_value-1;
}
else
{
- old_value = fft_info[i<-7];
+ old_value = audiodata->fft_info.write[0 @ (i <- 7)];
#if HARDWARE_MULTIPLY
- fft_info[i<-7] = (old_value<=(unsigned)(p[15:9])) ? (unsigned)(p[15:9]) : old_value-1;
+ audiodata->fft_info.write[0 @ (i <- 7)] = (old_value<=(unsigned)(p[15:9])) ? (unsigned)(p[15:9]) : old_value-1;
#else
- fft_info[i<-7] = (old_value<=(unsigned)(p[21:15])) ? (unsigned)(p[21:15]) : old_value-1;
+ audiodata->fft_info.write[0 @ (i <- 7)] = (old_value<=(unsigned)(p[21:15])) ? (unsigned)(p[21:15]) : old_value-1;
#endif
}
}
// add DC component again before inverse FFT calculation is performed
-#if HARDWARE_MULTIPLY
- p = real.read[0] +10;// + DC_COMPONENT;
-#else
+
p = real.read[0] + DC_COMPONENT;
-#endif
real.rwrite[0] = p;
-#endif
}