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
Hi @jarman_zhou ,
For the bus data and the real data is correct or not, it's easy to check.
You can printf your related data, then check the SAI bus data.
Best Regards,
Kerry
Hi @jarman_zhou ,
Thanks for your trust!
Now, do you check what's the detail wrong after you do the data processing?
The data is wrong, or just send out have delay, as the data process need time.
You can check the SAI bus, then check the real audio sent out data.
Best Regards,
Kerry
Or do you have a demo of collecting data from multiple channels and then processing the data for each channel?
Hi @jarman_zhou ,
You can refer to the application note:
https://www.nxp.com/docs/en/application-note/AN12090.pdf
You issue may caused by the data process time is long, and it is not fast to fill the DMA.
Maybe you can prepare another buffer, which is used to do the dataprocessing, then to the DMA data fill, you even don't need to use the unfinished data buffer.
In my memory, the SDK already have that code, you can check the related sai code, with more data buffers.
Wish it helps you!
Best Regards,
Kerry
I don't think it's because the data processing time is too long.
First of all, the processing of data is just shifting and assigning values, which does not require too much computation. Secondly, it is normal for me to restore the data after shifting.
You can take a look at the following code, so that it is normal to handle sound
In comments (1) and (2), no matter which line of code is removed, the output is incorrect.
I don't know if there is any particularity in the audio data of RT1021. I have also handled this problem similarly on other platforms.Our project is currently stuck in this location,I can attach my code and you can run it directly on the EVK board
Best Regards,
Jarman
Hi @jarman_zhou ,
Sorry for my later reply!
Do you try to add a buffer.
eg.
Buffer=pMic[j*64+i];
pMic[j*64+i]=Buffer>>1.
Whether this method let the data correct or not?
Do you check the SAI bus data, what the bus data now?
Best Regards,
Kerry
Thank you for your reply. Now I just extract the received data into a new buffer, and then then shift it.There is almost no delay in sending
Now, do you check what's the detail wrong after you do the data processing?
I suspect there is a problem with extracting data from each channel, but I am not sure the above code is correct, I have no clue
Best Regards,
Jarman