/**************************************************************** * * * 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 * * * ****************************************************************/ #define PAL_TARGET_CLOCK_RATE 25175000 #include #include "pal_master.hch" #include "debug.hch" #include "fft.hch" #include "presets.hch" #include "config.hch" /* * Forward declarations */ static macro proc RunFFT (AudioIn, AudioOut); static macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE; //input buffer ram signed 16 audio_buffer_in[256] with { block = "BlockRAM"}; //output buffer ram signed 16 audio_buffer_out[128] with { block = "BlockRAM"}; //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"}; signed 16 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4; signed 16 *audioptr_out1,*audioptr_out2; signed 16 *audioptr_temp; unsigned 3 active_preset; shared expr preset_address = (0@(active_preset-1))<<7; /* * Main program */ void main(void) { macro expr AudioIn = PalAudioInCT (0); macro expr AudioOut = PalAudioOutCT (0); /* * Check we've got everything we need */ PalVersionRequire (1, 2); PalAudioInRequire (1); PalAudioOutRequire (1); PalDataPortRequire (1); /* * Run */ par { PalAudioInRun (AudioIn, ClockRate); PalAudioOutRun (AudioOut, ClockRate); PalDataPortRun (PalRS232PortCT(0), PAL_ACTUAL_CLOCK_RATE ); seq { par { PalAudioInEnable (AudioIn); PalAudioOutEnable (AudioOut); PalDataPortEnable (PalRS232PortCT(0)); } RC200AudioInSetInput(RC200AudioInLineIn); RC200AudioInSetGain(0,6,6); PalAudioInSetSampleRate (AudioIn, 44100); PalAudioOutSetSampleRate (AudioOut, 44100); RunFFT(AudioIn, AudioOut); } } } 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 */ static macro proc RunFFT (AudioIn, AudioOut) { signed 16 sample; unsigned 6 sample_count; unsigned 8 i; unsigned 4 eqinfo; unsigned 1 FFT_Sync; macro expr OW = PalAudioOutGetMaxDataWidthCT (); macro expr IW = PalAudioInGetMaxDataWidthCT (); signed LeftNew, RightNew; signed Output_sample; 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); /* for(i=0;i