- Timestamp:
- Feb 22, 2014, 8:38:07 PM (11 years ago)
- 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:
- bafa767
- Parents:
- 8a5148e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/phasevoc.c
r8a5148e r687eead 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2014 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 36 36 fvec_t * synthold; /** memory of past grain, [win_s-hop_s] frames */ 37 37 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 */ 38 43 }; 39 44 40 45 41 46 /** 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); 47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new); 44 48 45 49 /** 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); 50 static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew); 48 51 49 52 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) { 50 53 /* 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); 53 55 /* windowing */ 54 56 fvec_weight(pv->data, pv->w); … … 64 66 /* unshift */ 65 67 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); 68 70 } 69 71 … … 105 107 pv->win_s = win_s; 106 108 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 107 121 return pv; 108 122 … … 122 136 } 123 137 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) 138 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new) 126 139 { 140 /* some convenience pointers */ 141 smpl_t * data = pv->data->data; 142 smpl_t * dataold = pv->dataold->data; 143 smpl_t * datanew = new->data; 127 144 #if !HAVE_MEMCPY_HACKS 128 145 uint_t i; 129 for (i = 0; i < win_s - hop_s; i++)146 for (i = 0; i < pv->end; i++) 130 147 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]; 135 152 #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); 142 159 #endif 143 160 } 144 161 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) 162 static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t *synth_new) 147 163 { 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; 150 169 151 170 /* 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 154 174 /* no overlap, nothing else to do */ 155 if ( win_s <= hop_s) return;175 if (pv->end == 0) return; 156 176 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++) 159 179 synthnew[i] += synthold[i]; 160 180 161 181 /* 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]; 164 184 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;169 185 /* erase last frame in synthold */ 170 for (i = start; i < win_s - hop_s; i++)186 for (i = pv->start; i < pv->end; i++) 171 187 synthold[i] = 0.; 172 188 173 189 /* 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; 176 192 } 177
Note: See TracChangeset
for help on using the changeset viewer.