#include "ADDS_21161_EzKit.h" #include #include #include #include #define FFT /*wybor przez uzytkownika trybu strojenia */ #define Stroik //odznaczyc dla zgrubnego strojenia //#define Stroik_Gitara //odznaczyc dla dokladniejszego strojenia //#define nie_z_pliku //dla operacji wczytania próbek z plikow - zakomentowana linie #define dziel 16 //dzielnik czestotliwoci probkowania - ustawiamy w ten sposob software'owa czestotliwosc probkowania #define z dziel*2048/48000 #define e1 329.63*z //nr probki dla struny obiczany przez kompilator #define h2 246.96*z #define g3 196*z #define d4 146.83*z #define a5 110*z #define e6 82.41*z int f=440; //czestotliwosc podstawowa - ustawiona przed przycisnieciem ktoregokolwiek z przyciskow int N=2048; int blad=0; float real_input[2048]; float real_output[2048], imag_output[2048]; float real_2,imag_2; int Index1 = 0; int i=0,a=0,probka=0; float wart_max=0; float wart_max1=0; int Index = 0; int PushB = 0; int Leds = 0; int struna; // 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(); #ifdef FFT if (a==0)//wyłączenie diod { Leds = *(int*) IOFLAG; Leds = ~(FLG4|FLG5|FLG6|FLG7|FLG8|FLG9); *(int*) IOFLAG = Leds; a=1; struna=f*z; } //wybór struny do strojenia poprzez wciśnięcie odpowiedniego przycisku if (PushB == 0x8) struna=e1; if (PushB == 0x4) struna=h2; if (PushB == 0x2) struna=g3; if (PushB == 0x1) struna=d4; if (PushB == 0xc) struna=a5; if (PushB == 0x6) struna=e6; //pobieranie co dziel-tej próbki #ifdef nie_z_pliku if (Index1%dziel==0) { real_input[Index++] = Left_Channel_In1; } Index1++; // po pobraniu 2048 próbek, przejście do następnego etapu if (Index==(N-1)) #endif { // zerowanie diod Leds = *(int*) IOFLAG; Leds = ~(FLG4|FLG5|FLG6|FLG7|FLG8|FLG9); *(int*) IOFLAG = Leds; blad=0; //sprawdzenie warunku nasycienia sie przetwornik for (i=1;i=0.1||wart_max<=-0.1)) { blad=1; Leds = 0x3F; *(int*) IOFLAG = Leds; break; //kiedy wykryje nasycenie przetwornika zaswieca sie wszystkie diody } } Index1=0; Index=0; //jesli przetwornik jest nienasycony wykonuj dalej program if (blad==0) { rfft2048 (real_input, real_output, imag_output); wart_max=0; probka=0; //obliczenie modułu z otrzymanych wartości for (i=0;iwart_max) { wart_max=real_input[i]; probka=i; } } { //sprawdzanie stopnia dostrojenia strun i wyświetlenie na go na diodach if (probka==struna) { // X-dioda nie świeci, 0-dioda świeci Leds |= 0x0000000C; //XX00XX – struna prawidłowo dostrojona *(int*) IOFLAG = Leds; } #ifdef Stroik //wykonuje gdy w definicji jest odznaczony Stroik - strojenie zgrubne if ((probka>=(struna-struna/5))&&(probka<=(struna-1))) { Leds |= 0x00000008; //XX0XXX *(int*) IOFLAG = Leds; } if ((probka>=(struna+1))&&(probka<=(struna+struna/5))) { Leds |= 0x00000004; //XXX0XX *(int*) IOFLAG = Leds; } if ((probka>=(struna-2*struna/5))&&(probka<(struna-struna/5))) { Leds |= 0x00000018; //X00XXX *(int*) IOFLAG = Leds; } if ((probka>(struna+struna/5))&&(probka<=(struna+2*struna/5))) { Leds |= 0x00000006; //XXX00X *(int*) IOFLAG = Leds; } if ((probka>=(struna-3*struna/5))&&(probka<(struna-2*struna/5))) { Leds |= 0x00000010; //X0XXXX *(int*) IOFLAG = Leds; } if ((probka>(struna+2*struna/5))&&(probka<=(struna+3*struna/5))) { Leds |= 0x00000002; //XXXX0X *(int*) IOFLAG = Leds; } if ((probka>=(struna-4*struna/5))&&(probka<(struna-3*struna/5))) { Leds |= 0x00000030; //00XXXX *(int*) IOFLAG = Leds; } if ((probka>(struna+3*struna/5))&&(probka<=(struna+4*struna/5))) { Leds |= 0x00000003; //XXXX00 *(int*) IOFLAG = Leds; } if (probka<((struna-4*struna/5))) { Leds |= 0x00000020; //0XXXXX *(int*) IOFLAG = Leds; } if (probka>=(struna+4*struna/5)) { Leds |= 0x00000001; //XXXXX0 *(int*) IOFLAG = Leds; } #endif //dla dokladniejszego strojenia #ifdef Stroik_Gitara //wykonuje gdy w definicji jest odznaczony Stroik_Gitara - strojenie dokladne if ((probka>=(struna-1))&&(probka<=(struna-5))) { Leds |= 0x00000008; //XX0XXX *(int*) IOFLAG = Leds; } if ((probka>=(struna+1))&&(probka<=(struna+5))) { Leds |= 0x00000004; //XXX0XX *(int*) IOFLAG = Leds; } if ((probka>=(struna-10))&&(probka<(struna-5))) { Leds |= 0x00000018; //X00XXX *(int*) IOFLAG = Leds; } if ((probka>(struna+5))&&(probka<=(struna+10))) { Leds |= 0x00000006; //XXX00X *(int*) IOFLAG = Leds; } if ((probka>=(struna-15))&&(probka<(struna-10))) { Leds |= 0x00000010; //X0XXXX *(int*) IOFLAG = Leds; } if ((probka>(struna+10))&&(probka<=(struna+15))) { Leds |= 0x00000002; //XXXX0X *(int*) IOFLAG = Leds; } if ((probka>=(struna-20))&&(probka<(struna-15))) { Leds |= 0x00000030; //00XXXX *(int*) IOFLAG = Leds; } if ((probka>(struna+15))&&(probka<=(struna+20))) { Leds |= 0x00000003; //XXXX00 *(int*) IOFLAG = Leds; } if (probka<((struna-20))) { Leds |= 0x00000020; //0XXXXX *(int*) IOFLAG = Leds; } if (probka>=(struna+20)) { Leds |= 0x00000001; //XXXXX0 *(int*) IOFLAG = Leds; } #endif } } } #endif // Ledy i przyciski (FLAGS): #ifndef DTMF asm("dm(_PushB) = FLAGS;"); #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;"); }