diff --git a/Makefile b/Makefile index c31ebb5..bb87775 100644 --- a/Makefile +++ b/Makefile @@ -22,5 +22,5 @@ clean: encode: encode.o mmap_file.o -decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o +decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o diff --git a/decode.c b/decode.c index a557a2f..e9f8795 100644 --- a/decode.c +++ b/decode.c @@ -9,6 +9,7 @@ #include "mmap_file.h" #include "pcm.h" #include "ddc.h" +#include "delay.h" float lerp(float a, float b, float x) { @@ -31,36 +32,6 @@ float limit(float min, float max, float x) return tmp > max ? max : tmp; } -typedef struct { - float *s; - int last; - int len; -} delay_t; - -float do_delay(delay_t *d, float input) -{ - d->s[d->last] = input; - d->last = (d->last + 1) < d->len ? d->last + 1 : 0; - return d->s[d->last]; -} - -delay_t *alloc_delay(int samples) -{ - int len = samples + 1; - delay_t *d = malloc(sizeof(delay_t)); - d->s = malloc(sizeof(float) * len); - d->last = 0; - d->len = len; - for (int i = 0; i < len; i++) - d->s[i] = 0.0; - return d; -} -void free_delay(delay_t *delay) -{ - free(delay->s); - free(delay); -} - typedef struct { uint32_t ChunkID; uint32_t ChunkSize; diff --git a/delay.c b/delay.c new file mode 100644 index 0000000..6d52406 --- /dev/null +++ b/delay.c @@ -0,0 +1,28 @@ + +#include "delay.h" +#include + +float do_delay(delay_t *d, float input) +{ + d->s[d->last] = input; + d->last = (d->last + 1) < d->len ? d->last + 1 : 0; + return d->s[d->last]; +} + +delay_t *alloc_delay(int samples) +{ + int len = samples + 1; + delay_t *d = malloc(sizeof(delay_t)); + d->s = malloc(sizeof(float) * len); + d->last = 0; + d->len = len; + for (int i = 0; i < len; i++) + d->s[i] = 0.0; + return d; +} +void free_delay(delay_t *delay) +{ + free(delay->s); + free(delay); +} + diff --git a/delay.h b/delay.h new file mode 100644 index 0000000..4e7979d --- /dev/null +++ b/delay.h @@ -0,0 +1,14 @@ + +#ifndef DELAY_H +#define DELAY_H +typedef struct { + float *s; + int last; + int len; +} delay_t; + +float do_delay(delay_t *, float); +delay_t *alloc_delay(int); +void free_delay(delay_t *); +#endif +