/* sine_generator.pde (MAPLE) guest openmusiclabs 7.13.11 this program creates a sinewave of variable frequency and amplitude, presented at both left and right outputs. there isnt any interpolation, so you only get 256 discrete frequencies across the span of 44Hz to 10kHz. */ // 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 // note the Maple library #include //#include //#include //#include // create data variables for audio transfer // even though there is no input needed, the codec requires stereo data // note the uint16 typedef, there is no "unsigned int16" type int16 left_in = 0; // in from codec (LINE_IN) int16 right_in = 0; int16 left_out = 0; // out to codec (HP_OUT) int16 right_out = 0; // create variables for ADC results // it only has positive values -> unsigned uint16 mod0_value = 0; uint16 mod1_value = 0; float dt; float dxdt=0,dydt=0,dzdt=0; float a,b,c; float x=0.1,y=0.0,z=0.0; // note initial condition! void setup() { SerialUSB.end(); // usb conflicts with the codec in this mode // a different operating mode which allows both // is in the works // setup codec and microcontroller registers AudioCodec_init(); // call this last if you are setting up other things } void loop() { while (1); // reduces clock jitter } // timer1 interrupt routine - all data processed here void AudioCodec_interrupt() { // &'s are necessary on data_in variables AudioCodec_data(&left_in, &right_in, left_out, right_out); a = 10.0; b = 28.0; c = 8.0/3.0; dt = (1.0/1000.0) + (((float)mod0_value)/65535.0)/100.0; //if( (t%480)==0){x=.1;} dxdt = a * (y-x); dydt = x * (b-z) - y; dzdt = x * y - c * z; x += dxdt*dt; y += dydt*dt; z += dzdt*dt; left_out = x*600.0; right_out = y*600.0; // get ADC values // & is required before adc variables AudioCodec_ADC(&mod0_value, &mod1_value); // you dont need to reti() with Maple }