/*! \file runfft.hcc * * \section generic This module will handle the audio I/O. It will ensure the * audiosamples are correctly buffered and fed correctly to the FFT.\n * This module will also handle the output of the modified audio samples. * * \section project Project information. * Project Graphic Equalizer\n * \author M. Lauwerijssen * \date 20041110 * \version 0.1 * * \section copyright Copyright * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved * * \section history Change history * 20041110: M. Lauwerijssen\n Initial version * ********************************************************************/ #include #include "pal_master.hch" #include "configuration.hch" #if USE_RUNFFT #include "audio.hch" #include "fft.hch" #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 /*! \fn macro proc audio_main(AUDIOIN, AUDIOOUT); * \brief Audio I/O component main. * * \param audiodata Pointer to audiodata struct * \param AUDIOIN Handle to audio-input * \param AUDIOOUT Handle to audio-output * * \return Never Returns. * \retval void */ 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]; //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; par { /* * 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. */ 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; } /* * 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. */ 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]; } } } else { delay; } } /* * 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)); } }//end par }// end function #endif