RT1020 SAI audio buffer manipulation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1020 SAI audio buffer manipulation

705 Views
dykwong
Contributor III

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: 1mstime span: 1ms

16ms frame boundaries16ms 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.

0 Kudos
4 Replies

681 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @dykwong ,

You can check each buffer block's data after it is send by interrupt. Maybe it is changed by some other code.

 

Regards,

Jing

0 Kudos

677 Views
dykwong
Contributor III

Thank you, jingpan, for your response.

 

My observation was made by modifying the example project from the RT1020 SDK. It was described as "baremetal" in the MCUXpresso IDE. Without an operating system, it is hard to find another process to overwrite the buffer.

 

Perhaps the method I used to perform the overwriting was incorrect. In that case, please suggest a better alternative.

 

0 Kudos

670 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @dykwong ,

I can't find problem in your code. But the phenomenon looks so strange. If you don't touch anything, is there problems? If you compare data after copy, is there difference? Or even after the buffer is transmitted, is the data different?

 

Regards,

Jing

0 Kudos

664 Views
dykwong
Contributor III

 

Thanks again, @jingpan .

 

The example project sai_edma_record_playback from the SDK captures by SAI RX the audio inputs from the on-board microphone and the line-in socket through the WM8960 codec continuously. The captured audio samples are untouched in the buffer, while SAI TX is used to play these captured samples back to the codec to complete the loopback.

 

Before I have inserted my code fragment to overwrite the on-board microphone audio samples by the line-in ones, the output waveform on both output channels do not exhibit any observable gaps.

It may be useful to reproduce my observation by running the example project code.

 

0 Kudos