13#ifndef __UTILS_DSP_H__
14#define __UTILS_DSP_H__
16#include "zrythm-config.h"
26# include <lsp-plug.in/dsp/dsp.h>
32NONNULL HOT
static inline void
33dsp_fill (
float * buf,
float val,
size_t size)
36 if (ZRYTHM_USE_OPTIMIZED_DSP)
38 lsp::dsp::fill (buf, val, size);
43 for (
size_t i = 0; i < size; i++)
55NONNULL HOT
static inline void
56dsp_limit1 (
float * buf,
float minf,
float maxf,
size_t size)
59 if (ZRYTHM_USE_OPTIMIZED_DSP)
61 lsp::dsp::limit1 (buf, minf, maxf, size);
66 for (
size_t i = 0; i < size; i++)
68 buf[i] = CLAMP (buf[i], minf, maxf);
78NONNULL HOT
static inline void
79dsp_copy (
float * dest,
const float * src,
size_t size)
82 if (ZRYTHM_USE_OPTIMIZED_DSP)
84 lsp::dsp::copy (dest, src, size);
89 for (
size_t i = 0; i < size; i++)
101NONNULL HOT
static inline void
102dsp_mul_k2 (
float * dest,
float k,
size_t size)
105 if (ZRYTHM_USE_OPTIMIZED_DSP)
107 lsp::dsp::mul_k2 (dest, k, size);
112 for (
size_t i = 0; i < size; i++)
124NONNULL WARN_UNUSED_RESULT
static inline float
125dsp_abs_max (
float * buf,
size_t size)
128 if (ZRYTHM_USE_OPTIMIZED_DSP)
130 return lsp::dsp::abs_max (buf, size);
136 for (
size_t i = 0; i < size; i++)
138 if (fabsf (buf[i]) > ret)
140 ret = fabsf (buf[i]);
154HOT NONNULL
static inline bool
155dsp_abs_max_with_existing_peak (
float * buf,
float * cur_peak,
size_t size)
157 float new_peak = *cur_peak;
160 if (ZRYTHM_USE_OPTIMIZED_DSP)
162 new_peak = lsp::dsp::abs_max (buf, size);
167 for (
size_t i = 0; i < size; i++)
169 float val = fabsf (buf[i]);
180 *cur_peak = new_peak;
200NONNULL HOT
static inline void
201dsp_add2 (
float * dest,
const float * src,
size_t count)
204 if (ZRYTHM_USE_OPTIMIZED_DSP)
206 lsp::dsp::add2 (dest, src, count);
211 for (
size_t i = 0; i < count; i++)
213 dest[i] = dest[i] + src[i];
223NONNULL HOT
static inline void
224dsp_mix2 (
float * dest,
const float * src,
float k1,
float k2,
size_t size)
227 if (ZRYTHM_USE_OPTIMIZED_DSP)
229 lsp::dsp::mix2 (dest, src, k1, k2, size);
234 for (
size_t i = 0; i < size; i++)
236 dest[i] = dest[i] * k1 + src[i] * k2;
246NONNULL HOT
static inline void
247dsp_reverse1 (
float * dest,
size_t size)
250 if (ZRYTHM_USE_OPTIMIZED_DSP)
252 lsp::dsp::reverse1 (dest, size);
257 for (
size_t i = 0; i < size; i++)
259 dest[i] = dest[(size - i) - 1];
269NONNULL HOT
static inline void
270dsp_reverse2 (
float * dest,
float * src,
size_t size)
273 if (ZRYTHM_USE_OPTIMIZED_DSP)
275 lsp::dsp::reverse2 (dest, src, size);
280 for (
size_t i = 0; i < size; i++)
282 dest[i] = src[(size - i) - 1];
293NONNULL HOT
static inline void
294dsp_normalize (
float * dest,
const float * src,
size_t size)
297 if (ZRYTHM_USE_OPTIMIZED_DSP)
299 lsp::dsp::normalize (dest, src, size);
304 dsp_copy (dest, src, size);
305 float abs_peak = dsp_abs_max (dest, size);
306 dsp_mul_k2 (dest, 1.f / abs_peak, size);
342 int32_t start_offset,
343 int32_t total_frames_to_fade,
345 float fade_from_multiplier);
361 int32_t start_offset,
362 int32_t total_frames_to_fade,
364 float fade_to_multiplier);
NONNULL float dsp_min(float *buf, size_t size)
Gets the minimum of the buffer.
NONNULL void dsp_make_mono(float *l, float *r, size_t size, bool equal_power)
Makes the two signals mono.
NONNULL void dsp_mix_add2(float *dest, const float *src1, const float *src2, float k1, float k2, size_t size)
Calculate dst[i] = dst[i] + src1[i] * k1 + src2[i] * k2.
NONNULL void dsp_linear_fade_in_from(float *dest, int32_t start_offset, int32_t total_frames_to_fade, size_t size, float fade_from_multiplier)
Calculate linear fade by multiplying from 0 to 1 for.
NONNULL float dsp_max(float *buf, size_t size)
Gets the maximum of the buffer.
NONNULL void dsp_linear_fade_out_to(float *dest, int32_t start_offset, int32_t total_frames_to_fade, size_t size, float fade_to_multiplier)
Calculate linear fade by multiplying from 0 to 1 for.
#define math_floats_equal(a, b)
Checks if 2 doubles are equal.