// setup codec parameters // must be done before #includes // see readme file in libraries folder for explanations #define SAMPLE_RATE 22 // 44.1Khz #define ADCS 0 // no ADCs are being used #define MICBOOST 1 #define MUTEMIC 0 #define INSEL 1 // include necessary libraries #include #include #include // create data variables for audio transfer int left_in = 0x0000; int left_out = 0x0000; int right_in = 0x0000; int right_out = 0x0000; unsigned int mod0_value; #define SLOPE 3 #define SAMPLES 4 #define SIZE 840 // make this smaller if it clicks int buffer[SIZE]; // sample buffer int offset[SAMPLES] = {0,210,420,630}; unsigned int location = 0; // current sample input position byte counter = 1; void setup() { // clear buffer for (int i = 0 ; i < SIZE ; i++) { buffer[i] = 0; } AudioCodec_init(); // setup codec registers } void loop() { while (1); // reduces clock jitter } // timer1 interrupt routine - all data processed here ISR(TIMER1_COMPA_vect, ISR_NAKED) { // dont store any registers // &'s are necessary on data_in variables AudioCodec_data(&left_in, &right_in, left_out, right_out); buffer[location] = left_in; // store incoming data location++; // increment storage location if (location >= SIZE) location = 0; // boundary wrap int sum = 0; for (byte i = 0; i < SAMPLES; i++) { int offset1 = offset[i]; unsigned int temp = location + offset1; // find next sample if (temp >= SIZE) temp -= SIZE; // boundary wrap int output = buffer[temp]; // fetch sample unsigned int distance; // find distance to buffer boundary if (offset1 < (SIZE >> SLOPE)) distance = offset1 << (SLOPE-1); else if (offset1 >= (SIZE-(SIZE >> SLOPE))) distance = ((SIZE - 1) - offset1) << (SLOPE-1); else distance = (SIZE >> 1); int result; MultiSU16X16toH16(result, output, (distance << 5)); sum += result; } if (counter == 0) { counter = 1; for (byte i = 0; i < SAMPLES; i++) { int offset2 = offset[i]; offset2--; if (offset2 < 0) { offset[i] = (SIZE - 1); } else offset[i] = offset2; } } else counter = 0; left_out = (sum >> 1) + left_in; // right_out = sum; // dont forget to return from interrupt reti(); }