summaryrefslogtreecommitdiffstats
path: root/FFT_Test/runfft.hcc
diff options
context:
space:
mode:
Diffstat (limited to 'FFT_Test/runfft.hcc')
-rw-r--r--FFT_Test/runfft.hcc216
1 files changed, 216 insertions, 0 deletions
diff --git a/FFT_Test/runfft.hcc b/FFT_Test/runfft.hcc
new file mode 100644
index 0000000..8f34f12
--- /dev/null
+++ b/FFT_Test/runfft.hcc
@@ -0,0 +1,216 @@
+/****************************************************************
+* *
+* Copyright (C) 1991-2003 Celoxica Ltd. All rights reserved. *
+* *
+*****************************************************************
+* *
+* Project : PAL *
+* Date : 31 JAN 2003 *
+* File : reverb.hcc *
+* Author : Matthew Aubury (MA) *
+* Contributors: *
+* *
+* Description: *
+* Simple audio reverb. *
+* *
+* Date Version Author Reason for change *
+* *
+* 29 OCT 2002 1.00 MA Created *
+* *
+****************************************************************/
+
+
+#include <stdlib.hch>
+#include "pal_master.hch"
+
+#include "config.hch"
+#include "debug.hch"
+#include "fft.hch"
+#include "runfft.hch"
+
+#include "presets.hch"
+
+/*
+ * Forward declarations
+ */
+
+static macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE;
+#if HARDWARE_MULTIPLY
+//input buffer
+ram signed 18 audio_buffer_in[256] with { block = "BlockRAM"};
+//output buffer
+ram signed 18 audio_buffer_out[128] with { block = "BlockRAM"};
+#else
+//input buffer
+ram signed 16 audio_buffer_in[256] with { block = "BlockRAM"};
+//output buffer
+ram signed 16 audio_buffer_out[128] with { block = "BlockRAM"};
+#endif
+//EQ settings for the FFT
+ram unsigned 4 EQ_info[128] with { block = "BlockRAM"};
+//EQ settings received from the display
+mpram
+{
+ ram unsigned 4 write[768];
+ rom unsigned 4 read[768];
+}EQ_level with { block = "BlockRAM"};
+
+mpram
+{
+ ram unsigned 7 write[256];
+ rom unsigned 7 read[256];
+}fft_info with { block = "BlockRAM"};
+
+#if HARDWARE_MULTIPLY
+signed 18 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
+signed 18 *audioptr_out1,*audioptr_out2;
+signed 18 *audioptr_temp;
+#else
+signed 16 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
+signed 16 *audioptr_out1,*audioptr_out2;
+signed 16 *audioptr_temp;
+#endif
+unsigned 3 active_preset;
+
+shared expr preset_address = (0@(active_preset-1))<<7;
+
+void LoadPresets()
+{
+ unsigned 16 temp;
+ unsigned 10 count;
+ unsigned 8 index;
+
+ count=0;
+ do
+ {
+ par
+ {
+ temp = presets[index];
+ index++;
+ }
+ par { EQ_level.write[count] = temp[7:4]; count++; }
+ par { EQ_level.write[count] = temp[3:0]; count++; }
+ par { EQ_level.write[count] = temp[15:12]; count++; }
+ par { EQ_level.write[count] = temp[11:8]; count++; }
+ } while (count<768);
+
+}
+
+/*
+ * FFT routine
+ */
+macro proc RunFFT (AudioIn, AudioOut)
+{
+ signed 18 sample;
+ unsigned 6 sample_count;
+ unsigned 8 i,cycle;
+ unsigned 4 eqinfo;
+
+ unsigned 1 FFT_Sync;
+ macro expr OW = PalAudioOutGetMaxDataWidthCT ();
+ macro expr IW = PalAudioInGetMaxDataWidthCT ();
+ signed LeftNew, RightNew;
+ signed Output_sample;
+
+ ram unsigned 6 input[64];
+ active_preset = 3;
+
+ //pointers for double and quadruple buffering:
+ audioptr_in1=&audio_buffer_in[0];
+ audioptr_in2=&audio_buffer_in[64];
+ audioptr_in3=&audio_buffer_in[128];
+ audioptr_in4=&audio_buffer_in[192];
+
+ audioptr_out1=&audio_buffer_out[0];
+ audioptr_out2=&audio_buffer_out[64];
+
+ FFT_Sync=0;
+
+ LoadPresets();
+
+par
+{
+ for(;;)
+ {
+ if (FFT_Sync) //if 64 samples are read from ADC...
+ {
+ par
+ {
+ // switch pointers
+ audioptr_in1 = audioptr_in2;
+ audioptr_in2 = audioptr_in3;
+ audioptr_in3 = audioptr_in4;
+ audioptr_in4 = audioptr_in1;
+
+ audioptr_out1 = audioptr_out2;
+ audioptr_out2 = audioptr_out1;
+ FFT_Sync = 0;
+ }
+
+ // FFT calculation
+ perform_fft(audioptr_in1);
+
+#if 1
+ for(i=0;i<NUMBER_OF_FREQUENCIES;i++)
+ {
+ eqinfo = EQ_level.read[preset_address+(0@i)];
+ EQ_info[i<-7] = 1;//eqinfo;
+ }
+
+ // set volume of each individual frequency bar (equalizer)
+ equalize_audio(&EQ_info[0], &fft_info.write[0]);
+
+#endif // inverse FFT calculation
+ perform_ifft(audioptr_out1);
+
+/*
+ for (i = 0; i != 64; i++)
+ {
+ sample = audioptr_in1[i];
+ audioptr_out1[i] = sample;
+ }
+*/
+ }
+ else
+ delay;
+ }
+
+ for(sample_count=0;;)//store the samples in the inputbuffer
+ {
+ if (!FFT_Sync)
+ {
+ par
+ {
+ seq
+ {
+ PalAudioInRead(AudioIn, &LeftNew, &RightNew);
+#if HARDWARE_MULTIPLY
+ audioptr_in1[sample_count] = LeftNew;//drop 2 LSB's
+#else
+ audioptr_in1[sample_count] = (LeftNew\\2);//drop 2 LSB's
+#endif
+ sample_count++;
+ if (!sample_count)
+ {
+ FFT_Sync = 1;
+ }
+ }
+ seq
+ {
+ Output_sample = audioptr_out2[sample_count];
+ }
+ }
+ }
+ else
+ {
+ delay;
+ }
+ }
+ for(;;)
+ {
+ PalAudioOutWrite(AudioOut,(signed OW)(Output_sample @ 0),(signed OW)(Output_sample @ 0));
+ }
+}//end par
+}// end function
+
+