FastLED 3.9.15
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 "platforms/audio_input_null.hpp"
12
13
14// Auto-determine platform audio input support
15
16// First check for Teensy (before Arduino, since Teensy is Arduino-compatible)
17// IWYU pragma: begin_keep
18#include "platforms/arm/teensy/audio_input_teensy_config.h" // ok platform headers
19// IWYU pragma: end_keep
20
21#ifndef FASTLED_USES_ARDUINO_AUDIO_INPUT
22 #if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
23 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
24 #elif defined(FL_IS_WASM)
25 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
26 #elif defined(FL_IS_TEENSY)
27 // Teensy uses the PJRC Audio backend when enabled, never generic Arduino I2S.
28 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
29 #elif FL_HAS_INCLUDE(<Arduino.h>)
30 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 1
31 #else
32 #define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
33 #endif
34#endif
35
36#if !FASTLED_USES_ARDUINO_AUDIO_INPUT
37#if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
38#define FASTLED_USES_ESP32_AUDIO_INPUT 1
39#else
40#define FASTLED_USES_ESP32_AUDIO_INPUT 0
41#endif
42#else
43#define FASTLED_USES_ESP32_AUDIO_INPUT 0
44#endif
45
46// Determine WASM audio input support
47#if !FASTLED_USES_ARDUINO_AUDIO_INPUT && !FASTLED_USES_ESP32_AUDIO_INPUT
48#if defined(FL_IS_WASM)
49#define FASTLED_USES_WASM_AUDIO_INPUT 1
50#else
51#define FASTLED_USES_WASM_AUDIO_INPUT 0
52#endif
53#else
54#define FASTLED_USES_WASM_AUDIO_INPUT 0
55#endif
56
57// Include platform-specific audio input implementation
58// IWYU pragma: begin_keep
59#if FASTLED_USES_TEENSY_AUDIO_INPUT
60#define FASTLED_TEENSY_AUDIO_INPUT_HEADER \
61 "platforms/arm/teensy/audio_input_teensy.h"
62#include FASTLED_TEENSY_AUDIO_INPUT_HEADER
63#undef FASTLED_TEENSY_AUDIO_INPUT_HEADER
64#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
65#include "platforms/arduino/audio_input.hpp" // ok platform headers
66#elif FASTLED_USES_ESP32_AUDIO_INPUT
67#include "platforms/esp/32/audio/audio_impl.hpp" // ok platform headers
68#elif FASTLED_USES_WASM_AUDIO_INPUT
69#include "platforms/wasm/audio_input_wasm.hpp" // ok platform headers
70#endif
71// IWYU pragma: end_keep
72
73namespace fl {
74namespace audio {
75
76#if FASTLED_USES_TEENSY_AUDIO_INPUT
77// Use Teensy audio implementation
78fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
79 return teensy_create_audio_input(config, error_message);
80}
81#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
82// Use Arduino audio implementation
83fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
84 return arduino_create_audio_input(config, error_message);
85}
86#elif FASTLED_USES_ESP32_AUDIO_INPUT
87// ESP32 native implementation
88fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
89 return esp32_create_audio_input(config, error_message);
90}
91#elif FASTLED_USES_WASM_AUDIO_INPUT
92// WASM implementation - audio comes from JavaScript
93fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
94 return wasm_create_audio_input(config, error_message);
95}
96#else
97// Weak default implementation - no audio support
100 if (error_message) {
101 *error_message = "AudioInput not supported on this platform.";
102 }
104}
105#endif
106
107// Static method delegates to free function
109IInput::create(const Config &config, fl::string *error_message) {
110 auto input = platform_create_audio_input(config, error_message);
111 if (input) {
112 input->setGain(config.getGain());
113 }
114 return input;
115}
116
117} // namespace audio
118} // namespace fl
fl::UIAudio audio("Audio Input")
float getGain() const FL_NOEXCEPT
Definition input.h:240
static fl::shared_ptr< IInput > create(const Config &config, fl::string *error_message=nullptr) FL_NOEXCEPT
FL_LINK_WEAK fl::shared_ptr< IInput > platform_create_audio_input(const Config &config, fl::string *error_message)
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_LINK_WEAK