FastLED 3.10.9
Loading...
Searching...
No Matches
audio_input.cpp.hpp
Go to the documentation of this file.
1
2
3
4
5#include "platforms/is_platform.h"
7#include "fl/stl/shared_ptr.h"
8#include "fl/stl/shared_ptr.h" // For shared_ptr
9#include "fl/stl/string.h"
10#include "fl/stl/has_include.h"
11#include "fl/stl/noexcept.h"
12#include "platforms/audio_input_null.hpp"
13
14
15// Auto-determine platform audio input support
16
17// First check for Teensy (before Arduino, since Teensy is Arduino-compatible)
18// IWYU pragma: begin_keep
19#include "platforms/arm/teensy/audio_input_teensy_config.h" // ok platform headers
20// IWYU pragma: end_keep
21
22#ifndef FASTLED_USES_ARDUINO_AUDIO_INPUT
23 // ESP32 (excluding ESP8266) has a dedicated native engine below. ESP8266 has
24 // no dedicated engine and deliberately falls through to the shared Arduino-I2S
25 // backend (`platforms/arduino/audio_input.hpp`) when <I2S.h> is present — see
26 // issue #4948 and `platforms/esp/8266/README.md`.
27 #if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
28 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
29 #elif defined(FL_IS_WASM)
30 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
31 #elif defined(FL_IS_TEENSY)
32 // Teensy uses the PJRC Audio backend when enabled, never generic Arduino I2S.
33 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
34 #elif FL_HAS_INCLUDE(<Arduino.h>)
35 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 1
36 #else
37 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
38 #endif
39#endif
40
41#if !FASTLED_USES_ARDUINO_AUDIO_INPUT
42#if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
43#define FASTLED_USES_ESP32_AUDIO_INPUT 1
44#else
45#define FASTLED_USES_ESP32_AUDIO_INPUT 0
46#endif
47#else
48#define FASTLED_USES_ESP32_AUDIO_INPUT 0
49#endif
50
51// Determine WASM audio input support
52#if !FASTLED_USES_ARDUINO_AUDIO_INPUT && !FASTLED_USES_ESP32_AUDIO_INPUT
53#if defined(FL_IS_WASM)
54#define FASTLED_USES_WASM_AUDIO_INPUT 1
55#else
56#define FASTLED_USES_WASM_AUDIO_INPUT 0
57#endif
58#else
59#define FASTLED_USES_WASM_AUDIO_INPUT 0
60#endif
61
62// Include platform-specific audio input implementation
63// IWYU pragma: begin_keep
64#if FASTLED_USES_TEENSY_AUDIO_INPUT
65#define FASTLED_TEENSY_AUDIO_INPUT_HEADER \
66 "platforms/arm/teensy/audio_input_teensy.h"
67#include FASTLED_TEENSY_AUDIO_INPUT_HEADER
68#undef FASTLED_TEENSY_AUDIO_INPUT_HEADER
69#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
70#include "platforms/arduino/audio_input.hpp" // ok platform headers
71#elif FASTLED_USES_ESP32_AUDIO_INPUT
72#include "platforms/esp/32/audio/audio_impl.hpp" // ok platform headers
73#elif FASTLED_USES_WASM_AUDIO_INPUT
74#include "platforms/wasm/audio_input_wasm.hpp" // ok platform headers
75#endif
76// IWYU pragma: end_keep
77
78namespace fl {
79namespace audio {
80
81#if FASTLED_USES_TEENSY_AUDIO_INPUT
82// Use Teensy audio implementation
84 return teensy_create_audio_input(config, error_message);
85}
86#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
87// Use Arduino audio implementation
89 return arduino_create_audio_input(config, error_message);
90}
91#elif FASTLED_USES_ESP32_AUDIO_INPUT
92// ESP32 native implementation
94 return esp32_create_audio_input(config, error_message);
95}
96#elif FASTLED_USES_WASM_AUDIO_INPUT
97// WASM implementation - audio comes from JavaScript
99 return wasm_create_audio_input(config, error_message);
100}
101#else
102// Weak default implementation - no audio support
105 FL_UNUSED(config); // no audio input here to configure
106 if (error_message) {
107 *error_message = "AudioInput not supported on this platform.";
108 }
110}
111#endif
112
113// Static method delegates to free function
115IInput::create(const Config &config, fl::string *error_message) FL_NO_EXCEPT {
116 auto input = platform_create_audio_input(config, error_message);
117 if (input) {
118 input->setGain(config.getGain());
119 }
120 return input;
121}
122
123} // namespace audio
124} // namespace fl
fl::UIAudio audio("Audio Input")
static fl::shared_ptr< IInput > create(const Config &config, fl::string *error_message=nullptr) FL_NO_EXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
FL_LINK_WEAK fl::shared_ptr< IInput > platform_create_audio_input(const Config &config, fl::string *error_message) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
#define FL_UNUSED(x)
#define FL_NO_EXCEPT
#define FL_LINK_WEAK