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!

1 ACCEPTED SOLUTION

Accepted Solutions
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 😉 

View solution in original post

12 REPLIES 12
AScha.3
Chief II

Hi,

so you got it working...right ?

But you use the BSP functions - i never did.

>The issue is that the sound plays way too fast 

from source:

 

/**
  * @brief  Updates the audio frequency.
  *   AudioFreq: Audio frequency used to play the audio stream.
  * @note   This API should be called after the BSP_AUDIO_OUT_Init() to adjust the
  *         audio frequency.
  */
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)

 

 and you use:

 

  BSP_AUDIO_OUT_Init(2, 60, 44100);
  AUDIO_Play_Start((uint32_t *)0x08080000, (uint32_t)0x143046);
  HAL_Delay(500);
  BSP_AUDIO_OUT_Pause();
  BSP_AUDIO_OUT_SetFrequency(8000);
  BSP_AUDIO_OUT_Resume();

 

So start with 44k1 , then switch to 8k ? why ?

Did you check, whats written to CSxxx codec ? And whats set in SAIx_Init(..) to the SAI ?

If you feel a post has answered your question, please click "Accept as Solution".

so you got it working...right ?

Yeah, but just way to fast.

 


So start with 44k1 , then switch to 8k ? why ?


It was just to test if it would run slower with it, because in the BSP file, it was much slower with 8k. Unfortunately, it sounds nearly the same with 8k or 44k1.

 


Did you check, whats written to CSxxx codec ? And whats set in SAIx_Init(..) to the SAI ?


Yes but I don't understand where I could "slow" the code down

 

"I also tried to copy the SAI initialization from the BSP to my SAI initialization (in main.c line 675), but it resulted in the same issue."

>Yes but I don't understand where I could "slow" the code down

The audio speed (= sample rate) is set by the SAI master and what you set it to.

in Cube:

AScha3_0-1716285411158.png

then start it, from now its continuously running... (Check with scope the signal, word clk...to prove your setting.)

 

 

 fresult = HAL_DMA_Init(&hdma_sai1_a); 

fresult = HAL_SAI_Transmit_DMA(&hsai_BlockA1,  (uint8_t *)playbuf , (sizeof(playbuf))/4);// SAI start

 

 

(playbuf is int32_t here, because i use 32b sample format, so you might adjust for int16 )

Then just feed it in half/full callbacks - thats it, to get it running. 🙂

 

If you feel a post has answered your question, please click "Accept as Solution".

 

 fresult = HAL_DMA_Init(&hdma_sai1_a); 

fresult = HAL_SAI_Transmit_DMA(&hsai_BlockA1,  (uint8_t *)playbuf , (sizeof(playbuf))/4);// SAI start

 

I tried a bit with the code but had no success; now i cant hear anything

I also inserted HAL_DMA_Init(&hdma_sai1_a) as you suggested.

I changed the following:

 

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)
  {
	// Changed here 
    if ( HAL_SAI_Transmit_DMA(&haudio_out_sai,  (uint8_t *)pBuffer , (sizeof(pBuffer))/4)!= HAL_OK)
    {
      ret = AUDIO_ERROR;
    }
  }

  return ret;
}

 

And I think it would be an good idea, to upload my SAI config: 

DerFreaker_0-1716291567405.pngDerFreaker_2-1716291620351.png

 

DerFreaker_3-1716291645344.png

 

 

 

>And I think it would be an good idea, to upload my SAI config

"Config" ...is wrong word for this , more "disfig". 🙂

 

1. SAI DMA data with : word + word ? (32b) -> half-word +  half-word (16b) 

2. SAI parameters : data size : 8 bit ??? -> 16 bit

+ protocol : free ?? -> I2S standard

+ frame : 8b ???? -> (stereo) -> 32 b (or 2 slot , whatever it shows you for I2S )

Then check with a scope : all signals ok, as should it be .

Your CSxxx dac is ..? + set to I2S , 16b stereo , right ?

If you feel a post has answered your question, please click "Accept as Solution".

So, I changed everything you mentioned, but without any success; it's still the same issue.

 

  I am not using I²S.

DerFreaker_0-1716364831044.png

 


@AScha.3 wrote:

Your CSxxx dac is ..? + set to I2S , 16b stereo , right ?


So, I changed everything you mentioned, but I have some issues with the protocol i only have Free and AC97 . I am not using I²S. What do you mean by "Your csxxx DAC"? If you mean the chip on the board, it's the CS43L22.

Yes , CS43L22 .

+

> I am not using I²S.

Why ? just set it to I2S , also SAI - and it should work.

 

AScha3_0-1716370226376.png

 

If you feel a post has answered your question, please click "Accept as Solution".

I can't choose the I2S standard for the SAI protocol. Maybe there is something wrong with my I2S configuration?

 

I2S:

DerFreaker_2-1716371600756.png

 

SAI:

DerFreaker_3-1716371613020.png

 

 

Ok...i see, on F4xxx , seems no I2S preset 🙂   (what a mess ... I only use H743 and H563 for this, they have it.)

so we try free :

AScha3_0-1716372567336.png

 

If you feel a post has answered your question, please click "Accept as Solution".