Vital
Loading...
Searching...
No Matches
utils.h File Reference

Provides various utility functions, classes, and constants for audio, math, and general-purpose operations within Vital. More...

#include "common.h"
#include <cmath>
#include <complex>
#include <cstdlib>
#include <random>

Go to the source code of this file.

Classes

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

Namespaces

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

Functions

constexpr int vital::utils::factorial (int value)
 Computes the factorial of a given integer at compile time.
 
force_inline mono_float vital::utils::intToFloatBits (int i)
 Reinterprets an int as a float (bitwise).
 
force_inline int vital::utils::floatToIntBits (mono_float f)
 Reinterprets a float as an int (bitwise).
 
force_inline mono_float vital::utils::min (mono_float one, mono_float two)
 Returns the minimum of two floats.
 
force_inline mono_float vital::utils::max (mono_float one, mono_float two)
 Returns the maximum of two floats.
 
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].
 
template<class T >
force_inlinevital::utils::pass (T input)
 A pass-through function that simply returns the input. Often used in templated code.
 
force_inline int vital::utils::imax (int one, int two)
 Returns the maximum of two integers.
 
force_inline int vital::utils::imin (int one, int two)
 Returns the minimum of two integers.
 
force_inline double vital::utils::interpolate (double from, double to, double t)
 Linearly interpolates between two double values.
 
force_inline mono_float vital::utils::interpolate (mono_float from, mono_float to, mono_float t)
 Linearly interpolates between two floats.
 
force_inline mono_float vital::utils::mod (double value, double *divisor)
 Returns the fractional part of value, storing the integer part in divisor (double).
 
force_inline mono_float vital::utils::mod (float value, float *divisor)
 Returns the fractional part of value, storing the integer part in divisor (float).
 
force_inline int vital::utils::iclamp (int value, int min_val, int max_val)
 Clamps an integer between [min_val, max_val].
 
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).
 
force_inline bool vital::utils::closeToZero (mono_float value)
 Determines if a float is close to zero (within ±kEpsilon).
 
force_inline mono_float vital::utils::magnitudeToDb (mono_float magnitude)
 Converts a magnitude to decibels using 20*log10(magnitude).
 
force_inline mono_float vital::utils::dbToMagnitude (mono_float decibels)
 Converts decibels to linear magnitude using 10^(dB / 20).
 
force_inline mono_float vital::utils::centsToRatio (mono_float cents)
 Converts cents to a ratio. A value of 1200 cents is 2.0.
 
force_inline mono_float vital::utils::noteOffsetToRatio (mono_float cents)
 Converts a note offset in semitones (or partial) to a frequency ratio.
 
force_inline mono_float vital::utils::ratioToMidiTranspose (mono_float ratio)
 Converts a frequency ratio to a MIDI transpose value (in semitones).
 
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.
 
force_inline mono_float vital::utils::midiNoteToFrequency (mono_float note)
 Converts a MIDI note number to frequency in Hz.
 
force_inline mono_float vital::utils::frequencyToMidiNote (mono_float frequency)
 Converts a frequency in Hz to a MIDI note number.
 
force_inline mono_float vital::utils::frequencyToMidiCents (mono_float frequency)
 Converts a frequency in Hz to MIDI cents relative to MIDI note 0.
 
force_inline int vital::utils::nextPowerOfTwo (mono_float value)
 Finds the next power of two greater than or equal to a float value.
 
force_inline bool vital::utils::isSilent (const mono_float *buffer, int length)
 Checks if all samples in a buffer are close to zero.
 
force_inline mono_float vital::utils::rms (const mono_float *buffer, int num)
 Computes the Root Mean Square (RMS) of a buffer of floats.
 
force_inline mono_float vital::utils::inversePowerScale (mono_float t)
 A curve function used for specific shaping or scaling of a parameter.
 
force_inline mono_float vital::utils::inverseFltScale (mono_float t)
 Another curve function, typically used for certain shape transformations.
 
mono_float vital::utils::encodeOrderToFloat (int *order, int size)
 Encodes a permutation (stored in order) into a single float.
 
void vital::utils::decodeFloatToOrder (int *order, mono_float float_code, int size)
 Decodes a float-encoded permutation back into order.
 
void vital::utils::floatToPcmData (int16_t *pcm_data, const float *float_data, int size)
 Converts floating-point audio data to 16-bit PCM data.
 
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.
 
void vital::utils::pcmToFloatData (float *float_data, const int16_t *pcm_data, int size)
 Converts 16-bit PCM data to floating-point audio data.
 
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.
 

Variables

constexpr mono_float vital::utils::kDbGainConversionMult = 20.0f
 Multiplicative factor for converting dB <-> magnitude using dB = 20*log10(magnitude).
 
constexpr int vital::utils::kMaxOrderLength = 10
 Maximum length for orders that can be encoded as a float via encodeOrderToFloat().
 
constexpr mono_float vital::utils::kLogOf2 = 0.69314718056f
 Natural log of 2.
 
constexpr mono_float vital::utils::kInvLogOf2 = 1.44269504089f
 Reciprocal of the natural log of 2 (1 / ln(2)).
 

Detailed Description

Provides various utility functions, classes, and constants for audio, math, and general-purpose operations within Vital.