util library

Functions

clamp(int x, int y) int
Returns the closest number to x int the range 0, y.
fold(int x, int bits) int
Shifts int x of bit width bits up by half the total range, then wraps any overflowing values around to maintain the bit width. This is used to convert between signed and unsigned PCM.
intToSample(int x, int bits) double
Converts an int x of bit width bits to an audio sample in the range -1, 1.
roundUpToEven(int x) int
Rounds x up to the nearest even number.
sampleToInt(double x, int bits) int
Converts an audio sample x in the range -1, 1 to an unsigned integer of bit width bits.