kopia lustrzana https://github.com/xdsopl/robot36
moved delay to own files
rodzic
27132b6e00
commit
1e7c47c1e2
2
Makefile
2
Makefile
|
@ -22,5 +22,5 @@ clean:
|
||||||
|
|
||||||
encode: encode.o mmap_file.o
|
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
|
||||||
|
|
||||||
|
|
31
decode.c
31
decode.c
|
@ -9,6 +9,7 @@
|
||||||
#include "mmap_file.h"
|
#include "mmap_file.h"
|
||||||
#include "pcm.h"
|
#include "pcm.h"
|
||||||
#include "ddc.h"
|
#include "ddc.h"
|
||||||
|
#include "delay.h"
|
||||||
|
|
||||||
float lerp(float a, float b, float x)
|
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;
|
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 {
|
typedef struct {
|
||||||
uint32_t ChunkID;
|
uint32_t ChunkID;
|
||||||
uint32_t ChunkSize;
|
uint32_t ChunkSize;
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
#include "delay.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Ładowanie…
Reference in New Issue