80 lines
2.6 KiB
C
80 lines
2.6 KiB
C
/*
|
|
* Copyright (C) 2018, Hogeschool Rotterdam, Harry Broeders
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <NoRTOS.h>
|
|
|
|
#include <ti/devices/cc32xx/inc/hw_memmap.h>
|
|
#include <ti/devices/cc32xx/inc/hw_types.h>
|
|
#include <ti/devices/cc32xx/driverlib/prcm.h>
|
|
#include <ti/devices/cc32xx/driverlib/i2s.h>
|
|
#include <ti/drivers/I2C.h>
|
|
|
|
#include "ti_drivers_config.h"
|
|
#include "config.h"
|
|
|
|
// You can select the sample rate here:
|
|
#define SAMPLINGFREQUENCY 8000
|
|
#if SAMPLINGFREQUENCY < 8000 || SAMPLINGFREQUENCY > 48000 || SAMPLINGFREQUENCY % 4000 != 0
|
|
#error Sampling Frequency must be between 8 kHz and 48 kHz (included) and must be a multiple of 4 kHz.
|
|
#endif
|
|
|
|
#define N 15
|
|
|
|
#define BL 15
|
|
const float B[15] = { -0.03215415403, -0.0530516468, -0.04501581565,
|
|
9.745429214e-18, 0.07502636313, 0.1591549367,
|
|
0.2250790745, 0.25, 0.2250790745, 0.1591549367,
|
|
0.07502636313, 9.745429214e-18, -0.04501581565,
|
|
-0.0530516468, -0.03215415403 };
|
|
|
|
|
|
float buffer_R[N] = { 0 };
|
|
|
|
int main(void)
|
|
{
|
|
// Init CC3220S LAUNCHXL board.
|
|
Board_initGeneral();
|
|
// Prepare to use TI drivers without operating system.
|
|
NoRTOS_start();
|
|
|
|
printf("line-in_2_line_out: STEREO LINE IN ==> HP LINE OUT.\n");
|
|
printf("Sampling frequency = %d Hz.\n", SAMPLINGFREQUENCY);
|
|
|
|
// Configure an I2C connection which is used to configure the audio codec.
|
|
I2C_Handle i2cHandle = ConfigureI2C(CONFIG_I2C_0, I2C_400kHz);
|
|
// Configure the audio codec.
|
|
ConfigureAudioCodec(i2cHandle, SAMPLINGFREQUENCY);
|
|
|
|
// Configure an I2S connection which is use to send/receive samples to/from the codec.
|
|
ConfigureI2S(CONFIG_I2S_0, I2S_BASE, SAMPLINGFREQUENCY);
|
|
int16_t dataLeft, dataRight;
|
|
int k;
|
|
int i;
|
|
while (1)
|
|
{
|
|
float outR;
|
|
// The 16-bit samples are stored in 32-bit variables because the API also supports 24-bit samples.
|
|
I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataLeft);
|
|
// You can process the 16-bit left sample here.
|
|
I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, 0);
|
|
I2SDataGet(I2S_BASE, I2S_DATA_LINE_1, &dataRight);
|
|
buffer_R[0] = dataRight;
|
|
outR = 0;
|
|
for (k = 0; k < BL; k++){
|
|
outR += B[k] * buffer_R[k];
|
|
}
|
|
for (i = BL - 1; i >= 1; i--){
|
|
buffer_R[i] = buffer_R[i - 1];
|
|
}
|
|
// You can process the 16-bit right sample here.
|
|
I2SDataPut(I2S_BASE, I2S_DATA_LINE_0, outR);
|
|
|
|
}
|
|
return 0;
|
|
}
|