diff options
Diffstat (limited to 'libaf')
-rw-r--r-- | libaf/af_resample.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/libaf/af_resample.c b/libaf/af_resample.c index 2536c0706d..2844940000 100644 --- a/libaf/af_resample.c +++ b/libaf/af_resample.c @@ -33,7 +33,7 @@ Valid definitions are L8 and L16, where the number denotes the length of the filter. This definition affects the computational complexity (see play()), the performance (see filter.h) and the - memory usage. The filterlength is choosen to 8 if the machine is + memory usage. The filter length is chosen to 8 if the machine is slow and to 16 if the machine is fast and has MMX. */ @@ -174,16 +174,14 @@ static int control(struct af_instance_s* af, int cmd, void* arg) { switch(cmd){ case AF_CONTROL_REINIT:{ - af_resample_t* s = (af_resample_t*)af->setup; - af_data_t* n = (af_data_t*)arg; // New configureation + af_resample_t* s = af->setup; + af_data_t* n = arg; // New configuration int i,d = 0; int rv = AF_OK; - // Free space for circular bufers + // Free space for circular buffers if(s->xq){ - for(i=1;i<af->data->nch;i++) - if(s->xq[i]) - free(s->xq[i]); + free(s->xq[0]); free(s->xq); s->xq = NULL; } @@ -216,13 +214,14 @@ static int control(struct af_instance_s* af, int cmd, void* arg) d*=m; } - // Create space for circular bufers + // Create space for circular buffers s->xq = malloc(n->nch*sizeof(void*)); - for(i=0;i<n->nch;i++) - s->xq[i] = malloc(2*L*af->data->bps); + s->xq[0] = calloc(n->nch, 2*L*af->data->bps); + for(i=1;i<n->nch;i++) + s->xq[i] = (uint8_t *)s->xq[i-1] + 2*L*af->data->bps; s->xi = 0; - // Check if the the design needs to be redone + // Check if the design needs to be redone if(s->up != af->data->rate/d || s->dn != n->rate/d){ float* w; float* wt; @@ -233,9 +232,9 @@ static int control(struct af_instance_s* af, int cmd, void* arg) s->wi = 0; s->i = 0; - // Calculate cuttof frequency for filter + // Calculate cutoff frequency for filter fc = 1/(float)(max(s->up,s->dn)); - // Allocate space for polyphase filter bank and protptype filter + // Allocate space for polyphase filter bank and prototype filter w = malloc(sizeof(float) * s->up *L); if(NULL != s->w) free(s->w); @@ -271,7 +270,7 @@ static int control(struct af_instance_s* af, int cmd, void* arg) return rv; } case AF_CONTROL_COMMAND_LINE:{ - af_resample_t* s = (af_resample_t*)af->setup; + af_resample_t* s = af->setup; int rate=0; int type=RSMP_INT; int sloppy=1; @@ -306,6 +305,13 @@ static int control(struct af_instance_s* af, int cmd, void* arg) // Deallocate memory static void uninit(struct af_instance_s* af) { + af_resample_t *s = af->setup; + if (s) { + if (s->xq) free(s->xq[0]); + free(s->xq); + free(s->w); + free(s); + } if(af->data) free(af->data->audio); free(af->data); @@ -317,7 +323,7 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data) int len = 0; // Length of output data af_data_t* c = data; // Current working data af_data_t* l = af->data; // Local data - af_resample_t* s = (af_resample_t*)af->setup; + af_resample_t* s = af->setup; if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) return NULL; |