cancel
Showing results for 
Search instead for 
Did you mean: 

BSP_AUDIO_OUT_Play never finishes and blocks execution

JLubb.1
Associate III

Hi all,

I'm having trouble implementing audio output into a TouchGFX application for the STM32F746G-DISCO board.

The TouchGFX part is done, and I also managed to include the necessary files for audio output into the project and call a function to start playing audio.

However, once that function is called, it blocks everything else and the entire board becomes unresponsive. Audio is played in an endless loop and no other interaction is possible.

The nearly exact same question was asked a couple of years ago already, but got no answer because of missing details:

https://community.st.com/s/question/0D50X00009XkdwfSAB/bspaudiooutplay-function-stops-program-execution

So, here are some more details. I've reduced the code as much as possible.

Call hierarchy:

  • TouchGFX button press
    • Interaction "Call virtual function" --> in the corresponding View.cpp class
      • View calls Presenter, Presenter Calls Model
        • Model has an include of "myaudio.c" and calls the PlaySound() function
          • Class "myaudio.c" then calls the necessary BSP functions

The relevant parts of the class "myaudio.c" are:

#include "main.h"
#include "myaudio.h"
#include "math.h"
 
static uint16_t audioBuf[4096];
 
static int PlayerInit()
{
  if(BSP_AUDIO_OUT_INIT(OUTPUT_DEVICE_HEADPHONE, 20, 48000) != 0)
  {
    return -1;
  }
  else
  {
    BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
    return 0;
  }
}
 
static int PlaySound()
{
  for(int i=0; i<=4094; i+=2)
  {
    audioBuf[2*i] = 32767.0f + roundf(32767.0f * sinf((2.0f * 3.14159f + 440.0f * (float)i) / 48000));
    audioBuf[2*i+1] = 32767.0f + roundf(32767.0f * sinf((2.0f * 3.14159f + 220.0f * (float)i) / 48000));
  }
 
  if(BSP_AUDIO_OUT_Play( (uint16_t *) audioBuf, 4096 ) != 0)
  {
    return -1;
  }
  else {
    return 0;
  }
}

The return values are propagated back up to the View, where they are displayed in the UI.

However, none of that happens because the code gets stuck at the BSP_AUDIO_OUT_Play step. Nothing after that gets executed. If I comment it out, everything works fine (but then there is no audio output, obviously).

Where is my mistake, or is this a bug in the audio driver?

Is it intended behaviour of the BSP Play function to play the given audio buffer array in an endless loop? If so, how can it be changed to play a sound only as a one-shot event and then stop?

11 REPLIES 11

Hello JLubb.1,

You're welcome. Just try to help here, there's not much I can do if I don't know the subject, can I? 😅

If you want to get personal assistance, I invite you to fill out this form: Online Support (st.com) my colleagues will take care of this subject and I believe we can find a solution to your issue.

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

Thanks, and no hard feelings. I know everyone here is just trying to help, it's just very frustrating. As I said, we moved on for now, so I won't inquire more about this topic.