Vital
Loading...
Searching...
No Matches
vital::utils Namespace Reference

A collection of inline helper functions and constants used for SIMD computations, interpolation, and other audio-related utilities. More...

Classes

union  int_float
 A small union to reinterpret an int as a float or vice versa. More...
 
class  RandomGenerator
 A basic random number generator for producing uniform distributions of floats. More...
 

Functions

force_inline poly_float mulAdd (poly_float a, poly_float b, poly_float c)
 Performs a fused multiply-add on SIMD data: (a * b) + c.
 
force_inline poly_float mulSub (poly_float a, poly_float b, poly_float c)
 Performs a fused multiply-sub on SIMD data: (a * b) - c.
 
template<mono_float(*)(mono_float) func>
force_inline poly_float map (poly_float value)
 Applies a scalar function to each element in a poly_float.
 
force_inline poly_float centsToRatio (poly_float value)
 Converts semitone cents to a linear frequency ratio (vectorized).
 
force_inline poly_float noteOffsetToRatio (poly_float value)
 Converts note offsets to frequency ratios. Similar to centsToRatio, but may differ in how offset is defined.
 
force_inline poly_float ratioToMidiTranspose (poly_float value)
 Converts a ratio to MIDI transpose (vectorized).
 
force_inline poly_float midiCentsToFrequency (poly_float value)
 Converts MIDI cents to frequency (vectorized).
 
force_inline poly_float midiNoteToFrequency (poly_float value)
 Converts a MIDI note to a frequency (vectorized).
 
force_inline poly_float frequencyToMidiNote (poly_float value)
 Converts a frequency to a MIDI note (vectorized).
 
force_inline poly_float frequencyToMidiCents (poly_float value)
 Converts a frequency to MIDI cents (vectorized).
 
force_inline poly_float magnitudeToDb (poly_float value)
 Converts a magnitude value to decibels (vectorized).
 
force_inline poly_float dbToMagnitude (poly_float value)
 Converts a dB value to linear magnitude (vectorized).
 
force_inline poly_float tan (poly_float value)
 Computes the tangent of each element (in radians) in a poly_float.
 
force_inline poly_float sin (poly_float value)
 Computes the sine of each element (in radians).
 
force_inline poly_float cos (poly_float value)
 Computes the cosine of each element (in radians).
 
force_inline poly_float sqrt (poly_float value)
 Computes the square root of each element in a poly_float.
 
force_inline poly_float interpolate (poly_float from, poly_float to, mono_float t)
 Performs a linear interpolation between two poly_floats using a scalar t in [0..1].
 
force_inline poly_float getCubicInterpolationValues (mono_float mono_t)
 Returns the cubic Lagrange interpolation constants for a scalar mono_t.
 
force_inline poly_float getOptimalInterpolationValues (mono_float mono_t)
 Returns an "optimal" polynomial interpolation for a scalar mono_t.
 
force_inline matrix getPolynomialInterpolationMatrix (poly_float t_from)
 Creates a matrix for polynomial interpolation given a starting poly_float t_from.
 
force_inline matrix getCatmullInterpolationMatrix (poly_float t)
 Creates a Catmull-Rom interpolation matrix from a poly_float t.
 
force_inline matrix getLinearInterpolationMatrix (poly_float t)
 Creates a matrix for simple linear interpolation using scalar or vector t.
 
force_inline poly_float toPolyFloatFromUnaligned (const mono_float *unaligned)
 Loads a poly_float from an unaligned float pointer.
 
force_inline matrix getValueMatrix (const mono_float *buffer, poly_int indices)
 Creates a matrix of 4 poly_float lanes from a single buffer at varying indices.
 
force_inline matrix getValueMatrix (const mono_float *const *buffers, poly_int indices)
 Creates a matrix of 4 poly_float lanes from 4 separate buffers at varying indices.
 
force_inline poly_float interpolate (poly_float from, poly_float to, poly_float t)
 Interpolates between two SIMD values with a SIMD fraction t.
 
force_inline poly_float interpolate (mono_float from, mono_float to, poly_float t)
 Interpolates between two scalars with a SIMD fraction t.
 
force_inline poly_float perlinInterpolate (poly_float from, poly_float to, poly_float t)
 A specialized interpolation function used in perlin-like routines.
 
force_inline poly_float clamp (poly_float value, mono_float min, mono_float max)
 Clamps each lane of a vector to [min, max].
 
force_inline poly_float clamp (poly_float value, poly_float min, poly_float max)
 Clamps each lane of a vector to [min, max], where min and max are themselves poly_floats.
 
force_inline poly_int clamp (poly_int value, poly_int min, poly_int max)
 Clamps a poly_int to [min, max].
 
force_inline poly_float max (poly_float left, poly_float right)
 Returns the maximum of two poly_floats lane-by-lane.
 
force_inline poly_float min (poly_float left, poly_float right)
 Returns the minimum of two poly_floats lane-by-lane.
 
force_inline bool equal (poly_float left, poly_float right)
 Checks if two poly_floats are equal lane-by-lane. Returns true if all lanes match.
 
force_inline poly_float maskLoad (poly_float zero_value, poly_float one_value, poly_mask reset_mask)
 Selects between two values (zero_value or one_value) based on a mask in each lane.
 
force_inline poly_int maskLoad (poly_int zero_value, poly_int one_value, poly_mask reset_mask)
 Overload for poly_int.
 
force_inline poly_float modOnce (poly_float value)
 A special mod operation that ensures the result stays below 1.0, subtracting 1.0 if needed.
 
force_inline poly_mask closeToZeroMask (poly_float value)
 Returns a mask where lanes are true if value is close to 0.
 
force_inline poly_float pow (poly_float base, poly_float exponent)
 Raises each lane in base to the power of the corresponding lane in exponent.
 
force_inline poly_mask getSilentMask (const poly_float *buffer, int length)
 Creates a mask indicating whether all values in the given buffer are near zero.
 
