MayaFlux 0.2.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 234 of file NodeGraphManager.cpp.

235{
236 if (num_nodes == 0)
237 return;
238
239 sample /= std::sqrt(static_cast<double>(num_nodes));
240
241 const double threshold = 0.95;
242 const double knee = 0.1;
243 const double abs_sample = std::abs(sample);
244
245 if (abs_sample > threshold) {
246 const double excess = abs_sample - threshold;
247 const double compressed_excess = std::tanh(excess / knee) * knee;
248 const double limited_abs = threshold + compressed_excess;
249 sample = std::copysign(limited_abs, sample);
250 }
251}

Referenced by process_channel(), and process_sample().

+ Here is the caller graph for this function: