Vital
Loading...
Searching...
No Matches
poly_utils.h File Reference
#include "matrix.h"
#include "utils.h"
#include <cmath>

Go to the source code of this file.

Namespaces

namespace  vital
 Contains classes and functions used within the Vital synthesizer framework.
 
namespace  vital::utils
 A collection of inline helper functions and constants used for SIMD computations, interpolation, and other audio-related utilities.
 

Functions

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.
 
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.
 
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.
 
force_inline poly_float vital::utils::centsToRatio (poly_float value)
 Converts semitone cents to a linear frequency ratio (vectorized).
 
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.
 
force_inline poly_float vital::utils::ratioToMidiTranspose (poly_float value)
 Converts a ratio to MIDI transpose (vectorized).
 
force_inline poly_float vital::utils::midiCentsToFrequency (poly_float value)
 Converts MIDI cents to frequency (vectorized).
 
force_inline poly_float vital::utils::midiNoteToFrequency (poly_float value)
 Converts a MIDI note to a frequency (vectorized).
 
force_inline poly_float vital::utils::frequencyToMidiNote (poly_float value)
 Converts a frequency to a MIDI note (vectorized).
 
force_inline poly_float vital::utils::frequencyToMidiCents (poly_float value)
 Converts a frequency to MIDI cents (vectorized).
 
force_inline poly_float vital::utils::magnitudeToDb (poly_float value)
 Converts a magnitude value to decibels (vectorized).
 
force_inline poly_float vital::utils::dbToMagnitude (poly_float value)
 Converts a dB value to linear magnitude (vectorized).
 
force_inline poly_float vital::utils::tan (poly_float value)
 Computes the tangent of each element (in radians) in a poly_float.
 
force_inline poly_float vital::utils::sin (poly_float value)
 Computes the sine of each element (in radians).
 
force_inline poly_float vital::utils::cos (poly_float value)
 Computes the cosine of each element (in radians).
 
force_inline poly_float vital::utils::sqrt (poly_float value)
 Computes the square root of each element in a poly_float.
 
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].
 
force_inline poly_float vital::utils::getCubicInterpolationValues (mono_float mono_t)
 Returns the cubic Lagrange interpolation constants for a scalar mono_t.
 
force_inline poly_float vital::utils::getOptimalInterpolationValues (mono_float mono_t)
 Returns an "optimal" polynomial interpolation for a scalar mono_t.
 
force_inline matrix vital::utils::getPolynomialInterpolationMatrix (poly_float t_from)
 Creates a matrix for polynomial interpolation given a starting poly_float t_from.
 
force_inline matrix vital::utils::getCatmullInterpolationMatrix (poly_float t)
 Creates a Catmull-Rom interpolation matrix from a poly_float t.
 
force_inline matrix vital::utils::getLinearInterpolationMatrix (poly_float t)
 Creates a matrix for simple linear interpolation using scalar or vector t.
 
force_inline poly_float vital::utils::toPolyFloatFromUnaligned (const mono_float *unaligned)
 Loads a poly_float from an unaligned float pointer.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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].
 
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.
 
force_inline poly_int vital::utils::clamp (poly_int value, poly_int min, poly_int max)
 Clamps a poly_int to [min, max].
 
force_inline poly_float vital::utils::max (poly_float left, poly_float right)
 Returns the maximum of two poly_floats lane-by-lane.
 
force_inline poly_float vital::utils::min (poly_float left, poly_float right)
 Returns the minimum of two poly_floats lane-by-lane.
 
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.
 
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.
 
force_inline poly_int vital::utils::maskLoad (poly_int zero_value, poly_int one_value, poly_mask reset_mask)
 Overload for poly_int.
 
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.
 
force_inline poly_mask vital::utils::closeToZeroMask (poly_float value)
 Returns a mask where lanes are true if value is close to 0.
 
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.
 
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.
 
force_inline poly_float vital::utils::swapStereo (poly_float value)
 Swaps the left and right channels of a stereo poly_float.
 
force_inline poly_int vital::utils::swapStereo (poly_int value)
 Same as swapStereo but for poly_int.
 
force_inline poly_float vital::utils::swapVoices (poly_float value)
 Swaps the first half of the lanes with the second half.
 
force_inline poly_int vital::utils::swapVoices (poly_int value)
 Overload for poly_int.
 
force_inline poly_float vital::utils::swapInner (poly_float value)
 Reorders internal stereo lanes.
 
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).
 
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.
 
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.
 
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.
 
force_inline mono_float vital::utils::maxFloat (poly_float values)
 Returns the maximum lane value from a poly_float.
 
force_inline mono_float vital::utils::minFloat (poly_float values)
 Returns the minimum lane value from a poly_float.
 
force_inline poly_float vital::utils::encodeMidSide (poly_float value)
 Converts an L/R stereo representation into M/S (mid/side) encoding.
 
force_inline poly_float vital::utils::decodeMidSide (poly_float value)
 Converts a mid/side encoded stereo value back to L/R (decodes).
 
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).
 
force_inline void vital::utils::zeroBuffer (mono_float *buffer, int size)
 Zeros a mono buffer (standard array).
 
force_inline void vital::utils::zeroBuffer (poly_float *buffer, int size)
 Zeros a vector buffer (poly_float).
 
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.
 
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.
 
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.
 
force_inline bool vital::utils::isFinite (poly_float value)
 Checks if all lanes in a poly_float are finite.
 
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].
 
force_inline bool vital::utils::isContained (poly_float value)
 Checks if all lanes in a poly_float are within a broad range [-8000..8000].
 
force_inline bool vital::utils::isFinite (const poly_float *buffer, int size)
 Checks if all values in a buffer of poly_floats are finite.
 
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].
 
force_inline bool vital::utils::isContained (const poly_float *buffer, int size)
 Checks if a buffer of poly_float is entirely within [-8000..8000].
 
force_inline bool vital::utils::isSilent (const poly_float *buffer, int size)
 Determines if the entire buffer is silent (very close to zero).
 
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.
 
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.
 
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.
 
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.
 
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).
 
force_inline poly_float vital::utils::toFloat (poly_int integers)
 Casts a poly_int to poly_float lane-by-lane.
 
force_inline poly_int vital::utils::toInt (poly_float floats)
 Casts a poly_float to poly_int by truncation.
 
force_inline poly_int vital::utils::truncToInt (poly_float value)
 Truncates a poly_float to an integer (effectively floor for positive values).
 
force_inline poly_float vital::utils::trunc (poly_float value)
 Returns the truncated value of each lane in value.
 
force_inline poly_float vital::utils::floor (poly_float value)
 Floors each lane in value.
 
force_inline poly_int vital::utils::floorToInt (poly_float value)
 Floors each lane and returns the result as an integer.
 
force_inline poly_int vital::utils::roundToInt (poly_float value)
 Rounds each lane to the nearest integer.
 
force_inline poly_float vital::utils::ceil (poly_float value)
 Ceils each lane in value.
 
force_inline poly_float vital::utils::round (poly_float value)
 Rounds each lane to the nearest integer as a poly_float.
 
force_inline poly_float vital::utils::mod (poly_float value)
 Returns the fractional part of each lane by subtracting the floored value.
 
force_inline poly_float vital::utils::reinterpretToFloat (poly_int value)
 Reinterprets a poly_int as a poly_float (bitcast).
 
force_inline poly_int vital::utils::reinterpretToInt (poly_float value)
 Reinterprets a poly_float as a poly_int (bitcast).
 
template<size_t shift>
force_inline poly_int vital::utils::shiftRight (poly_int integer)
 
template<size_t shift>
force_inline poly_int vital::utils::shiftLeft (poly_int integer)
 
force_inline poly_float vital::utils::pow2ToFloat (poly_int value)
 
force_inline poly_float vital::utils::triangleWave (poly_float t)
 Generates a simple triangle wave [0..1] from a fraction t in [0..1].
 
force_inline poly_float vital::utils::getCycleOffsetFromSeconds (double seconds, poly_float frequency)
 Computes a cycle offset given a time in seconds and a frequency.
 
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.
 
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).
 
force_inline void vital::utils::fillSnapBuffer (int transpose_quantize, float *snap_buffer)
 Fills a buffer with snap offsets for a given quantize mask.
 
force_inline bool vital::utils::isTransposeQuantizeGlobal (int quantize)
 Checks if the transpose quantize mask applies globally (over multiple octaves).
 
force_inline bool vital::utils::isTransposeSnapping (int quantize)
 Checks if any snapping bits are set in the transpose quantize mask.
 
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.
 
force_inline std::pair< poly_float, poly_floatvital::utils::decodePhaseAndVoice (poly_float encoded)
 Decodes a phase and voice from an encoded float, returning (phase, voice).
 

Variables

constexpr mono_float vital::utils::kPhaseEncodingMultiplier = 0.9f
 Used as a multiplier when encoding phase and voice data in a single float.
 
constexpr unsigned int vital::utils::kNotePressedMask = 0xf
 A bitmask used in voice encoding for note-on states.