forked from FastLED/FastLED
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_input.cpp.hpp
More file actions
122 lines (107 loc) · 3.85 KB
/
audio_input.cpp.hpp
File metadata and controls
122 lines (107 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "platforms/is_platform.h"
#include "fl/system/sketch_macros.h"
#include "fl/stl/shared_ptr.h"
#include "fl/stl/shared_ptr.h" // For shared_ptr
#include "fl/stl/string.h"
#include "fl/stl/has_include.h"
#include "platforms/audio_input_null.hpp"
// Auto-determine platform audio input support
// First check for Teensy (before Arduino, since Teensy is Arduino-compatible)
// IWYU pragma: begin_keep
#include "platforms/arm/teensy/is_teensy.h" // ok platform headers
// IWYU pragma: end_keep
#ifndef FASTLED_USES_TEENSY_AUDIO_INPUT
#if defined(FL_IS_TEENSY)
#define FASTLED_USES_TEENSY_AUDIO_INPUT 1
#else
#define FASTLED_USES_TEENSY_AUDIO_INPUT 0
#endif
#endif
#ifndef FASTLED_USES_ARDUINO_AUDIO_INPUT
#if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
#define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
#elif defined(FL_IS_WASM)
#define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
#elif FASTLED_USES_TEENSY_AUDIO_INPUT
// Teensy uses its own audio implementation, not generic Arduino
#define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
#elif FL_HAS_INCLUDE(<Arduino.h>)
#define FASTLED_USES_ARDUINO_AUDIO_INPUT 1
#else
#define FASTLED_USES_ARDUINO_AUDIO_INPUT 0
#endif
#endif
#if !FASTLED_USES_ARDUINO_AUDIO_INPUT
#if defined(FL_IS_ESP32) && !defined(FL_IS_ESP8266)
#define FASTLED_USES_ESP32_AUDIO_INPUT 1
#else
#define FASTLED_USES_ESP32_AUDIO_INPUT 0
#endif
#else
#define FASTLED_USES_ESP32_AUDIO_INPUT 0
#endif
// Determine WASM audio input support
#if !FASTLED_USES_ARDUINO_AUDIO_INPUT && !FASTLED_USES_ESP32_AUDIO_INPUT
#if defined(FL_IS_WASM)
#define FASTLED_USES_WASM_AUDIO_INPUT 1
#else
#define FASTLED_USES_WASM_AUDIO_INPUT 0
#endif
#else
#define FASTLED_USES_WASM_AUDIO_INPUT 0
#endif
// Include platform-specific audio input implementation
// IWYU pragma: begin_keep
#if FASTLED_USES_TEENSY_AUDIO_INPUT
#include "platforms/arm/teensy/audio_input_teensy.h" // ok platform headers
#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
#include "platforms/arduino/audio_input.hpp" // ok platform headers
#elif FASTLED_USES_ESP32_AUDIO_INPUT
#include "platforms/esp/32/audio/audio_impl.hpp" // ok platform headers
#elif FASTLED_USES_WASM_AUDIO_INPUT
#include "platforms/wasm/audio_input_wasm.hpp" // ok platform headers
#endif
// IWYU pragma: end_keep
namespace fl {
namespace audio {
#if FASTLED_USES_TEENSY_AUDIO_INPUT
// Use Teensy audio implementation
fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
return teensy_create_audio_input(config, error_message);
}
#elif FASTLED_USES_ARDUINO_AUDIO_INPUT
// Use Arduino audio implementation
fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
return arduino_create_audio_input(config, error_message);
}
#elif FASTLED_USES_ESP32_AUDIO_INPUT
// ESP32 native implementation
fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
return esp32_create_audio_input(config, error_message);
}
#elif FASTLED_USES_WASM_AUDIO_INPUT
// WASM implementation - audio comes from JavaScript
fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
return wasm_create_audio_input(config, error_message);
}
#else
// Weak default implementation - no audio support
FL_LINK_WEAK
fl::shared_ptr<IInput> platform_create_audio_input(const Config &config, fl::string *error_message) {
if (error_message) {
*error_message = "AudioInput not supported on this platform.";
}
return fl::make_shared<fl::Null_Audio>();
}
#endif
// Static method delegates to free function
fl::shared_ptr<IInput>
IInput::create(const Config &config, fl::string *error_message) {
auto input = platform_create_audio_input(config, error_message);
if (input) {
input->setGain(config.getGain());
}
return input;
}
} // namespace audio
} // namespace fl