Changeset ef7df76 for src/phasevoc.c


Ignore:
Timestamp:
Nov 6, 2007, 11:53:50 AM (16 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
f218f29
Parents:
82c588a (diff), 2b3280a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from banane

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/phasevoc.c

    r82c588a ref7df76  
    2626/** phasevocoder internal object */
    2727struct _aubio_pvoc_t {
    28         /** grain length */
    29         uint_t win_s;
    30         /** overlap step */
    31         uint_t hop_s;
    32         /** number of channels */
    33         uint_t channels;
    34         /** spectral data */
    35         aubio_mfft_t * fft;
    36         /**cur output grain             [win_s] */
    37         fvec_t * synth;         
    38         /**last input frame             [win_s-hop_s] */
    39         fvec_t * synthold;
    40         /**current input grain          [win_s] */
    41         fvec_t * data;           
    42         /**last input frame             [win_s-hop_s] */
    43         fvec_t * dataold; 
    44         /** grain window                [win_s] */
    45         float * w;
     28  uint_t win_s;       /** grain length */
     29  uint_t hop_s;       /** overlap step */
     30  uint_t channels;    /** number of channels */
     31  aubio_mfft_t * fft; /** spectral data */
     32  fvec_t * synth;     /**cur output grain [win_s] */
     33  fvec_t * synthold;  /**last input frame [win_s-hop_s] */
     34  fvec_t * data;      /**current input grain [win_s] */
     35  fvec_t * dataold;   /**last input frame [win_s-hop_s] */
     36  smpl_t * w;          /** grain window [win_s] */
    4637};
    4738
    4839
    4940/** returns data and dataold slided by hop_s */
    50 static void aubio_pvoc_swapbuffers(
    51                 smpl_t * data,
    52                 smpl_t * dataold,
    53                 const smpl_t * datanew,
    54                 uint_t win_s, uint_t hop_s);
     41static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const
     42    smpl_t * datanew, uint_t win_s, uint_t hop_s);
     43
    5544/** do additive synthesis from 'old' and 'cur' */
    56 static void aubio_pvoc_addsynth(
    57                 const smpl_t * synth,
    58                 smpl_t * synthold,
    59                 smpl_t * synthnew,
    60                 uint_t win_s, uint_t hop_s);
    61 
     45static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
     46    smpl_t * synthnew, uint_t win_s, uint_t hop_s);
    6247
    6348void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
    64         uint_t i,j;
    65         for (i=0; i<pv->channels; i++) {
    66                 /* slide  */
    67                 aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
    68                                 datanew->data[i],pv->win_s,pv->hop_s);
    69                 /* windowing */
    70                 for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
    71         }
    72         /* shift */
    73         vec_shift(pv->data);
    74         /* calculate fft */
    75         aubio_mfft_do (pv->fft,pv->data,fftgrain);
     49  uint_t i,j;
     50  for (i=0; i<pv->channels; i++) {
     51    /* slide  */
     52    aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
     53        datanew->data[i],pv->win_s,pv->hop_s);
     54    /* windowing */
     55    for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
     56  }
     57  /* shift */
     58  vec_shift(pv->data);
     59  /* calculate fft */
     60  aubio_mfft_do (pv->fft,pv->data,fftgrain);
    7661}
    7762
    7863void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
    79         uint_t i,j;
    80         /* calculate rfft */
    81         aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
    82         /* unshift */
    83         vec_shift(pv->synth);
    84         for (i=0; i<pv->channels; i++) {
    85                 for (j=0; j<pv->win_s; j++) pv->synth->data[i][j] *= pv->w[j];
    86                 aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
    87                                 synthnew->data[i],pv->win_s,pv->hop_s);
    88         }
     64  uint_t i;
     65  /* calculate rfft */
     66  aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
     67  /* unshift */
     68  vec_shift(pv->synth);
     69  for (i=0; i<pv->channels; i++) {
     70    aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
     71        synthnew->data[i],pv->win_s,pv->hop_s);
     72  }
    8973}
    9074
    9175aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
    92         aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
     76  aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
    9377
    94         if (win_s < 2*hop_s) {
    95                 AUBIO_ERR("Hop size bigger than half the window size!\n");
    96                 AUBIO_ERR("Resetting hop size to half the window size.\n");
    97                 hop_s = win_s / 2;
    98         }
     78  if (win_s < 2*hop_s) {
     79    AUBIO_ERR("Hop size bigger than half the window size!\n");
     80    AUBIO_ERR("Resetting hop size to half the window size.\n");
     81    hop_s = win_s / 2;
     82  }
    9983
    100         if (hop_s < 1) {
    101                 AUBIO_ERR("Hop size is smaller than 1!\n");
    102                 AUBIO_ERR("Resetting hop size to half the window size.\n");
    103                 hop_s = win_s / 2;
    104         }
    105        
    106         pv->fft      = new_aubio_mfft(win_s,channels);
     84  if (hop_s < 1) {
     85    AUBIO_ERR("Hop size is smaller than 1!\n");
     86    AUBIO_ERR("Resetting hop size to half the window size.\n");
     87    hop_s = win_s / 2;
     88  }
    10789
    108         /* remember old */
    109         pv->data     = new_fvec (win_s, channels);
    110         pv->synth    = new_fvec (win_s, channels);
     90  pv->fft      = new_aubio_mfft(win_s,channels);
    11191
    112         /* new input output */
    113         pv->dataold  = new_fvec  (win_s-hop_s, channels);
    114         pv->synthold = new_fvec (win_s-hop_s, channels);
    115         pv->w        = AUBIO_ARRAY(smpl_t,win_s);
    116         aubio_window(pv->w,win_s,aubio_win_hanningz);
     92  /* remember old */
     93  pv->data     = new_fvec (win_s, channels);
     94  pv->synth    = new_fvec (win_s, channels);
    11795
    118         pv->channels = channels;
    119         pv->hop_s    = hop_s;
    120         pv->win_s    = win_s;
     96  /* new input output */
     97  pv->dataold  = new_fvec  (win_s-hop_s, channels);
     98  pv->synthold = new_fvec (win_s-hop_s, channels);
     99  pv->w        = AUBIO_ARRAY(smpl_t,win_s);
     100  aubio_window(pv->w,win_s,aubio_win_hanningz);
    121101
    122         return pv;
     102  pv->channels = channels;
     103  pv->hop_s    = hop_s;
     104  pv->win_s    = win_s;
     105
     106  return pv;
    123107}
    124108
    125109void del_aubio_pvoc(aubio_pvoc_t *pv) {
    126         del_fvec(pv->data);
    127         del_fvec(pv->synth);
    128         del_fvec(pv->dataold);
    129         del_fvec(pv->synthold);
    130         del_aubio_mfft(pv->fft);
    131         AUBIO_FREE(pv->w);
    132         AUBIO_FREE(pv);
     110  del_fvec(pv->data);
     111  del_fvec(pv->synth);
     112  del_fvec(pv->dataold);
     113  del_fvec(pv->synthold);
     114  del_aubio_mfft(pv->fft);
     115  AUBIO_FREE(pv->w);
     116  AUBIO_FREE(pv);
    133117}
    134118
    135119static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold,
    136                 const smpl_t * datanew, uint_t win_s, uint_t hop_s)
     120    const smpl_t * datanew, uint_t win_s, uint_t hop_s)
    137121{
    138         uint_t i;
    139         for (i=0;i<win_s-hop_s;i++)
    140                 data[i] = dataold[i];
    141         for (i=0;i<hop_s;i++)
    142                 data[win_s-hop_s+i] = datanew[i];
    143         for (i=0;i<win_s-hop_s;i++)
    144                 dataold[i] = data[i+hop_s];
     122  uint_t i;
     123  for (i=0;i<win_s-hop_s;i++)
     124    data[i] = dataold[i];
     125  for (i=0;i<hop_s;i++)
     126    data[win_s-hop_s+i] = datanew[i];
     127  for (i=0;i<win_s-hop_s;i++)
     128    dataold[i] = data[i+hop_s];
    145129}
    146130
     
    148132                smpl_t * synthnew, uint_t win_s, uint_t hop_s)
    149133{
    150         uint_t i;
    151         smpl_t scale = 2*hop_s/(win_s+.0);
    152         /* add new synth to old one and put result in synthnew */
    153         for (i=0;i<hop_s;i++)                                           
    154                 synthnew[i] = synthold[i]+synth[i]*scale;
    155         /* shift synthold */
    156         for (i=0;i<win_s-2*hop_s;i++)   
    157                 synthold[i] = synthold[i+hop_s];
    158         /* erase last frame in synthold */
    159         for (i=win_s-hop_s;i<win_s;i++)
    160                 synthold[i-hop_s]=0.;
    161         /* additive synth */
    162         for (i=0;i<win_s-hop_s;i++)     
    163                 synthold[i] += synth[i+hop_s]*scale;
     134  uint_t i;
     135  smpl_t scale = 2*hop_s/(win_s+.0);
     136  /* add new synth to old one and put result in synthnew */
     137  for (i=0;i<hop_s;i++)
     138    synthnew[i] = synthold[i]+synth[i]*scale;
     139  /* shift synthold */
     140  for (i=0;i<win_s-2*hop_s;i++)
     141    synthold[i] = synthold[i+hop_s];
     142  /* erase last frame in synthold */
     143  for (i=win_s-hop_s;i<win_s;i++)
     144    synthold[i-hop_s]=0.;
     145  /* additive synth */
     146  for (i=0;i<win_s-hop_s;i++)
     147    synthold[i] += synth[i+hop_s]*scale;
    164148}
    165149
Note: See TracChangeset for help on using the changeset viewer.