From 687eead069518fa64d6791c42eab9b09496a9cbb Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 22 Feb 2014 16:38:07 -0300 Subject: [PATCH] src/spectral/phasevoc.c: compute start, end, scale, and memory sizes only once --- src/spectral/phasevoc.c | 97 ++++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/src/spectral/phasevoc.c b/src/spectral/phasevoc.c index b83474ad..53d1170c 100644 --- a/src/spectral/phasevoc.c +++ b/src/spectral/phasevoc.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2003-2009 Paul Brossier + Copyright (C) 2003-2014 Paul Brossier This file is part of aubio. @@ -35,21 +35,23 @@ struct _aubio_pvoc_t { fvec_t * synth; /** current output grain, [win_s] frames */ fvec_t * synthold; /** memory of past grain, [win_s-hop_s] frames */ fvec_t * w; /** grain window [win_s] */ + uint_t start; /** where to start additive synthesis */ + uint_t end; /** where to end it */ + smpl_t scale; /** scaling factor for synthesis */ + uint_t end_datasize; /** size of memory to end */ + uint_t hop_datasize; /** size of memory to hop_s */ }; /** returns data and dataold slided by hop_s */ -static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const - smpl_t * datanew, uint_t win_s, uint_t hop_s); +static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new); /** do additive synthesis from 'old' and 'cur' */ -static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold, - smpl_t * synthnew, uint_t win_s, uint_t hop_s); +static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew); void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) { /* slide */ - aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data, - datanew->data,pv->win_s,pv->hop_s); + aubio_pvoc_swapbuffers(pv, datanew); /* windowing */ fvec_weight(pv->data, pv->w); /* shift */ @@ -63,8 +65,8 @@ void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) { aubio_fft_rdo(pv->fft,fftgrain,pv->synth); /* unshift */ fvec_shift(pv->synth); - aubio_pvoc_addsynth(pv->synth->data,pv->synthold->data, - synthnew->data,pv->win_s,pv->hop_s); + /* additive synthesis */ + aubio_pvoc_addsynth(pv, synthnew); } aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) { @@ -104,6 +106,18 @@ aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) { pv->hop_s = hop_s; pv->win_s = win_s; + /* more than 50% overlap, overlap anyway */ + if (win_s < 2 * hop_s) pv->start = 0; + /* less than 50% overlap, reset latest grain trail */ + else pv->start = win_s - hop_s - hop_s; + + pv->end = MAX(0, win_s - hop_s); + + pv->end_datasize = pv->end * sizeof(smpl_t); + pv->hop_datasize = pv->hop_s * sizeof(smpl_t); + + pv->scale = pv->hop_s * 2. / pv->win_s; + return pv; beach: @@ -121,57 +135,58 @@ void del_aubio_pvoc(aubio_pvoc_t *pv) { AUBIO_FREE(pv); } -static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, - const smpl_t * datanew, uint_t win_s, uint_t hop_s) +static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new) { + /* some convenience pointers */ + smpl_t * data = pv->data->data; + smpl_t * dataold = pv->dataold->data; + smpl_t * datanew = new->data; #if !HAVE_MEMCPY_HACKS uint_t i; - for (i = 0; i < win_s - hop_s; i++) + for (i = 0; i < pv->end; i++) data[i] = dataold[i]; - for (i = 0; i < hop_s; i++) - data[win_s - hop_s + i] = datanew[i]; - for (i = 0; i < win_s - hop_s; i++) - dataold[i] = data[i + hop_s]; + for (i = 0; i < pv->hop_s; i++) + data[pv->end + i] = datanew[i]; + for (i = 0; i < pv->end; i++) + dataold[i] = data[i + pv->hop_s]; #else - memcpy(data, dataold, (win_s - hop_s) * sizeof(smpl_t)); - data += win_s - hop_s; - memcpy(data, datanew, hop_s * sizeof(smpl_t)); - data -= win_s - hop_s; - data += hop_s; - memcpy(dataold, data, (win_s - hop_s) * sizeof(smpl_t)); + memcpy(data, dataold, pv->end_datasize); + data += pv->end; + memcpy(data, datanew, pv->hop_datasize); + data -= pv->end; + data += pv->hop_s; + memcpy(dataold, data, pv->end_datasize); #endif } -static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold, - smpl_t * synthnew, uint_t win_s, uint_t hop_s) +static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t *synth_new) { - uint_t i, start; - smpl_t scale = hop_s * 2. / win_s; + uint_t i; + /* some convenience pointers */ + smpl_t * synth = pv->synth->data; + smpl_t * synthold = pv->synthold->data; + smpl_t * synthnew = synth_new->data; /* put new result in synthnew */ - for (i = 0; i < hop_s; i++) - synthnew[i] = synth[i] * scale; + for (i = 0; i < pv->hop_s; i++) + synthnew[i] = synth[i] * pv->scale; + /* no overlap, nothing else to do */ - if (win_s <= hop_s) return; + if (pv->end == 0) return; - /* add new synth to old one and */ - for (i = 0; i < hop_s; i++) + /* add new synth to old one */ + for (i = 0; i < pv->hop_s; i++) synthnew[i] += synthold[i]; /* shift synthold */ - for (i = hop_s; i < win_s - hop_s; i++) - synthold[i - hop_s] = synthold[i]; + for (i = 0; i < pv->start; i++) + synthold[i] = synthold[i + pv->hop_s]; - /* more than 50% overlap, overlap anyway */ - if (win_s < 2 * hop_s) start = 0; - /* less than 50% overlap, reset latest grain trail */ - else start = win_s - hop_s - hop_s; /* erase last frame in synthold */ - for (i = start; i < win_s - hop_s; i++) + for (i = pv->start; i < pv->end; i++) synthold[i] = 0.; /* additive synth */ - for (i = 0; i < win_s - hop_s; i++) - synthold[i] += synth[i + hop_s] * scale; + for (i = 0; i < pv->end; i++) + synthold[i] += synth[i + pv->hop_s] * pv->scale; } - -- 2.11.0