47 lines
1.2 KiB
Arduino
47 lines
1.2 KiB
Arduino
|
|
/**
|
||
|
|
* @file streams-generator-audiokit.ino
|
||
|
|
* @brief Tesing I2S output for ESP32-S3-AI-Smart-Speaker with generated sine wave
|
||
|
|
*
|
||
|
|
* Dependencies:
|
||
|
|
* - https://github.com/pschatzmann/arduino-audio-tools
|
||
|
|
* - https://github.com/pschatzmann/arduino-audio-driver
|
||
|
|
*
|
||
|
|
* @author Phil Schatzmann
|
||
|
|
* @copyright GPLv3
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "AudioTools.h"
|
||
|
|
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||
|
|
|
||
|
|
|
||
|
|
AudioInfo info(32000, 2, 16);
|
||
|
|
SineGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||
|
|
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||
|
|
AudioBoardStream out(ESP32S3AISmartSpeaker);
|
||
|
|
StreamCopy copier(out, sound); // copies sound into i2s
|
||
|
|
|
||
|
|
// Arduino Setup
|
||
|
|
void setup(void) {
|
||
|
|
// Open Serial
|
||
|
|
Serial.begin(115200);
|
||
|
|
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||
|
|
|
||
|
|
// start I2S
|
||
|
|
Serial.println("starting I2S...");
|
||
|
|
auto config = out.defaultConfig(TX_MODE);
|
||
|
|
config.copyFrom(info);
|
||
|
|
out.begin(config);
|
||
|
|
|
||
|
|
// set the volume
|
||
|
|
out.setVolume(0.4f);
|
||
|
|
|
||
|
|
// Setup sine wave
|
||
|
|
sineWave.begin(info, N_B4);
|
||
|
|
Serial.println("started...");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Arduino loop - copy sound to out
|
||
|
|
void loop() {
|
||
|
|
copier.copy();
|
||
|
|
}
|