force_inline poly_float swapStereo (poly_float value)
 Swaps the left and right channels of a stereo poly_float.
 
force_inline poly_int swapStereo (poly_int value)
 Same as swapStereo but for poly_int.
 
force_inline poly_float swapVoices (poly_float value)
 Swaps the first half of the lanes with the second half.
 
force_inline poly_int swapVoices (poly_int value)
 Overload for poly_int.
 
force_inline poly_float swapInner (poly_float value)
 Reorders internal stereo lanes.
 
force_inline poly_float reverse (poly_float value)
 Reverses the order of stereo lanes from (L, R, L, R) to (R, L, R, L).
 
force_inline poly_float consolidateAudio (poly_float one, poly_float two)
 Interleaves two stereo poly_floats into a single vector with left channels first, then right channels.
 
force_inline poly_float compactFirstVoices (poly_float one, poly_float two)
 Packs the first voice from two different poly_floats into a single vector.
 
force_inline poly_float sumSplitAudio (poly_float sum)
 Adds two stereo lanes for each voice, returning a combined mono result in each lane.
 
force_inline mono_float maxFloat (poly_float values)
 Returns the maximum lane value from a poly_float.
 
force_inline mono_float minFloat (poly_float values)
 Returns the minimum lane value from a poly_float.
 
force_inline poly_float encodeMidSide (poly_float value)
 Converts an L/R stereo representation into M/S (mid/side) encoding.
 
force_inline poly_float decodeMidSide (poly_float value)
 Converts a mid/side encoded stereo value back to L/R (decodes).
 
force_inline poly_float peak (const poly_float *buffer, int num, int skip=1)
 Returns the peak magnitude of a buffer (considering both positive and negative values).
 
force_inline void zeroBuffer (mono_float *buffer, int size)
 Zeros a mono buffer (standard array).
 
force_inline void zeroBuffer (poly_float *buffer, int size)
 Zeros a vector buffer (poly_float).
 
force_inline void copyBuffer (mono_float *dest, const mono_float *source, int size)
 Copies data from a source mono buffer to a destination mono buffer.
 
force_inline void copyBuffer (poly_float *dest, const poly_float *source, int size)
 Copies data from a poly_float source buffer to another poly_float buffer.
 
force_inline void addBuffers (poly_float *dest, const poly_float *b1, const poly_float *b2, int size)
 Adds two poly_float buffers element-by-element, storing in dest.
 
force_inline bool isFinite (poly_float value)
 Checks if all lanes in a poly_float are finite.
 
force_inline bool isInRange (poly_float value, mono_float min, mono_float max)
 Checks if each lane in a poly_float is within [min, max].
 
force_inline bool isContained (poly_float value)
 Checks if all lanes in a poly_float are within a broad range [-8000..8000].
 
force_inline bool isFinite (const poly_float *buffer, int size)
 Checks if all values in a buffer of poly_floats are finite.
 
force_inline bool isInRange (const poly_float *buffer, int size, mono_float min, mono_float max)
 Checks if all values in a poly_float buffer are within [min, max].
 
force_inline bool isContained (const poly_float *buffer, int size)
 Checks if a buffer of poly_float is entirely within [-8000..8000].
 
force_inline bool isSilent (const poly_float *buffer, int size)
 Determines if the entire buffer is silent (very close to zero).
 
force_inline poly_float gather (const mono_float *buffer, const poly_int &indices)
 Gathers values from a mono float buffer into a poly_float, using per-lane indices.
 
force_inline void adjacentGather (const mono_float *buffer, const poly_int &indices, poly_float &value, poly_float &next)
 Gathers adjacent values for each lane, storing them in value and next.
 
force_inline poly_float gatherSeparate (const mono_float *const *buffers, const poly_int &indices)
 Gathers values from different buffers, with each lane potentially reading from a different buffer index.
 
force_inline void adjacentGatherSeparate (const mono_float *const *buffers, const poly_int &indices, poly_float &value, poly_float &next)
 Similar to adjacentGather but for separate buffers.
 
force_inline poly_float fltScale (poly_float value, poly_float power)
 Performs a simple filter scaling operation (power * value) / ((power - 1)*value + 1).
 
force_inline poly_float toFloat (poly_int integers)
 Casts a poly_int to poly_float lane-by-lane.
 
force_inline poly_int toInt (poly_float floats)
 Casts a poly_float to poly_int by truncation.
 
force_inline poly_int truncToInt (poly_float value)
 Truncates a poly_float to an integer (effectively floor for positive values).
 
force_inline poly_float trunc (poly_float value)
 Returns the truncated value of each lane in value.
 
force_inline poly_float floor (poly_float value)
 Floors each lane in value.
 
force_inline poly_int floorToInt (poly_float value)
 Floors each lane and returns the result as an integer.
 
force_inline poly_int roundToInt (poly_float value)
 Rounds each lane to the nearest integer.
 
force_inline poly_float ceil (poly_float value)
 Ceils each lane in value.
 
force_inline poly_float round (poly_float value)
 Rounds each lane to the nearest integer as a poly_float.
 
force_inline poly_float mod (poly_float value)
 Returns the fractional part of each lane by subtracting the floored value.
 
force_inline poly_float reinterpretToFloat (poly_int value)
 Reinterprets a poly_int as a poly_float (bitcast).
 
force_inline poly_int reinterpretToInt (poly_float value)
 Reinterprets a poly_float as a poly_int (bitcast).
 
template<size_t shift>
force_inline poly_int shiftRight (poly_int integer)
 
template<size_t shift>
force_inline poly_int shiftLeft (poly_int integer)
 
force_inline poly_float pow2ToFloat (poly_int value)
 
force_inline poly_float triangleWave (poly_float t)
 Generates a simple triangle wave [0..1] from a fraction t in [0..1].
 
