Hi @kerryzhou
I have another question about the extraction of TDM multi-channel data. My current project is in the format of TDM, 48k, 32bit, and 4 channels. There is no problem with the audio when I directly receive and send, but now I want to extract the data of 4 channels separately for algorithm processing, and the audio sent out is wrong. My code is posted below, please help me to check it.Thank you!
#define SIGLE_SAMPLE (DEMO_AUDIO_SAMPLE_RATE*4/1000)//4MS Data
#define BUFFER_SIZE (3072U)//48*4=192 192*4byte*4ch = 3072
int *pMic = (int *)malloc(BUFFER_SIZE);
int *pTemp = (int *)malloc(BUFFER_SIZE);
while (1)
{
//PRINTF("emptyBlock1=%d\r\n", emptyBlock);
if (emptyBlock > 0)
{
xfer.data = Buffer + rx_index * BUFFER_SIZE;
xfer.dataSize = BUFFER_SIZE;
if (kStatus_Success == SAI_TransferReceiveEDMA(DEMO_SAI, &rxHandle, &xfer))
{
memcpy((void *)pTemp, xfer.data, BUFFER_SIZE);
for(int i=0; i<SIGLE_SAMPLE; i++)
{
for(int j=0; j<DEMO_AUDIO_DATA_CHANNEL; j++)
{
//The data of 4 channels were extracted, and each channel data was 4ms
pMic[j*SIGLE_SAMPLE + i] = pTemp[DEMO_AUDIO_DATA_CHANNEL*i+j];
}
}
for(int i=0; i<SIGLE_SAMPLE; i++)
{
for(int j=0; j<DEMO_AUDIO_DATA_CHANNEL; j++)
{
//Move data saturation 1 bit to the left,Enlarge 6db
//If you do not move 1 bit to the left, the audio is normal
pMic[j*SIGLE_SAMPLE + i] = L_shl(pMic[j*SIGLE_SAMPLE + i],1);
}
}
for(int i=0; i<SIGLE_SAMPLE; i++)
{
for(int j=0; j<DEMO_AUDIO_DATA_CHANNEL; j++)
{
pTemp[DEMO_AUDIO_DATA_CHANNEL*i+j] = pMic[j*SIGLE_SAMPLE + i];
}
}
memcpy(xfer.data, (void *)pTemp, BUFFER_SIZE);
rx_index++;
}
if (rx_index == BUFFER_NUMBER)
{
rx_index = 0U;
}
}
if (emptyBlock < BUFFER_NUMBER)
{
xfer.data = Buffer + tx_index * BUFFER_SIZE;
xfer.dataSize = BUFFER_SIZE;
//PRINTF("emptyBlock2=%d\r\n",emptyBlock);
if (kStatus_Success == SAI_TransferSendEDMA(DEMO_SAI, &txHandle, &xfer))
{
tx_index++;
}
if (tx_index == BUFFER_NUMBER)
{
tx_index = 0U;
}
}
}
}
Best Regards,
Jarman