@geastack/host 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +25 -0
- package/audio_runtime.cpp +807 -0
- package/bluetooth.cpp +125 -0
- package/geolocation.cpp +43 -0
- package/host/apps.cpp +20 -0
- package/host/audio.cpp +240 -0
- package/host/ble.cpp +239 -0
- package/host/camera.cpp +193 -0
- package/host/display.cpp +230 -0
- package/host/fetch.cpp +1060 -0
- package/host/geolocation.cpp +31 -0
- package/host/gpio.cpp +55 -0
- package/host/http.cpp +349 -0
- package/host/image.cpp +335 -0
- package/host/imu.cpp +51 -0
- package/host/input.cpp +12 -0
- package/host/media.cpp +579 -0
- package/host/memory.cpp +91 -0
- package/host/rtc.cpp +212 -0
- package/host/rtc_esp.cpp +291 -0
- package/host/tile_loader.cpp +478 -0
- package/host/timers.cpp +327 -0
- package/host/touch.cpp +25 -0
- package/host/websocket.cpp +279 -0
- package/host/wifi.cpp +99 -0
- package/include/gea/embedded-host.h +38 -0
- package/include/host/apps.h +15 -0
- package/include/host/audio.h +158 -0
- package/include/host/backends.h +455 -0
- package/include/host/battery.h +25 -0
- package/include/host/camera.h +236 -0
- package/include/host/clock.h +45 -0
- package/include/host/device_control.h +23 -0
- package/include/host/display.h +266 -0
- package/include/host/display_orientation.h +291 -0
- package/include/host/fetch.h +310 -0
- package/include/host/gpio.h +36 -0
- package/include/host/http.h +161 -0
- package/include/host/image.h +144 -0
- package/include/host/input.h +14 -0
- package/include/host/media.h +165 -0
- package/include/host/memory.h +44 -0
- package/include/host/navigator.h +283 -0
- package/include/host/notify.h +41 -0
- package/include/host/profiler.h +49 -0
- package/include/host/rtc.h +174 -0
- package/include/host/storage.h +141 -0
- package/include/host/tile_loader.h +59 -0
- package/include/host/timers.h +41 -0
- package/include/host/touch.h +20 -0
- package/include/host/websocket.h +179 -0
- package/include/host/window.h +31 -0
- package/input.cpp +68 -0
- package/package.json +27 -0
- package/services/app_state.cpp +19 -0
- package/services/battery_service.cpp +19 -0
- package/services/bluetooth_service.cpp +37 -0
- package/services/diagnostics.cpp +233 -0
- package/services/diagnostics_connection.cpp +231 -0
- package/services/diagnostics_internal.h +15 -0
- package/services/diagnostics_server.cpp +135 -0
- package/services/mirror.cpp +364 -0
- package/services/network_services.cpp +62 -0
- package/services/runtime_log.cpp +23 -0
- package/services/settings_surface.h +221 -0
- package/wifi.cpp +185 -0
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#define GEA_AUDIO_DRIVER_INTERNAL 1
|
|
3
|
+
#include "audio.h"
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <atomic>
|
|
7
|
+
#include <climits>
|
|
8
|
+
#include <cmath>
|
|
9
|
+
#include <cstdint>
|
|
10
|
+
#include <cstdio>
|
|
11
|
+
#include <cstring>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
#include "esp_log.h"
|
|
16
|
+
#include "esp_timer.h"
|
|
17
|
+
#include "freertos/FreeRTOS.h"
|
|
18
|
+
#include "freertos/queue.h"
|
|
19
|
+
#include "freertos/task.h"
|
|
20
|
+
#include "platform/file_cache.h"
|
|
21
|
+
|
|
22
|
+
namespace audio = gea::platform::audio;
|
|
23
|
+
|
|
24
|
+
namespace {
|
|
25
|
+
|
|
26
|
+
constexpr int kSampleRate = 16000;
|
|
27
|
+
constexpr int kChannels = 2;
|
|
28
|
+
constexpr int kQueueDepth = 16;
|
|
29
|
+
// ESP-IDF sizes a task stack in BYTES (`StackType_t` is `uint8_t` on this
|
|
30
|
+
// port), not in FreeRTOS "words". This constant was named and sized as words:
|
|
31
|
+
// the tone task ran on 4 KB, and the first `OutputDriver::open()` on
|
|
32
|
+
// ESP-IDF 6 -- I2S channel creation, the ES8311 bring-up over the I2C master
|
|
33
|
+
// driver and the log lines that pass through the diagnostics vprintf sink,
|
|
34
|
+
// all on this task -- overran it before a single sample played
|
|
35
|
+
// ("A stack overflow in task gea_audio has been detected"; button-tetris on
|
|
36
|
+
// the 2.06 AMOLED rebooted every 3 seconds). The task logs its high-water
|
|
37
|
+
// mark once after the driver opens so the next reader sizes it from a number.
|
|
38
|
+
constexpr int kTaskStackBytes = 8192;
|
|
39
|
+
constexpr int kChunkSamples = 512;
|
|
40
|
+
constexpr int kAmplitude = 5200;
|
|
41
|
+
constexpr int kMaxOscillators = 8;
|
|
42
|
+
constexpr int kMaxActiveTones = 12;
|
|
43
|
+
constexpr int kMaxToneMs = 2500;
|
|
44
|
+
constexpr int kWriteTimeoutMs = 250;
|
|
45
|
+
constexpr int64_t kDropLogIntervalUs = 1000000;
|
|
46
|
+
constexpr int kPlaybackChunkFrames = 512;
|
|
47
|
+
constexpr int kPlaybackWriteTimeoutMs = 250;
|
|
48
|
+
constexpr int kChunkDurationMs = (kChunkSamples * 1000) / kSampleRate;
|
|
49
|
+
// Notes are scheduled back-to-back with no built-in gap, but render-thread
|
|
50
|
+
// jitter (line clears, board redraws) can momentarily empty activeTones_
|
|
51
|
+
// between notes. Closing the codec on every such gap and reopening it for the
|
|
52
|
+
// next note reinitializes the ES8311 over I2C and retoggles the PA GPIO each
|
|
53
|
+
// time (see chip_bindings/audio/es8311.cpp open()/close()) — audible as
|
|
54
|
+
// clicking/stutter through a whole melody. Ride out short gaps with silence
|
|
55
|
+
// instead of tearing the codec down.
|
|
56
|
+
constexpr int kCloseGraceChunks = 10;
|
|
57
|
+
|
|
58
|
+
#ifndef GEA_AUDIO_DEBUG_TIMING
|
|
59
|
+
#define GEA_AUDIO_DEBUG_TIMING 0
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
#ifndef GEA_AUDIO_DEBUG_TIMING_THRESHOLD_US
|
|
63
|
+
#define GEA_AUDIO_DEBUG_TIMING_THRESHOLD_US 500
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#ifndef GEA_EMBEDDED_AUDIO_DISABLED
|
|
67
|
+
#define GEA_EMBEDDED_AUDIO_DISABLED 0
|
|
68
|
+
#endif
|
|
69
|
+
|
|
70
|
+
class AudioEngine {
|
|
71
|
+
public:
|
|
72
|
+
static AudioEngine &instance() {
|
|
73
|
+
static AudioEngine engine;
|
|
74
|
+
return engine;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
double currentTime() const {
|
|
78
|
+
return static_cast<double>(esp_timer_get_time()) / 1000000.0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
audio::NativeAudioHandle destination() const {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
audio::NativeAudioHandle createOscillator() {
|
|
86
|
+
const int slot = nextOscillatorSlot_;
|
|
87
|
+
nextOscillatorSlot_ = (nextOscillatorSlot_ + 1) % kMaxOscillators;
|
|
88
|
+
auto &oscillator = oscillators_[slot];
|
|
89
|
+
oscillator = OscillatorState{};
|
|
90
|
+
oscillator.inUse = true;
|
|
91
|
+
return nativeHandle(oscillator);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
audio::OscillatorType oscillatorType(audio::NativeAudioHandle handle) const {
|
|
95
|
+
const auto *osc = oscillator(handle);
|
|
96
|
+
return osc ? osc->type : audio::OscillatorType::Sine;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
void setOscillatorType(audio::NativeAudioHandle handle, audio::OscillatorType type) {
|
|
100
|
+
auto *osc = oscillator(handle);
|
|
101
|
+
if (!osc) return;
|
|
102
|
+
osc->type = normalizeType(type);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
double oscillatorFrequency(audio::NativeAudioHandle handle) const {
|
|
106
|
+
const auto *osc = oscillator(handle);
|
|
107
|
+
return osc ? osc->frequencyHz : 0.0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void setOscillatorFrequency(audio::NativeAudioHandle handle, double frequencyHz) {
|
|
111
|
+
auto *osc = oscillator(handle);
|
|
112
|
+
if (!osc) return;
|
|
113
|
+
osc->frequencyHz = frequencyHz;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void setOscillatorFrequencyAtTime(audio::NativeAudioHandle handle, double frequencyHz, double startTime) {
|
|
117
|
+
(void)startTime;
|
|
118
|
+
setOscillatorFrequency(handle, frequencyHz);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void connectOscillator(audio::NativeAudioHandle handle, audio::NativeAudioHandle destination) {
|
|
122
|
+
(void)destination;
|
|
123
|
+
auto *osc = oscillator(handle);
|
|
124
|
+
if (!osc) return;
|
|
125
|
+
osc->connected = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void startOscillator(audio::NativeAudioHandle handle, double when) {
|
|
129
|
+
auto *osc = oscillator(handle);
|
|
130
|
+
if (!osc) return;
|
|
131
|
+
if (when <= 0.0) when = currentTime();
|
|
132
|
+
osc->startTime = when;
|
|
133
|
+
osc->started = true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
void stopOscillator(audio::NativeAudioHandle handle, double when) {
|
|
137
|
+
auto *osc = oscillator(handle);
|
|
138
|
+
if (!osc || !osc->connected) return;
|
|
139
|
+
|
|
140
|
+
const double now = currentTime();
|
|
141
|
+
const double startTime = osc->started ? osc->startTime : now;
|
|
142
|
+
if (when <= 0.0) when = now;
|
|
143
|
+
if (when < startTime) when = startTime;
|
|
144
|
+
|
|
145
|
+
const int durationMs = static_cast<int>((when - startTime) * 1000.0 + 0.5);
|
|
146
|
+
const int delayMs = startTime > now ? static_cast<int>((startTime - now) * 1000.0 + 0.5) : 0;
|
|
147
|
+
if (durationMs <= 0) return;
|
|
148
|
+
|
|
149
|
+
submitTone(Tone{
|
|
150
|
+
osc->type,
|
|
151
|
+
osc->frequencyHz,
|
|
152
|
+
durationMs,
|
|
153
|
+
delayMs,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
int volume() const {
|
|
158
|
+
return audio::OutputDriver::volume();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void setVolume(int volumePercent) {
|
|
162
|
+
audio::OutputDriver::setVolume(volumePercent);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void beginExclusivePlayback() {
|
|
166
|
+
exclusivePlayback_.store(true, std::memory_order_release);
|
|
167
|
+
clearTones();
|
|
168
|
+
if (driverOpen_.exchange(false, std::memory_order_acq_rel)) {
|
|
169
|
+
audio::OutputDriver::close();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void endExclusivePlayback() {
|
|
174
|
+
clearTones();
|
|
175
|
+
exclusivePlayback_.store(false, std::memory_order_release);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
void stopPlayback() {
|
|
179
|
+
clearTones();
|
|
180
|
+
driverOpen_.store(false, std::memory_order_release);
|
|
181
|
+
audio::OutputDriver::close();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private:
|
|
185
|
+
struct Tone {
|
|
186
|
+
audio::OscillatorType type = audio::OscillatorType::Sine;
|
|
187
|
+
double frequencyHz = 440.0;
|
|
188
|
+
int durationMs = 0;
|
|
189
|
+
int delayMs = 0;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
struct OscillatorState {
|
|
193
|
+
bool inUse = false;
|
|
194
|
+
audio::OscillatorType type = audio::OscillatorType::Sine;
|
|
195
|
+
double frequencyHz = 440.0;
|
|
196
|
+
bool connected = false;
|
|
197
|
+
bool started = false;
|
|
198
|
+
double startTime = 0.0;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
struct ActiveTone {
|
|
202
|
+
bool inUse = false;
|
|
203
|
+
audio::OscillatorType type = audio::OscillatorType::Sine;
|
|
204
|
+
std::uint32_t phase = 0;
|
|
205
|
+
std::uint32_t phaseStep = 0;
|
|
206
|
+
int totalSamples = 0;
|
|
207
|
+
int sampleIndex = 0;
|
|
208
|
+
int delaySamples = 0;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
AudioEngine() = default;
|
|
212
|
+
|
|
213
|
+
static audio::OscillatorType normalizeType(audio::OscillatorType type) {
|
|
214
|
+
switch (type) {
|
|
215
|
+
case audio::OscillatorType::Square:
|
|
216
|
+
case audio::OscillatorType::Sawtooth:
|
|
217
|
+
case audio::OscillatorType::Triangle:
|
|
218
|
+
case audio::OscillatorType::Sine: return type;
|
|
219
|
+
}
|
|
220
|
+
return audio::OscillatorType::Sine;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static int envelope(int sampleIndex, int remainingSamples) {
|
|
224
|
+
constexpr int attackSamples = 80;
|
|
225
|
+
constexpr int releaseSamples = 180;
|
|
226
|
+
int level = 256;
|
|
227
|
+
if (sampleIndex < attackSamples) level = (sampleIndex * 256) / attackSamples;
|
|
228
|
+
if (remainingSamples < releaseSamples) {
|
|
229
|
+
const int releaseLevel = (remainingSamples * 256) / releaseSamples;
|
|
230
|
+
if (releaseLevel < level) level = releaseLevel;
|
|
231
|
+
}
|
|
232
|
+
if (level < 0) return 0;
|
|
233
|
+
if (level > 256) return 256;
|
|
234
|
+
return level;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static int waveformSample(audio::OscillatorType type, std::uint32_t phase) {
|
|
238
|
+
if (type == audio::OscillatorType::Square) {
|
|
239
|
+
return (phase & 0x80000000u) ? kAmplitude : -kAmplitude;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (type == audio::OscillatorType::Sine) {
|
|
243
|
+
constexpr double kTau = 6.28318530717958647692;
|
|
244
|
+
const double cycle = static_cast<double>(phase) / 4294967296.0;
|
|
245
|
+
return static_cast<int>(std::sin(cycle * kTau) * static_cast<double>(kAmplitude));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const std::uint32_t pos = phase >> 16;
|
|
249
|
+
if (type == audio::OscillatorType::Sawtooth) {
|
|
250
|
+
return ((static_cast<int>(pos) - 32768) * kAmplitude) / 32768;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (pos < 32768) {
|
|
254
|
+
return -kAmplitude + (static_cast<int>(pos) * kAmplitude * 2) / 32768;
|
|
255
|
+
}
|
|
256
|
+
return kAmplitude - ((static_cast<int>(pos) - 32768) * kAmplitude * 2) / 32768;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static int clampSample(int sample) {
|
|
260
|
+
if (sample > 32767) return 32767;
|
|
261
|
+
if (sample < -32768) return -32768;
|
|
262
|
+
return sample;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static void normalizeTone(Tone &tone) {
|
|
266
|
+
tone.type = normalizeType(tone.type);
|
|
267
|
+
if (tone.frequencyHz < 40.0) tone.frequencyHz = 40.0;
|
|
268
|
+
if (tone.frequencyHz > 4000.0) tone.frequencyHz = 4000.0;
|
|
269
|
+
if (tone.durationMs < 10) tone.durationMs = 10;
|
|
270
|
+
if (tone.durationMs > kMaxToneMs) tone.durationMs = kMaxToneMs;
|
|
271
|
+
if (tone.delayMs < 0) tone.delayMs = 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static audio::NativeAudioHandle nativeHandle(OscillatorState &oscillator) {
|
|
275
|
+
return reinterpret_cast<audio::NativeAudioHandle>(&oscillator);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
OscillatorState *oscillator(audio::NativeAudioHandle handle) {
|
|
279
|
+
auto *osc = reinterpret_cast<OscillatorState *>(handle);
|
|
280
|
+
if (!owns(osc) || !osc->inUse) return nullptr;
|
|
281
|
+
return osc;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const OscillatorState *oscillator(audio::NativeAudioHandle handle) const {
|
|
285
|
+
const auto *osc = reinterpret_cast<const OscillatorState *>(handle);
|
|
286
|
+
if (!owns(osc) || !osc->inUse) return nullptr;
|
|
287
|
+
return osc;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
bool owns(const OscillatorState *oscillator) const {
|
|
291
|
+
const auto address = reinterpret_cast<audio::NativeAudioHandle>(oscillator);
|
|
292
|
+
const auto begin = reinterpret_cast<audio::NativeAudioHandle>(oscillators_);
|
|
293
|
+
const auto end = reinterpret_cast<audio::NativeAudioHandle>(oscillators_ + kMaxOscillators);
|
|
294
|
+
return address >= begin && address < end;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
int activeToneRemaining(const ActiveTone &tone) const {
|
|
298
|
+
if (!tone.inUse) return 0;
|
|
299
|
+
int remaining = tone.totalSamples - tone.sampleIndex;
|
|
300
|
+
if (remaining < 0) remaining = 0;
|
|
301
|
+
return tone.delaySamples + remaining;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
bool hasActiveTones() const {
|
|
305
|
+
for (const auto &tone : activeTones_) {
|
|
306
|
+
if (tone.inUse) return true;
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
void clearTones() {
|
|
312
|
+
for (auto &tone : activeTones_) tone = ActiveTone{};
|
|
313
|
+
if (!toneQueue_) return;
|
|
314
|
+
Tone dropped;
|
|
315
|
+
while (xQueueReceive(toneQueue_, &dropped, 0) == pdTRUE) {}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
void addActiveTone(Tone tone) {
|
|
319
|
+
normalizeTone(tone);
|
|
320
|
+
|
|
321
|
+
const int totalSamples = (kSampleRate * tone.durationMs) / 1000;
|
|
322
|
+
if (totalSamples <= 0) return;
|
|
323
|
+
|
|
324
|
+
int slot = -1;
|
|
325
|
+
int shortestRemaining = INT_MAX;
|
|
326
|
+
for (int i = 0; i < kMaxActiveTones; i++) {
|
|
327
|
+
if (!activeTones_[i].inUse) {
|
|
328
|
+
slot = i;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
const int remaining = activeToneRemaining(activeTones_[i]);
|
|
332
|
+
if (remaining < shortestRemaining) {
|
|
333
|
+
shortestRemaining = remaining;
|
|
334
|
+
slot = i;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
activeTones_[slot] = ActiveTone{
|
|
339
|
+
true,
|
|
340
|
+
tone.type,
|
|
341
|
+
0,
|
|
342
|
+
static_cast<std::uint32_t>((tone.frequencyHz * 4294967296.0) / kSampleRate),
|
|
343
|
+
totalSamples,
|
|
344
|
+
0,
|
|
345
|
+
(kSampleRate * tone.delayMs) / 1000,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
void renderChunk(std::int16_t *pcm, int samples) {
|
|
350
|
+
for (int i = 0; i < samples; i++) {
|
|
351
|
+
int mixed = 0;
|
|
352
|
+
for (auto &tone : activeTones_) {
|
|
353
|
+
if (!tone.inUse) continue;
|
|
354
|
+
|
|
355
|
+
if (tone.delaySamples > 0) {
|
|
356
|
+
tone.delaySamples--;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const int remaining = tone.totalSamples - tone.sampleIndex;
|
|
361
|
+
if (remaining <= 0) {
|
|
362
|
+
tone.inUse = false;
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const int level = envelope(tone.sampleIndex, remaining);
|
|
367
|
+
mixed += (waveformSample(tone.type, tone.phase) * level) / 256;
|
|
368
|
+
tone.phase += tone.phaseStep;
|
|
369
|
+
tone.sampleIndex++;
|
|
370
|
+
if (tone.sampleIndex >= tone.totalSamples) {
|
|
371
|
+
tone.inUse = false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const auto sample = static_cast<std::int16_t>(clampSample(mixed));
|
|
376
|
+
for (int ch = 0; ch < kChannels; ch++) {
|
|
377
|
+
pcm[i * kChannels + ch] = sample;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
void runAudioTask() {
|
|
383
|
+
Tone tone;
|
|
384
|
+
std::int16_t pcm[kChunkSamples * kChannels];
|
|
385
|
+
int idleChunks = 0;
|
|
386
|
+
|
|
387
|
+
while (true) {
|
|
388
|
+
if (exclusivePlayback_.load(std::memory_order_acquire)) {
|
|
389
|
+
clearTones();
|
|
390
|
+
idleChunks = 0;
|
|
391
|
+
vTaskDelay(pdMS_TO_TICKS(10));
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
while (xQueueReceive(toneQueue_, &tone, 0) == pdTRUE) {
|
|
396
|
+
addActiveTone(tone);
|
|
397
|
+
idleChunks = 0;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (!hasActiveTones()) {
|
|
401
|
+
if (!driverOpen_.load(std::memory_order_acquire)) {
|
|
402
|
+
if (xQueueReceive(toneQueue_, &tone, portMAX_DELAY) == pdTRUE) {
|
|
403
|
+
addActiveTone(tone);
|
|
404
|
+
idleChunks = 0;
|
|
405
|
+
}
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Driver is open but momentarily idle between notes — wait one
|
|
410
|
+
// chunk's worth of time for the next tone instead of tearing the
|
|
411
|
+
// codec down immediately, so back-to-back notes stay gapless.
|
|
412
|
+
if (xQueueReceive(toneQueue_, &tone, pdMS_TO_TICKS(kChunkDurationMs)) == pdTRUE) {
|
|
413
|
+
addActiveTone(tone);
|
|
414
|
+
idleChunks = 0;
|
|
415
|
+
} else {
|
|
416
|
+
idleChunks++;
|
|
417
|
+
if (idleChunks >= kCloseGraceChunks) {
|
|
418
|
+
audio::OutputDriver::close();
|
|
419
|
+
driverOpen_.store(false, std::memory_order_release);
|
|
420
|
+
idleChunks = 0;
|
|
421
|
+
} else {
|
|
422
|
+
std::memset(pcm, 0, sizeof(pcm));
|
|
423
|
+
audio::OutputDriver::write(pcm, kChunkSamples * kChannels, kWriteTimeoutMs);
|
|
424
|
+
}
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (!driverOpen_.load(std::memory_order_acquire)) {
|
|
430
|
+
if (!audio::OutputDriver::open(kSampleRate, kChannels, 16)) {
|
|
431
|
+
vTaskDelay(pdMS_TO_TICKS(50));
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
driverOpen_.store(true, std::memory_order_release);
|
|
435
|
+
if (!stackReported_) {
|
|
436
|
+
stackReported_ = true;
|
|
437
|
+
ESP_LOGI(kTag,
|
|
438
|
+
"Audio task stack: %u of %d bytes still free after the driver opened",
|
|
439
|
+
static_cast<unsigned>(uxTaskGetStackHighWaterMark(nullptr)),
|
|
440
|
+
kTaskStackBytes);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
renderChunk(pcm, kChunkSamples);
|
|
445
|
+
if (!audio::OutputDriver::write(pcm, kChunkSamples * kChannels, kWriteTimeoutMs)) {
|
|
446
|
+
ESP_LOGW(kTag, "PCM write failed");
|
|
447
|
+
vTaskDelay(pdMS_TO_TICKS(10));
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
void ensureTask() {
|
|
453
|
+
#if GEA_AUDIO_DEBUG_TIMING
|
|
454
|
+
const int64_t totalStartUs = esp_timer_get_time();
|
|
455
|
+
int64_t queueUs = 0;
|
|
456
|
+
int64_t taskUs = 0;
|
|
457
|
+
bool createdQueue = false;
|
|
458
|
+
bool attemptedTask = false;
|
|
459
|
+
bool startedTask = false;
|
|
460
|
+
#endif
|
|
461
|
+
|
|
462
|
+
if (!toneQueue_) {
|
|
463
|
+
#if GEA_AUDIO_DEBUG_TIMING
|
|
464
|
+
const int64_t queueStartUs = esp_timer_get_time();
|
|
465
|
+
#endif
|
|
466
|
+
toneQueue_ = xQueueCreateStatic(kQueueDepth, sizeof(Tone), toneQueueBuffer_, &toneQueueStorage_);
|
|
467
|
+
#if GEA_AUDIO_DEBUG_TIMING
|
|
468
|
+
queueUs = esp_timer_get_time() - queueStartUs;
|
|
469
|
+
createdQueue = toneQueue_ != nullptr;
|
|
470
|
+
#endif
|
|
471
|
+
if (!toneQueue_) {
|
|
472
|
+
ESP_LOGE(kTag, "Tone queue creation failed");
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (!audioTask_) {
|
|
478
|
+
#if GEA_AUDIO_DEBUG_TIMING
|
|
479
|
+
const int64_t taskStartUs = esp_timer_get_time();
|
|
480
|
+
attemptedTask = true;
|
|
481
|
+
#endif
|
|
482
|
+
audioTask_ = xTaskCreateStatic(
|
|
483
|
+
&AudioEngine::audioTaskEntry,
|
|
484
|
+
"gea_audio",
|
|
485
|
+
kTaskStackBytes,
|
|
486
|
+
this,
|
|
487
|
+
6,
|
|
488
|
+
audioTaskStack_,
|
|
489
|
+
&audioTaskStorage_);
|
|
490
|
+
#if GEA_AUDIO_DEBUG_TIMING
|
|
491
|
+
taskUs = esp_timer_get_time() - taskStartUs;
|
|
492
|
+
startedTask = audioTask_ != nullptr;
|
|
493
|
+
#endif
|
|
494
|
+
if (!audioTask_) {
|
|
495
|
+
if (!audioTaskFailureLogged_) {
|
|
496
|
+
audioTaskFailureLogged_ = true;
|
|
497
|
+
ESP_LOGE(kTag, "Audio task creation failed");
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
audioTaskFailureLogged_ = false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
#if GEA_AUDIO_DEBUG_TIMING
|
|
505
|
+
const int64_t totalUs = esp_timer_get_time() - totalStartUs;
|
|
506
|
+
const bool shouldLogTiming = totalUs >= GEA_AUDIO_DEBUG_TIMING_THRESHOLD_US;
|
|
507
|
+
if (createdQueue || attemptedTask || shouldLogTiming) {
|
|
508
|
+
ESP_LOGI(kTag,
|
|
509
|
+
"debug: ensure_audio_task queue=%lldus task=%lldus total=%lldus created_queue=%d attempted_task=%d started_task=%d",
|
|
510
|
+
static_cast<long long>(queueUs),
|
|
511
|
+
static_cast<long long>(taskUs),
|
|
512
|
+
static_cast<long long>(totalUs),
|
|
513
|
+
createdQueue ? 1 : 0,
|
|
514
|
+
attemptedTask ? 1 : 0,
|
|
515
|
+
startedTask ? 1 : 0);
|
|
516
|
+
}
|
|
517
|
+
#endif
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
void submitTone(const Tone &tone) {
|
|
521
|
+
#if GEA_EMBEDDED_AUDIO_DISABLED
|
|
522
|
+
(void)tone;
|
|
523
|
+
return;
|
|
524
|
+
#else
|
|
525
|
+
if (exclusivePlayback_.load(std::memory_order_acquire)) return;
|
|
526
|
+
ensureTask();
|
|
527
|
+
if (!toneQueue_) return;
|
|
528
|
+
|
|
529
|
+
if (xQueueSend(toneQueue_, &tone, 0) != pdPASS) {
|
|
530
|
+
const int64_t nowUs = esp_timer_get_time();
|
|
531
|
+
if (nowUs - lastDropLogUs_ > kDropLogIntervalUs) {
|
|
532
|
+
lastDropLogUs_ = nowUs;
|
|
533
|
+
ESP_LOGW(kTag, "Tone queue full; dropping tone");
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
#endif
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
static void audioTaskEntry(void *arg) {
|
|
540
|
+
static_cast<AudioEngine *>(arg)->runAudioTask();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
static constexpr const char *kTag = "gea_audio";
|
|
544
|
+
|
|
545
|
+
QueueHandle_t toneQueue_ = nullptr;
|
|
546
|
+
TaskHandle_t audioTask_ = nullptr;
|
|
547
|
+
OscillatorState oscillators_[kMaxOscillators]{};
|
|
548
|
+
ActiveTone activeTones_[kMaxActiveTones]{};
|
|
549
|
+
int nextOscillatorSlot_ = 0;
|
|
550
|
+
int64_t lastDropLogUs_ = 0;
|
|
551
|
+
StaticQueue_t toneQueueStorage_{};
|
|
552
|
+
std::uint8_t toneQueueBuffer_[kQueueDepth * sizeof(Tone)]{};
|
|
553
|
+
StaticTask_t audioTaskStorage_{};
|
|
554
|
+
StackType_t audioTaskStack_[kTaskStackBytes]{};
|
|
555
|
+
std::atomic<bool> exclusivePlayback_{false};
|
|
556
|
+
std::atomic<bool> driverOpen_{false};
|
|
557
|
+
bool audioTaskFailureLogged_ = false;
|
|
558
|
+
bool stackReported_ = false;
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
} // namespace
|
|
562
|
+
|
|
563
|
+
namespace {
|
|
564
|
+
|
|
565
|
+
std::uint16_t readLe16(FILE *file)
|
|
566
|
+
{
|
|
567
|
+
std::uint8_t bytes[2] = {};
|
|
568
|
+
if (std::fread(bytes, 1, sizeof(bytes), file) != sizeof(bytes)) return 0;
|
|
569
|
+
return static_cast<std::uint16_t>(bytes[0] | (static_cast<std::uint16_t>(bytes[1]) << 8));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
std::uint32_t readLe32(FILE *file)
|
|
573
|
+
{
|
|
574
|
+
std::uint8_t bytes[4] = {};
|
|
575
|
+
if (std::fread(bytes, 1, sizeof(bytes), file) != sizeof(bytes)) return 0;
|
|
576
|
+
return static_cast<std::uint32_t>(bytes[0]) |
|
|
577
|
+
(static_cast<std::uint32_t>(bytes[1]) << 8) |
|
|
578
|
+
(static_cast<std::uint32_t>(bytes[2]) << 16) |
|
|
579
|
+
(static_cast<std::uint32_t>(bytes[3]) << 24);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
bool readTag(FILE *file, const char *expected)
|
|
583
|
+
{
|
|
584
|
+
char tag[4] = {};
|
|
585
|
+
return std::fread(tag, 1, sizeof(tag), file) == sizeof(tag) && std::memcmp(tag, expected, sizeof(tag)) == 0;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
struct ExclusivePlaybackScope {
|
|
589
|
+
ExclusivePlaybackScope() { AudioEngine::instance().beginExclusivePlayback(); }
|
|
590
|
+
~ExclusivePlaybackScope() { AudioEngine::instance().endExclusivePlayback(); }
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
struct OutputCloseScope {
|
|
594
|
+
bool active = false;
|
|
595
|
+
~OutputCloseScope()
|
|
596
|
+
{
|
|
597
|
+
if (active) audio::OutputDriver::close();
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
bool playPcmSync(const std::int16_t *samples, std::size_t sampleCount, int sampleRate, int channels)
|
|
602
|
+
{
|
|
603
|
+
if (!samples || sampleCount == 0) return false;
|
|
604
|
+
if (sampleRate <= 0) sampleRate = kSampleRate;
|
|
605
|
+
if (channels <= 0) channels = 1;
|
|
606
|
+
ExclusivePlaybackScope playbackScope;
|
|
607
|
+
|
|
608
|
+
if (!audio::OutputDriver::open(sampleRate, 2, 16)) return false;
|
|
609
|
+
OutputCloseScope closeOutput{true};
|
|
610
|
+
|
|
611
|
+
std::vector<std::int16_t> stereo(kPlaybackChunkFrames * 2);
|
|
612
|
+
std::size_t frame = 0;
|
|
613
|
+
const std::size_t frameCount = sampleCount / static_cast<std::size_t>(channels);
|
|
614
|
+
while (frame < frameCount) {
|
|
615
|
+
const std::size_t frames = std::min<std::size_t>(kPlaybackChunkFrames, frameCount - frame);
|
|
616
|
+
if (channels == 2) {
|
|
617
|
+
const std::size_t src = frame * 2;
|
|
618
|
+
if (!audio::OutputDriver::write(samples + src, frames * 2, kPlaybackWriteTimeoutMs)) return false;
|
|
619
|
+
} else {
|
|
620
|
+
for (std::size_t i = 0; i < frames; ++i) {
|
|
621
|
+
const std::size_t src = (frame + i) * static_cast<std::size_t>(channels);
|
|
622
|
+
stereo[i * 2] = samples[src];
|
|
623
|
+
stereo[i * 2 + 1] = channels == 1 ? samples[src] : samples[src + 1];
|
|
624
|
+
}
|
|
625
|
+
if (!audio::OutputDriver::write(stereo.data(), frames * 2, kPlaybackWriteTimeoutMs)) return false;
|
|
626
|
+
}
|
|
627
|
+
frame += frames;
|
|
628
|
+
}
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// Stream a 16-bit PCM WAV from disk to the output driver in bounded chunks.
|
|
633
|
+
// Playback memory stays ~constant (one small chunk buffer) regardless of file
|
|
634
|
+
// length. The previous path loaded the ENTIRE file into a std::vector first,
|
|
635
|
+
// which OOM-crashed on long recordings — a 20-minute 16 kHz mono clip is
|
|
636
|
+
// ~38 MB, far past available PSRAM. Parses the header (must be PCM 16-bit),
|
|
637
|
+
// then reads+plays the data chunk incrementally.
|
|
638
|
+
bool streamPcm16File(const std::string &path)
|
|
639
|
+
{
|
|
640
|
+
if (path.empty() || !gea::platform::storage::ensureMounted()) return false;
|
|
641
|
+
FILE *file = std::fopen(path.c_str(), "rb");
|
|
642
|
+
if (!file) return false;
|
|
643
|
+
|
|
644
|
+
bool ok = false;
|
|
645
|
+
do {
|
|
646
|
+
if (!readTag(file, "RIFF")) break;
|
|
647
|
+
(void)readLe32(file);
|
|
648
|
+
if (!readTag(file, "WAVE")) break;
|
|
649
|
+
|
|
650
|
+
std::uint16_t audioFormat = 0;
|
|
651
|
+
std::uint16_t channels = 0;
|
|
652
|
+
std::uint32_t sampleRate = 0;
|
|
653
|
+
std::uint16_t bitsPerSample = 0;
|
|
654
|
+
long dataStart = -1;
|
|
655
|
+
std::uint32_t dataSize = 0;
|
|
656
|
+
|
|
657
|
+
while (!std::feof(file)) {
|
|
658
|
+
char chunkId[4] = {};
|
|
659
|
+
if (std::fread(chunkId, 1, sizeof(chunkId), file) != sizeof(chunkId)) break;
|
|
660
|
+
const std::uint32_t chunkSize = readLe32(file);
|
|
661
|
+
const long payloadStart = std::ftell(file);
|
|
662
|
+
if (payloadStart < 0) break;
|
|
663
|
+
if (std::memcmp(chunkId, "fmt ", 4) == 0 && chunkSize >= 16) {
|
|
664
|
+
audioFormat = readLe16(file);
|
|
665
|
+
channels = readLe16(file);
|
|
666
|
+
sampleRate = readLe32(file);
|
|
667
|
+
(void)readLe32(file);
|
|
668
|
+
(void)readLe16(file);
|
|
669
|
+
bitsPerSample = readLe16(file);
|
|
670
|
+
} else if (std::memcmp(chunkId, "data", 4) == 0 && chunkSize >= 2) {
|
|
671
|
+
dataStart = payloadStart;
|
|
672
|
+
dataSize = chunkSize;
|
|
673
|
+
break; // stream the data chunk below rather than loading it
|
|
674
|
+
}
|
|
675
|
+
const long next = payloadStart + static_cast<long>(chunkSize) + static_cast<long>(chunkSize & 1u);
|
|
676
|
+
if (std::fseek(file, next, SEEK_SET) != 0) break;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
if (audioFormat != 1 || bitsPerSample != 16 || dataStart < 0 || dataSize < 2) break;
|
|
680
|
+
if (channels == 0) channels = 1;
|
|
681
|
+
const int outSampleRate = sampleRate == 0 ? kSampleRate : static_cast<int>(sampleRate);
|
|
682
|
+
if (std::fseek(file, dataStart, SEEK_SET) != 0) break;
|
|
683
|
+
|
|
684
|
+
ExclusivePlaybackScope playbackScope;
|
|
685
|
+
if (!audio::OutputDriver::open(outSampleRate, 2, 16)) break;
|
|
686
|
+
OutputCloseScope closeOutput{true};
|
|
687
|
+
|
|
688
|
+
const std::size_t ch = static_cast<std::size_t>(channels);
|
|
689
|
+
std::size_t framesLeft = dataSize / (sizeof(std::int16_t) * ch);
|
|
690
|
+
std::vector<std::int16_t> in(kPlaybackChunkFrames * ch);
|
|
691
|
+
std::vector<std::int16_t> stereo(kPlaybackChunkFrames * 2);
|
|
692
|
+
bool wrote = true;
|
|
693
|
+
while (framesLeft > 0) {
|
|
694
|
+
const std::size_t frames = std::min<std::size_t>(kPlaybackChunkFrames, framesLeft);
|
|
695
|
+
const std::size_t want = frames * ch;
|
|
696
|
+
// WAV PCM is little-endian and the ESP32 is little-endian, so raw int16
|
|
697
|
+
// reads need no byte swap.
|
|
698
|
+
const std::size_t got = std::fread(in.data(), sizeof(std::int16_t), want, file);
|
|
699
|
+
const std::size_t framesGot = got / ch;
|
|
700
|
+
if (framesGot == 0) break;
|
|
701
|
+
if (channels == 2) {
|
|
702
|
+
if (!audio::OutputDriver::write(in.data(), framesGot * 2, kPlaybackWriteTimeoutMs)) { wrote = false; break; }
|
|
703
|
+
} else {
|
|
704
|
+
for (std::size_t i = 0; i < framesGot; ++i) {
|
|
705
|
+
const std::size_t src = i * ch;
|
|
706
|
+
stereo[i * 2] = in[src];
|
|
707
|
+
stereo[i * 2 + 1] = channels == 1 ? in[src] : in[src + 1];
|
|
708
|
+
}
|
|
709
|
+
if (!audio::OutputDriver::write(stereo.data(), framesGot * 2, kPlaybackWriteTimeoutMs)) { wrote = false; break; }
|
|
710
|
+
}
|
|
711
|
+
framesLeft -= framesGot;
|
|
712
|
+
if (got < want) break; // short read = EOF
|
|
713
|
+
}
|
|
714
|
+
ok = wrote;
|
|
715
|
+
} while (false);
|
|
716
|
+
|
|
717
|
+
std::fclose(file);
|
|
718
|
+
return ok;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
} // namespace
|
|
722
|
+
|
|
723
|
+
audio::AudioParam::AudioParam(audio::NativeAudioHandle oscillator) : oscillator_(oscillator) {}
|
|
724
|
+
|
|
725
|
+
double audio::AudioParam::value() const {
|
|
726
|
+
return AudioEngine::instance().oscillatorFrequency(oscillator_);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
void audio::AudioParam::setValue(double value) {
|
|
730
|
+
AudioEngine::instance().setOscillatorFrequency(oscillator_, value);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
void audio::AudioParam::setValueAtTime(double value, double startTime) {
|
|
734
|
+
AudioEngine::instance().setOscillatorFrequencyAtTime(oscillator_, value, startTime);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
audio::AudioNode::AudioNode(audio::NativeAudioHandle native) : native_(native) {}
|
|
738
|
+
|
|
739
|
+
audio::NativeAudioHandle audio::AudioNode::nativeId() const {
|
|
740
|
+
return native_;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
audio::AudioDestinationNode::AudioDestinationNode(audio::NativeAudioHandle native) : AudioNode(native) {}
|
|
744
|
+
|
|
745
|
+
audio::OscillatorNode::OscillatorNode(audio::NativeAudioHandle native) : AudioNode(native), frequency(native) {}
|
|
746
|
+
|
|
747
|
+
audio::OscillatorType audio::OscillatorNode::type() const {
|
|
748
|
+
return AudioEngine::instance().oscillatorType(nativeId());
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
void audio::OscillatorNode::setType(audio::OscillatorType type) {
|
|
752
|
+
AudioEngine::instance().setOscillatorType(nativeId(), type);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
void audio::OscillatorNode::connect(const audio::AudioDestinationNode &destination) {
|
|
756
|
+
AudioEngine::instance().connectOscillator(nativeId(), destination.nativeId());
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
void audio::OscillatorNode::start(double when) {
|
|
760
|
+
AudioEngine::instance().startOscillator(nativeId(), when);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
void audio::OscillatorNode::stop(double when) {
|
|
764
|
+
AudioEngine::instance().stopOscillator(nativeId(), when);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
double audio::AudioContext::currentTime() const {
|
|
768
|
+
return AudioEngine::instance().currentTime();
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
audio::AudioDestinationNode audio::AudioContext::destination() const {
|
|
772
|
+
return audio::AudioDestinationNode(AudioEngine::instance().destination());
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
audio::OscillatorNode audio::AudioContext::createOscillator() const {
|
|
776
|
+
return audio::OscillatorNode(AudioEngine::instance().createOscillator());
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
audio::AudioContext audio::AudioSystem::sharedContext() {
|
|
780
|
+
return audio::AudioContext{};
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
int audio::AudioSystem::volume() {
|
|
784
|
+
return AudioEngine::instance().volume();
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
void audio::AudioSystem::setVolume(int volumePercent) {
|
|
788
|
+
AudioEngine::instance().setVolume(volumePercent);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
bool audio::AudioSystem::playFile(const std::string &path) {
|
|
792
|
+
// Stream from disk in bounded chunks — never load the whole file (a long
|
|
793
|
+
// recording is tens of MB and would exhaust PSRAM).
|
|
794
|
+
if (!streamPcm16File(path)) {
|
|
795
|
+
ESP_LOGW("gea_audio", "Unable to play WAV file: %s", path.c_str());
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
return true;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
bool audio::AudioSystem::playPcm(const std::int16_t *samples, std::size_t sampleCount, int sampleRate, int channels) {
|
|
802
|
+
return playPcmSync(samples, sampleCount, sampleRate, channels);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
void audio::AudioSystem::stopPlayback() {
|
|
806
|
+
AudioEngine::instance().stopPlayback();
|
|
807
|
+
}
|