Pressing SW2 sometimes has the same effect as pressing SW1! By the way, 2-D arrays appear to act weird in CCS, so I just went with one-d arrays for the HRIRs.
Also, some of the azimuths of these HRIRs give super high volumes. Its very scary.
Things to be improved:
- Using one FIR routine instead of 2!
- Some gain control?
- Smoothing out the transitions between HRIRs. Actually, it would be nice to use the LCD to see how rapidly the azimuths are changing (using WTIME in the following code is not really good…)
/* * fir_filter.c * A crude implementation for using HRIRs. A 100 tap HRIR was loaded for each channel. * Author: GSI */ #include <usbstk5515.h> #include <usbstk5515_i2c.h> #include <AIC_func.h> #include <sar.h> #include <stdio.h> #include "hrir_l_subject3_el10_azAll.h" #include "hrir_r_subject3_el10_azAll.h" #define ASIZE 200 #define TCR0 *((ioport volatile Uint16 *)0x1810) #define TIMCNT1_0 *((ioport volatile Uint16 *)0x1814) #define TIME_START 0x8001 #define TIME_STOP 0x8000 Int16 in_left[ASIZE], in_right[ASIZE]; Uint16 delta_time; Int16 FIR_left(Uint16 i, Uint16 az) { Int32 sum; Uint16 j; Uint32 index; sum=0; //The actual filter work for(j=0; j<ASIZE; j++) { if(i>=j) index = i - j; else index = ASIZE + i - j; sum += (Int32)in_left[index] * (Int32)hrir_l[az*ASIZE + j]; } sum = sum + 0x00004000; // So we round rather than truncate. return (Int16) (sum >> 15); // Conversion from 32 Q30 to 16 Q15. } Int16 FIR_right(Uint16 i, Uint16 az) { Int32 sum; Uint16 j; Uint32 index; sum=0; //The actual filter work for(j=0; j<ASIZE; j++) { if(i>=j) index = i - j; else index = ASIZE + i - j; sum += (Int32)in_right[index] * (Int32)hrir_r[az*ASIZE + j]; } sum = sum + 0x00004000; // So we round rather than truncate. return (Int16) (sum >> 15); // Conversion from 32 Q30 to 16 Q15. } void main(void) { Uint16 i, az = 0, j = 0, WTIME = 100; // Uint16 start_time; // Uint16 end_time; Int16 right, left; //AIC inputs Int16 out_left, out_right; Uint16 key; Uint16 filter = 0; USBSTK5515_init(); //Initializing the Processor AIC_init(); //Initializing the Audio Codec Init_SAR(); //Initializing the SAR ADC for key presses //Priming the PUMP for(i = 0; i < (ASIZE); i++) { AIC_read2(&right, &left); in_right[i] = right; in_left[i] = left; } while(1) { if(i>=ASIZE) i=0; if(j>=WTIME){ if(key == SW2) az += 1; j = 0; } AIC_read2(&right, &left); in_left[i] = left; in_right[i] = right; out_left = FIR_left(i, az); out_right = FIR_right(i, az); //POSTFILTER: key = Get_Key_Human(); if (key == SW1) filter = !filter; if (az > 50) az = 0; //filter = 1; if (filter) AIC_write2(16*out_right, 16*out_left); else AIC_write2(right, left); i++, j++; } }
Advertisements