summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer
diff options
context:
space:
mode:
authorMarcel Lauwerijssen <paranoya@morphcore.com>2005-01-06 14:41:00 (GMT)
committerMarcel Lauwerijssen <paranoya@morphcore.com>2005-01-06 14:41:00 (GMT)
commit269b93dc65ce1df8061b1b9056da3bb68ee3d544 (patch)
tree1524ef6ffc80fb51b35e92962eb4edaf24b90b7a /Graphic_Equalizer
parent53f0c4a0e0eef8e6f41252521f0183fbf8f177e7 (diff)
downloadTASS-269b93dc65ce1df8061b1b9056da3bb68ee3d544.zip
TASS-269b93dc65ce1df8061b1b9056da3bb68ee3d544.tar.gz
TASS-269b93dc65ce1df8061b1b9056da3bb68ee3d544.tar.bz2
merged runfft into audio.hcc
Diffstat (limited to 'Graphic_Equalizer')
-rw-r--r--Graphic_Equalizer/src/audio.hcc229
1 files changed, 208 insertions, 21 deletions
diff --git a/Graphic_Equalizer/src/audio.hcc b/Graphic_Equalizer/src/audio.hcc
index 2cf0edc..b461812 100644
--- a/Graphic_Equalizer/src/audio.hcc
+++ b/Graphic_Equalizer/src/audio.hcc
@@ -15,17 +15,55 @@
* 20041011: \n Initial version
*
********************************************************************/
-
-/******** System Includes *************/
#include <stdlib.hch>
-
#include "pal_master.hch"
-/******** Application Includes ********/
#include "configuration.hch"
+#if USE_RUNFFT
#include "audio.hch"
+#include "fft.hch"
+#endif
+#if HAVE_DEBUG
+ #include "debug.hch"
+#endif
+
+/*
+ * 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;
+unsigned 6 *displayptr1,*displayptr2,*displayptr3,*displayptr4;
+#else
+signed 16 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
+signed 16 *audioptr_out1,*audioptr_out2;
+
+unsigned 6 *displayptr1,*displayptr2,*displayptr3,*displayptr4;
+#endif
+
+unsigned 6 sample_count;
+unsigned 1 FFT_Sync;
+signed Output_sample;
/*! \fn macro proc audio_init(gain_level, input_source, sample_rate, AUDIOIN, AUDIOOUT)
*
@@ -56,14 +94,10 @@ macro proc audio_init(input_source, sample_rate, AUDIOIN, AUDIOOUT) {
#if !USE_RUNFFT
-//TODO: put runfft here!
/*! @fn macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT);
*
- * @brief Main audiodriver. This function never returns! It calls the
- * audiohandlers and stores samples into a global array. Once 64
- * Samples are collected it raises a signal AUDIO_READY to let
- * other processes know it's ready. We use quadruple buffering for
- * audio input and double buffering for audio output.
+ * @brief Main audiodriver. This function never returns! It copies the audio
+ * input directly to the audio output
*
* @param *audiodata pointer to audio information structure.
* @param AUDIOIN Audio Input Handler
@@ -84,18 +118,171 @@ macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT) {
while (TRUE) {
PalAudioInRead(AUDIOIN, &sample_left_in, &sample_right_in);
+ PalAudioOutWrite(AUDIOOUT, (signed OW)(sample_left_in @ 0), (signed OW)(sample_right_in @ 0));
+ }
+} /* --- audio_main() --- */
+#else
+
+/*! @fn macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT);
+ *
+ * @brief Main audiodriver. This function never returns! It calls the
+ * audiohandlers and stores samples into a global array. Once 64
+ * Samples are collected it raises a signal AUDIO_READY to let
+ * other processes know it's ready. We use quadruple buffering for
+ * audio input and double buffering for audio output.
+ *
+ * @param audiodata pointer to audio information structure.
+ * @param AUDIOIN Audio Input Handler
+ * @param AUDIOOUT Audio Output Handler
+ *
+ * @return Never Returns.
+ * @retval void
+ */
+macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT)
+{
+ //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];
-/* par {
- sample_add(sample_left_in);
- sample_get(&sample_left_out);
- sample_right_out = sample_right_in;
+ FFT_Sync=0;
+ par
+ {
+ runfft(audiodata);
+ sample_audio(AUDIOOIN);
+ output_audio(AUDIOOOUT);
+ }//end par
+} /* --- audio_main() --- */
+#endif
+
+/*! @fn macro proc run_fft(audiodata);
+ *
+ * @brief FFT loop, waits until 64 samples are read from the audio input
+ * before switching the pointers needed for double and quadruple buffering,
+ * after that sequentially calling the perform_fft, equalize_audio and
+ * perform_ifft functions.
+ *
+ * @param audiodata pointer to audio information structure.
+ *
+ * @return Never Returns.
+ * @retval void
+ */
+macro proc run_fft(audiodata)
+{
+
+ 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 PERFORM_FFT_CALCULATION
+ equalize_audio(&audiodata);
+#endif
+ // inverse FFT calculation
+ perform_ifft(audioptr_out1,displayptr1);
+ }
+ else
+ delay;
+ }
+} /* --- run_fft() --- */
+
+/*! @fn macro proc sample_audio(ADUIOIN);
+ *
+ * @brief Sampling loop, fills the audio input and output arrays and uses FFT_Sync
+ * to notify the FFT when 64 samples are read from the audio input.
+ *
+ * @param audiodata pointer to audio information structure.
+ *
+ * @return Never Returns.
+ * @retval void
+ */
+macro proc sample_audio(AUDIOOIN)
+{
+ macro expr IW = PalAudioInGetMaxDataWidthCT();
+ signed LeftNew, RightNew;
+
+ 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;
+#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];
+ }
+ }
}
- if (rotate_samples()) {
- / *
- * 64 Samples have been processed, calculate.
- * /
+ else
+ {
+ delay;
}
-*/ PalAudioOutWrite(AUDIOOUT, (signed OW)(sample_left_in @ 0), (signed OW)(sample_right_in @ 0));
}
-} /* --- audio_main() --- */
-#endif
+}/* --- sample_audio() --- */
+
+/*! @fn macro proc output_audio(ADUIOOUT);
+ *
+ * @brief Sampling loop, fills the audio input and output arrays and uses FFT_Sync
+ * to notify the FFT when 64 samples are read from the audio input.
+ *
+ * @param audiodata pointer to audio information structure.
+ *
+ * @return Never Returns.
+ * @retval void
+ */
+macro proc output_audio(AUDIOOUT)
+{
+ /*
+ * Audio output loop, writes the modified audio samples to the audio output.
+ */
+ for(;;)
+ {
+ PalAudioOutWrite(AUDIOOUT,(signed OW)(Output_sample @ 0),(signed OW)(Output_sample @ 0));
+ }
+}/* --- output_audio() --- */
+
+