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

◆ processing_function()

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

Processes a buffer by enforcing boundary conditions.

Parameters
bufferBuffer to process

This method applies a non-linear boundary enforcement algorithm to ensure all values stay within the valid range (typically -1.0 to 1.0) before being transmitted to hardware interfaces, while preserving the perceptual characteristics of the original signal.

Implements MayaFlux::Buffers::BufferProcessor.

Definition at line 157 of file RootAudioBuffer.cpp.

158{
159 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
160 if (!audio_buffer) {
161 return;
162 }
163
164 auto& data = audio_buffer->get_data();
165
166 constexpr double threshold = 0.95;
167 constexpr double knee = 0.1;
168
169 for (double& sample : data) {
170 const double abs_sample = std::abs(sample);
171
172 if (abs_sample > threshold) {
173 const double excess = abs_sample - threshold;
174 const double compressed_excess = std::tanh(excess / knee) * knee;
175 const double limited_abs = threshold + compressed_excess;
176
177 sample = (sample >= 0.0) ? limited_abs : -limited_abs;
178 }
179 }
180}