/*---------------------------------------------------------------------- File: irr.c Description: Perform 1-stage and 4-stage quad IIR filter and output to left and right channel of line-out respectively. * Note: cutoff of single stage is 6 kHz @ 20 kHz. -----------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #define SAMPLING_RATE 20000 extern int inicodec (int sampling_rate); #pragma CODE_SECTION(isr_rint0,".iprog") interrupt void isr_rint0 (void) { short a1 = 0xd0b4; // Negative value of a1 short a2 = 0xe6f0; // Negative value of a2 short b0 = 0x3217; short b1 = 0x642e; short b2 = 0x3217; static short d01=0, d02=0, d00; static short d11=0, d12=0, d10; static short d21=0, d22=0, d20; static short d31=0, d32=0, d30; short xn, y0, y1, y2, y3; int prod1, prod2, prod3, prod4, prod5; int sin, sout; //============= pre filter ============= sin = MCBSP0_DRR; //============= stage 0 ============= xn = (short) (sin & 0x000ffff); prod1 = _mpy(d02,a2)>>15; prod2 = _mpy(d01,a1)>>15; d00 = xn + (short)(prod1 + prod2); prod3 = _mpy(d01,b1); prod4 = _mpy(d02,b2); prod5 = _mpy(d00,b0); y0 = (short)((prod3+prod4+prod5)>>15); d02 = d01; d01 = d00; //============= stage 1 ============= prod1 = _mpy(d12,a2)>>15; prod2 = _mpy(d11,a1)>>15; d10 = y0 + (short)(prod1 + prod2); prod3 = _mpy(d11,b1); prod4 = _mpy(d12,b2); prod5 = _mpy(d10,b0); y1 = (short)((prod3+prod4+prod5)>>15); d12 = d11; d11 = d10; //============= stage 2 ============= prod1 = _mpy(d22,a2)>>15; prod2 = _mpy(d21,a1)>>15; d20 = y1 + (short)(prod1 + prod2); prod3 = _mpy(d21,b1); prod4 = _mpy(d22,b2); prod5 = _mpy(d20,b0); y2 = (short)((prod3+prod4+prod5)>>15); d22 = d21; d21 = d20; //============= stage 3 ============= prod1 = _mpy(d32,a2)>>15; prod2 = _mpy(d31,a1)>>15; d30 = y2 + (short)(prod1 + prod2); prod3 = _mpy(d31,b1); prod4 = _mpy(d32,b2); prod5 = _mpy(d30,b0); y3 = (short)((prod3+prod4+prod5)>>15); d32 = d31; d31 = d30; //============= post filter ============= sout = (((int)y3)<<16)|(((int)y0)&0xffff); MCBSP0_DXR = sout; 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. }