Main Page | Data Structures | Directories | File List | Data Fields | Globals

runfft.hcc

Go to the documentation of this file.
00001 
00020 #include <stdlib.hch>
00021 #include "pal_master.hch"
00022 
00023 #include "configuration.hch"
00024 #if USE_RUNFFT
00025 #include "audio.hch"
00026 #include "fft.hch"
00027 
00028 #if HAVE_DEBUG
00029         #include "debug.hch"
00030 #endif
00031 
00032 /*
00033  * Forward declarations
00034  */
00035 static macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE;
00036 #if HARDWARE_MULTIPLY
00037 //input buffer
00038 ram signed 18 audio_buffer_in[256] with { block = "BlockRAM"};
00039 //output buffer
00040 ram signed 18 audio_buffer_out[128] with { block = "BlockRAM"}; 
00041 #else
00042 //input buffer
00043 ram signed 16 audio_buffer_in[256] with { block = "BlockRAM"};
00044 //output buffer
00045 ram signed 16 audio_buffer_out[128] with { block = "BlockRAM"}; 
00046 #endif
00047 //EQ settings for the FFT
00048 ram unsigned 4 EQ_info[128] with { block = "BlockRAM"}; 
00049 //EQ settings received from the display
00050 
00051 
00052 #if HARDWARE_MULTIPLY
00053 signed 18 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
00054 
00055 signed 18 *audioptr_out1,*audioptr_out2;
00056 
00057 unsigned 6 *displayptr1,*displayptr2,*displayptr3,*displayptr4;
00058 #else
00059 signed 16 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;
00060 
00061 signed 16 *audioptr_out1,*audioptr_out2;
00062 
00063 unsigned 6 *displayptr1,*displayptr2,*displayptr3,*displayptr4;
00064 #endif
00065 
00076 macro proc audio_main(audiodata, AUDIOIN, AUDIOOUT)
00077 {
00078         signed 18 sample;
00079         unsigned 6 sample_count;
00080         unsigned 8 i,cycle;
00081         unsigned 4 eqinfo;
00082 
00083         unsigned 1 FFT_Sync, first;
00084         macro expr OW = PalAudioOutGetMaxDataWidthCT ();
00085         macro expr IW = PalAudioInGetMaxDataWidthCT  ();
00086         signed LeftNew, RightNew;
00087         signed Output_sample;
00088 
00089         ram unsigned 6 input[64];
00090 
00091         //pointers for double and quadruple buffering:
00092         audioptr_in1 = &audio_buffer_in[0];
00093         audioptr_in2 = &audio_buffer_in[64];
00094         audioptr_in3 = &audio_buffer_in[128];
00095         audioptr_in4 = &audio_buffer_in[192];
00096 
00097         audioptr_out1 = &audio_buffer_out[0];
00098         audioptr_out2 = &audio_buffer_out[64];
00099 
00100         displayptr1 = &audiodata.ifft_info.write[0];
00101         displayptr2 = &audiodata.ifft_info.write[64];
00102         displayptr3 = &audiodata.ifft_info.write[128];
00103         displayptr4 = &audiodata.ifft_info.write[192];
00104 
00105         FFT_Sync=0;
00106 par
00107 {
00108         for(;;)
00109         {
00110                 if (FFT_Sync)   //if 64 samples are read from ADC...
00111                 {
00112                         par
00113                         {
00114                                 // switch pointers 
00115                                 audioptr_in1 = audioptr_in2;
00116                                 audioptr_in2 = audioptr_in3;
00117                                 audioptr_in3 = audioptr_in4;
00118                                 audioptr_in4 = audioptr_in1;
00119                                 
00120                                 audioptr_out1 = audioptr_out2;
00121                                 audioptr_out2 = audioptr_out1;
00122 
00123                                 displayptr1=displayptr2;
00124                                 displayptr2=displayptr3;
00125                                 displayptr3=displayptr4;
00126                                 displayptr4=displayptr1;
00127                                 
00128                                 FFT_Sync = 0;
00129                         }
00130                 
00131                         // FFT calculation
00132                         perform_fft(audioptr_in1);
00133                         
00134 #if PERFORM_FFT_CALCULATION
00135                         equalize_audio(&audiodata);
00136 #endif
00137                         // inverse FFT calculation
00138                         perform_ifft(audioptr_out1,displayptr1);                
00139                 }
00140                 else
00141                         delay;
00142         }       
00143 
00144         for(sample_count=0;;)//store the samples in the inputbuffer
00145         {
00146                 if (!FFT_Sync)
00147                 {
00148                         par
00149                         {
00150                                 seq
00151                                 {
00152                                         PalAudioInRead(AUDIOIN, &LeftNew, &RightNew);
00153 #if HARDWARE_MULTIPLY                                   
00154                                         audioptr_in1[sample_count] = LeftNew;//drop 2 LSB's
00155 #else
00156                                         audioptr_in1[sample_count] = (LeftNew\\2);//drop 2 LSB's
00157 #endif
00158                                         sample_count++; 
00159                                         if (!sample_count) 
00160                                         {
00161                                                 FFT_Sync = 1; 
00162                                         }
00163                                 }
00164                                 seq
00165                                 {
00166                                         Output_sample = audioptr_out2[sample_count];
00167                                 }
00168                         }
00169                 }
00170                 else
00171                 {
00172                         delay;
00173                 }
00174         }
00175         for(;;)
00176         {
00177                 PalAudioOutWrite(AUDIOOUT,(signed OW)(Output_sample @ 0),(signed OW)(Output_sample @ 0));
00178         }
00179 }//end par
00180 }// end function
00181 #endif
00182 

Generated on Thu Dec 9 14:37:07 2004 for Graphic Equalizer 2 by  doxygen 1.3.9.1