shithub: soundpipe

ref: 25a9fcc24ad00c6a406042818b9e6f2e7bba0dd1
dir: /modules/sdelay.c/

View raw version
/* This code is placed in the public domain. */

#include <stdlib.h>
#include "soundpipe.h"

int sp_sdelay_create(sp_sdelay **p)
{
    sp_sdelay *pp;
    *p = malloc(sizeof(sp_sdelay));
    pp = *p;
    pp->size = 0;
    return SP_OK;
}

int sp_sdelay_destroy(sp_sdelay **p)
{
    sp_sdelay *pp = *p;

    if(pp->size > 0) {
        free(pp->buf);
    }

    free(*p);
    return SP_OK;
}

int sp_sdelay_init(sp_data *sp, sp_sdelay *p, int size)
{
    USED(sp);

    int n;
    p->size = size;
    p->buf = malloc(size * sizeof(SPFLOAT));
    for(n = 0; n < p->size; n++) p->buf[n] = 0;
    p->pos = 0;
    return SP_OK;
}

int sp_sdelay_compute(sp_data *sp, sp_sdelay *p, SPFLOAT *in, SPFLOAT *out)
{
    USED(sp);

    *out = p->buf[p->pos];
    p->buf[p->pos] = *in;
    p->pos = (p->pos + 1) % p->size;
    return SP_OK;
}