Ivan Klochkov

FATFS and audio play

Discussion created by Ivan Klochkov on Jun 3, 2017

Hi everyone,

I'm trying to play audio file using FaTFs library on Open 4X9I-C board with UDA1380 audio decoder.

I looked over examples for my board and other eval boards and found AudioPlay() function which sends the data over I2S and updates Position and Remainig Size. However when I try to read data from a file on a SD-card and send it over I2S it just ends in massive noise.

Here's what I have so far:

extern uint32_t AudioRemSize;  
extern uint16_t *CurrentPos;  
int BUFSIZE=512;
int position=0;

    UDA1380_Init();

    res = f_mount(&fs, "", 0);

   res = f_open(&fil, "0:ob.wav", FA_READ);

  while (1)
  {
        while(!f_eof(&fil)) {
    res = f_lseek(&fil, position);
    res = f_read(&fil, rtext, BUFSIZE, (UINT*)&bytesread);
    AUDIO_Play((uint16_t*)rtext, BUFSIZE);
    position += BUFSIZE;        
        }
  }

 

uint32_t AUDIO_Play(uint16_t* pBuffer, uint32_t Size)
{
  /* Set the total number of data to be played (count in half-word) */
  AudioTotalSize = Size;
 
  /* Update the Media layer and enable it for play */  
  HAL_I2S_Transmit_DMA(&hi2s2,pBuffer, (uint32_t)(DMA_MAX(Size/2)));
 
  /* Update the remaining number of data to be played */
  AudioRemSize = Size/2 - DMA_MAX(AudioTotalSize);
 
  /* Update the current audio pointer position */
  CurrentPos = pBuffer + DMA_MAX(AudioTotalSize);
 
  return 0;
}

I would be greatly appreciated if someone could suggest anything.

I know I must be using f_forward instead of f_read and there is also an I2S Callback function which doesn't affect anything, but I'm just stuck.

Outcomes