force_inline poly_float getCycleOffsetFromSeconds (double seconds, poly_float frequency)
 Computes a cycle offset given a time in seconds and a frequency.
 
force_inline poly_float getCycleOffsetFromSamples (long long samples, poly_float frequency, int sample_rate, int oversample_amount)
 Computes a cycle offset given a sample count, frequency, sample rate, and oversampling factor.
 
force_inline poly_float snapTranspose (poly_float transpose, int quantize)
 Snaps a MIDI transpose value to a quantization mask (e.g., scale degrees).
 
force_inline void fillSnapBuffer (int transpose_quantize, float *snap_buffer)
 Fills a buffer with snap offsets for a given quantize mask.
 
force_inline bool isTransposeQuantizeGlobal (int quantize)
 Checks if the transpose quantize mask applies globally (over multiple octaves).
 
force_inline bool isTransposeSnapping (int quantize)
 Checks if any snapping bits are set in the transpose quantize mask.
 
force_inline poly_float encodePhaseAndVoice (poly_float phase, poly_float voice)
 Encodes a phase [0..1) and a voice index into a single float, storing the voice in the integer portion.
 
force_inline std::pair< poly_float, poly_floatdecodePhaseAndVoice (poly_float encoded)
 Decodes a phase and voice from an encoded float, returning (phase, voice).
 
mono_float encodeOrderToFloat (int *order, int size)
 Encodes a permutation (stored in order) into a single float.
 
void decodeFloatToOrder (int *order, mono_float float_code, int size)
 Decodes a float-encoded permutation back into order.
 
void floatToPcmData (int16_t *pcm_data, const float *float_data, int size)
 Converts floating-point audio data to 16-bit PCM data.
 
void complexToPcmData (int16_t *pcm_data, const std::complex< float > *complex_data, int size)
 Converts an array of complex floats (magnitude/phase) to PCM data.
 
void pcmToFloatData (float *float_data, const int16_t *pcm_data, int size)
 Converts 16-bit PCM data to floating-point audio data.
 
void pcmToComplexData (std::complex< float > *complex_data, const int16_t *pcm_data, int size)
 Converts 16-bit PCM data representing complex info (amp/phase) back to std::complex floats.
 
constexpr int factorial (int value)
 Computes the factorial of a given integer at compile time.
 
force_inline mono_float intToFloatBits (int i)
 Reinterprets an int as a float (bitwise).
 
force_inline int floatToIntBits (mono_float f)
 Reinterprets a float as an int (bitwise).
 
force_inline mono_float min (mono_float one, mono_float two)
 Returns the minimum of two floats.
 
force_inline mono_float max (mono_float one, mono_float two)
 Returns the maximum of two floats.
 
force_inline mono_float clamp (mono_float value, mono_float min_val, mono_float max_val)
 Clamps a value between [min_val, max_val].
 
template<class T >
force_inlinepass (T input)
 A pass-through function that simply returns the input. Often used in templated code.
 
force_inline int imax (int one, int two)
 Returns the maximum of two integers.
 
force_inline int imin (int one, int two)
 Returns the minimum of two integers.
 
force_inline double interpolate (double from, double to, double t)
 Linearly interpolates between two double values.
 
force_inline mono_float interpolate (mono_float from, mono_float to, mono_float t)
 Linearly interpolates between two floats.
 
force_inline mono_float mod (double value, double *divisor)
 Returns the fractional part of value, storing the integer part in divisor (double).
 
force_inline mono_float mod (float value, float *divisor)
 Returns the fractional part of value, storing the integer part in divisor (float).
 
force_inline int iclamp (int value, int min_val, int max_val)
 Clamps an integer between [min_val, max_val].
 
force_inline int ilog2 (int value)
 Computes the floor of the base-2 logarithm of an integer (effectively the index of the highest set bit).
 
force_inline bool closeToZero (mono_float value)
 Determines if a float is close to zero (within ±kEpsilon).
 
force_inline mono_float magnitudeToDb (mono_float magnitude)
 Converts a magnitude to decibels using 20*log10(magnitude).
 
force_inline mono_float dbToMagnitude (mono_float decibels)
 Converts decibels to linear magnitude using 10^(dB / 20).
 
force_inline mono_float centsToRatio (mono_float cents)
 Converts cents to a ratio. A value of 1200 cents is 2.0.
 
force_inline mono_float noteOffsetToRatio (mono_float cents)
 Converts a note offset in semitones (or partial) to a frequency ratio.
 
force_inline mono_float ratioToMidiTranspose (mono_float ratio)
 Converts a frequency ratio to a MIDI transpose value (in semitones).
 
force_inline mono_float midiCentsToFrequency (mono_float cents)
 Converts a MIDI-based cents value to an absolute frequency, relative to MIDI note 0.
 
force_inline mono_float midiNoteToFrequency (mono_float note)
 Converts a MIDI note number to frequency in Hz.
 
force_inline mono_float frequencyToMidiNote (mono_float frequency)
 Converts a frequency in Hz to a MIDI note number.
 
force_inline mono_float frequencyToMidiCents (mono_float frequency)
 Converts a frequency in Hz to MIDI cents relative to MIDI note 0.
 
force_inline int nextPowerOfTwo (mono_float value)
 Finds the next power of two greater than or equal to a float value.
 
force_inline bool isSilent (const mono_float *buffer, int length)
 Checks if all samples in a buffer are close to zero.
 
force_inline mono_float rms (const mono_float *buffer, int num)
 Computes the Root Mean Square (RMS) of a buffer of floats.
 
force_inline mono_float inversePowerScale (mono_float t)
 A curve function used for specific shaping or scaling of a parameter.
 
force_inline mono_float inverseFltScale (mono_float t)
 Another curve function, typically used for certain shape transformations.
 

Variables

constexpr mono_float kPhaseEncodingMultiplier = 0.9f
 Used as a multiplier when encoding phase and voice data in a single float.
 
