int main(){ float input_data; int32 output_data; //Configure hardware codec_init(); fir_init(banda1,banda2,banda3,banda4,banda5); while(1){ //Processing data if(DSK6713_DIP_get(3)==0){ //Initialize processing leds_output(LED_STATE_ACTIVE); while(DSK6713_DIP_get(3)==0){ input_data = codec_read(); output_data = fir_filter(input_data); codec_write(output_data); } } //Waiting else{ leds_output(LED_STATE_WATING); } } }
static bool write_handler(uint8_t *buf, size_t sz, void *arg) { struct audio_loop *al = arg; ++al->n_write; /* read from beginning */ if (al->ac) { (void)codec_read(al, buf, sz); } else { aubuf_read(al->ab, buf, sz); } return true; }
static void write_handler(int16_t *sampv, size_t sampc, void *arg) { struct audio_loop *al = arg; int err; ++al->n_write; /* read from beginning */ if (al->ac) { err = codec_read(al, sampv, sampc); if (err) { warning("auloop: codec_read error " "on %zu samples (%m)\n", sampc, err); } } else { aubuf_read_samp(al->ab, sampv, sampc); } }
int main(void) { uint16_t i; char temp_char; uint8_t num_chars_ret; // For CS4272 (uC i2s interface in slave mode) not sure about // initialization sequence (i2s interface first, or setup cs4272 first) // For now, start with codec (get interface clocks started first) // Initialize USB usb_init(); delay(100); // Initialize I2C subsystem i2c_init(); delay(100); for(i = 0; i < 64; i++) { buffer[i] = 0; } // Wait to setup codec to make sure user has turned on audio board power while((buffer[0] != 'y') && (buffer[0] != 'Y')) { serial_write_string("Init codec? (y/n)\r\n>"); // Wait for response num_chars_ret = serial_read_line(buffer,64); if(num_chars_ret < 1) { serial_write_string("Error reading line. Please try again.\r\n"); } } for(i = 0; i < 64; i++) { buffer[i] = 0; } // Initialize CS4272 codec_init(); delay(100); // Initialize I2S subsystem i2s_init(); delay(10); serial_write_string("Codec Initialized\r\n"); delay(10); // Test to see if i2c is working uint8_t reg_result; uint8_t ii; for(ii = 1; ii < 9; ii++) { itoa(ii,buffer,10); serial_write_string("Address "); serial_write_string(buffer); serial_write_string(": "); reg_result = codec_read(ii); itoa(reg_result,buffer,10); serial_write_string(buffer); serial_write_string("\r\n"); delay(100); } for(i = 0; i < 64; i++) { buffer[i] = 0; } serial_write_string("Waiting 10 seconds for ADC high pass filter to stabilize\r\n"); delay(10000); while(1) { // Initialize indices, etc tx_buf_idx = 0; rx_buf_idx = 0; curr_run = 0; for(i = 0; i < NUM_SAMP; i++) { //recv_data_real[i] = 0; //recv_data_imag[i] = 0; recv_data_right[i] = 0; //recv_data_left[i] = 0; } for(i = 0; i < 64; i++) { buffer[i] = 0; } while((buffer[0] != 'y') && (buffer[0] != 'Y')) { serial_write_string("Start test? (y/n)\r\n>"); // Wait for response num_chars_ret = serial_read_line(buffer,64); if(num_chars_ret < 1) { serial_write_string("Error reading line. Please try again.\r\n"); } } // Start test serial_write_string("Starting test.\r\n"); //output_real_part = 1; test_running = 1; i2s_start(); // Wait for real part to finish while(test_running) { //serial_write_string("Running real part. Please wait .....\r\n"); delay(1000); } // Test is now finished // serial_write_string("Real part is finished. Starting imaginary part.\r\n"); // // delay(1000); // // // Start imaginary part // output_real_part = 0; // test_running = 1; // i2s_start(); // // // Wait for real part to finish // while(test_running) // { // //serial_write_string("Running imaginary part. Please wait .....\r\n"); // delay(1000); // } // // // Test is now finished // serial_write_string("Imaginary part is finished. Printing Data.\r\n"); // Print data for(i = 0; i < NUM_SAMP; i++) { itoa(recv_data_right[i],buffer,10); serial_write_string(buffer); serial_write_string(","); itoa(recv_data_left[i],buffer,10); serial_write_string(buffer); serial_write_string("\r\n"); delay(50); } serial_write_string("End of data.\r\n"); } return 0; }
int main() { init_platform(); XIOModule_Initialize(&iomod_inst, 0); wait_ms(&iomod_inst,1000); codec_init(&iomod_inst); wait_ms(&iomod_inst,1000); print("Codec Initialized\r\n"); print("Reading back registers\r\n"); int i; uint8_t regData; for(i = 1; i < 9; i++) { regData = codec_read(&iomod_inst,i); print("Address "); print_u32_hex((u32)i); print(" "); print_u32_hex((u32)regData); print("\r\n"); } print("Waiting 5 seconds for codec HPF to stabilize...\r\n"); wait_ms(&iomod_inst,5000); u8 numCharsRet; clearInpBuffer(); while(1) { print("Please select the channel (L/R)\r\n> "); numCharsRet = serial_read_line(serialInputBuffer,SERIAL_INPUT_BUFFER_LEN); if(numCharsRet > 0) { if((serialInputBuffer[0] == 'l') || (serialInputBuffer[0] == 'L')) { selectedChannel = Left; break; } else if((serialInputBuffer[0] == 'r') || (serialInputBuffer[0] == 'R')) { selectedChannel = Right; break; } } print("Invalid channel selection.\r\n"); } clearInpBuffer(); RunSineTest(); for(i = 0; i < MAX_INPUT_LEN; i++) { xil_printf("%d\r\n",input_buffer[i]); } print("End of samples\r\n"); return 0; }
/* ====================== S_UpdateBackgroundTrack ====================== */ void S_UpdateBackgroundTrack( void ) { int bufferSamples; int fileSamples; byte raw[ 30000 ]; // just enough to fit in a mac stack frame int fileBytes; int r; static float musicVolume = 0.5f; if ( !s_backgroundStream ) { return; } // graeme see if this is OK musicVolume = ( musicVolume + ( s_musicVolume->value * 2 ) ) / 4.0f; // don't bother playing anything if musicvolume is 0 if ( musicVolume <= 0 ) { return; } // see how many samples should be copied into the raw buffer if ( s_rawend < s_soundtime ) { s_rawend = s_soundtime; } while ( s_rawend < s_soundtime + MAX_RAW_SAMPLES ) { bufferSamples = MAX_RAW_SAMPLES - ( s_rawend - s_soundtime ); // decide how much data needs to be read from the file fileSamples = bufferSamples * s_backgroundStream->info.rate / dma.speed; // our max buffer size fileBytes = fileSamples * ( s_backgroundStream->info.width * s_backgroundStream->info.channels ); if ( fileBytes > sizeof( raw ) ) { fileBytes = sizeof( raw ); fileSamples = fileBytes / ( s_backgroundStream->info.width * s_backgroundStream->info.channels ); } // Read r = codec_read( s_backgroundStream, fileBytes, raw ); if ( r < fileBytes ) { fileBytes = r; fileSamples = r / ( s_backgroundStream->info.width * s_backgroundStream->info.channels ); } if ( r > 0 ) { // add to raw buffer SOrig_RawSamples( 0, fileSamples, s_backgroundStream->info.rate, s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, s_musicVolume->value, -1 ); } else { // loop if ( s_backgroundLoop[ 0 ] ) { codec_close( s_backgroundStream ); s_backgroundStream = NULL; SOrig_StartBackgroundTrack( s_backgroundLoop, s_backgroundLoop ); if ( !s_backgroundStream ) { return; } } else { SOrig_StopBackgroundTrack(); return; } } } }