FastLED 3.10.8
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 #if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
24 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
25 #elif defined(FL_IS_WASM)
26 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
27 #elif defined(FL_IS_TEENSY)
28 // Teensy uses the PJRC Audio backend when enabled, never generic Arduino I2S.
29 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
30 #elif FL_HAS_INCLUDE(<Arduino.h>)
31 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 1
32 #else
33 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
34 #endif
35#endif
36
37#if !FASTLED_USES_ARDUINO_AUDIO_INPUT
38#if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
39#define FASTLED_USES_ESP32_AUDIO_INPUT 1
40#else
41#define FASTLED_USES_ESP32_AUDIO_INPUT 0
42#endif
43#else
44#define FASTLED_USES_ESP32_AUDIO_INPUT 0
45#endif
46
47// Determine WASM audio input support
48#if !FASTLED_USES_ARDUINO_AUDIO_INPUT && !FASTLED_USES_ESP32_AUDIO_INPUT
49#if defined(FL_IS_WASM)
50#define FASTLED_USES_WASM_AUDIO_INPUT 1
51#else
52#define FASTLED_USES_WASM_AUDIO_INPUT 0
53#endif
54#else
55#define FASTLED_USES_WASM_AUDIO_INPUT 0
56#endif
57
58// Include platform-specific audio input implementation
59// IWYU pragma: begin_keep
60#if FASTLED_USES_TEENSY_AUDIO_INPUT
61#define FASTLED_TEENSY_AUDIO_INPUT_HEADER \
62 "platforms/arm/teensy/audio_input_teensy.h"
63#include FASTLED_TEENSY_AUDIO_INPUT_HEADER
64#undef FASTLED_TEENSY_AUDIO_INPUT_HEADER
65#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
66#include "platforms/arduino/audio_input.hpp" // ok platform headers
67#elif FASTLED_USES_ESP32_AUDIO_INPUT
68#include "platforms/esp/32/audio/audio_impl.hpp" // ok platform headers
69#elif FASTLED_USES_WASM_AUDIO_INPUT
70#include "platforms/wasm/audio_input_wasm.hpp" // ok platform headers
71#endif
72// IWYU pragma: end_keep
73
74namespace fl {
75namespace audio {
76
77#if FASTLED_USES_TEENSY_AUDIO_INPUT
78// Use Teensy audio implementation
80 return teensy_create_audio_input(config, error_message);
81}
82#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
83// Use Arduino audio implementation
85 return arduino_create_audio_input(config, error_message);
86}
87#elif FASTLED_USES_ESP32_AUDIO_INPUT
88// ESP32 native implementation
90 return esp32_create_audio_input(config, error_message);
91}
92#elif FASTLED_USES_WASM_AUDIO_INPUT
93// WASM implementation - audio comes from JavaScript
95 return wasm_create_audio_input(config, error_message);
96}
97#else
98// Weak default implementation - no audio support
101 FL_UNUSED(config); // no audio input here to configure
102 if (error_message) {
103 *error_message = "AudioInput not supported on this platform.";
104 }
106}
107#endif
108
109// Static method delegates to free function
111IInput::create(const Config &config, fl::string *error_message) FL_NO_EXCEPT {
112 auto input = platform_create_audio_input(config, error_message);
113 if (input) {
114 input->setGain(config.getGain());
115 }
116 return input;
117}
118
119} // namespace audio
120} // namespace fl
fl::UIAudio audio("Audio Input")
static fl::shared_ptr< IInput > create(const Config &config, fl::string *error_message=nullptr) FL_NO_EXCEPT
#define FL_UNUSED(x)
#define FL_LINK_WEAK
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.
Definition crgb.hpp:179
#define FL_NO_EXCEPT