cancel
Showing results for 
Search instead for 
Did you mean: 

Slow down SAI Audio output

DerFreaker
Associate III

 

Hello,

I am currently programming an STM32F469I in STM32CubeIDE (I am a beginner with STM) and I am facing some issues.

  1. What I want: I want to read WAV file data from an SD card and send it to the AUX output so I can hear it on my headset/speaker. Currently, I am reading the data from a buffer, but I will change that afterwards once I know that everything works.

  2. What is the issue?: The issue is that the sound plays way too fast and I don't know why. I am attaching my project so you can download it and look at it.

My main files are saved under /Core/Src

 

Thank you for your help!

12 REPLIES 12

So I managed to get sound again by changing this value:

 

	                                                                            //HERE
    if (HAL_SAI_Transmit_DMA(&haudio_out_sai,  (uint8_t *)pBuffer , (sizeof(pBuffer))/4) != HAL_OK)
    {
      ret = AUDIO_ERROR;
    }
  }

 

To: 

 

                                                                     //Changed from 4 to 2
 if (HAL_SAI_Transmit_DMA(&haudio_out_sai,  (uint8_t *)pBuffer , (sizeof(pBuffer))/2) != HAL_OK)
    {
      ret = AUDIO_ERROR;
    }
  }

 

 However, it is even more unintelligible and almost sounds like just noise.

 

Edit:

As I change the SIZE, the sound gets clearer! I think this is a good sign. I can now understand what I want to hear! So, it was actually a problem with the size variable (it was too low) from the HAL_SAI_Transmit_DMA function call.

 

So, the last step for me is to find out how to calculate the size. Thank you very much! I am going to post the code once I'm done, for everyone who may have the same issue.

DerFreaker
Associate III

Unfortunately, after implementing the SD card, it no longer works as it should. If the data size increases, more problems occur. I have WAV files that are 60 seconds in length, and the speed issue persists, but this time changing the size variable doesn't work anymore (It just gets worse and worse)

 

 

uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size)
{
  uint8_t ret = AUDIO_OK;

  /*Call the audio Codec Play function */
  if(audio_drv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0)
  {
    ret = AUDIO_ERROR;
  }

  /* Initiate a DMA transfer of PCM samples towards the serial audio interface */
  if(ret == AUDIO_OK)
  {
	  	  	  	  	  	  	  	  	  	  	  	  	    		// Speed variable = 4000
    if (HAL_SAI_Transmit_DMA(&haudio_out_sai,  (uint8_t *)pBuffer , 4000) != HAL_OK)
    {
      ret = AUDIO_ERROR;
    }

  }

  return ret;
}

 

 

Ive also made some changes to main.c so im just gonna attach it here 

DerFreaker
Associate III

Hey, after reviewing the code I'm using, I discovered that I'm modifying the SAI data size within the code.

So, that was the issue.

 

 

// From
haudio_out_sai.Init.DataSize = SAI_DATASIZE_16;

// To
haudio_out_sai.Init.DataSize = SAI_DATASIZE_32;

 

 

 

If you encounter any errors because it's too fast, simply change the data size to 32.

 

Thanks for the help 😉