Skip to content

Commit e61a788

Browse files
committed
rtttl example
1 parent 0956f94 commit e61a788

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "AudioTools.h"
2+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
3+
4+
AudioInfo info(44100, 2, 16);
5+
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
6+
AudioBoardStream out(AudioKitEs8388V1);
7+
RTTTLOutput<int16_t> rtttl(sineWave, out);
8+
9+
// Arduino Setup
10+
void setup(void) {
11+
// Open Serial
12+
Serial.begin(115200);
13+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
14+
delay(5000);
15+
16+
// start I2S
17+
Serial.println("starting I2S...");
18+
auto config = out.defaultConfig(TX_MODE);
19+
config.copyFrom(info);
20+
out.begin(config);
21+
22+
// Setup sine wave (optional)
23+
sineWave.begin(info);
24+
Serial.println("started...");
25+
}
26+
27+
// Arduino loop - copy sound to out
28+
void loop() {
29+
rtttl.begin(info);
30+
rtttl.print("ComplexDemo: d=8, o=5, b=140: c4 e g c6 a5 g4 e g a g4 e c4 e2 g4 c6 a5 g4 e g a g4 e c2 p c4 e g c6 a5 g4 e g a g4 e c4 e2 g4 c6 a5 g4 e g a g4 e c2");
31+
delay(1000);
32+
}

src/AudioTools/CoreAudio/RTTTLOutput.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class RTTTLOutput : public AudioOutput {
139139
* successful.
140140
*/
141141
bool begin() override {
142+
LOGD("RTTTLOutput::begin");
142143
if (p_generator) {
143144
p_generator->begin(audioInfo());
144145
}
@@ -169,6 +170,7 @@ class RTTTLOutput : public AudioOutput {
169170
ring_buffer.writeArray(const_cast<uint8_t*>(data), len);
170171
// If we haven't started yet and we find a ':', we need to call begin()
171172
if (!is_start && find_byte(data, len, ':') >= 0) {
173+
LOGI("found ':' - resetting parser state by calling begin()");
172174
begin();
173175
}
174176
// start parsing of new rtttl string
@@ -207,11 +209,11 @@ class RTTTLOutput : public AudioOutput {
207209
bool is_start = true;
208210
char m_actual = 0;
209211
char m_prec = 0;
210-
Str m_title{100};
211-
int m_octave{4};
212-
int m_duration{4};
213-
int m_bpm{120};
214-
float m_msec_semi{750};
212+
Str m_title{40};
213+
int m_octave = 4;
214+
int m_duration = 4;
215+
int m_bpm = 120;
216+
float m_msec_semi = 750;
215217
void* reference = nullptr;
216218
std::function<void(float, int, int, void*)> noteCallback;
217219

0 commit comments

Comments
 (0)