/********************************** 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); } }
void ISR_AIC(void) { /* * Since we have to write a 16 bit value, we cast to `short`, since there is no half * precision floating point number type in C. However, since our sample will be between * -1 and 1, casting to a short would mean we would only ever get the values 0, 1 and * -1. So, we scale the value up by 2^15-1 (since 2^15 would cause overflow and * incorrect output) before casting to ensure we don't lose information in the cast. */ float shifted_sample = sinegen()*32767; sample = (short)fabs(shifted_sample); mono_write_16Bit(sample); }