[aubio-user] Fwd: aubio help
Илья
ilya at perevoznik.name
Tue Nov 22 20:43:10 CET 2016
> Начало переадресованного сообщения:
>
> Отправитель: Илья <ilya at perevoznik.name <mailto:ilya at perevoznik.name>>
> Тема: aubio help
> Дата: 22 ноября 2016 г., 19:25:41 GMT+3
> Получатель: piem at piem.org <mailto:piem at piem.org>
>
> Hello, i’m coding app, that use `aubio` in it and i want to make a time-stretch of sound. (i’m using python module)
>
> i found a demo (in you’re python/demos folder) that actually what I’m looking for, but i need to rewrite it to compatibility with my already existing functions etc.
> I have a trouble with sink_out, i tried to look in clang code of it, but anyway i can’t understand, but i can’t use it cause i have my own file saving system. i tried to emulate sink_out with a list (that would convert to ndarray after stretching) and it doesn’t works, cuz i have just 1279 samples at the out, but at in it was 352800 :D
>
> please, help me to understand how to rewrite it without sink_out. i need to write all to ndarray. my code below:
>
> def time_stretch(self, rate):
> win_s = self._win_size
> hop_s = self._hop_size
>
> warmup = win_s // hop_s - 1
>
> p = pvoc(win_s, hop_s)
>
> # allocate memory to store norms and phases
> n_blocks = len(self._samples) // hop_s + 1
> # adding an empty frame at end of spectrogram
> norms = np.zeros((n_blocks + 1, win_s // 2 + 1), dtype=float_type)
> phases = np.zeros((n_blocks + 1, win_s // 2 + 1), dtype=float_type)
>
> block_read = 0
> samples = self._samples
> steps_max = len(samples) - (len(samples) % hop_s)
>
> for i in range(0, steps_max, hop_s):
> # pitchin = pitch_o(samples[i:i + self._hop_size])
> # read from source
> samples_proc = np.asarray(samples[i:i + hop_s]).astype(np.float32)
> # compute fftgrain
> spec = p(samples_proc)
> # store current grain
> norms[block_read] = spec.norm
> phases[block_read] = spec.phas
> # increment block counter
> block_read += 1
>
> # just to make sure
> # source_in.close()
>
> sink_out = []
>
> # interpolated time steps (j = alpha * i)
> steps = np.arange(0, n_blocks, rate, dtype=float_type)
> # initial phase
> phas_acc = phases[0]
> # excepted phase advance in each bin
> phi_advance = np.linspace(0, np.pi * hop_s, win_s / 2 + 1).astype(float_type)
>
> new_grain = cvec(win_s)
>
> for (t, step) in enumerate(steps):
>
> frac = 1. - np.mod(step, 1.0)
> # get pair of frames
> t_norms = norms[int(step):int(step + 2)]
> t_phases = phases[int(step):int(step + 2)]
>
> # compute interpolated frame
> new_grain.norm = frac * t_norms[0] + (1. - frac) * t_norms[1]
> new_grain.phas = phas_acc
> # print t, step, new_grain.norm
> # print t, step, phas_acc
>
> # psola
> samples_proc = p.rdo(new_grain)
> if t > warmup: # skip the first few frames to warm up phase vocoder
> # write to sink
> sink_out.append(samples_proc[:hop_s])
>
> # calculate phase advance
> dphas = t_phases[1] - t_phases[0] - phi_advance
> # unwrap angle to [-pi; pi]
> dphas = unwrap2pi(dphas)
> # cumulate phase, to be used for next frame
> phas_acc += phi_advance + dphas
>
> for t in range(warmup + 1): # purge the last frames from the phase vocoder
> new_grain.norm[:] = 0
> new_grain.phas[:] = 0
> samples_proc = p.rdo(new_grain)
> sink_out.append(samples_proc[:hop_s])
>
> self._samples = np.asarray(sink_out).astype(np.int16)
> P.S. Sorry for my bad English.
>
> Thank You!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.aubio.org/pipermail/aubio-user/attachments/20161122/dc763a1a/attachment-0001.html>
More information about the aubio-user
mailing list