/********************************** Main routine ************************************/ void main() { // initialize board and the audio port init_hardware(); sine_init(); // Loop endlessley generating a sine wave while(1) { // Calculate next sample sample = sinegen(); /* Send a sample to the audio port if it is ready to transmit. Note: DSK6713_AIC23_write() returns false if the port if is not ready */ // send to LEFT channel (poll until ready) while (!DSK6713_AIC23_write(H_Codec, ((Int32)(sample * L_Gain)))) {}; // send same sample to RIGHT channel (poll until ready) while (!DSK6713_AIC23_write(H_Codec, ((Int32)(sample * R_Gain)))) {}; // Set the sampling frequency. This function updates the frequency only if it // has changed. Frequency set must be one of the supported sampling freq. set_samp_freq(&sampling_freq, Config, &H_Codec); } }
/* The cosOut outputs a cosine of frequency "freq" for "duration" seconds * to the codec with handle "hCodec" * This is basically a utility function that busy-waits while generating * and outputting a cosine wave */ void cosOut(double freq, double duration, DSK6713_AIC23_CodecHandle hCodec){ double i; int sample; for (i = SAMPLE_PERIOD; i < duration; i+=SAMPLE_PERIOD){ sample = (int)(2048.0*cos(2*PI*freq*i)); // Send a sample to the left channel while (!DSK6713_AIC23_write(hCodec, sample )); //Send a sample to the right channel while (!DSK6713_AIC23_write(hCodec, sample )); } return; }
/** * outputs the left and right channel then sets the output ready flag */ void transmit_interrupt(void) { if(out_channel_flag){ DSK6713_AIC23_write(hCodec, out_left & 0xFFFF); out_channel_flag = 0; output_ready = 1; } else { DSK6713_AIC23_write(hCodec, out_right & 0xFFFF); out_channel_flag = 1; output_ready = 1; } }
/** * main method * contains main run loop */ int main() { //prototype for linear assembly convolution function extern int convolve_as_func(int x[], int w[], int x_idx, int w_length); DSK6713_init(); hCodec = DSK6713_AIC23_openCodec(0,&config); DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ); // enable interrupts IRQ_globalEnable(); IRQ_enable(IRQ_EVT_RINT1); IRQ_enable(IRQ_EVT_XINT1); reset(); // init the input buffer to zeros // get the time to make a clock() funciton call; used only for profiling /* start = clock(); end = clock(); diff = end - start; */ // the first write is needed to trigger the transmit interrupt while(!DSK6713_AIC23_write(hCodec, 0)); in_channel_flag = 1; out_channel_flag = 1; while(1) { if(input_ready) { //process sample when input is ready sig_error = process_sample(in_left, in_right); input_ready = 0; } // set output when ready if(output_ready) { out_left = in_left; out_right = sig_error; output_ready = 0; } }; /* The program will never exit this loop */ /* However, if you _do_ exit the loop (say, using a break * statement) close the D/A converter properly */ DSK6713_AIC23_closeCodec(hCodec); exit(); }
void codec_write(int32 output_data){ while(!(DSK6713_AIC23_write(manejador,output_data))); }