ref: 7c90a8a8dcf46c6ec5ae39df21911e0053e72eda
parent: 9211d95a76975169ee7b71fc74582e5707e3fa04
author: Paul Batchelor <[email protected]>
date: Mon Oct 5 15:30:07 EDT 2020
removed auxdata from rpt
--- a/h/rpt.h
+++ b/h/rpt.h
@@ -7,8 +7,9 @@
uint32_t size;
SPFLOAT bpm;
int div, rep;
- sp_auxdata aux;
+ SPFLOAT *buf;
int rc;
+ uint32_t maxlen;
} sp_rpt;
int sp_rpt_create(sp_rpt **p);
--- a/modules/rpt.c
+++ b/modules/rpt.c
@@ -13,8 +13,7 @@
int sp_rpt_destroy(sp_rpt **p)
{
- sp_rpt *pp = *p;
- sp_auxdata_free(&pp->aux);
+ free((*p)->buf);
free(*p);
return SP_OK;
}
@@ -21,13 +20,16 @@
int sp_rpt_init(sp_data *sp, sp_rpt *p, SPFLOAT maxdur)
{
- sp_auxdata_alloc(&p->aux, sizeof(SPFLOAT) * (uint32_t)maxdur * sp->sr);
+ uint32_t maxlen;
+ maxlen = (uint32_t)maxdur * sp->sr;
p->playpos = 0;
p->bufpos = 0;
p->running = 0;
p->reps = 4;
p->count = p->reps;
- p->size = (int)p->aux.size;
+ p->maxlen = maxlen;
+ p->buf = calloc(1, sizeof(SPFLOAT) * maxlen);
+ p->size = maxlen;
p->sr = sp->sr;
p->bpm = 130;
p->div = 4;
@@ -39,7 +41,7 @@
int sp_rpt_compute(sp_data *sp, sp_rpt *p, SPFLOAT *trig,
SPFLOAT *in, SPFLOAT *out)
{
- SPFLOAT *buf = (SPFLOAT *)p->aux.ptr;
+ SPFLOAT *buf = p->buf;
if (p->rc == SP_NOT_OK) {
*out = 0;
@@ -54,7 +56,7 @@
p->count = p->reps + 1;
}
- if (p->bufpos * sizeof(SPFLOAT) < p->aux.size) {
+ if (p->bufpos < p->maxlen) {
p->rc = sp_rpt_set(p, p->bpm, p->div, p->rep);
buf[p->bufpos] = *in;
p->bufpos++;
@@ -79,7 +81,7 @@
{
uint32_t size = (p->sr * (60.0 / bpm)) / (SPFLOAT) div;
p->reps = rep;
- if (size * sizeof(SPFLOAT) > p->aux.size) {
+ if (size > p->maxlen) {
fprintf(stderr, "Error: not enough memory allocated for buffer.\n");
return SP_NOT_OK;
} else if(size <= 0) {