33 lines
766 B
C
33 lines
766 B
C
|
#include <stdint.h>
|
||
|
#include <stddef.h>
|
||
|
#include <stdlib.h>
|
||
|
#include "delay.h"
|
||
|
|
||
|
void delay_init(
|
||
|
struct delay * delay
|
||
|
) {
|
||
|
delay->duration = 15000;
|
||
|
delay->mix = 0.8;
|
||
|
delay->feedback = 0.6;
|
||
|
|
||
|
delay->buf_idx = 0;
|
||
|
delay->buf = calloc( delay->duration, sizeof(float) );
|
||
|
}
|
||
|
|
||
|
void delay_process(
|
||
|
struct delay * delay,
|
||
|
size_t frame_size,
|
||
|
float const * in,
|
||
|
float * out
|
||
|
) {
|
||
|
for( size_t i = 0; i < frame_size; ++i ) {
|
||
|
out[i] =
|
||
|
(1.0 - delay->mix) * in[i]
|
||
|
+ delay->mix * delay->buf[ delay->buf_idx ];
|
||
|
|
||
|
delay->buf[ delay->buf_idx ] *= delay->feedback;
|
||
|
delay->buf[ delay->buf_idx ] += (1.0 - delay->feedback) * in[i];
|
||
|
delay->buf_idx = (delay->buf_idx + 1) % delay->duration;
|
||
|
}
|
||
|
}
|