Simplest possible example
Hi,
Some code I wrote/modified-- feel free to use it for anything.
I think this is the simplest possible code that I can come up with based on Mark's Arduino code-- the two knobs are just volume controls for the left and right channels.
Also, here are a couple lines of Python that I wrote to generate 1024-entry lookup tables.
As it is, the first line just maps the values 0-1024 to the square of itself (x**2), but you could replace the x**2 with any other mathematical expression.
Some code I wrote/modified-- feel free to use it for anything.
I think this is the simplest possible code that I can come up with based on Mark's Arduino code-- the two knobs are just volume controls for the left and right channels.
// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1kHz sample rate
#define ADCS 2 // use both ADCs
// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>
// create data variables for audio transfer
// even though the function is mono, the codec requires stereo data
int left_in = 0; // in from codec (LINE_IN)
int right_in = 0;
int left_out = 0; // out to codec (HP_OUT)
int right_out = 0;
// create variables for ADC results
// it only has positive values -> unsigned
unsigned int mod0_value = 0;
unsigned int mod1_value = 0;
void setup() {
// call this last if you are setting up other things
AudioCodec_init(); // setup codec and microcontroller 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);
MultiSU16X16toH16(left_out, left_in, mod0_value);
MultiSU16X16toH16(right_out, right_in, mod1_value);
// & is required before adc variables
AudioCodec_ADC(&mod0_value, &mod1_value);
reti(); // dont forget to return from the interrupt
}Also, here are a couple lines of Python that I wrote to generate 1024-entry lookup tables.
As it is, the first line just maps the values 0-1024 to the square of itself (x**2), but you could replace the x**2 with any other mathematical expression.
lookup = [x**2 for x in range (0, 1024)]
f = open('lookup.inc', 'w')
for line in lookup:
f.write(str(line) + ',\n')
f.close()