2023-02-08 18:12:00 +01:00
|
|
|
/* Spa */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2022-03-01 09:53:40 +01:00
|
|
|
|
|
|
|
|
#ifndef DELAY_H
|
|
|
|
|
#define DELAY_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static inline void delay_run(float *buffer, uint32_t *pos,
|
|
|
|
|
uint32_t n_buffer, uint32_t delay,
|
|
|
|
|
float *dst, const float *src, const float vol, uint32_t n_samples)
|
|
|
|
|
{
|
|
|
|
|
uint32_t i;
|
2024-10-15 12:14:57 +02:00
|
|
|
uint32_t w = *pos;
|
|
|
|
|
uint32_t o = n_buffer - delay;
|
2022-03-01 09:53:40 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < n_samples; i++) {
|
2024-10-15 12:14:57 +02:00
|
|
|
buffer[w] = buffer[w + n_buffer] = src[i];
|
|
|
|
|
dst[i] = buffer[w + o] * vol;
|
|
|
|
|
w = w + 1 >= n_buffer ? 0 : w + 1;
|
2022-03-01 09:53:40 +01:00
|
|
|
}
|
2024-10-15 12:14:57 +02:00
|
|
|
*pos = w;
|
2022-03-01 09:53:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void delay_convolve_run(float *buffer, uint32_t *pos,
|
|
|
|
|
uint32_t n_buffer, uint32_t delay,
|
|
|
|
|
const float *taps, uint32_t n_taps,
|
|
|
|
|
float *dst, const float *src, const float vol, uint32_t n_samples)
|
|
|
|
|
{
|
|
|
|
|
uint32_t i, j;
|
2024-10-15 12:14:57 +02:00
|
|
|
uint32_t w = *pos;
|
|
|
|
|
uint32_t o = n_buffer - delay - n_taps-1;
|
2022-03-01 09:53:40 +01:00
|
|
|
|
2024-10-15 12:14:57 +02:00
|
|
|
if (n_taps == 1) {
|
|
|
|
|
delay_run(buffer, pos, n_buffer, delay, dst, src, vol, n_samples);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-03-01 09:53:40 +01:00
|
|
|
for (i = 0; i < n_samples; i++) {
|
|
|
|
|
float sum = 0.0f;
|
|
|
|
|
|
2024-10-15 12:14:57 +02:00
|
|
|
buffer[w] = buffer[w + n_buffer] = src[i];
|
2022-03-01 09:53:40 +01:00
|
|
|
for (j = 0; j < n_taps; j++)
|
2024-10-15 12:14:57 +02:00
|
|
|
sum += taps[j] * buffer[w+o+j];
|
2022-03-01 09:53:40 +01:00
|
|
|
dst[i] = sum * vol;
|
|
|
|
|
|
2024-10-15 12:14:57 +02:00
|
|
|
w = w + 1 >= n_buffer ? 0 : w + 1;
|
2022-03-01 09:53:40 +01:00
|
|
|
}
|
2024-10-15 12:14:57 +02:00
|
|
|
*pos = w;
|
2022-03-01 09:53:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* DELAY_H */
|