40 for (
int i = 2; i <= value; ++i)
80 distribution_(other.distribution_.
min(), other.distribution_.
max()) { }
86 return distribution_(engine_);
95 for (
int i = 0; i < poly_float::kSize; ++i)
107 for (
int i = 0; i < poly_float::kSize; i += 2) {
109 result.
set(i, value);
110 result.
set(i + 1, value);
122 for (
int i = 0; i < poly_float::kSize; ++i) {
134 engine_.seed(new_seed);
138 std::mt19937 engine_;
139 std::uniform_real_distribution<mono_float> distribution_;
170 return fmin(one, two);
177 return fmax(one, two);
188 return fmin(max_val, fmax(value, min_val));
206 return (one > two) ? one : two;
213 return (one > two) ? two : one;
223 return t * (to - from) + from;
230 return from + t * (to - from);
237 return modf(value, divisor);
244 return modff(value, divisor);
251 return value > max_val ? max_val : (value < min_val ? min_val : value);
260 #if defined(__GNUC__) || defined(__clang__)
261 constexpr int kMaxBitIndex =
sizeof(int) * 8 - 1;
262 return kMaxBitIndex - __builtin_clz(std::max(value, 1));
263 #elif defined(_MSC_VER)
264 unsigned long result = 0;
265 _BitScanReverse(&result, value);
281 return value <= kEpsilon && value >= -
kEpsilon;
371 return roundf(powf(2.0f, ceilf(logf(value) *
kInvLogOf2)));
381 for (
int i = 0; i < length; ++i) {
396 for (
int i = 0; i < num; ++i)
397 square_total += buffer[i] * buffer[i];
399 return sqrtf(square_total / num);
408 return 2.0f * logf((-t + 1.0f) / t);
417 return (t - 1.0f) / t;
442 void floatToPcmData(int16_t* pcm_data,
const float* float_data,
int size);
450 void complexToPcmData(int16_t* pcm_data,
const std::complex<float>* complex_data,
int size);
458 void pcmToFloatData(
float* float_data,
const int16_t* pcm_data,
int size);
466 void pcmToComplexData(std::complex<float>* complex_data,
const int16_t* pcm_data,
int size);
A basic random number generator for producing uniform distributions of floats.
Definition utils.h:61
force_inline mono_float next()
Returns the next random float in [min, max].
Definition utils.h:85
static int next_seed_
Static seed counter used to automatically assign seeds if none specified.
Definition utils.h:64
force_inline poly_float polyVoiceNext()
Produces a poly_float with random values assigned in pairs (every 2 lanes share the same random value...
Definition utils.h:105
RandomGenerator(mono_float min, mono_float max)
Constructs a RandomGenerator with specified min and max values.
Definition utils.h:71
force_inline void seed(int new_seed)
Reseeds the internal random engine with new_seed.
Definition utils.h:133
force_inline poly_float polyNext()
Produces a poly_float with random values in each lane.
Definition utils.h:93
force_inline poly_float polyNext(poly_mask mask)
Produces a poly_float of random values, only generated for lanes set in mask.
Definition utils.h:120
RandomGenerator(const RandomGenerator &other)
Copy constructor, but it re-seeds the engine for uniqueness.
Definition utils.h:78
#define force_inline
Definition common.h:23
Contains a collection of utility functions and classes used throughout Vital.
force_inline int iclamp(int value, int min_val, int max_val)
Clamps an integer between [min_val, max_val].
Definition utils.h:250
force_inline poly_float mod(poly_float value)
Returns the fractional part of each lane by subtracting the floored value.
Definition poly_utils.h:814
constexpr mono_float kDbGainConversionMult
Multiplicative factor for converting dB <-> magnitude using dB = 20*log10(magnitude).
Definition utils.h:25
force_inline poly_float clamp(poly_float value, mono_float min, mono_float max)
Clamps each lane of a vector to [min, max].
Definition poly_utils.h:306
force_inline bool isSilent(const poly_float *buffer, int size)
Determines if the entire buffer is silent (very close to zero).
Definition poly_utils.h:669
constexpr int kMaxOrderLength
Maximum length for orders that can be encoded as a float via encodeOrderToFloat().
Definition utils.h:27
force_inline T pass(T input)
A pass-through function that simply returns the input. Often used in templated code.
Definition utils.h:198
force_inline mono_float inverseFltScale(mono_float t)
Another curve function, typically used for certain shape transformations.
Definition utils.h:416
force_inline int imax(int one, int two)
Returns the maximum of two integers.
Definition utils.h:205
force_inline mono_float inversePowerScale(mono_float t)
A curve function used for specific shaping or scaling of a parameter.
Definition utils.h:407
force_inline int ilog2(int value)
Computes the floor of the base-2 logarithm of an integer (effectively the index of the highest set bi...
Definition utils.h:259
force_inline poly_float min(poly_float left, poly_float right)
Returns the minimum of two poly_floats lane-by-lane.
Definition poly_utils.h:334
force_inline int nextPowerOfTwo(mono_float value)
Finds the next power of two greater than or equal to a float value.
Definition utils.h:370
constexpr mono_float kLogOf2
Natural log of 2.
Definition utils.h:29
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.
Definition utils.cpp:99
void floatToPcmData(int16_t *pcm_data, const float *float_data, int size)
Converts floating-point audio data to 16-bit PCM data.
Definition utils.cpp:77
force_inline poly_float magnitudeToDb(poly_float value)
Converts a magnitude value to decibels (vectorized).
Definition poly_utils.h:144
force_inline int floatToIntBits(mono_float f)
Reinterprets a float as an int (bitwise).
Definition utils.h:160
void decodeFloatToOrder(int *order, mono_float float_code, int size)
Decodes a float-encoded permutation back into order.
Definition utils.cpp:55
force_inline poly_float frequencyToMidiNote(poly_float value)
Converts a frequency to a MIDI note (vectorized).
Definition poly_utils.h:130
constexpr mono_float kInvLogOf2
Reciprocal of the natural log of 2 (1 / ln(2)).
Definition utils.h:31
constexpr int factorial(int value)
Computes the factorial of a given integer at compile time.
Definition utils.h:38
force_inline poly_float dbToMagnitude(poly_float value)
Converts a dB value to linear magnitude (vectorized).
Definition poly_utils.h:149
mono_float encodeOrderToFloat(int *order, int size)
Encodes a permutation (stored in order) into a single float.
Definition utils.cpp:32
force_inline mono_float rms(const mono_float *buffer, int num)
Computes the Root Mean Square (RMS) of a buffer of floats.
Definition utils.h:394
force_inline poly_float ratioToMidiTranspose(poly_float value)
Converts a ratio to MIDI transpose (vectorized).
Definition poly_utils.h:109
force_inline poly_float max(poly_float left, poly_float right)
Returns the maximum of two poly_floats lane-by-lane.
Definition poly_utils.h:327
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.
Definition utils.cpp:82
force_inline poly_float midiNoteToFrequency(poly_float value)
Converts a MIDI note to a frequency (vectorized).
Definition poly_utils.h:123
void pcmToFloatData(float *float_data, const int16_t *pcm_data, int size)
Converts 16-bit PCM data to floating-point audio data.
Definition utils.cpp:94
force_inline poly_float noteOffsetToRatio(poly_float value)
Converts note offsets to frequency ratios. Similar to centsToRatio, but may differ in how offset is d...
Definition poly_utils.h:102
force_inline int imin(int one, int two)
Returns the minimum of two integers.
Definition utils.h:212
force_inline bool closeToZero(mono_float value)
Determines if a float is close to zero (within ±kEpsilon).
Definition utils.h:280
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].
Definition poly_utils.h:182
force_inline poly_float frequencyToMidiCents(poly_float value)
Converts a frequency to MIDI cents (vectorized).
Definition poly_utils.h:137
force_inline poly_float midiCentsToFrequency(poly_float value)
Converts MIDI cents to frequency (vectorized).
Definition poly_utils.h:116
force_inline mono_float intToFloatBits(int i)
Reinterprets an int as a float (bitwise).
Definition utils.h:149
force_inline poly_float centsToRatio(poly_float value)
Converts semitone cents to a linear frequency ratio (vectorized).
Definition poly_utils.h:95
Contains classes and functions used within the Vital synthesizer framework.
constexpr mono_float kMidi0Frequency
Frequency of MIDI note 0 (C-1).
Definition common.h:47
constexpr int kNotesPerOctave
Number of semitones per octave.
Definition common.h:51
constexpr int kCentsPerOctave
Cents per octave (1200).
Definition common.h:53
constexpr int kCentsPerNote
Number of cents per semitone.
Definition common.h:52
constexpr mono_float kEpsilon
A small epsilon for floating comparisons.
Definition common.h:38
float mono_float
Definition common.h:33
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
force_inline void vector_call set(size_t index, float new_value) noexcept
Sets a specific element in the SIMD register.
Definition poly_values.h:1182
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56
A small union to reinterpret an int as a float or vice versa.
Definition utils.h:49
int i
Integer representation.
Definition utils.h:50
mono_float f
Float representation.
Definition utils.h:51