diff options
-rw-r--r-- | Graphic_Equalizer/Graphic_Equalizer.hp | 12 | ||||
-rw-r--r-- | Graphic_Equalizer/Graphic_Equalizer.pref | 91 | ||||
-rw-r--r-- | Graphic_Equalizer/include/audio.hch | 9 | ||||
-rw-r--r-- | Graphic_Equalizer/include/configuration.hch | 22 | ||||
-rw-r--r-- | Graphic_Equalizer/include/fft.hch | 6 | ||||
-rw-r--r-- | Graphic_Equalizer/include/runfft.hch | 1 | ||||
-rw-r--r-- | Graphic_Equalizer/include/weights_256.hch | 264 | ||||
-rw-r--r-- | Graphic_Equalizer/src/audio.hcc | 5 | ||||
-rw-r--r-- | Graphic_Equalizer/src/display.hcc | 2 | ||||
-rw-r--r-- | Graphic_Equalizer/src/eventhandler.hcc | 11 | ||||
-rw-r--r-- | Graphic_Equalizer/src/fft.hcc | 93 | ||||
-rw-r--r-- | Graphic_Equalizer/src/main.hcc | 5 | ||||
-rw-r--r-- | Graphic_Equalizer/src/runfft.hcc | 222 | ||||
-rw-r--r-- | Graphic_Equalizer/src/smartmedia.hcc | 2 |
14 files changed, 632 insertions, 113 deletions
diff --git a/Graphic_Equalizer/Graphic_Equalizer.hp b/Graphic_Equalizer/Graphic_Equalizer.hp index 15bc63f..35f658c 100644 --- a/Graphic_Equalizer/Graphic_Equalizer.hp +++ b/Graphic_Equalizer/Graphic_Equalizer.hp @@ -109,6 +109,9 @@ document include\\eventhandler.hch { document include\\eventhandler_shared.hch {
type hch
}
+document include\\fft.hch {
+ type hch
+}
document include\\mouse.hch {
type hch
}
@@ -118,6 +121,9 @@ document include\\mouse_shared.hch { document include\\smartmedia.hch {
type hch
}
+document include\\weights_256.hch {
+ type hch
+}
document src\\audio.hcc {
type hcc
}
@@ -127,6 +133,9 @@ document src\\display.hcc { document src\\eventhandler.hcc {
type hcc
}
+document src\\fft.hcc {
+ type hcc
+}
document src\\main.hcc {
type hcc
}
@@ -142,3 +151,6 @@ document ..\\support_libs\\debug\\debug.hcc { document ..\\support_libs\\debug\\debug.hch {
type hch
}
+document src\\runfft.hcc {
+ type hcc
+}
diff --git a/Graphic_Equalizer/Graphic_Equalizer.pref b/Graphic_Equalizer/Graphic_Equalizer.pref index 0bdcac0..dd53c28 100644 --- a/Graphic_Equalizer/Graphic_Equalizer.pref +++ b/Graphic_Equalizer/Graphic_Equalizer.pref @@ -38,30 +38,6 @@ DocumentString= DocTemplateIndex=5
WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPCEAAAAAACEAAAAAAPNCAAAAAFCBAAAAA
IsActiveChildFrame=False
-[WorkState_v1_2.Frames.ChildFrames.Document-3]
-ptn_Child1=ViewFrame-0
-[WorkState_v1_2.Frames.ChildFrames.Document-3.ViewFrame-0]
-DocPathName=C:\Project_CVS\support_libs\debug\debug.hcc
-DocumentString=
-DocTemplateIndex=4
-WindowPlacement=MCAAAAAACAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPGBAAAAAAGBAAAAAAHICAAAAANCBAAAAA
-IsActiveChildFrame=True
-[WorkState_v1_2.Frames.ChildFrames.Document-4]
-ptn_Child1=ViewFrame-0
-[WorkState_v1_2.Frames.ChildFrames.Document-4.ViewFrame-0]
-DocPathName=C:\Project_CVS\Graphic_Equalizer\include\mouse.hch
-DocumentString=
-DocTemplateIndex=5
-WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPMCAAAAAAMCAAAAAANJCAAAAADEBAAAAA
-IsActiveChildFrame=False
-[WorkState_v1_2.Frames.ChildFrames.Document-5]
-ptn_Child1=ViewFrame-0
-[WorkState_v1_2.Frames.ChildFrames.Document-5.ViewFrame-0]
-DocPathName=C:\Project_CVS\Graphic_Equalizer\include\mouse_shared.hch
-DocumentString=
-DocTemplateIndex=5
-WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPCEAAAAAACEAAAAAADLCAAAAAJFBAAAAA
-IsActiveChildFrame=False
[WorkState_v1_2.Frames.ChildFrames.Document-6]
ptn_Child1=ViewFrame-0
[WorkState_v1_2.Frames.ChildFrames.Document-6.ViewFrame-0]
@@ -78,37 +54,68 @@ DocumentString= DocTemplateIndex=5
WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPAAAAAAAAAAAAAAAABHCAAAAAHBBAAAAA
IsActiveChildFrame=False
+[WorkState_v1_2]
+ptn_Child1=Frames
+ptn_Child2=DK Design Suite Preferences
+ptn_Child3=Breakpoints
+ptn_Child4=WatchVars
+[WorkState_v1_2.Frames]
+ptn_Child1=ChildFrames
+[WorkState_v1_2.Frames.ChildFrames]
+ptn_Child1=Document-0
+ptn_Child2=Document-1
+ptn_Child3=Document-2
+ptn_Child4=Document-3
+ptn_Child5=Document-4
+ptn_Child6=Document-5
+[WorkState_v1_2.Frames.ChildFrames.Document-0]
+ptn_Child1=ViewFrame-0
+[WorkState_v1_2.Frames.ChildFrames.Document-0.ViewFrame-0]
+DocPathName=C:\Project_CVS\Graphic_Equalizer\src\fft.hcc
+DocumentString=
+DocTemplateIndex=4
+WindowPlacement=MCAAAAAACAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPEIAAAAAAEIAAAAAALOCAAAAAGJBAAAAA
+IsActiveChildFrame=True
[WorkState_v1_2.Frames.ChildFrames.Document-1]
ptn_Child1=ViewFrame-0
[WorkState_v1_2.Frames.ChildFrames.Document-1.ViewFrame-0]
-DocPathName=C:\project_cvs\graphic_equalizer\src\display.hcc
+DocPathName=C:\project_cvs\graphic_equalizer\src\main.hcc
DocumentString=
DocTemplateIndex=4
-WindowPlacement=MCAAAAAACAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPGBAAAAAAGBAAAAAABICAAAAAMCBAAAAA
-IsActiveChildFrame=True
+WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPMCAAAAAAMCAAAAAAHJCAAAAACEBAAAAA
+IsActiveChildFrame=False
[WorkState_v1_2.Frames.ChildFrames.Document-2]
ptn_Child1=ViewFrame-0
[WorkState_v1_2.Frames.ChildFrames.Document-2.ViewFrame-0]
-DocPathName=C:\Project_CVS\Graphic_Equalizer\include\audio.hch
+DocPathName=C:\project_cvs\graphic_equalizer\src\display.hcc
DocumentString=
-DocTemplateIndex=5
-WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPEIAAAAAAEIAAAAAALOCAAAAAGJBAAAAA
+DocTemplateIndex=4
+WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPOGAAAAAAOGAAAAAAJNCAAAAAEIBAAAAA
IsActiveChildFrame=False
-[WorkState_v1_2.Frames.ChildFrames.Document-0]
+[WorkState_v1_2.Frames.ChildFrames.Document-3]
ptn_Child1=ViewFrame-0
-[WorkState_v1_2.Frames.ChildFrames.Document-0.ViewFrame-0]
-DocPathName=C:\Project_CVS\Graphic_Equalizer\src\eventhandler.hcc
+[WorkState_v1_2.Frames.ChildFrames.Document-3.ViewFrame-0]
+DocPathName=C:\project_cvs\graphic_equalizer\src\runfft.hcc
DocumentString=
DocTemplateIndex=4
-WindowPlacement=MCAAAAAACAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPOGAAAAAAOGAAAAAAFNCAAAAAAIBAAAAA
-IsActiveChildFrame=True
-[WorkState_v1_2]
-ptn_Child1=Frames
-ptn_Child2=DK Design Suite Preferences
-ptn_Child3=Breakpoints
-ptn_Child4=WatchVars
-[WorkState_v1_2.Frames]
-ptn_Child1=ChildFrames
+WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPEIAAAAAAEIAAAAAAPOCAAAAAKJBAAAAA
+IsActiveChildFrame=False
+[WorkState_v1_2.Frames.ChildFrames.Document-4]
+ptn_Child1=ViewFrame-0
+[WorkState_v1_2.Frames.ChildFrames.Document-4.ViewFrame-0]
+DocPathName=C:\Project_CVS\Graphic_Equalizer\include\configuration.hch
+DocumentString=
+DocTemplateIndex=5
+WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPAAAAAAAAAAAAAAAALGCAAAAAGBBAAAAA
+IsActiveChildFrame=False
+[WorkState_v1_2.Frames.ChildFrames.Document-5]
+ptn_Child1=ViewFrame-0
+[WorkState_v1_2.Frames.ChildFrames.Document-5.ViewFrame-0]
+DocPathName=C:\project_cvs\graphic_equalizer\include\fft.hch
+DocumentString=
+DocTemplateIndex=5
+WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPMPPPPPPPJOPPPPPPGBAAAAAAGBAAAAAABICAAAAAMCBAAAAA
+IsActiveChildFrame=False
[WorkState_v1_2.DK Design Suite Preferences]
Active Project Index=0
Active Configuration Index=3
diff --git a/Graphic_Equalizer/include/audio.hch b/Graphic_Equalizer/include/audio.hch index 79f9e9b..a09fe8d 100644 --- a/Graphic_Equalizer/include/audio.hch +++ b/Graphic_Equalizer/include/audio.hch @@ -28,15 +28,16 @@ typedef struct { rom unsigned 7 read[256];
} fft_info with { block = "BlockRAM"};
mpram {
- ram unsigned 6 write[256];
- rom unsigned 6 read[256];
+ ram signed 6 write[256];
+ rom signed 6 read[256];
} ifft_info with { block = "BlockRAM"};
mpram {
ram unsigned 4 write[768];
rom unsigned 4 read[768];
} equalizer_levels with { block = "BlockRAM"};
unsigned 10 active_preset;
- unsigned 1 log;
+ unsigned 4 *equalizer_levels_ptr;
+ unsigned 1 display_log;
} audiodata_t;
@@ -83,7 +84,7 @@ macro proc audio_init(gain_level, input_source, sample_rate, AUDIOIN, AUDIOOUT); * Main audiodriver loop. This procedure never returns! It handles audio io and
* updates the shared memory. It needs Audio I/O handlers passed.
*/
-macro proc audio_main(AUDIOIN, AUDIOOUT);
+macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT);
#else
#error "ERROR file audio.hch multiple times included"
diff --git a/Graphic_Equalizer/include/configuration.hch b/Graphic_Equalizer/include/configuration.hch index 3984404..a92fb7c 100644 --- a/Graphic_Equalizer/include/configuration.hch +++ b/Graphic_Equalizer/include/configuration.hch @@ -33,7 +33,7 @@ * 1. 0 will load all bitmaps.
*/
#define HAVE_SMARTMEDIA 0
-#define USE_MASK_ONLY 1
+#define USE_MASK_ONLY 0
#define SKIP_LOAD 1
@@ -100,6 +100,26 @@ #define PIXEL_VOLUME_YAXIS (0x0000ff)
#define PIXEL_EQUALIZER (0xff0000)
+
+
+/*
+ * FFT specific. TODO: Clean Up!
+ */
+#define USE_RUNFFT 1
+#define HARDWARE_MULTIPLY 1
+#define NUMBER_OF_COLUMNS 8
+#define NUMBER_OF_POINTS (1<<NUMBER_OF_COLUMNS)
+#define NUMBER_OF_FREQUENCIES (NUMBER_OF_POINTS>>1)
+#define PERFORM_FFT_CALCULATION 1
+#define USE_UNSIGNED_AUDIO 0
+#define PRINT_DEBUG 0
+
+#if HARDWARE_MULTIPLY
+#define DC_COMPONENT 0
+#else
+#define DC_COMPONENT 8470527
+#endif
+
#else
#error "ERROR file configuration.hch multiple times included"
#endif /* --- _CONFIGURATION_HCH --- */
diff --git a/Graphic_Equalizer/include/fft.hch b/Graphic_Equalizer/include/fft.hch index 6bcc8cc..bc812d5 100644 --- a/Graphic_Equalizer/include/fft.hch +++ b/Graphic_Equalizer/include/fft.hch @@ -1,8 +1,8 @@ #if HARDWARE_MULTIPLY
void perform_fft(signed 18 *pcm_audio);
-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_fft(signed 16 *pcm_audio);
-void perform_ifft(signed 16 *modified_audio /*,unsigned 6 *ifft_info*/);
+void perform_ifft(signed 16 *modified_audio ,signed 6 *ifft_info);
#endif
-void equalize_audio(unsigned 4 *eq_level, unsigned 7 *fft_info);
+void equalize_audio(audiodata_t *audiodata);
diff --git a/Graphic_Equalizer/include/runfft.hch b/Graphic_Equalizer/include/runfft.hch new file mode 100644 index 0000000..d6f6ce0 --- /dev/null +++ b/Graphic_Equalizer/include/runfft.hch @@ -0,0 +1 @@ +extern macro proc RunFFT (AudioIn, AudioOut);
diff --git a/Graphic_Equalizer/include/weights_256.hch b/Graphic_Equalizer/include/weights_256.hch new file mode 100644 index 0000000..b2b2377 --- /dev/null +++ b/Graphic_Equalizer/include/weights_256.hch @@ -0,0 +1,264 @@ +#define INTBITS 1 +#define FRACBITS 14 + +ram signed 16 weight_re[128] = { + 16384, + 16379, + 16364, + 16340, + 16305, + 16261, + 16207, + 16143, + 16069, + 15986, + 15893, + 15791, + 15679, + 15557, + 15426, + 15286, + 15137, + 14978, + 14811, + 14635, + 14449, + 14256, + 14053, + 13842, + 13623, + 13395, + 13160, + 12916, + 12665, + 12406, + 12140, + 11866, + 11585, + 11297, + 11003, + 10702, + 10394, + 10080, + 9760, + 9434, + 9102, + 8765, + 8423, + 8076, + 7723, + 7366, + 7005, + 6639, + 6270, + 5897, + 5520, + 5139, + 4756, + 4370, + 3981, + 3590, + 3196, + 2801, + 2404, + 2006, + 1606, + 1205, + 804, + 402, + 0, + -402, + -804, + -1205, + -1606, + -2006, + -2404, + -2801, + -3196, + -3590, + -3981, + -4370, + -4756, + -5139, + -5520, + -5897, + -6270, + -6639, + -7005, + -7366, + -7723, + -8076, + -8423, + -8765, + -9102, + -9434, + -9760, + -10080, + -10394, + -10702, + -11003, + -11297, + -11585, + -11866, + -12140, + -12406, + -12665, + -12916, + -13160, + -13395, + -13623, + -13842, + -14053, + -14256, + -14449, + -14635, + -14811, + -14978, + -15137, + -15286, + -15426, + -15557, + -15679, + -15791, + -15893, + -15986, + -16069, + -16143, + -16207, + -16261, + -16305, + -16340, + -16364, + -16379 +} with {block = "BlockRAM"}; + +ram signed 16 weight_im[128] = { + 0, + -402, + -804, + -1205, + -1606, + -2006, + -2404, + -2801, + -3196, + -3590, + -3981, + -4370, + -4756, + -5139, + -5520, + -5897, + -6270, + -6639, + -7005, + -7366, + -7723, + -8076, + -8423, + -8765, + -9102, + -9434, + -9760, + -10080, + -10394, + -10702, + -11003, + -11297, + -11585, + -11866, + -12140, + -12406, + -12665, + -12916, + -13160, + -13395, + -13623, + -13842, + -14053, + -14256, + -14449, + -14635, + -14811, + -14978, + -15137, + -15286, + -15426, + -15557, + -15679, + -15791, + -15893, + -15986, + -16069, + -16143, + -16207, + -16261, + -16305, + -16340, + -16364, + -16379, + -16384, + -16379, + -16364, + -16340, + -16305, + -16261, + -16207, + -16143, + -16069, + -15986, + -15893, + -15791, + -15679, + -15557, + -15426, + -15286, + -15137, + -14978, + -14811, + -14635, + -14449, + -14256, + -14053, + -13842, + -13623, + -13395, + -13160, + -12916, + -12665, + -12406, + -12140, + -11866, + -11585, + -11297, + -11003, + -10702, + -10394, + -10080, + -9760, + -9434, + -9102, + -8765, + -8423, + -8076, + -7723, + -7366, + -7005, + -6639, + -6270, + -5897, + -5520, + -5139, + -4756, + -4370, + -3981, + -3590, + -3196, + -2801, + -2404, + -2006, + -1606, + -1205, + -804, + -402, +} with {block = "BlockRAM"}; diff --git a/Graphic_Equalizer/src/audio.hcc b/Graphic_Equalizer/src/audio.hcc index b38805b..bc84ce0 100644 --- a/Graphic_Equalizer/src/audio.hcc +++ b/Graphic_Equalizer/src/audio.hcc @@ -56,7 +56,7 @@ macro proc audio_init(gain_level, input_source, sample_rate, AUDIOIN, AUDIOOUT) } /* --- audio_init() --- */
-
+#if !USE_RUNFFT
/*! \fn void audio_main(AUDIOIN, AUDIOOUT);
*
* \brief Main audiodriver. This function never returns! It calls the
@@ -71,7 +71,7 @@ macro proc audio_init(gain_level, input_source, sample_rate, AUDIOIN, AUDIOOUT) * \return Never Returns.
* \retval void
*/
-macro proc audio_main(AUDIOIN, AUDIOOUT) {
+macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT) {
/*
* Determin the data width for the current platform.
*/
@@ -97,3 +97,4 @@ macro proc audio_main(AUDIOIN, AUDIOOUT) { */ PalAudioOutWrite(AUDIOOUT, (signed OW)(sample_left_in @ 0), (signed OW)(sample_right_in @ 0));
}
} /* --- audio_main() --- */
+#endif
diff --git a/Graphic_Equalizer/src/display.hcc b/Graphic_Equalizer/src/display.hcc index 9625506..2238c1d 100644 --- a/Graphic_Equalizer/src/display.hcc +++ b/Graphic_Equalizer/src/display.hcc @@ -141,7 +141,7 @@ macro proc display_main(audiodata, events, mousedata, CLOCKRATE, VIDEOOUT, RAM_B break;
case BUTTON_LOG:
- draw_button((0 @ audiodata.log) +BUTTON_LOG);
+ draw_button((0 @ audiodata.display_log) +BUTTON_LOG);
break;
default:
diff --git a/Graphic_Equalizer/src/eventhandler.hcc b/Graphic_Equalizer/src/eventhandler.hcc index 1ec8468..6194a77 100644 --- a/Graphic_Equalizer/src/eventhandler.hcc +++ b/Graphic_Equalizer/src/eventhandler.hcc @@ -47,6 +47,7 @@ extern chan unsigned 1 maskupdate_notification; * \retval void
*/
void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mousedata) {
+ unsigned 10 preset_offset;
unsigned 8 equalizer_bands;
unsigned 5 volume_left;
unsigned 1 newmaskupdate;
@@ -55,6 +56,10 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo maskupdate_notification ? newmaskupdate;
/*
+ */
+ preset_offset = 0 @ events->mask -AREA_EQUALIZER_MIN;
+
+ /*
* First we determine what mousestate we currently have. Then
* we check where we are to decide what to do.
*/
@@ -86,7 +91,7 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo }
if (BUTTON_LOG == events->mask) {
- audiodata->log = !audiodata->log;
+ audiodata->display_log = !audiodata->display_log;
} else {
delay;
}
@@ -132,7 +137,7 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo * The index is determined by the mask
* minus the maskoffset.
*/
- events->equalizer_position[(events->mask -AREA_EQUALIZER_MIN) <- 7] = mousedata->y;
+ events->equalizer_position[preset_offset <- 7] = mousedata->y;
/*
* We look our current possition up in
* the lookup table. We determin our
@@ -147,7 +152,7 @@ void eventhandler_main(audiodata_t *audiodata, events_t *events, mousedata_t *mo * TODO: lock equalizer store with a
* semaphore!
*/
- audiodata->equalizer_levels.write[(( 0 @ events->mask -AREA_EQUALIZER_MIN) +(audiodata->active_preset << 7))] = equalizer_table[((mousedata->y) -382) <- 7];
+ audiodata->equalizer_levels.write[(preset_offset +(audiodata->active_preset << 7))] = equalizer_table[((mousedata->y) -382) <- 7];
} else {
delay;
}
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
}
diff --git a/Graphic_Equalizer/src/main.hcc b/Graphic_Equalizer/src/main.hcc index 1afcd1d..b460a0e 100644 --- a/Graphic_Equalizer/src/main.hcc +++ b/Graphic_Equalizer/src/main.hcc @@ -35,7 +35,6 @@ #include "display.hch"
#include "smartmedia.hch"
-#include "config.hch"
#include "fft.hch"
#include "runfft.hch"
@@ -136,7 +135,7 @@ void main(void) { * data folowed by our main program loop.
*/
result = smartmedia_init();
- if (0 == result) {
+ if (!result) {
#endif
#if HAVE_DEBUG
print_string("Loading Skin ...");
@@ -162,7 +161,7 @@ void main(void) { mouse_main(mousedata);
display_main(audiodata, events, mousedata, ClockRate, VideoOut, RAM_BANK0);
eventhandler_main(&audiodata, &events, &mousedata);
- audio_main(AudioIn, AudioOut);
+ audio_main(audiodata, AudioIn, AudioOut);
}
#if HAVE_SMARTMEDIA
} else {
diff --git a/Graphic_Equalizer/src/runfft.hcc b/Graphic_Equalizer/src/runfft.hcc new file mode 100644 index 0000000..02642cc --- /dev/null +++ b/Graphic_Equalizer/src/runfft.hcc @@ -0,0 +1,222 @@ +/****************************************************************
+* *
+* 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 "configuration.hch"
+#if USE_RUNFFT
+#include "audio.hch"
+#include "fft.hch"
+
+#include "presets.hch"
+#include "debug.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
+
+
+#if HARDWARE_MULTIPLY
+signed 18 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
+
+signed 18 *audioptr_out1,*audioptr_out2;
+
+signed 6 *displayptr1,*displayptr2,*displayptr3,*displayptr4;
+#else
+signed 16 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
+
+signed 16 *audioptr_out1,*audioptr_out2;
+
+#endif
+
+void LoadPresets(audiodata_t * audiodata)
+{
+ unsigned 16 temp;
+ unsigned 10 count;
+ unsigned 8 index;
+
+ count=0;
+ do
+ {
+ par
+ {
+ temp = presets[index];
+ index++;
+ }
+ par { audiodata->equalizer_levels.write[count] = temp[7:4]; count++; }
+ par { audiodata->equalizer_levels.write[count] = temp[3:0]; count++; }
+ par { audiodata->equalizer_levels.write[count] = temp[15:12]; count++; }
+ par { audiodata->equalizer_levels.write[count] = temp[11:8]; count++; }
+ } while (count<768);
+
+}
+
+/*
+ * FFT routine
+ */
+macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT)
+{
+ signed 18 sample;
+ unsigned 6 sample_count;
+ unsigned 8 i,cycle;
+ unsigned 4 eqinfo;
+
+ unsigned 1 FFT_Sync, first;
+ macro expr OW = PalAudioOutGetMaxDataWidthCT ();
+ macro expr IW = PalAudioInGetMaxDataWidthCT ();
+ signed LeftNew, RightNew;
+ signed Output_sample;
+
+ ram unsigned 6 input[64];
+
+ shared expr preset_address = (audiodata.active_preset << 7);
+
+ //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];
+
+ displayptr1 = &audiodata.ifft_info.write[0];
+ displayptr2 = &audiodata.ifft_info.write[64];
+ displayptr3 = &audiodata.ifft_info.write[128];
+ displayptr4 = &audiodata.ifft_info.write[192];
+
+ FFT_Sync=0;
+
+ LoadPresets(&audiodata);
+ first = 1;
+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;
+
+ displayptr1=displayptr2;
+ displayptr2=displayptr3;
+ displayptr3=displayptr4;
+ displayptr4=displayptr1;
+
+ FFT_Sync = 0;
+ }
+
+ // FFT calculation
+ perform_fft(audioptr_in1);
+
+#if 0
+ for(i=0;i<NUMBER_OF_FREQUENCIES;i++)
+ {
+ eqinfo = audiodata.equalizer_levels.read[preset_address+(0 @ i)];
+ EQ_info[i<-7] = eqinfo;
+ }
+
+
+ // set volume of each individual frequency bar (equalizer)
+
+#endif
+#if PERFORM_FFT_CALCULATION
+ equalize_audio(&audiodata);
+#endif
+ // inverse FFT calculation
+ perform_ifft(audioptr_out1,displayptr1);
+
+/*
+ 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
+#endif
+
diff --git a/Graphic_Equalizer/src/smartmedia.hcc b/Graphic_Equalizer/src/smartmedia.hcc index fc9ff25..5e7e250 100644 --- a/Graphic_Equalizer/src/smartmedia.hcc +++ b/Graphic_Equalizer/src/smartmedia.hcc @@ -97,7 +97,7 @@ macro proc smartmedia_loaddata(RAM_BANK0) { * Once we are done with the loading of our skin, we need to
* change the smartmedia start addresses.
*/
- if (address == ADDRESS_HELP_START) {
+ if (address == ADDRESS_SKIN_END) {
smartmedia_address = SMARTMEDIA_ADDRESS_HELP_START;
smartmedia_address_mask = SMARTMEDIA_ADDRESS_HELPMASK_START;
}
|