Fixed speaker.h spacing

This commit is contained in:
Dionysus 2024-06-05 18:13:36 -04:00
parent 5845a84250
commit b00d779471
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

View File

@ -8,6 +8,7 @@
#include "pins.h" #include "pins.h"
#define BOARD_I2S_PORT I2S_NUM_0 #define BOARD_I2S_PORT I2S_NUM_0
#define SAMPLE_RATE 44100 #define SAMPLE_RATE 44100
@ -39,6 +40,7 @@ void setupI2S() {
i2s_set_clk(BOARD_I2S_PORT, SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); i2s_set_clk(BOARD_I2S_PORT, SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO);
} }
void playTone(float frequency, int duration, int volume = 16383) { void playTone(float frequency, int duration, int volume = 16383) {
volume = constrain(volume, 0, 32767); volume = constrain(volume, 0, 32767);
const int wave_period = SAMPLE_RATE / frequency; const int wave_period = SAMPLE_RATE / frequency;
@ -57,6 +59,7 @@ void playTone(float frequency, int duration, int volume = 16383) {
} }
} }
void playRTTTL(const char* rtttl) { void playRTTTL(const char* rtttl) {
static AudioGeneratorRTTTL *rtttlGenerator = new AudioGeneratorRTTTL(); static AudioGeneratorRTTTL *rtttlGenerator = new AudioGeneratorRTTTL();
static AudioOutputI2S *audioOutput = new AudioOutputI2S(); static AudioOutputI2S *audioOutput = new AudioOutputI2S();
@ -64,13 +67,15 @@ void playRTTTL(const char* rtttl) {
audioOutput->begin(); audioOutput->begin();
rtttlGenerator->begin(fileSource, audioOutput); rtttlGenerator->begin(fileSource, audioOutput);
while (rtttlGenerator->isRunning()) {
while (rtttlGenerator->isRunning())
rtttlGenerator->loop(); rtttlGenerator->loop();
}
rtttlGenerator->stop(); rtttlGenerator->stop();
fileSource->close(); fileSource->close();
} }
void playNotificationSound() { void playNotificationSound() {
playTone(1000, 200); playTone(1000, 200);
delay(100); delay(100);