MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FilterProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
6class Filter;
7class FIR;
8class IIR;
9} // namespace MayaFlux::Nodes::Filters
10
11namespace MayaFlux::Buffers {
12
13/**
14 * @class FilterProcessor
15 * @brief Buffer processor that applies filter nodes to audio data
16 *
17 * This processor connects a Filter node (FIR or IIR) to an AudioBuffer,
18 * allowing filtering operations to be applied to buffer data. It supports
19 * both internally managed filter nodes and externally provided filter nodes.
20 */
21class MAYAFLUX_API FilterProcessor : public BufferProcessor {
22public:
23 FilterProcessor() = default;
24
25 /**
26 * @brief Creates processor with FIR filter
27 */
28 template <typename... Args>
29 requires std::constructible_from<Nodes::Filters::FIR, Args...>
30 FilterProcessor(Args&&... args)
31 : m_filter(std::make_shared<Nodes::Filters::FIR>(std::forward<Args>(args)...))
32 , m_use_internal(true)
33 {
34 }
35
36 /**
37 * @brief Creates processor with IIR filter
38 */
39 template <typename... Args>
40 requires std::constructible_from<Nodes::Filters::IIR, Args...>
41 FilterProcessor(Args&&... args)
42 : m_filter(std::make_shared<Nodes::Filters::IIR>(std::forward<Args>(args)...))
43 , m_use_internal(true)
44 {
45 }
46
47 /**
48 * @brief Creates processor with external filter node
49 */
50 FilterProcessor(const std::shared_ptr<Nodes::Filters::Filter>& filter)
51 : m_filter(filter)
52 {
53 }
54
55 void processing_function(std::shared_ptr<Buffer> buffer) override;
56
57 void on_attach(std::shared_ptr<Buffer> buffer) override;
58
59 [[nodiscard]] inline std::shared_ptr<Nodes::Filters::Filter> get_filter() const
60 {
61 return m_filter;
62 }
63
64 [[nodiscard]] inline bool is_using_internal() const { return m_use_internal; }
65
66 inline void update_filter_node(const std::shared_ptr<Nodes::Filters::Filter>& filter)
67 {
68 m_pending_filter = filter;
69 }
70
71private:
72 std::shared_ptr<Nodes::Filters::Filter> m_filter;
73 std::shared_ptr<Nodes::Filters::Filter> m_pending_filter;
74 bool m_use_internal {};
75 size_t m_current_position = 0;
76
77 void process_single_sample(double& sample);
78};
79
80} // namespace MayaFlux::Buffers
Central computational transformation interface for continuous buffer processing.
std::shared_ptr< Nodes::Filters::Filter > m_pending_filter
FilterProcessor(Args &&... args)
Creates processor with FIR filter.
FilterProcessor(const std::shared_ptr< Nodes::Filters::Filter > &filter)
Creates processor with external filter node.
std::shared_ptr< Nodes::Filters::Filter > get_filter() const
std::shared_ptr< Nodes::Filters::Filter > m_filter
FilterProcessor(Args &&... args)
Creates processor with IIR filter.
void update_filter_node(const std::shared_ptr< Nodes::Filters::Filter > &filter)
Buffer processor that applies filter nodes to audio data.
Finite Impulse Response filter implementation.
Definition FIR.hpp:34
Infinite Impulse Response filter implementation.
Definition IIR.hpp:36