i2s dma popping issue

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

i2s dma popping issue

602 Views
rory78
Contributor III

Hi -

I have been trying to implement a simple project on an LPC55S69EVK, where I read in audio samples from .wav files on an sd card, and then send them out to the audio codec on the board using I2S DMA. I have attempted this by adapting the FatFS and the I2S_DMA examples included in the MCUXpresso SDK.

So far i have got something to playback; however there is a popping sound and I do not know what causes it.

The popping is very intermittent, but gets more frequent the shorter the pieces of data I transmit. (i.e., the length of "data" as shown in my code).

The relevant parts of my code are attached below.

As you can see from the code, I set up the initial transfer of the data in "StartSoundPlayback();" .  Then in the main while loop, I read in another n bytes of data before the next TxCallback is triggered.  And so on.

Many thanks in advance.

Rory

short data4[200];

//main code

....

   StartSoundPlayback();

    while (1)

    {

    if(flag==1)

    {

    }

    else{

    error = f_read(&g_fileObject1,&data, sizeof(data),&bytesRead);

        s_TxTransfer.data     = &data[0];

        s_TxTransfer.dataSize = sizeof(data);

    flag = 1;

    }

    }

}

static void StartSoundPlayback(void)

{

    PRINTF("Setup looping playback of sine wave\r\n");

    s_TxTransfer.data     = &data[0];

    s_TxTransfer.dataSize = sizeof(data);

    //s_TxTransfer.data     = &g_Music[0];

    //s_TxTransfer.dataSize = sizeof(g_Music);

    I2S_TxTransferCreateHandleDMA(DEMO_I2S_TX, &s_TxHandle, &s_DmaTxHandle, TxCallback, (void *)&s_TxTransfer);

    /* need to queue two transmit buffers so when the first one

     * finishes transfer, the other immediatelly starts */

    I2S_TxTransferSendDMA(DEMO_I2S_TX, &s_TxHandle, s_TxTransfer);

    I2S_TxTransferSendDMA(DEMO_I2S_TX, &s_TxHandle, s_TxTransfer);

}

//callback for data transmit

static void TxCallback(I2S_Type *base, i2s_dma_handle_t *handle, status_t completionStatus, void *userData)

{

    //if (completionStatus == kStatus_I2S_BufferComplete)

    //{

    /* Enqueue the same original buffer all over again */

    i2s_transfer_t *transfer = (i2s_transfer_t *)userData;

    I2S_TxTransferSendDMA(base, handle, *transfer);

    count = 0;

    flag  = 0;

   // }

}

Labels (1)
0 Kudos
1 Reply

507 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Rory,

I suppose that the following code seems to have issue:

else{

    error = f_read(&g_fileObject1,&data, sizeof(data),&bytesRead);

        s_TxTransfer.data     = &data[0];

        s_TxTransfer.dataSize = sizeof(data);

    flag = 1;

    }

As you know that the I2S is stream media, but reading SD card (executing f_read()) takes time, so during the time, the I2S can not get PCM,, it leads to the popping sound.

This is only my guess, pls have a try.

BR

Xiangjun Rong

0 Kudos