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

◆ normalize_sample()

void MayaFlux::Nodes::NodeGraphManager::normalize_sample ( double &  sample,
uint32_t  num_nodes 
)
private

Normalizes a sample to the range [-1, 1] based on the number of nodes.

Parameters
sampleReference to the sample value to normalize
num_nodesNumber of nodes in the processing chain

Ensures that the sample value is within the valid range for audio processing.

Definition at line 222 of file NodeGraphManager.cpp.

223{
224 if (num_nodes == 0)
225 return;
226
227 sample /= std::sqrt(static_cast<double>(num_nodes));
228
229 const double threshold = 0.95;
230 const double knee = 0.1;
231 const double abs_sample = std::abs(sample);
232
233 if (abs_sample > threshold) {
234 const double excess = abs_sample - threshold;
235 const double compressed_excess = std::tanh(excess / knee) * knee;
236 const double limited_abs = threshold + compressed_excess;
237 sample = std::copysign(limited_abs, sample);
238 }
239}

Referenced by process_channel(), and process_sample().

+ Here is the caller graph for this function: