/*---------------------------------------------------------------------- File: gtz.c Description: Perform goertzel algorithm on 200 samples of codec input. Sends goetzel value periodically to mailbox. Each sample generates an interrupt, after each 200 interrupts, a goertzel value is generated. -----------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #define SAMPLING_RATE 8000 extern int inicodec (int sampling_rate); #pragma CODE_SECTION (isr_rint0, ".iprog") interrupt void isr_rint0 (void) { static short delay; static short delay_1 = 0; static short delay_2 = 0; static int N = 0; static int Goertzel_Value = 0; int prod1, prod2, prod3; int R_in; short input; int output; short coef_1 = 0x4A70; // For detecting 1209 Hz R_in = MCBSP0_DRR; input = (short) R_in; input = input >> 4; // Scale down input to prevent overflow. prod1 = (delay_1*coef_1)>>14; delay = input + (short)prod1 - delay_2; delay_2 = delay_1; delay_1 = delay; N++; if (N==206) { prod1 = (delay_1 * delay_1); prod2 = (delay_2 * delay_2); prod3 = (delay_1 * coef_1)>>14; prod3 = prod3 * delay_2; Goertzel_Value = (prod1 + prod2 - prod3) >> 15; Goertzel_Value <<= 4; // Scale up value for sensitivity. N = 0; delay_1 = delay_2 = 0; } output = (((short) R_in) * ((short)Goertzel_Value)) >> 15; MCBSP0_DXR = (output<<16) | (output & 0x0000ffff); return; } void Init_Interrupts () { intr_reset(); // Reset the interrupt system, // disable all interrupts. INTR_CLR_FLAG (CPU_INT15); // Clear previous interrupt request INTR_ENABLE (CPU_INT15); // Enable cpu interrupt line 15 intr_map(CPU_INT15,ISN_RINT0); // Link receive interrupt of serial // port 0 to interrupt line 15. intr_hook (isr_rint0,CPU_INT15); // Assign the interrupt service routine } void main(void) { evm_init(); // Initialise EVM board. inicodec (SAMPLING_RATE); // Initialise codec, adjust sampling rate. Init_Interrupts (); // Initialise interrupts and hook isr. INTR_GLOBAL_ENABLE(); // Enable global interrupt. for (;;); // Main loop, does nothing. }