constexpr unsigned int kNotePressedMask = 0xf
 A bitmask used in voice encoding for note-on states.
 
constexpr mono_float kDbGainConversionMult = 20.0f
 Multiplicative factor for converting dB <-> magnitude using dB = 20*log10(magnitude).
 
constexpr int kMaxOrderLength = 10
 Maximum length for orders that can be encoded as a float via encodeOrderToFloat().
 
constexpr mono_float kLogOf2 = 0.69314718056f
 Natural log of 2.
 
constexpr mono_float kInvLogOf2 = 1.44269504089f
 Reciprocal of the natural log of 2 (1 / ln(2)).
 

Detailed Description

A collection of inline helper functions and constants used for SIMD computations, interpolation, and other audio-related utilities.

The functions within this namespace primarily operate on poly_float and poly_int (SIMD vector types) to efficiently handle multi-sample or multi-voice operations.

Function Documentation

◆ addBuffers()

force_inline void vital::utils::addBuffers ( poly_float * dest,
const poly_float * b1,
const poly_float * b2,
int size )

Adds two poly_float buffers element-by-element, storing in dest.

◆ adjacentGather()

force_inline void vital::utils::adjacentGather ( const mono_float * buffer,
const poly_int & indices,
poly_float & value,
poly_float & next )

Gathers adjacent values for each lane, storing them in value and next.

◆ adjacentGatherSeparate()

force_inline void vital::utils::adjacentGatherSeparate ( const mono_float *const * buffers,
const poly_int & indices,
poly_float & value,
poly_float & next )

Similar to adjacentGather but for separate buffers.

◆ ceil()

force_inline poly_float vital::utils::ceil ( poly_float value)

Ceils each lane in value.

◆ centsToRatio() [1/2]

force_inline mono_float vital::utils::centsToRatio ( mono_float cents)

Converts cents to a ratio. A value of 1200 cents is 2.0.

Parameters
centsThe number of cents (1 semitone = 100 cents).
Returns
A ratio of the frequency.

◆ centsToRatio() [2/2]

force_inline poly_float vital::utils::centsToRatio ( poly_float value)

Converts semitone cents to a linear frequency ratio (vectorized).

Parameters
valueThe input in cents (e.g., 1200 = +1 octave).
Returns
The ratio as 2^(value / 1200).

◆ clamp() [1/4]

force_inline mono_float vital::utils::clamp ( mono_float value,
mono_float min_val,
mono_float max_val )

Clamps a value between [min_val, max_val].

Parameters
valueThe value to clamp.
min_valThe minimum bound.
max_valThe maximum bound.
Returns
The clamped value.

◆ clamp() [2/4]

force_inline poly_float vital::utils::clamp ( poly_float value,
mono_float min,
mono_float max )

Clamps each lane of a vector to [min, max].

◆ clamp() [3/4]

force_inline poly_float vital::utils::clamp ( poly_float value,
poly_float min,
poly_float max )

Clamps each lane of a vector to [min, max], where min and max are themselves poly_floats.

◆ clamp() [4/4]

force_inline poly_int vital::utils::clamp ( poly_int value,
poly_int min,
poly_int max )

Clamps a poly_int to [min, max].

◆ closeToZero()

force_inline bool vital::utils::closeToZero ( mono_float value)

Determines if a float is close to zero (within ±kEpsilon).

Parameters
valueThe float to test.
Returns
True if |value| < kEpsilon, false otherwise.

◆ closeToZeroMask()

force_inline poly_mask vital::utils::closeToZeroMask ( poly_float value)

Returns a mask where lanes are true if value is close to 0.

◆ compactFirstVoices()

force_inline poly_float vital::utils::compactFirstVoices ( poly_float one,
poly_float two )

Packs the first voice from two different poly_floats into a single vector.

◆ complexToPcmData()

void vital::utils::complexToPcmData ( int16_t * pcm_data,
const std::complex< float > * complex_data,
int size )

Converts an array of complex floats (magnitude/phase) to PCM data.

Parameters
pcm_dataDestination PCM array (size must be at least size).
complex_dataSource complex float array.
sizeNumber of samples in the complex array (note that real PCM size is double).

◆ consolidateAudio()

force_inline poly_float vital::utils::consolidateAudio ( poly_float one,
poly_float two )

Interleaves two stereo poly_floats into a single vector with left channels first, then right channels.

◆ copyBuffer() [1/2]

force_inline void vital::utils::copyBuffer ( mono_float * dest,
const mono_float * source,
int size )

Copies data from a source mono buffer to a destination mono buffer.

◆ copyBuffer() [2/2]

force_inline void vital::utils::copyBuffer ( poly_float * dest,
const poly_float * source,
int size )

Copies data from a poly_float source buffer to another poly_float buffer.

◆ cos()

force_inline poly_float vital::utils::cos ( poly_float value)

Computes the cosine of each element (in radians).

◆ dbToMagnitude() [1/2]

force_inline mono_float vital::utils::dbToMagnitude ( mono_float decibels)

Converts decibels to linear magnitude using 10^(dB / 20).

Parameters
decibelsThe dB value.
Returns
The corresponding magnitude.

◆ dbToMagnitude() [2/2]

force_inline poly_float vital::utils::dbToMagnitude ( poly_float value)

Converts a dB value to linear magnitude (vectorized).

◆ decodeFloatToOrder()

void vital::utils::decodeFloatToOrder ( int * order,
mono_float float_code,
int size )

Decodes a float-encoded permutation back into order.

Decodes a float-encoded permutation (from encodeOrderToFloat) back into an integer array.

Parameters
orderThe integer array to fill.
float_codeThe encoded float from encodeOrderToFloat.
sizeNumber of elements in order.
orderThe integer array to fill with the permutation.
float_codeThe float code containing the encoded order.
sizeThe length of the order array.

◆ decodeMidSide()

