Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
float_ranges.h File Reference

Optimized DSP functions. More...

#include <cstdint>
#include <span>
Include dependency graph for float_ranges.h:

Go to the source code of this file.

Namespaces

namespace  zrythm::utils
 String utilities.

Functions

void zrythm::utils::float_ranges::fill (std::span< float > buf, float val)
 Fill the buffer with the given value.
void zrythm::utils::float_ranges::clip (std::span< float > buf, float minf, float maxf)
 Clamp the buffer to min/max.
void zrythm::utils::float_ranges::copy (std::span< float > dest, std::span< const float > src)
 Compute dest[i] = src[i].
void zrythm::utils::float_ranges::mul_k2 (std::span< float > dest, float k)
 Scale: dst[i] = dst[i] * k.
float zrythm::utils::float_ranges::abs_max (std::span< const float > buf)
 Gets the maximum absolute value of the buffer (as amplitude).
float zrythm::utils::float_ranges::min (std::span< const float > buf)
 Gets the minimum of the buffer.
float zrythm::utils::float_ranges::max (std::span< const float > buf)
 Gets the maximum of the buffer.
void zrythm::utils::float_ranges::add2 (std::span< float > dest, std::span< const float > src)
 Calculate dst[i] = dst[i] + src[i].
void zrythm::utils::float_ranges::product (std::span< float > dest, std::span< const float > src, float k)
 Calculate dest[i] = src[i] * k.
void zrythm::utils::float_ranges::mix_product (std::span< float > dest, std::span< const float > src, float k)
 Calculate dest[i] = dest[i] + src[i] * k.
void zrythm::utils::float_ranges::reverse (std::span< float > dest, std::span< const float > src)
 Reverse the order of samples: dst[i] <=> src[count - i - 1].
void zrythm::utils::float_ranges::normalize (std::span< float > dest, std::span< const float > src)
 Calculate normalized values: dst[i] = src[i] / (max { abs(src) }).
void zrythm::utils::float_ranges::linear_fade_in_from (std::span< float > dest, int32_t start_offset, int32_t total_frames_to_fade, float fade_from_multiplier)
 Calculate linear fade by multiplying from 0 to 1 for total_frames_to_fade samples.
void zrythm::utils::float_ranges::linear_fade_out_to (std::span< float > dest, int32_t start_offset, int32_t total_frames_to_fade, float fade_to_multiplier)
 Calculate linear fade by multiplying from 1 to 0 for total_frames_to_fade samples.
void zrythm::utils::float_ranges::make_mono (std::span< float > l, std::span< float > r, bool equal_power)
 Makes the two signals mono.

Detailed Description

Function Documentation

◆ linear_fade_in_from()

void zrythm::utils::float_ranges::linear_fade_in_from ( std::span< float > dest,
int32_t start_offset,
int32_t total_frames_to_fade,
float fade_from_multiplier )

Calculate linear fade by multiplying from 0 to 1 for total_frames_to_fade samples.

Note
Does not work properly when fade_from_multiplier is < 1k.
Parameters
destSpan of frames to process (size is the number of frames).
start_offsetStart offset in the fade interval.
total_frames_to_fadeTotal frames that should be faded.
fade_from_multiplierMultiplier to fade from (0 to fade from silence.)

◆ linear_fade_out_to()

void zrythm::utils::float_ranges::linear_fade_out_to ( std::span< float > dest,
int32_t start_offset,
int32_t total_frames_to_fade,
float fade_to_multiplier )

Calculate linear fade by multiplying from 1 to 0 for total_frames_to_fade samples.

Parameters
destSpan of frames to process (size is the number of frames).
start_offsetStart offset in the fade interval.
total_frames_to_fadeTotal frames that should be faded.
fade_to_multiplierMultiplier to fade to (0 to fade to silence.)

◆ make_mono()

void zrythm::utils::float_ranges::make_mono ( std::span< float > l,
std::span< float > r,
bool equal_power )

Makes the two signals mono.

Parameters
equal_powerTrue for equal power, false for equal amplitude.
Note
Equal amplitude is more suitable for mono compatibility checking. For reference:
  • equal power sum = (L+R) * 0.7079 (-3dB)
  • equal amplitude sum = (L+R) /2 (-6.02dB)