FastLED 3.9.15
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
7namespace fl {
8namespace audio {
9
13
17
19#if FASTLED_HAS_AUDIO_INPUT
20 fl::string errorMsg;
21 auto input = IInput::create(config, &errorMsg);
22 if (!input) {
23 FL_WARN("Failed to create audio input: " << errorMsg);
24 return nullptr;
25 }
26 input->start();
27 auto proc = Processor::createWithAutoInput(fl::move(input));
28 if (config.getMicProfile() != MicProfile::None) {
29 proc->setMicProfile(config.getMicProfile());
30 }
31 if (processor()) {
32 FL_WARN("Replacing existing audio processor");
33 }
34 processor() = proc;
35 return proc;
36#else
37 (void)config;
38 auto proc = fl::make_shared<Processor>();
39 if (processor()) {
40 FL_WARN("Replacing existing audio processor");
41 }
42 processor() = proc;
43 return proc;
44#endif
45}
46
48 if (!input) {
49 FL_WARN("Cannot add null audio input");
50 return nullptr;
51 }
52 input->start();
53 auto proc = Processor::createWithAutoInput(fl::move(input));
54 if (processor()) {
55 FL_WARN("Replacing existing audio processor");
56 }
57 processor() = proc;
58 return proc;
59}
60
62 auto input = uiAudio.audioInput();
63 if (input) {
64 return add(fl::move(input));
65 }
66 // No platform audio input (e.g. hardware stub) — use the stored config
67 // to create a real hardware audio input.
68 const auto& cfg = uiAudio.config();
69 if (cfg.has_value()) {
70 return add(*cfg);
71 }
72 FL_WARN("UIAudio has no audio input and no hardware config");
73 return nullptr;
74}
75
77 if (!proc) {
78 return;
79 }
80 if (processor() == proc) {
81 processor().reset();
82 }
83}
84
85} // namespace audio
86} // namespace fl
static T & instance() FL_NOEXCEPT
Definition singleton.h:41
fl::shared_ptr< audio::IInput > audioInput() FL_NOEXCEPT
Definition audio.h:71
const fl::optional< audio::Config > & config() const FL_NOEXCEPT
Definition audio.h:74
shared_ptr< Processor > add(const Config &config) FL_NOEXCEPT
static AudioManager & instance() FL_NOEXCEPT
void remove(shared_ptr< Processor > processor) FL_NOEXCEPT
shared_ptr< Processor > & processor() FL_NOEXCEPT
AudioManager() FL_NOEXCEPT=default
MicProfile getMicProfile() const FL_NOEXCEPT
Definition input.h:247
static fl::shared_ptr< IInput > create(const Config &config, fl::string *error_message=nullptr) FL_NOEXCEPT
static fl::shared_ptr< Processor > createWithAutoInput(fl::shared_ptr< IInput > input) FL_NOEXCEPT
#define FL_WARN(X)
Definition log.h:276
Centralized logging categories for FastLED hardware interfaces and subsystems.
@ None
No correction (flat response assumed)
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition s16x16x4.h:28
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
Base definition for an LED controller.
Definition crgb.hpp:179
Aggregator header for the fl/ui/ family of per-element UI types.