force_inline poly_float vital::utils::decodeMidSide ( poly_float value)

Converts a mid/side encoded stereo value back to L/R (decodes).

◆ decodePhaseAndVoice()

force_inline std::pair< poly_float, poly_float > vital::utils::decodePhaseAndVoice ( poly_float encoded)

Decodes a phase and voice from an encoded float, returning (phase, voice).

◆ encodeMidSide()

force_inline poly_float vital::utils::encodeMidSide ( poly_float value)

Converts an L/R stereo representation into M/S (mid/side) encoding.

◆ encodeOrderToFloat()

mono_float vital::utils::encodeOrderToFloat ( int * order,
int size )

Encodes a permutation (stored in order) into a single float.

Encodes a permutation order array into a single float (bit-packed).

Parameters
orderInteger array representing the permutation.
sizeLength of the array (up to kMaxOrderLength).
Returns
Encoded float.

Each element in order is used to compute a factorial-based integer code. It is then returned as a float.

Parameters
orderAn integer array representing the permutation order.
sizeThe length of the array (up to kMaxOrderLength).
Returns
A float representation of the permutation.

◆ encodePhaseAndVoice()

force_inline poly_float vital::utils::encodePhaseAndVoice ( poly_float phase,
poly_float voice )

Encodes a phase [0..1) and a voice index into a single float, storing the voice in the integer portion.

◆ equal()

force_inline bool vital::utils::equal ( poly_float left,
poly_float right )

Checks if two poly_floats are equal lane-by-lane. Returns true if all lanes match.

◆ factorial()

int vital::utils::factorial ( int value)
constexpr

Computes the factorial of a given integer at compile time.

Parameters
valueThe integer whose factorial is needed.
Returns
The factorial of value.

◆ fillSnapBuffer()

force_inline void vital::utils::fillSnapBuffer ( int transpose_quantize,
float * snap_buffer )

Fills a buffer with snap offsets for a given quantize mask.

◆ floatToIntBits()

force_inline int vital::utils::floatToIntBits ( mono_float f)

Reinterprets a float as an int (bitwise).

Parameters
fThe float to reinterpret.
Returns
The int representation of the same bits.

◆ floatToPcmData()

void vital::utils::floatToPcmData ( int16_t * pcm_data,
const float * float_data,
int size )

Converts floating-point audio data to 16-bit PCM data.

Parameters
pcm_dataDestination PCM array.
float_dataSource float array.
sizeNumber of samples to convert.

◆ floor()

force_inline poly_float vital::utils::floor ( poly_float value)

Floors each lane in value.

◆ floorToInt()

force_inline poly_int vital::utils::floorToInt ( poly_float value)

Floors each lane and returns the result as an integer.

◆ fltScale()

force_inline poly_float vital::utils::fltScale ( poly_float value,
poly_float power )

Performs a simple filter scaling operation (power * value) / ((power - 1)*value + 1).

◆ frequencyToMidiCents() [1/2]

force_inline mono_float vital::utils::frequencyToMidiCents ( mono_float frequency)

Converts a frequency in Hz to MIDI cents relative to MIDI note 0.

Parameters
frequencyThe frequency in Hz.
Returns
The cents value (1 semitone = 100).

◆ frequencyToMidiCents() [2/2]

force_inline poly_float vital::utils::frequencyToMidiCents ( poly_float value)

Converts a frequency to MIDI cents (vectorized).

◆ frequencyToMidiNote() [1/2]

force_inline mono_float vital::utils::frequencyToMidiNote ( mono_float frequency)

Converts a frequency in Hz to a MIDI note number.

Parameters
frequencyThe frequency in Hz.
Returns
The approximate MIDI note number.

◆ frequencyToMidiNote() [2/2]

force_inline poly_float vital::utils::frequencyToMidiNote ( poly_float value)

Converts a frequency to a MIDI note (vectorized).

◆ gather()

force_inline poly_float vital::utils::gather ( const mono_float * buffer,
const poly_int & indices )

Gathers values from a mono float buffer into a poly_float, using per-lane indices.

◆ gatherSeparate()

force_inline poly_float vital::utils::gatherSeparate ( const mono_float *const * buffers,
const poly_int & indices )

Gathers values from different buffers, with each lane potentially reading from a different buffer index.

◆ getCatmullInterpolationMatrix()

force_inline matrix vital::utils::getCatmullInterpolationMatrix ( poly_float t)

Creates a Catmull-Rom interpolation matrix from a poly_float t.

◆ getCubicInterpolationValues()

force_inline poly_float vital::utils::getCubicInterpolationValues ( mono_float mono_t)

Returns the cubic Lagrange interpolation constants for a scalar mono_t.

◆ getCycleOffsetFromSamples()

force_inline poly_float vital::utils::getCycleOffsetFromSamples ( long long samples,
poly_float frequency,
int sample_rate,
int oversample_amount )

Computes a cycle offset given a sample count, frequency, sample rate, and oversampling factor.

◆ getCycleOffsetFromSeconds()

force_inline poly_float vital::utils::getCycleOffsetFromSeconds ( double seconds,
poly_float frequency )

Computes a cycle offset given a time in seconds and a frequency.

Parameters
secondsThe elapsed time in seconds.
frequencyThe per-lane frequency.
Returns
The fractional cycle offset in [0..1).

◆ getLinearInterpolationMatrix()

force_inline matrix vital::utils::getLinearInterpolationMatrix ( poly_float t)

Creates a matrix for simple linear interpolation using scalar or vector t.

◆ getOptimalInterpolationValues()

force_inline poly_float vital::utils::getOptimalInterpolationValues ( mono_float mono_t)

Returns an "optimal" polynomial interpolation for a scalar mono_t.

◆ getPolynomialInterpolationMatrix()

force_inline matrix vital::utils::getPolynomialInterpolationMatrix ( poly_float t_from)

Creates a matrix for polynomial interpolation given a starting poly_float t_from.

