The MIMXRT1020-EVK is a convenient platform for evaluating the RT1021 MCU, especially with the help of a good selection of example projects. It is equipped with a Wolfson WM8960 codec which is wired to separate analogue input sources - a 3.5mm headphone-mic socket (J11) on the left channel, and an onboard microphone (P1) on the right.
From the SDK, the sai_edma_record_playback example project performs a simple loopback of the audio inputs to play them out on as stereo output on the socket. I have attempted to duplicate the left channel audio samples to overwrite the ones from the right channel by modification of the example source code:
if (emptyBlock < BUFFER_NUMBER)
{
xfer.data = Buffer + tx_index * BUFFER_SIZE;
xfer.dataSize = BUFFER_SIZE;
{
// copy line-in mono audio to overwrite on-board mic
uint8_t *lc, *rc;
int cnt;
lc = xfer.data;
rc = lc + 2;
for(cnt = 0; cnt < BUFFER_SIZE / 2 / 2; cnt++)
{
*rc++ = *lc++;
*rc++ = *lc++;
lc += 2;
rc += 2;
}
if (kStatus_Success == SAI_TransferSendNonBlocking(DEMO_SAI, &txHandle, &xfer))
{
tx_index++;
}
if (tx_index == BUFFER_NUMBER)
{
tx_index = 0U;
}
}
}
The above appeared to work, except that at the boundary of every block of 256 samples, a few samples appear to be missing. Please see the following screen capture of the analogue output channels which is zoomed in to show just 1ms. (The bottom trace is the unmodified left channel, and the top is the right one which was the duplicate.)
time span: 1ms
16ms frame boundaries
I am at a loss searching for the origin of the apparent loss of these audio samples. I guess there may be some subtleties about the use of SAI.
The above observation may be applicable to other evaluation boards in the i.MX series.