#include "AudioTools.h" // ESP32-S3 I2S pins #define I2S_BCLK 1 // Bit Clock #define I2S_LRC 2 // Left/Right Clock #define I2S_DIN 43 // Data to MAX98357A const int freqs[] = {220, 440, 660, 880}; const int amps[] = {4000, 8000, 16000, 32000}; int freqIndex = 0; int ampIndex = 0; unsigned long lastChange = 0; const int sampleRate = 22000; // Hz AudioInfo info(sampleRate, 1, 16); SineWaveGenerator sineWave(32000); GeneratedSoundStream sound(sineWave); I2SStream out; StreamCopy copier(out, sound); void setup() { Serial.begin(115200); Serial.println("I2S Sine Wave Playback"); AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning); // I2S pin configuration auto config = out.defaultConfig(TX_MODE); config.copyFrom(info); config.pin_bck = I2S_BCLK; config.pin_ws = I2S_LRC; config.pin_data = I2S_DIN; out.begin(config); sineWave.begin(info, freqs[0]); Serial.println("Started sine wave playback"); } void loop() { if (millis() - lastChange >= 2000) { lastChange = millis(); freqIndex = (freqIndex + 1) % 4; if (freqIndex == 0) ampIndex = (ampIndex + 1) % 4; sineWave.setFrequency(freqs[freqIndex]); sineWave.setAmplitude(amps[ampIndex]); } copier.copy(); }