I'm very beginner of programing and STM.
I'd like to make it sound the audio line out with sine wave from STM32H735G-DK.
I read the document(UM2679) and understood that SAI and I2C4 are connected to the audio.
But I don't know how to use these.
Especially, I couldn't understand how to set volume and start to play.
Attached files are the one I tried and it doesn't work.
I put a button on the screen and set the interaction with function name "startAudio" as it sounds when I push the button.
Please tell me your advice.
I couldn't attach the file Screen1View.cpp.
So I put it down in text below.
#include <gui/screen1_screen/Screen1View.hpp>
#include "main.h"
#include <stdio.h>
#include <math.h>
#define SAMPLE_RATE 48000
#define BUFFER_SIZE 1024
#define PI 3.141592
uint8_t audioBuffer[BUFFER_SIZE];
void generateAudioData();
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::startAudio()
{
generateAudioData();
HAL_SAI_Transmit_DMA(&hsai_BlockA1,(uint8_t*)audioBuffer,BUFFER_SIZE);
}
void generateAudioData(){
float frequency = 440.0;
float amplitude = 0.5;
for(int i = 0; i < BUFFER_SIZE; i++)
{
float t = (float)i / SAMPLE_RATE;
float sine_wave = sin(2 * PI * frequency * t);
audioBuffer[i] = (uint8_t)((sine_wave * amplitude + 0.5) * 255);
}
}