◆ getSilentMask()

force_inline poly_mask vital::utils::getSilentMask ( const poly_float * buffer,
int length )

Creates a mask indicating whether all values in the given buffer are near zero.

◆ getValueMatrix() [1/2]

force_inline matrix vital::utils::getValueMatrix ( const mono_float * buffer,
poly_int indices )

Creates a matrix of 4 poly_float lanes from a single buffer at varying indices.

◆ getValueMatrix() [2/2]

force_inline matrix vital::utils::getValueMatrix ( const mono_float *const * buffers,
poly_int indices )

Creates a matrix of 4 poly_float lanes from 4 separate buffers at varying indices.

◆ iclamp()

force_inline int vital::utils::iclamp ( int value,
int min_val,
int max_val )

Clamps an integer between [min_val, max_val].

◆ ilog2()

force_inline int vital::utils::ilog2 ( int value)

Computes the floor of the base-2 logarithm of an integer (effectively the index of the highest set bit).

Parameters
valueThe integer to compute log2 for (must be > 0).
Returns
The integer part of log2(value).

◆ imax()

force_inline int vital::utils::imax ( int one,
int two )

Returns the maximum of two integers.

◆ imin()

force_inline int vital::utils::imin ( int one,
int two )

Returns the minimum of two integers.

◆ interpolate() [1/5]

force_inline double vital::utils::interpolate ( double from,
double to,
double t )

Linearly interpolates between two double values.

Parameters
fromThe starting value.
toThe ending value.
tA fraction in [0, 1], where 0 returns from and 1 returns to.

◆ interpolate() [2/5]

force_inline mono_float vital::utils::interpolate ( mono_float from,
mono_float to,
mono_float t )

Linearly interpolates between two floats.

◆ interpolate() [3/5]

force_inline poly_float vital::utils::interpolate ( mono_float from,
mono_float to,
poly_float t )

Interpolates between two scalars with a SIMD fraction t.

◆ interpolate() [4/5]

force_inline poly_float vital::utils::interpolate ( poly_float from,
poly_float to,
mono_float t )

Performs a linear interpolation between two poly_floats using a scalar t in [0..1].

◆ interpolate() [5/5]

force_inline poly_float vital::utils::interpolate ( poly_float from,
poly_float to,
poly_float t )

Interpolates between two SIMD values with a SIMD fraction t.

◆ intToFloatBits()

force_inline mono_float vital::utils::intToFloatBits ( int i)

Reinterprets an int as a float (bitwise).

Parameters
iThe int to reinterpret.
Returns
The float representation of the same bits.

◆ inverseFltScale()

force_inline mono_float vital::utils::inverseFltScale ( mono_float t)

Another curve function, typically used for certain shape transformations.

Parameters
tInput value in [0, 1].
Returns
A scaled result.

◆ inversePowerScale()

force_inline mono_float vital::utils::inversePowerScale ( mono_float t)

A curve function used for specific shaping or scaling of a parameter.

Parameters
tInput value in [0, 1].
Returns
A scaled value, used in certain curve transformations.

◆ isContained() [1/2]

force_inline bool vital::utils::isContained ( const poly_float * buffer,
int size )

Checks if a buffer of poly_float is entirely within [-8000..8000].

◆ isContained() [2/2]

force_inline bool vital::utils::isContained ( poly_float value)

Checks if all lanes in a poly_float are within a broad range [-8000..8000].

◆ isFinite() [1/2]

force_inline bool vital::utils::isFinite ( const poly_float * buffer,
int size )

Checks if all values in a buffer of poly_floats are finite.

◆ isFinite() [2/2]

force_inline bool vital::utils::isFinite ( poly_float value)

Checks if all lanes in a poly_float are finite.

◆ isInRange() [1/2]

force_inline bool vital::utils::isInRange ( const poly_float * buffer,
int size,
mono_float min,
mono_float max )

Checks if all values in a poly_float buffer are within [min, max].

◆ isInRange() [2/2]

force_inline bool vital::utils::isInRange ( poly_float value,
mono_float min,
mono_float max )

Checks if each lane in a poly_float is within [min, max].

◆ isSilent() [1/2]

force_inline bool vital::utils::isSilent ( const mono_float * buffer,
int length )

Checks if all samples in a buffer are close to zero.

Parameters
bufferA pointer to an array of mono_float samples.
lengthThe number of samples in the buffer.
Returns
True if all samples are near zero, false otherwise.

◆ isSilent() [2/2]

force_inline bool vital::utils::isSilent ( const poly_float * buffer,
int size )

Determines if the entire buffer is silent (very close to zero).

◆ isTransposeQuantizeGlobal()

force_inline bool vital::utils::isTransposeQuantizeGlobal ( int quantize)

Checks if the transpose quantize mask applies globally (over multiple octaves).

◆ isTransposeSnapping()

force_inline bool vital::utils::isTransposeSnapping ( int quantize)

Checks if any snapping bits are set in the transpose quantize mask.

◆ magnitudeToDb() [1/2]

force_inline mono_float vital::utils::magnitudeToDb ( mono_float magnitude)

Converts a magnitude to decibels using 20*log10(magnitude).

Parameters
magnitudeThe non-negative amplitude or magnitude.
Returns
The dB value.

◆ magnitudeToDb() [2/2]

force_inline poly_float vital::utils::magnitudeToDb ( poly_float value)

Converts a magnitude value to decibels (vectorized).

◆ map()

template<mono_float(*)(mono_float) func>
force_inline poly_float vital::utils::map ( poly_float value)

Applies a scalar function to each element in a poly_float.

Template Parameters
funcPointer to a function (mono_float -> mono_float).
Parameters
valueThe SIMD vector on which to apply the function element-by-element.
Returns
A new SIMD vector containing func(value[i]) for each lane.

◆ maskLoad() [1/2]

