MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ processing_function()

void MayaFlux::Buffers::FeedbackProcessor::processing_function ( std::shared_ptr< Buffer buffer)
overridevirtual

Processes a buffer by applying the recursive algorithm.

Parameters
bufferBuffer to process

This method:

  1. Combines the current state with the stored previous state
  2. Stores the resulting output as the new previous state

The combination is weighted by the feedback coefficient, with higher values resulting in stronger influence from the previous state.

Implements MayaFlux::Buffers::BufferProcessor.

Definition at line 38 of file FeedbackBuffer.cpp.

39{
40 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
41 if (!audio_buffer)
42 return;
43
44 std::vector<double>* previous_data = nullptr;
45 auto& buffer_data = audio_buffer->get_data();
46
47 if (auto feedback_buffer = std::dynamic_pointer_cast<FeedbackBuffer>(buffer)) {
48 previous_data = &feedback_buffer->get_previous_buffer();
50 } else {
51 if (m_previous_buffer.size() != m_feed_samples) {
54 }
55 previous_data = &m_previous_buffer;
56 }
57
58 for (double& sample : buffer_data) {
59 double delayed_sample = (*previous_data)[m_buffer_index];
60
61 double output_sample = sample + (m_feedback_amount * delayed_sample);
62
63 if (m_feed_samples > 1) {
64 size_t next_index = (m_buffer_index + 1) % m_feed_samples;
65 output_sample = (output_sample + (*previous_data)[next_index]) * 0.5;
66 }
67
68 sample = output_sample;
69
70 (*previous_data)[m_buffer_index] = output_sample;
71
73 }
74}
bool m_using_internal_buffer
Flag indicating whether to use the buffer's internal previous state.
uint32_t m_feed_samples
Number of samples to feed back.
std::vector< double > m_previous_buffer
Storage for the previous system state.
float m_feedback_amount
Feedback coefficient (0.0-1.0)

References m_buffer_index, m_feed_samples, m_feedback_amount, m_previous_buffer, and m_using_internal_buffer.