AnsweredAssumed Answered

I2s capture in vybrid is noisy

Question asked by Abdul Nihad on Nov 20, 2013
Latest reply on Mar 18, 2014 by Abdul Nihad

I want to capture audio using I2S protocol. I have connected my audio slave device to SAI2 of vybrid. I have configured vybrid as master and my audio device as slave.

We have configured vybid I2S as master Receiver and tuner I2S as slave transmitter. Here it is clear that we have to use vybrid receive channel. But according to vybrid reference manual I2S_RX_BCLK(Pin#58) and I2S_RX_SYNC (Pin#59) are bi-directional So vybrid master will provide all the clock signal for tuner through its I2S_RX_xx pins and vybrid receive PCM samples through its I2S_RX_DATA. But this configuration is not working and not able to get audio . But When I used SAI2_TX clock signals it worked. According to demo setup we are using SAI2_TX_BCLK (Y5) ,  SAI2_RX_WS (U6) , SAI2_RX_DATA (E17). But captured audio is noisy. How to fix this issue. I am pasting snaps of my initialization code here.

 

#define DEFAULT_SAMPLE_RATE_HZ   48000
#define DEFAULT_NUM_CHANNELS     2
#define DEFAULT_BITS_PER_SAMPLE  16
#define SAMPLE_SIZE_IN_BYTE     DEFAULT_BITS_PER_SAMPLE/8

 

_mqx_int InitTunerI2S(HTUNER h)

{

    TUNER* p = (TUNER*)h;

    _mqx_int     errcode = 0;

    uint_32        mclk_freq;

   // _mqx_int    param, temp;

 

    /* Prepare audio format struct */

    p->audio_format.ENDIAN         = AUDIO_LITTLE_ENDIAN;

    p->audio_format.ALIGNMENT     = AUDIO_ALIGNMENT_LEFT;

    p->audio_format.BITS         = DEFAULT_BITS_PER_SAMPLE;

    p->audio_format.SIZE         = SAMPLE_SIZE_IN_BYTE;

    p->audio_format.CHANNELS     = DEFAULT_NUM_CHANNELS;

    p->audioSamplingFreq         = DEFAULT_SAMPLE_RATE_HZ;

 

    mclk_freq = p->audioSamplingFreq * CLK_MULT;  /* Set master clock frequency so oversampling = 384 */

 

   uint_8 mode = I2S_MODE_MASTER;

    p->tunerI2S_fd = fopen(AUDIO_DEVICE, "r");

 

    if (p->tunerI2S_fd == NULL)

    {

        printf("\n  InitTunerI2S error: Unable to open audio device.\r\n");

        return(0xDEAD);

    }

 

    /* Setup device */

    if (ioctl(p->tunerI2S_fd, IO_IOCTL_AUDIO_SET_IO_DATA_FORMAT, &(p->audio_format)) != I2S_OK)

    {

        printf("  Error: Input data format not supported.\n");

        fclose(p->tunerI2S_fd);

        return (MQX_ERROR);

    }

 

    if(I2S_OK != ioctl(p->tunerI2S_fd, IO_IOCTL_I2S_SET_DATA_BITS, &(p->audio_format.BITS)))

        errcode = -1;

    if(I2S_OK != ioctl(p->tunerI2S_fd, IO_IOCTL_I2S_SET_MODE_MASTER, &mode))

        errcode = -1;

    if(I2S_OK != ioctl(p->tunerI2S_fd, IO_IOCTL_I2S_SET_MCLK_FREQ, &mclk_freq))

        errcode = -1;

    if(I2S_OK != ioctl(p->tunerI2S_fd, IO_IOCTL_I2S_SET_FS_FREQ, &p->audioSamplingFreq))

        errcode = -1;

 

    _time_delay(50);

 

    if(errcode != -1)

    {

        ioctl(p->tunerI2S_fd, IO_IOCTL_I2S_GET_FS_FREQ, &p->audioSamplingFreq);

        ioctl(p->tunerI2S_fd, IO_IOCTL_I2S_GET_BCLK_FREQ, &p->audioBitClkFreq);

        printf("I2S Settings:\r\n");

        printf("  Sampling frequency:     %d Hz\r\n", p->audioSamplingFreq);

        printf("  Bit depth:              %d bits\r\n", p->audio_format.BITS);

        printf("  Bit rate :              %d bits/sec\r\n", p->audioBitClkFreq);

        printf("  Channels:               ");

        if (p->audio_format.CHANNELS == 1)

        {

          printf("mono\n");

        }

        else

        {

            printf("stereo\n");

        }

        printf("I2S initialised.....\r\n");

    }

 

    return (MQX_OK);

}

Outcomes