Changeset 687eead


Ignore:
Timestamp:
Feb 22, 2014, 8:38:07 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
bafa767
Parents:
8a5148e
Message:

src/spectral/phasevoc.c: compute start, end, scale, and memory sizes only once

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/phasevoc.c

    r8a5148e r687eead  
    11/*
    2   Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2003-2014 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    3636  fvec_t * synthold;  /** memory of past grain, [win_s-hop_s] frames */
    3737  fvec_t * w;         /** grain window [win_s] */
     38  uint_t start;       /** where to start additive synthesis */
     39  uint_t end;         /** where to end it */
     40  smpl_t scale;       /** scaling factor for synthesis */
     41  uint_t end_datasize;  /** size of memory to end */
     42  uint_t hop_datasize;  /** size of memory to hop_s */
    3843};
    3944
    4045
    4146/** returns data and dataold slided by hop_s */
    42 static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const
    43     smpl_t * datanew, uint_t win_s, uint_t hop_s);
     47static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new);
    4448
    4549/** do additive synthesis from 'old' and 'cur' */
    46 static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
    47     smpl_t * synthnew, uint_t win_s, uint_t hop_s);
     50static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew);
    4851
    4952void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
    5053  /* slide  */
    51   aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data,
    52       datanew->data,pv->win_s,pv->hop_s);
     54  aubio_pvoc_swapbuffers(pv, datanew);
    5355  /* windowing */
    5456  fvec_weight(pv->data, pv->w);
     
    6466  /* unshift */
    6567  fvec_shift(pv->synth);
    66   aubio_pvoc_addsynth(pv->synth->data,pv->synthold->data,
    67       synthnew->data,pv->win_s,pv->hop_s);
     68  /* additive synthesis */
     69  aubio_pvoc_addsynth(pv, synthnew);
    6870}
    6971
     
    105107  pv->win_s    = win_s;
    106108
     109  /* more than 50% overlap, overlap anyway */
     110  if (win_s < 2 * hop_s) pv->start = 0;
     111  /* less than 50% overlap, reset latest grain trail */
     112  else pv->start = win_s - hop_s - hop_s;
     113
     114  pv->end = MAX(0, win_s - hop_s);
     115
     116  pv->end_datasize = pv->end * sizeof(smpl_t);
     117  pv->hop_datasize = pv->hop_s * sizeof(smpl_t);
     118
     119  pv->scale = pv->hop_s * 2. / pv->win_s;
     120
    107121  return pv;
    108122
     
    122136}
    123137
    124 static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold,
    125     const smpl_t * datanew, uint_t win_s, uint_t hop_s)
     138static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new)
    126139{
     140  /* some convenience pointers */
     141  smpl_t * data = pv->data->data;
     142  smpl_t * dataold = pv->dataold->data;
     143  smpl_t * datanew = new->data;
    127144#if !HAVE_MEMCPY_HACKS
    128145  uint_t i;
    129   for (i = 0; i < win_s - hop_s; i++)
     146  for (i = 0; i < pv->end; i++)
    130147    data[i] = dataold[i];
    131   for (i = 0; i < hop_s; i++)
    132     data[win_s - hop_s + i] = datanew[i];
    133   for (i = 0; i < win_s - hop_s; i++)
    134     dataold[i] = data[i + hop_s];
     148  for (i = 0; i < pv->hop_s; i++)
     149    data[pv->end + i] = datanew[i];
     150  for (i = 0; i < pv->end; i++)
     151    dataold[i] = data[i + pv->hop_s];
    135152#else
    136   memcpy(data, dataold, (win_s - hop_s) * sizeof(smpl_t));
    137   data += win_s - hop_s;
    138   memcpy(data, datanew, hop_s * sizeof(smpl_t));
    139   data -= win_s - hop_s;
    140   data += hop_s;
    141   memcpy(dataold, data, (win_s - hop_s) * sizeof(smpl_t));
     153  memcpy(data, dataold, pv->end_datasize);
     154  data += pv->end;
     155  memcpy(data, datanew, pv->hop_datasize);
     156  data -= pv->end;
     157  data += pv->hop_s;
     158  memcpy(dataold, data, pv->end_datasize);
    142159#endif
    143160}
    144161
    145 static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
    146                 smpl_t * synthnew, uint_t win_s, uint_t hop_s)
     162static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t *synth_new)
    147163{
    148   uint_t i, start;
    149   smpl_t scale = hop_s * 2. / win_s;
     164  uint_t i;
     165  /* some convenience pointers */
     166  smpl_t * synth    = pv->synth->data;
     167  smpl_t * synthold = pv->synthold->data;
     168  smpl_t * synthnew = synth_new->data;
    150169
    151170  /* put new result in synthnew */
    152   for (i = 0; i < hop_s; i++)
    153     synthnew[i] = synth[i] * scale;
     171  for (i = 0; i < pv->hop_s; i++)
     172    synthnew[i] = synth[i] * pv->scale;
     173
    154174  /* no overlap, nothing else to do */
    155   if (win_s <= hop_s) return;
     175  if (pv->end == 0) return;
    156176
    157   /* add new synth to old one and */
    158   for (i = 0; i < hop_s; i++)
     177  /* add new synth to old one */
     178  for (i = 0; i < pv->hop_s; i++)
    159179    synthnew[i] += synthold[i];
    160180
    161181  /* shift synthold */
    162   for (i = hop_s; i < win_s - hop_s; i++)
    163     synthold[i - hop_s] = synthold[i];
     182  for (i = 0; i < pv->start; i++)
     183    synthold[i] = synthold[i + pv->hop_s];
    164184
    165   /* more than 50% overlap, overlap anyway */
    166   if (win_s < 2 * hop_s) start = 0;
    167   /* less than 50% overlap, reset latest grain trail */
    168   else start = win_s - hop_s - hop_s;
    169185  /* erase last frame in synthold */
    170   for (i = start; i < win_s - hop_s; i++)
     186  for (i = pv->start; i < pv->end; i++)
    171187    synthold[i] = 0.;
    172188
    173189  /* additive synth */
    174   for (i = 0; i < win_s - hop_s; i++)
    175     synthold[i] += synth[i + hop_s] * scale;
     190  for (i = 0; i < pv->end; i++)
     191    synthold[i] += synth[i + pv->hop_s] * pv->scale;
    176192}
    177 
Note: See TracChangeset for help on using the changeset viewer.