force_inline poly_float vital::utils::maskLoad ( poly_float zero_value,
poly_float one_value,
poly_mask reset_mask )

Selects between two values (zero_value or one_value) based on a mask in each lane.

Parameters
zero_valueValue to select for false lanes.
one_valueValue to select for true lanes.
reset_maskThe mask indicating which lanes are true/false.

◆ maskLoad() [2/2]

force_inline poly_int vital::utils::maskLoad ( poly_int zero_value,
poly_int one_value,
poly_mask reset_mask )

Overload for poly_int.

◆ max() [1/2]

force_inline mono_float vital::utils::max ( mono_float one,
mono_float two )

Returns the maximum of two floats.

◆ max() [2/2]

force_inline poly_float vital::utils::max ( poly_float left,
poly_float right )

Returns the maximum of two poly_floats lane-by-lane.

◆ maxFloat()

force_inline mono_float vital::utils::maxFloat ( poly_float values)

Returns the maximum lane value from a poly_float.

◆ midiCentsToFrequency() [1/2]

force_inline mono_float vital::utils::midiCentsToFrequency ( mono_float cents)

Converts a MIDI-based cents value to an absolute frequency, relative to MIDI note 0.

Parameters
centsThe note offset in cents relative to MIDI note 0.
Returns
Frequency in Hz.

◆ midiCentsToFrequency() [2/2]

force_inline poly_float vital::utils::midiCentsToFrequency ( poly_float value)

Converts MIDI cents to frequency (vectorized).

◆ midiNoteToFrequency() [1/2]

force_inline mono_float vital::utils::midiNoteToFrequency ( mono_float note)

Converts a MIDI note number to frequency in Hz.

Parameters
noteMIDI note in semitones (C-1 is 0, A4 is 69, etc.).
Returns
The frequency in Hz.

◆ midiNoteToFrequency() [2/2]

force_inline poly_float vital::utils::midiNoteToFrequency ( poly_float value)

Converts a MIDI note to a frequency (vectorized).

◆ min() [1/2]

force_inline mono_float vital::utils::min ( mono_float one,
mono_float two )

Returns the minimum of two floats.

◆ min() [2/2]

force_inline poly_float vital::utils::min ( poly_float left,
poly_float right )

Returns the minimum of two poly_floats lane-by-lane.

◆ minFloat()

force_inline mono_float vital::utils::minFloat ( poly_float values)

Returns the minimum lane value from a poly_float.

◆ mod() [1/3]

force_inline mono_float vital::utils::mod ( double value,
double * divisor )

Returns the fractional part of value, storing the integer part in divisor (double).

◆ mod() [2/3]

force_inline mono_float vital::utils::mod ( float value,
float * divisor )

Returns the fractional part of value, storing the integer part in divisor (float).

◆ mod() [3/3]

force_inline poly_float vital::utils::mod ( poly_float value)

Returns the fractional part of each lane by subtracting the floored value.

◆ modOnce()

force_inline poly_float vital::utils::modOnce ( poly_float value)

A special mod operation that ensures the result stays below 1.0, subtracting 1.0 if needed.

Parameters
valueThe input vector in [0..2).

◆ mulAdd()

force_inline poly_float vital::utils::mulAdd ( poly_float a,
poly_float b,
poly_float c )

Performs a fused multiply-add on SIMD data: (a * b) + c.

Parameters
aThe first multiplicand.
bThe second multiplicand.
cThe addend.
Returns
Result of (a * b) + c.

◆ mulSub()

force_inline poly_float vital::utils::mulSub ( poly_float a,
poly_float b,
poly_float c )

Performs a fused multiply-sub on SIMD data: (a * b) - c.

Parameters
aThe first multiplicand.
bThe second multiplicand.
cThe subtrahend.
Returns
Result of (a * b) - c.

◆ nextPowerOfTwo()

force_inline int vital::utils::nextPowerOfTwo ( mono_float value)

Finds the next power of two greater than or equal to a float value.

Parameters
valueA float specifying the lower bound.
Returns
An integer that is a power of two >= value.

◆ noteOffsetToRatio() [1/2]

force_inline mono_float vital::utils::noteOffsetToRatio ( mono_float cents)

Converts a note offset in semitones (or partial) to a frequency ratio.

Parameters
centsThe number of semitones (100 cents each).
Returns
The resulting ratio.

◆ noteOffsetToRatio() [2/2]

force_inline poly_float vital::utils::noteOffsetToRatio ( poly_float value)

Converts note offsets to frequency ratios. Similar to centsToRatio, but may differ in how offset is defined.

◆ pass()

template<class T >
force_inline T vital::utils::pass ( T input)

A pass-through function that simply returns the input. Often used in templated code.

Template Parameters
TGeneric type.
Parameters
inputThe input value.
Returns
The same input value.

◆ pcmToComplexData()

void vital::utils::pcmToComplexData ( std::complex< float > * complex_data,
const int16_t * pcm_data,
int size )

Converts 16-bit PCM data representing complex info (amp/phase) back to std::complex floats.

Parameters
complex_dataDestination complex float array.
pcm_dataSource PCM array.
sizeNumber of samples in pcm_data (note that real complex size is half).

◆ pcmToFloatData()

void vital::utils::pcmToFloatData ( float * float_data,
const int16_t * pcm_data,
int size )

Converts 16-bit PCM data to floating-point audio data.

Parameters
float_dataDestination float array.
pcm_dataSource PCM array.
sizeNumber of samples to convert.

◆ peak()

force_inline poly_float vital::utils::peak ( const poly_float * buffer,
int num,
int skip = 1 )

Returns the peak magnitude of a buffer (considering both positive and negative values).

◆ perlinInterpolate()

force_inline poly_float vital::utils::perlinInterpolate ( poly_float from,
poly_float to,
poly_float t )

A specialized interpolation function used in perlin-like routines.

◆ pow()

