MayaFlux 0.4.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 260 of file NodeGraphManager.cpp.

261{
262 if (num_nodes == 0)
263 return;
264
265 sample /= std::sqrt(static_cast<double>(num_nodes));
266
267 const double threshold = 0.95;
268 const double knee = 0.1;
269 const double abs_sample = std::abs(sample);
270
271 if (abs_sample > threshold) {
272 const double excess = abs_sample - threshold;
273 const double compressed_excess = std::tanh(excess / knee) * knee;
274 const double limited_abs = threshold + compressed_excess;
275 sample = std::copysign(limited_abs, sample);
276 }
277}
Tendency< D, float > threshold(const Tendency< D, float > &t, float thresh)
Zero output below threshold, pass through above.
Definition Tendency.hpp:141

Referenced by process_channel(), and process_sample().

+ Here is the caller graph for this function: