#include "ADDS_21161_EzKit.h" #include #include #include #include #include "dane.h" #define FUNGEN // Generator funkcji: int n=1; int i ; float tempo=20000; float x=0.5; float * DelayLine; int liczba =0; int Index1 = 0; float phase = 0; // faza generatora sygnalowego float freq_ctrl = 0.05; // czestotliwosc generatora sygnalowego float taps_ifir[176]; // linia opozniajaca float taps_ir[32]; // linia opozniajaca int tap_ifir = 0; // akt. pozycja wpisywania nowych probek int tap_ir = 0; // akt. pozycja wpisywania nowych probek float result; float sample; int Index = 0; int PushB = 0; int Leds = 0; // Obsluga przerwan przyciskow: void Process_IRQ_0(int sig_int) { *(int*) IOFLAG ^= FLG8; } void Process_IRQ_1(int sig_int) { *(int*) IOFLAG ^= FLG9; } void Process_IRQ_2(int sig_int) { *(int*) IOFLAG ^= FLG9|FLG8; } // Obsluga przerwania portow kodeka (zmodyfikowana przez MK) void Process_Samples( int sig_int) { Receive_Samples(); /* Perform AD1836/AD1852/SPDIF Audio Processing Here */ // Wejscie: MIC IN, left&right (Left_Channel_In1, Right_Channel_In1) // Wyjscie: CH1 LINE OUT, left&right (Left_Channel_Out0, Right_Channel_Out0) (EAR) #ifdef DELLINE Left_Channel_Out0 = DelayLine[Index]; DelayLine[Index++] = Left_Channel_In1; Right_Channel_Out0 = DelayLine[Index]; DelayLine[Index++] = Right_Channel_In1; if (Index == 0x80000) Index = 0; Test_Wave[Index1++] = Left_Channel_In1; // do testowania funkcji "Plot" Index1 &= 0x00FF; #endif // Generator funkcji #ifdef FUNGEN Right_Channel_Out1 = x * sinf(phase); // sinus Left_Channel_Out1 = Right_Channel_Out1; // sinus + 180st if ((phase < 1.57079633) && (phase > -1.57079633)) // trojkat Left_Channel_Out2 = 0.3 * phase; else if (phase > 0) Left_Channel_Out2 = -0.3 * phase + 0.9424778; else Left_Channel_Out2 = -0.3 * phase - 0.9424778; if (phase > 0) // prostokat Right_Channel_Out2 = 0.5; else Right_Channel_Out2 = -0.5; phase = phase + freq_ctrl; // poprawka fazy if (phase > 3.141592654) phase = phase - 2*3.141592654; i=i+1; if (i==10000) { liczba=melodia[n] ; n=n+1;} if (n==melodia[0]) n=1; if (i>=tempo) i=0; if ((PushB & 0x8) && (tempo >10000))// zwiekszenie predkosci grania tempo -=0.05; if ((PushB & 0x4)&& (tempo<50000)) // zmniejszenie predkosci grania tempo +=0.05; if ((PushB & 0x2)&& (x>0.0001)) // zmniejszanie glosnosci grania x-=0.00001; if ((PushB & 0x1)&& (x<0.99999)) // zwiekszanie glosnosci grania x +=0.00001; switch (liczba) { case 0: freq_ctrl = 0.03424336 ; break;// c3 case 1: freq_ctrl = 0.036285395 ; break;// cis3 case 2: freq_ctrl = 0.03843215 ; break;// d3 case 3: freq_ctrl = 0.040722895 ; break;// dis3 case 4: freq_ctrl = 0.043144539 ; break;// e3 case 5: freq_ctrl = 0.045710173 ; break;// f3 case 6: freq_ctrl = 0.048432887 ; break;// fis3 case 7: freq_ctrl = 0.05131268 ; break;// g3 case 8: freq_ctrl = 0.054362643 ; break;// gis3 case 9: freq_ctrl = 0.057595865 ; break;// a3 case 10: freq_ctrl = 0.061012347 ; break;// b3 case 11: freq_ctrl = 0.064638269 ; break;// h3 case 12: freq_ctrl = 0.06848672 ; break;// c4 case 13: freq_ctrl = 0.0725577 ; break;// cis4 case 14: freq_ctrl = 0.07687739 ; break;// d4 case 15: freq_ctrl = 0.08144579 ; break;// dis4 case 16: freq_ctrl = 0.086289078 ; break;// e4 case 17: freq_ctrl = 0.091420346 ; break;// f4 case 18: freq_ctrl = 0.096852684 ; break;// fis4 case 19: freq_ctrl = 0.10261227 ; break;// g4 case 20: freq_ctrl = 0.108712196 ; break;// gis4 case 21: freq_ctrl = 0.115178641 ; break;// a4 case 22: freq_ctrl = 0.122024695 ; break;// b4 case 23: freq_ctrl = 0.129289628 ; break;// h4 case 24: freq_ctrl = 0.13697344 ; break;// c5 case 25: freq_ctrl = 0.145115401 ; break;// cis5 case 26: freq_ctrl = 0.153741691 ; break; // d5 case 27: freq_ctrl = 0.162891579 ; break;// dis5 case 28: freq_ctrl = 0.172578156 ; break;// e5 case 29: freq_ctrl = 0.182840692 ; break;// f5 case 30: freq_ctrl = 0.193705367 ; break;// fis5 case 31: freq_ctrl = 0.20522454 ; break;// g5 case 32: freq_ctrl = 0.217437482 ; break;// gis5 case 33: freq_ctrl = 0.230357281 ; break;// a5 case 34: freq_ctrl = 0.244062479 ; break;// b5 case 35: freq_ctrl = 0.258566165 ; break;// h5 case 36: freq_ctrl = 0.273946879 ; break;// c6 } #endif // Ledy i przyciski (FLAGS): #ifndef DTMF asm("dm(_PushB) = FLAGS;"); Leds = *(int*) IOFLAG; Leds &= ~(FLG4|FLG5|FLG6|FLG7); Leds |= PushB; *(int*) IOFLAG = Leds; #endif Transmit_Samples(); } void main() { /* Setup Interrupt edges and flag I/O directions */ Setup_ADSP21161N(); /* Setup SDRAM Controller */ Setup_SDRAM(); Setup_AD1836(); // Init_AD1852_DACs(); // usuniete przez MK - konfiguracja DAC4 przez SPI konfliktuje z FLAG1 // użytym jako pushbutton Program_SPORT02_TDM_Registers(); Program_SPORT02_DMA_Channels(); interruptf( SIG_SP0I, Process_Samples); #ifdef DTMF Leds = *(int*) IOFLAG; Leds &= ~(FLG4|FLG5|FLG6|FLG7|FLG8|FLG9); *(int*) IOFLAG = Leds; #else interruptf( SIG_IRQ0, Process_IRQ_0); interruptf( SIG_IRQ1, Process_IRQ_1); interruptf( SIG_IRQ2, Process_IRQ_2); #endif *(int *) SP02MCTL |= MCE; DelayLine = (float *) 0x00200000; for (;;) asm("idle;"); }