force_inline poly_float vital::utils::pow ( poly_float base,
poly_float exponent )

Raises each lane in base to the power of the corresponding lane in exponent.

◆ pow2ToFloat()

force_inline poly_float vital::utils::pow2ToFloat ( poly_int value)

◆ ratioToMidiTranspose() [1/2]

force_inline mono_float vital::utils::ratioToMidiTranspose ( mono_float ratio)

Converts a frequency ratio to a MIDI transpose value (in semitones).

Parameters
ratioThe frequency ratio (e.g., 2.0 for one octave above).
Returns
Number of semitones (MIDI note difference).

◆ ratioToMidiTranspose() [2/2]

force_inline poly_float vital::utils::ratioToMidiTranspose ( poly_float value)

Converts a ratio to MIDI transpose (vectorized).

◆ reinterpretToFloat()

force_inline poly_float vital::utils::reinterpretToFloat ( poly_int value)

Reinterprets a poly_int as a poly_float (bitcast).

◆ reinterpretToInt()

force_inline poly_int vital::utils::reinterpretToInt ( poly_float value)

Reinterprets a poly_float as a poly_int (bitcast).

◆ reverse()

force_inline poly_float vital::utils::reverse ( poly_float value)

Reverses the order of stereo lanes from (L, R, L, R) to (R, L, R, L).

◆ rms()

force_inline mono_float vital::utils::rms ( const mono_float * buffer,
int num )

Computes the Root Mean Square (RMS) of a buffer of floats.

Parameters
bufferThe pointer to the samples.
numThe number of samples.
Returns
The RMS of the buffer.

◆ round()

force_inline poly_float vital::utils::round ( poly_float value)

Rounds each lane to the nearest integer as a poly_float.

◆ roundToInt()

force_inline poly_int vital::utils::roundToInt ( poly_float value)

Rounds each lane to the nearest integer.

◆ shiftLeft()

template<size_t shift>
force_inline poly_int vital::utils::shiftLeft ( poly_int integer)

◆ shiftRight()

template<size_t shift>
force_inline poly_int vital::utils::shiftRight ( poly_int integer)

◆ sin()

force_inline poly_float vital::utils::sin ( poly_float value)

Computes the sine of each element (in radians).

◆ snapTranspose()

force_inline poly_float vital::utils::snapTranspose ( poly_float transpose,
int quantize )

Snaps a MIDI transpose value to a quantization mask (e.g., scale degrees).

◆ sqrt()

force_inline poly_float vital::utils::sqrt ( poly_float value)

Computes the square root of each element in a poly_float.

◆ sumSplitAudio()

force_inline poly_float vital::utils::sumSplitAudio ( poly_float sum)

Adds two stereo lanes for each voice, returning a combined mono result in each lane.

◆ swapInner()

force_inline poly_float vital::utils::swapInner ( poly_float value)

Reorders internal stereo lanes.

◆ swapStereo() [1/2]

force_inline poly_float vital::utils::swapStereo ( poly_float value)

Swaps the left and right channels of a stereo poly_float.

◆ swapStereo() [2/2]

force_inline poly_int vital::utils::swapStereo ( poly_int value)

Same as swapStereo but for poly_int.

◆ swapVoices() [1/2]

force_inline poly_float vital::utils::swapVoices ( poly_float value)

Swaps the first half of the lanes with the second half.

◆ swapVoices() [2/2]

force_inline poly_int vital::utils::swapVoices ( poly_int value)

Overload for poly_int.

◆ tan()

force_inline poly_float vital::utils::tan ( poly_float value)

Computes the tangent of each element (in radians) in a poly_float.

◆ toFloat()

force_inline poly_float vital::utils::toFloat ( poly_int integers)

Casts a poly_int to poly_float lane-by-lane.

◆ toInt()

force_inline poly_int vital::utils::toInt ( poly_float floats)

Casts a poly_float to poly_int by truncation.

◆ toPolyFloatFromUnaligned()

force_inline poly_float vital::utils::toPolyFloatFromUnaligned ( const mono_float * unaligned)

Loads a poly_float from an unaligned float pointer.

◆ triangleWave()

force_inline poly_float vital::utils::triangleWave ( poly_float t)

Generates a simple triangle wave [0..1] from a fraction t in [0..1].

◆ trunc()

force_inline poly_float vital::utils::trunc ( poly_float value)

Returns the truncated value of each lane in value.

◆ truncToInt()

force_inline poly_int vital::utils::truncToInt ( poly_float value)

Truncates a poly_float to an integer (effectively floor for positive values).

◆ zeroBuffer() [1/2]

force_inline void vital::utils::zeroBuffer ( mono_float * buffer,
int size )

Zeros a mono buffer (standard array).

◆ zeroBuffer() [2/2]

force_inline void vital::utils::zeroBuffer ( poly_float * buffer,
int size )

Zeros a vector buffer (poly_float).

Variable Documentation

◆ kDbGainConversionMult

mono_float vital::utils::kDbGainConversionMult = 20.0f
constexpr

Multiplicative factor for converting dB <-> magnitude using dB = 20*log10(magnitude).

◆ kInvLogOf2

mono_float vital::utils::kInvLogOf2 = 1.44269504089f
constexpr

Reciprocal of the natural log of 2 (1 / ln(2)).

◆ kLogOf2

mono_float vital::utils::kLogOf2 = 0.69314718056f
constexpr

Natural log of 2.

◆ kMaxOrderLength

int vital::utils::kMaxOrderLength = 10
constexpr

Maximum length for orders that can be encoded as a float via encodeOrderToFloat().

◆ kNotePressedMask

unsigned int vital::utils::kNotePressedMask = 0xf
constexpr

A bitmask used in voice encoding for note-on states.

◆ kPhaseEncodingMultiplier

mono_float vital::utils::kPhaseEncodingMultiplier = 0.9f
constexpr

Used as a multiplier when encoding phase and voice data in a single float.