2023-03-22 07:17 AM
Hi all,
I'm trying to get to know the STM32 world, and I have a STM32F746G-DISCOVERY board here. I've successfully tested a couple of TouchGFX things, and it seems quite neat.
Now I want to test the possibility to output audio signals on the TRS output connectors, so it could be played on a speaker or headphones.
However, I cannot for the life of me figure out how to do this.
What's strange is that there seems to be no real Documentation or Tutorial on how to do this. Best I could find were some forum posts and blog articles, which vary greatly in approach, effort and quality.
Also the Demo projects available in CubeIDE are not helpful, as they don't seem to work either. I flashed the "audio plackback and record" project onto my board, but only see 2 lines of log output on the screen and nothing else happens.
So my question is: What's the easiest way to produce audio output on the STM32F746? And is there any good documentation/tutorials on how to do it?
Any help would be much appreciated.
Regards
2023-03-24 06:27 AM
I totally get your point and would even agree -- if this was a forum for hobbyists.
But for a platform in a competitive market, having high entry barriers is not a good thing. Companies usually don't want to spend money on the "fun" of having to research how to get even the most trivial examples to run. I know prototyping and developing is a lot of work - I've been doing it for several years now. But if even the most trivial examples don't work, and there is no usable, helpful documentation, I think it's ok to get a little frustrated.
2023-03-24 06:48 AM
The problem with the examples is, that they are huge and not centered on a single feature.
The following minimalistic code works after adding BSP drivers to a freshly created STM32CubeMX/IDE project:
for(int i=0; i<AUDIO_OUT_BUFFER_SAMPLES; i+=2) {
// play nice sine waves on line-out. 3.3 V peak to peak
audio_out_buffer[2*i] = roundf(20000.0f * sinf(2.0f*3.14159f*440.0f/2*i/AUDIO_FREQUENCY));
audio_out_buffer[2*i+1] = roundf(20000.0f * sinf(2.0f*3.14159f*220.0f/2*i/AUDIO_FREQUENCY));
}
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, 100, AUDIO_FREQUENCY);
BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02); // magic
BSP_AUDIO_OUT_Play((void*)audio_out_buffer, sizeof(audio_out_buffer));
See also the impressive synth code: https://youtu.be/3lL-ZxyrHiE https://github.com/thi-ng/ws-ldn-7.git
hth
KnarfB
2023-03-24 07:34 AM
look:
https://github.com/pjanczyk/stm32-flac-player
here: STM32F746-Discovery board is used for SD audio playback.
https://github.com/spectran/CDJ-100S-STM32F7-Display
STM32F769 Audio (wav) Player
https://github.com/Yuanzjls/Audio_Player_stm32f769disco
Audio player (mp3, aac and wav files) based on nucleo-f429zi
https://github.com/silelis/STM32F4_MP3-AAC-WAV_player_helixMP3_helixAAC_USB_and_sdCard
*****************************************************
>Everything in between then needs time and "tinkering". (Isn't that the fun part anyway?) <
right ! building something new, at least for me, is like other people doing crossword puzzles or mountain climbing - when you reach the goal, the more difficult the path, the greater the sense of achievement. -- as a hobby or in my free time.
at work it is a little bit different: i try to find the most simple way and time efficient get the solution for a problem. So " just trying to see if it is possible " is usually no approach at work. Unless i am involved in a research project, in which case the fun factor is greater and efficiency is not the primary concern.
2023-03-30 05:11 AM
Thanks so much! With this, I was able to get at least something out of my board. It is however a rather unpleasant sound and not a nice sine wave. I can however change the pitch of it by changing the formula in line 3 of your example.
Could you please help me to understand that formula a bit more? I guess the 2*pi part is for radians conversion and the 440/220 are the frequencies to be created. But wouldn't the 2* in front of the i be used as a divisor? My understanding is that without additional brackets, * and / are simply applied left-to-right. And why is the 20000 needed?
2023-03-30 08:13 AM
You're right, the 2* is wrong, copied from another example. 20000 is the amplitude, the buffer is in int16_t format.
2023-05-05 11:53 AM
I tried but I couldn't to rebuild yet in the STM32CubeIDE Version 1.12.1 the project
Any advice after to import the files? Seems to be missing some files.
2023-05-09 05:29 AM
Unfortunately, I couldn't get that Demo Project to run as well, sorry. However, I re-used some of its audio code, and together with the code from @KnarfB I managed to at least produce some audio output on my board. But it still isn't usable, because as soon as audio output is started, the execution stops and the board freezes. In the end, my company decided to not continue development on that topic.
2023-12-29 02:16 PM
I'd suggest to take a look at the example STemWin, once it is the application that runs on the board when you buy it. Import, build and flash it on keil, for instance. On the menu, go to audio player, plug your flash drive in the CN13. It should play your audio file.