@@ -42,9 +42,9 @@ struct RealTimeConvolver { | |||||
this->blockSize = blockSize; | this->blockSize = blockSize; | ||||
pffft = pffft_new_setup(blockSize*2, PFFFT_REAL); | pffft = pffft_new_setup(blockSize*2, PFFFT_REAL); | ||||
outputTail = new float[blockSize]; | outputTail = new float[blockSize]; | ||||
memset(outputTail, 0, blockSize * sizeof(float)); | |||||
std::memset(outputTail, 0, blockSize * sizeof(float)); | |||||
tmpBlock = new float[blockSize*2]; | tmpBlock = new float[blockSize*2]; | ||||
memset(tmpBlock, 0, blockSize*2 * sizeof(float)); | |||||
std::memset(tmpBlock, 0, blockSize*2 * sizeof(float)); | |||||
} | } | ||||
~RealTimeConvolver() { | ~RealTimeConvolver() { | ||||
@@ -74,13 +74,13 @@ struct RealTimeConvolver { | |||||
// Allocate blocks | // Allocate blocks | ||||
kernelFfts = (float*) pffft_aligned_malloc(sizeof(float) * blockSize*2 * kernelBlocks); | kernelFfts = (float*) pffft_aligned_malloc(sizeof(float) * blockSize*2 * kernelBlocks); | ||||
inputFfts = (float*) pffft_aligned_malloc(sizeof(float) * blockSize*2 * kernelBlocks); | inputFfts = (float*) pffft_aligned_malloc(sizeof(float) * blockSize*2 * kernelBlocks); | ||||
memset(inputFfts, 0, sizeof(float) * blockSize*2 * kernelBlocks); | |||||
std::memset(inputFfts, 0, sizeof(float) * blockSize*2 * kernelBlocks); | |||||
for (size_t i = 0; i < kernelBlocks; i++) { | for (size_t i = 0; i < kernelBlocks; i++) { | ||||
// Pad each block with zeros | // Pad each block with zeros | ||||
memset(tmpBlock, 0, sizeof(float) * blockSize*2); | |||||
std::memset(tmpBlock, 0, sizeof(float) * blockSize*2); | |||||
size_t len = std::min((int) blockSize, (int) (length - i*blockSize)); | size_t len = std::min((int) blockSize, (int) (length - i*blockSize)); | ||||
memcpy(tmpBlock, &kernel[i*blockSize], sizeof(float)*len); | |||||
std::memcpy(tmpBlock, &kernel[i*blockSize], sizeof(float)*len); | |||||
// Compute fft | // Compute fft | ||||
pffft_transform(pffft, tmpBlock, &kernelFfts[blockSize*2 * i], NULL, PFFFT_FORWARD); | pffft_transform(pffft, tmpBlock, &kernelFfts[blockSize*2 * i], NULL, PFFFT_FORWARD); | ||||
} | } | ||||
@@ -92,19 +92,19 @@ struct RealTimeConvolver { | |||||
*/ | */ | ||||
void processBlock(const float *input, float *output) { | void processBlock(const float *input, float *output) { | ||||
if (kernelBlocks == 0) { | if (kernelBlocks == 0) { | ||||
memset(output, 0, sizeof(float) * blockSize); | |||||
std::memset(output, 0, sizeof(float) * blockSize); | |||||
return; | return; | ||||
} | } | ||||
// Step input position | // Step input position | ||||
inputPos = (inputPos + 1) % kernelBlocks; | inputPos = (inputPos + 1) % kernelBlocks; | ||||
// Pad block with zeros | // Pad block with zeros | ||||
memset(tmpBlock, 0, sizeof(float) * blockSize*2); | |||||
memcpy(tmpBlock, input, sizeof(float) * blockSize); | |||||
std::memset(tmpBlock, 0, sizeof(float) * blockSize*2); | |||||
std::memcpy(tmpBlock, input, sizeof(float) * blockSize); | |||||
// Compute input fft | // Compute input fft | ||||
pffft_transform(pffft, tmpBlock, &inputFfts[blockSize*2 * inputPos], NULL, PFFFT_FORWARD); | pffft_transform(pffft, tmpBlock, &inputFfts[blockSize*2 * inputPos], NULL, PFFFT_FORWARD); | ||||
// Create output fft | // Create output fft | ||||
memset(tmpBlock, 0, sizeof(float) * blockSize*2); | |||||
std::memset(tmpBlock, 0, sizeof(float) * blockSize*2); | |||||
// convolve input fft by kernel fft | // convolve input fft by kernel fft | ||||
// Note: This is the CPU bottleneck loop | // Note: This is the CPU bottleneck loop | ||||
for (size_t i = 0; i < kernelBlocks; i++) { | for (size_t i = 0; i < kernelBlocks; i++) { | ||||
@@ -95,7 +95,7 @@ struct SampleRateConverter { | |||||
else { | else { | ||||
// Simply copy the buffer without conversion | // Simply copy the buffer without conversion | ||||
int frames = std::min(*inFrames, *outFrames); | int frames = std::min(*inFrames, *outFrames); | ||||
memcpy(out, in, frames * sizeof(Frame<CHANNELS>)); | |||||
std::memcpy(out, in, frames * sizeof(Frame<CHANNELS>)); | |||||
*inFrames = frames; | *inFrames = frames; | ||||
*outFrames = frames; | *outFrames = frames; | ||||
} | } | ||||
@@ -117,12 +117,12 @@ struct Decimator { | |||||
} | } | ||||
void reset() { | void reset() { | ||||
inIndex = 0; | inIndex = 0; | ||||
memset(inBuffer, 0, sizeof(inBuffer)); | |||||
std::memset(inBuffer, 0, sizeof(inBuffer)); | |||||
} | } | ||||
/** `in` must be length OVERSAMPLE */ | /** `in` must be length OVERSAMPLE */ | ||||
float process(float *in) { | float process(float *in) { | ||||
// Copy input to buffer | // Copy input to buffer | ||||
memcpy(&inBuffer[inIndex], in, OVERSAMPLE*sizeof(float)); | |||||
std::memcpy(&inBuffer[inIndex], in, OVERSAMPLE*sizeof(float)); | |||||
// Advance index | // Advance index | ||||
inIndex += OVERSAMPLE; | inIndex += OVERSAMPLE; | ||||
inIndex %= OVERSAMPLE*QUALITY; | inIndex %= OVERSAMPLE*QUALITY; | ||||
@@ -152,7 +152,7 @@ struct Upsampler { | |||||
} | } | ||||
void reset() { | void reset() { | ||||
inIndex = 0; | inIndex = 0; | ||||
memset(inBuffer, 0, sizeof(inBuffer)); | |||||
std::memset(inBuffer, 0, sizeof(inBuffer)); | |||||
} | } | ||||
/** `out` must be length OVERSAMPLE */ | /** `out` must be length OVERSAMPLE */ | ||||
void process(float in, float *out) { | void process(float in, float *out) { | ||||
@@ -28,9 +28,9 @@ struct RingBuffer { | |||||
size_t i = mask(end); | size_t i = mask(end); | ||||
size_t e1 = i + n; | size_t e1 = i + n; | ||||
size_t e2 = (e1 < S) ? e1 : S; | size_t e2 = (e1 < S) ? e1 : S; | ||||
memcpy(&data[i], t, sizeof(T) * (e2 - i)); | |||||
std::memcpy(&data[i], t, sizeof(T) * (e2 - i)); | |||||
if (e1 > S) { | if (e1 > S) { | ||||
memcpy(data, &t[S - i], sizeof(T) * (e1 - S)); | |||||
std::memcpy(data, &t[S - i], sizeof(T) * (e1 - S)); | |||||
} | } | ||||
end += n; | end += n; | ||||
} | } | ||||
@@ -41,9 +41,9 @@ struct RingBuffer { | |||||
size_t i = mask(start); | size_t i = mask(start); | ||||
size_t s1 = i + n; | size_t s1 = i + n; | ||||
size_t s2 = (s1 < S) ? s1 : S; | size_t s2 = (s1 < S) ? s1 : S; | ||||
memcpy(t, &data[i], sizeof(T) * (s2 - i)); | |||||
std::memcpy(t, &data[i], sizeof(T) * (s2 - i)); | |||||
if (s1 > S) { | if (s1 > S) { | ||||
memcpy(&t[S - i], data, sizeof(T) * (s1 - S)); | |||||
std::memcpy(&t[S - i], data, sizeof(T) * (s1 - S)); | |||||
} | } | ||||
start += n; | start += n; | ||||
} | } | ||||
@@ -112,11 +112,11 @@ struct DoubleRingBuffer { | |||||
size_t e1 = e + n; | size_t e1 = e + n; | ||||
size_t e2 = (e1 < S) ? e1 : S; | size_t e2 = (e1 < S) ? e1 : S; | ||||
// Copy data forward | // Copy data forward | ||||
memcpy(&data[S + e], &data[e], sizeof(T) * (e2 - e)); | |||||
std::memcpy(&data[S + e], &data[e], sizeof(T) * (e2 - e)); | |||||
if (e1 > S) { | if (e1 > S) { | ||||
// Copy data backward from the doubled block to the main block | // Copy data backward from the doubled block to the main block | ||||
memcpy(data, &data[S], sizeof(T) * (e1 - S)); | |||||
std::memcpy(data, &data[S], sizeof(T) * (e1 - S)); | |||||
} | } | ||||
end += n; | end += n; | ||||
} | } | ||||
@@ -147,7 +147,7 @@ struct AppleRingBuffer { | |||||
// move end block to beginning | // move end block to beginning | ||||
// may overlap, but memmove handles that correctly | // may overlap, but memmove handles that correctly | ||||
size_t s = size(); | size_t s = size(); | ||||
memmove(data, &data[start], sizeof(T) * s); | |||||
std::memmove(data, &data[start], sizeof(T) * s); | |||||
start = 0; | start = 0; | ||||
end = s; | end = s; | ||||
} | } | ||||
@@ -13,7 +13,7 @@ struct VuMeter { | |||||
float dBScaled; | float dBScaled; | ||||
/** Value should be scaled so that 1.0 is clipping */ | /** Value should be scaled so that 1.0 is clipping */ | ||||
void setValue(float v) { | void setValue(float v) { | ||||
dBScaled = std::log10(std::abs(v)) * 20.0 / dBInterval; | |||||
dBScaled = std::log10(std::fabs(v)) * 20.0 / dBInterval; | |||||
} | } | ||||
/** Returns the brightness of the light indexed by i. | /** Returns the brightness of the light indexed by i. | ||||
Light 0 is a clip light (red) which is either on or off. | Light 0 is a clip light (red) which is either on or off. | ||||
@@ -71,7 +71,7 @@ struct VuMeter2 { | |||||
v += (value - v) * lambda * deltaTime; | v += (value - v) * lambda * deltaTime; | ||||
} | } | ||||
else { | else { | ||||
value = std::abs(value); | |||||
value = std::fabs(value); | |||||
if (value >= v) { | if (value >= v) { | ||||
v = value; | v = value; | ||||
} | } | ||||
@@ -81,9 +81,7 @@ struct Param { | |||||
return value; | return value; | ||||
} | } | ||||
/* Clamps and set the value. | |||||
Don't call this directly from Modules. Use `APP->engine->setParam()`. | |||||
*/ | |||||
/* Clamps and sets the value. */ | |||||
void setValue(float value) { | void setValue(float value) { | ||||
this->value = math::clamp(value, minValue, maxValue); | this->value = math::clamp(value, minValue, maxValue); | ||||
} | } | ||||
@@ -95,14 +95,14 @@ inline bool isPow2(int n) { | |||||
Assumes a <= b | Assumes a <= b | ||||
*/ | */ | ||||
inline float clamp(float x, float a, float b) { | inline float clamp(float x, float a, float b) { | ||||
return std::min(std::max(x, a), b); | |||||
return std::fmin(std::fmax(x, a), b); | |||||
} | } | ||||
/** Limits `x` between `a` and `b` | /** Limits `x` between `a` and `b` | ||||
If a > b, switches the two values | If a > b, switches the two values | ||||
*/ | */ | ||||
inline float clampSafe(float x, float a, float b) { | inline float clampSafe(float x, float a, float b) { | ||||
return clamp(x, std::min(a, b), std::max(a, b)); | |||||
return clamp(x, std::fmin(a, b), std::fmax(a, b)); | |||||
} | } | ||||
/** Returns 1 for positive numbers, -1 for negative numbers, and 0 for zero | /** Returns 1 for positive numbers, -1 for negative numbers, and 0 for zero | ||||
@@ -126,7 +126,7 @@ inline float eucMod(float a, float base) { | |||||
} | } | ||||
inline bool isNear(float a, float b, float epsilon = 1e-6f) { | inline bool isNear(float a, float b, float epsilon = 1e-6f) { | ||||
return std::abs(a - b) <= epsilon; | |||||
return std::fabs(a - b) <= epsilon; | |||||
} | } | ||||
/** If the magnitude of x if less than epsilon, return 0 */ | /** If the magnitude of x if less than epsilon, return 0 */ | ||||
@@ -201,7 +201,7 @@ struct Vec { | |||||
return x * b.x + y * b.y; | return x * b.x + y * b.y; | ||||
} | } | ||||
float norm() const { | float norm() const { | ||||
return std::hypotf(x, y); | |||||
return std::hypot(x, y); | |||||
} | } | ||||
float square() const { | float square() const { | ||||
return x * x + y * y; | return x * x + y * y; | ||||
@@ -219,10 +219,10 @@ struct Vec { | |||||
return Vec(y, x); | return Vec(y, x); | ||||
} | } | ||||
Vec min(Vec b) const { | Vec min(Vec b) const { | ||||
return Vec(std::min(x, b.x), std::min(y, b.y)); | |||||
return Vec(std::fmin(x, b.x), std::fmin(y, b.y)); | |||||
} | } | ||||
Vec max(Vec b) const { | Vec max(Vec b) const { | ||||
return Vec(std::max(x, b.x), std::max(y, b.y)); | |||||
return Vec(std::fmax(x, b.x), std::fmax(y, b.y)); | |||||
} | } | ||||
Vec round() const { | Vec round() const { | ||||
return Vec(std::round(x), std::round(y)); | return Vec(std::round(x), std::round(y)); | ||||
@@ -320,19 +320,19 @@ struct Rect { | |||||
/** Expands this Rect to contain `b` */ | /** Expands this Rect to contain `b` */ | ||||
Rect expand(Rect b) const { | Rect expand(Rect b) const { | ||||
Rect r; | Rect r; | ||||
r.pos.x = std::min(pos.x, b.pos.x); | |||||
r.pos.y = std::min(pos.y, b.pos.y); | |||||
r.size.x = std::max(pos.x + size.x, b.pos.x + b.size.x) - r.pos.x; | |||||
r.size.y = std::max(pos.y + size.y, b.pos.y + b.size.y) - r.pos.y; | |||||
r.pos.x = std::fmin(pos.x, b.pos.x); | |||||
r.pos.y = std::fmin(pos.y, b.pos.y); | |||||
r.size.x = std::fmax(pos.x + size.x, b.pos.x + b.size.x) - r.pos.x; | |||||
r.size.y = std::fmax(pos.y + size.y, b.pos.y + b.size.y) - r.pos.y; | |||||
return r; | return r; | ||||
} | } | ||||
/** Returns the intersection of `this` and `b` */ | /** Returns the intersection of `this` and `b` */ | ||||
Rect intersect(Rect b) const { | Rect intersect(Rect b) const { | ||||
Rect r; | Rect r; | ||||
r.pos.x = std::max(pos.x, b.pos.x); | |||||
r.pos.y = std::max(pos.y, b.pos.y); | |||||
r.size.x = std::min(pos.x + size.x, b.pos.x + b.size.x) - r.pos.x; | |||||
r.size.y = std::min(pos.y + size.y, b.pos.y + b.size.y) - r.pos.y; | |||||
r.pos.x = std::fmax(pos.x, b.pos.x); | |||||
r.pos.y = std::fmax(pos.y, b.pos.y); | |||||
r.size.x = std::fmin(pos.x + size.x, b.pos.x + b.size.x) - r.pos.x; | |||||
r.size.y = std::fmin(pos.y + size.y, b.pos.y + b.size.y) - r.pos.y; | |||||
return r; | return r; | ||||
} | } | ||||
/** Returns a Rect with its position set to zero */ | /** Returns a Rect with its position set to zero */ | ||||
@@ -368,8 +368,14 @@ inline Vec Vec::clampSafe(Rect bound) const { | |||||
} | } | ||||
/** Useful for debugging Vecs and Rects, e.g. | |||||
/** Expands a Vec and Rect into a comma-separated list. | |||||
Useful for print debugging. | |||||
printf("%f %f %f %f", RECT_ARGS(r)); | printf("%f %f %f %f", RECT_ARGS(r)); | ||||
Or passing the values to a C function. | |||||
nvgRect(vg, RECT_ARGS(r)); | |||||
*/ | */ | ||||
#define VEC_ARGS(v) (v).x, (v).y | #define VEC_ARGS(v) (v).x, (v).y | ||||
#define RECT_ARGS(r) (r).pos.x, (r).pos.y, (r).size.x, (r).size.y | #define RECT_ARGS(r) (r).pos.x, (r).pos.y, (r).size.x, (r).size.y | ||||
@@ -31,11 +31,11 @@ DEPRECATED inline float clamp2(float x, float a, float b) {return clampSafe(x, a | |||||
DEPRECATED inline int mini(int a, int b) {return std::min(a, b);} | DEPRECATED inline int mini(int a, int b) {return std::min(a, b);} | ||||
DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);} | DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);} | ||||
DEPRECATED inline int clampi(int x, int min, int max) {return math::clamp(x, min, max);} | DEPRECATED inline int clampi(int x, int min, int max) {return math::clamp(x, min, max);} | ||||
DEPRECATED inline int absi(int a) {return std::abs(a);} | |||||
DEPRECATED inline int absi(int a) {return std::fabs(a);} | |||||
DEPRECATED inline int eucmodi(int a, int base) {return eucMod(a, base);} | DEPRECATED inline int eucmodi(int a, int base) {return eucMod(a, base);} | ||||
DEPRECATED inline int log2i(int n) {return log2(n);} | |||||
DEPRECATED inline int log2i(int n) {return math::log2(n);} | |||||
DEPRECATED inline bool ispow2i(int n) {return isPow2(n);} | DEPRECATED inline bool ispow2i(int n) {return isPow2(n);} | ||||
DEPRECATED inline float absf(float x) {return std::abs(x);} | |||||
DEPRECATED inline float absf(float x) {return std::fabs(x);} | |||||
DEPRECATED inline float sgnf(float x) {return sgn(x);} | DEPRECATED inline float sgnf(float x) {return sgn(x);} | ||||
DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);} | DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);} | ||||
DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return math::isNear(a, b, epsilon);} | DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return math::isNear(a, b, epsilon);} | ||||
@@ -218,7 +218,7 @@ struct BridgeClientConnection { | |||||
} | } | ||||
float output[BRIDGE_OUTPUTS * frames]; | float output[BRIDGE_OUTPUTS * frames]; | ||||
memset(&output, 0, sizeof(output)); | |||||
std::memset(&output, 0, sizeof(output)); | |||||
processStream(input, output, frames); | processStream(input, output, frames); | ||||
if (!send(&output, BRIDGE_OUTPUTS * frames * sizeof(float))) { | if (!send(&output, BRIDGE_OUTPUTS * frames * sizeof(float))) { | ||||
DEBUG("Failed to send"); | DEBUG("Failed to send"); | ||||
@@ -340,7 +340,7 @@ static void serverConnect() { | |||||
// Get address | // Get address | ||||
struct sockaddr_in addr; | struct sockaddr_in addr; | ||||
memset(&addr, 0, sizeof(addr)); | |||||
std::memset(&addr, 0, sizeof(addr)); | |||||
addr.sin_family = AF_INET; | addr.sin_family = AF_INET; | ||||
addr.sin_port = htons(BRIDGE_PORT); | addr.sin_port = htons(BRIDGE_PORT); | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
@@ -24,15 +24,15 @@ void minBlepImpulse(int z, int o, float *output) { | |||||
RealFFT rfft(n); | RealFFT rfft(n); | ||||
rfft.rfft(x, fx); | rfft.rfft(x, fx); | ||||
// fx = log(abs(fx)) | // fx = log(abs(fx)) | ||||
fx[0] = std::log(std::abs(fx[0])); | |||||
fx[0] = std::log(std::fabs(fx[0])); | |||||
for (int i = 1; i < n; i++) { | for (int i = 1; i < n; i++) { | ||||
fx[2*i] = std::log(std::hypot(fx[2*i], fx[2*i+1])); | fx[2*i] = std::log(std::hypot(fx[2*i], fx[2*i+1])); | ||||
fx[2*i+1] = 0.f; | fx[2*i+1] = 0.f; | ||||
} | } | ||||
fx[1] = std::log(std::abs(fx[1])); | |||||
fx[1] = std::log(std::fabs(fx[1])); | |||||
// Clamp values in case we have -inf | // Clamp values in case we have -inf | ||||
for (int i = 0; i < 2*n; i++) { | for (int i = 0; i < 2*n; i++) { | ||||
fx[i] = std::max(-30.f, fx[i]); | |||||
fx[i] = std::fmax(-30.f, fx[i]); | |||||
} | } | ||||
rfft.irfft(fx, x); | rfft.irfft(fx, x); | ||||
rfft.scale(x); | rfft.scale(x); | ||||
@@ -52,14 +52,14 @@ uint64_t u64() { | |||||
float uniform() { | float uniform() { | ||||
// 24 bits of granularity is the best that can be done with floats while ensuring that the return value lies in [0.0, 1.0). | // 24 bits of granularity is the best that can be done with floats while ensuring that the return value lies in [0.0, 1.0). | ||||
return (xoroshiro128plus_next() >> (64 - 24)) / powf(2, 24); | |||||
return (xoroshiro128plus_next() >> (64 - 24)) / std::pow(2, 24); | |||||
} | } | ||||
float normal() { | float normal() { | ||||
// Box-Muller transform | // Box-Muller transform | ||||
float radius = sqrtf(-2.f * logf(1.f - uniform())); | |||||
float radius = std::sqrt(-2.f * std::log(1.f - uniform())); | |||||
float theta = 2.f * M_PI * uniform(); | float theta = 2.f * M_PI * uniform(); | ||||
return radius * sinf(theta); | |||||
return radius * std::sin(theta); | |||||
// // Central Limit Theorem | // // Central Limit Theorem | ||||
// const int n = 8; | // const int n = 8; | ||||
@@ -67,7 +67,7 @@ float normal() { | |||||
// for (int i = 0; i < n; i++) { | // for (int i = 0; i < n; i++) { | ||||
// sum += uniform(); | // sum += uniform(); | ||||
// } | // } | ||||
// return (sum - n / 2.f) / sqrtf(n / 12.f); | |||||
// return (sum - n / 2.f) / std::sqrt(n / 12.f); | |||||
} | } | ||||