FastLED 3.10.8
Loading...
Searching...
No Matches
audio_manager.cpp.hpp
Go to the documentation of this file.
2#include "fl/audio/input.h"
3#include "fl/stl/singleton.h"
4#include "fl/log/log.h"
5#include "fl/ui/ui.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9namespace audio {
10
14
18
20#if FASTLED_HAS_AUDIO_INPUT
21 fl::string errorMsg;
22 auto input = IInput::create(config, &errorMsg);
23 if (!input) {
24 FL_WARN("Failed to create audio input: " << errorMsg);
25 return nullptr;
26 }
27 input->start();
28 auto proc = Processor::createWithAutoInput(fl::move(input));
29 if (config.getMicProfile() != MicProfile::None) {
30 proc->setMicProfile(config.getMicProfile());
31 }
32 if (processor()) {
33 FL_WARN("Replacing existing audio processor");
34 }
35 processor() = proc;
36 return proc;
37#else
38 (void)config;
39 auto proc = fl::make_shared<Processor>();
40 if (processor()) {
41 FL_WARN("Replacing existing audio processor");
42 }
43 processor() = proc;
44 return proc;
45#endif
46}
47
49 if (!input) {
50 FL_WARN("Cannot add null audio input");
51 return nullptr;
52 }
53 input->start();
54 auto proc = Processor::createWithAutoInput(fl::move(input));
55 if (processor()) {
56 FL_WARN("Replacing existing audio processor");
57 }
58 processor() = proc;
59 return proc;
60}
61
63 auto input = uiAudio.audioInput();
64 if (input) {
65 return add(fl::move(input));
66 }
67 // No platform audio input (e.g. hardware stub) — use the stored config
68 // to create a real hardware audio input.
69 const auto& cfg = uiAudio.config();
70 if (cfg.has_value()) {
71 return add(*cfg);
72 }
73 FL_WARN("UIAudio has no audio input and no hardware config");
74 return nullptr;
75}
76
78 if (!proc) {
79 return;
80 }
81 if (processor() == proc) {
82 processor().reset();
83 }
84}
85
86} // namespace audio
87} // namespace fl
static T & instance() FL_NO_EXCEPT
Definition singleton.h:41
void remove(shared_ptr< Processor > processor) FL_NO_EXCEPT
static AudioManager & instance() FL_NO_EXCEPT
shared_ptr< Processor > add(const Config &config) FL_NO_EXCEPT
AudioManager() FL_NO_EXCEPT=default
shared_ptr< Processor > & processor() FL_NO_EXCEPT
static fl::shared_ptr< IInput > create(const Config &config, fl::string *error_message=nullptr) FL_NO_EXCEPT
static fl::shared_ptr< Processor > createWithAutoInput(fl::shared_ptr< IInput > input) FL_NO_EXCEPT
#define FL_WARN(...)
Definition log.h:437
Centralized logging categories for FastLED hardware interfaces and subsystems.
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
Definition move.h:30
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
@ None
No correction (flat response assumed)
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
float add(float &a, float &b) FL_NO_EXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
Aggregator header for the fl/ui/ family of per-element UI types.