‎2023-04-13 03:13 AM
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:
So, here are some more details. I've reduced the code as much as possible.
Call hierarchy:
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?
‎2023-05-10 02:36 AM
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? :grinning_face_with_sweat:
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
‎2023-05-14 11:41 PM
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.