/*---------------------------------------------------------------------- File: inicodec.c Description: Setups the on-board codec to sample from line-in, at 16-bit 2-channel per sample Set up mcbsp0 to at 32-bit per sample. -----------------------------------------------------------------------*/ #include #include #include int inicodec (int sampling_rate) { int status; Mcbsp_dev dev; Mcbsp_config mcbspConfig; status = mcbsp_drv_init(); if (status==ERROR) {printf("Error initialising the McBSP driver\n"); return (ERROR); } dev = mcbsp_open(0); if (dev == 0) return FALSE; memset(&mcbspConfig,0,sizeof(mcbspConfig)); mcbspConfig.loopback = FALSE; mcbspConfig.tx.update = TRUE; mcbspConfig.tx.clock_polarity = CLKX_POL_RISING; mcbspConfig.tx.frame_sync_polarity = FSYNC_POL_HIGH; mcbspConfig.tx.clock_mode = CLK_MODE_EXT; mcbspConfig.tx.frame_sync_mode = FSYNC_MODE_EXT; mcbspConfig.tx.phase_mode = SINGLE_PHASE; mcbspConfig.tx.frame_length1 = 0; mcbspConfig.tx.word_length1 = WORD_LENGTH_32; mcbspConfig.tx.frame_ignore = FRAME_IGNORE; mcbspConfig.tx.data_delay = DATA_DELAY0; mcbspConfig.rx.update = TRUE; mcbspConfig.rx.clock_polarity = CLKX_POL_RISING; mcbspConfig.rx.frame_sync_polarity = FSYNC_POL_HIGH; mcbspConfig.rx.clock_mode = CLK_MODE_EXT; mcbspConfig.rx.frame_sync_mode = FSYNC_MODE_EXT; mcbspConfig.rx.phase_mode = SINGLE_PHASE; mcbspConfig.rx.frame_length1 = 0; mcbspConfig.rx.word_length1 = WORD_LENGTH_32; mcbspConfig.rx.frame_ignore = FRAME_IGNORE; mcbspConfig.rx.data_delay = DATA_DELAY0; if (mcbsp_config(dev,&mcbspConfig)==ERROR) return FALSE; MCBSP_ENABLE (0, 3); // Bring Serial Port 0 out of reset, 3 means both rx and tx. codec_init (); // Initialise on-board codec, enabling it as well. codec_serial_port_enable (SERIAL_32BIT); // Enable codec serial i/o and set serial format to 32-bit. codec_change_sample_rate (sampling_rate, TRUE); // Set the sampling rate. codec_adc_control (LEFT, 0.0, FALSE, LINE_SEL); // Unmute left ADC, set gain select source from line input codec_adc_control (RIGHT, 0.0, FALSE, LINE_SEL); // Unmute right ADC, set gain select source from line input codec_line_in_control (LEFT, MAX_AUX_LINE_GAIN, TRUE); // Set left line input volume and mute direct loopback to DAC codec_line_in_control (RIGHT, MAX_AUX_LINE_GAIN, TRUE); // Set right line input volume and mute direct loopback to DAC codec_dac_control (LEFT, 0.0, FALSE); // Unmute left DAC and set volume. codec_dac_control (RIGHT, 0.0, FALSE); // Unmute right DAC and set volume. return TRUE; }