[aubio-user] Fwd: aubio help
Paul Brossier
piem at aubio.org
Tue Nov 22 22:45:10 CET 2016
Hi Ilya,
First, note that I am currently working on integrating time-stretch in
the C library (see the timestretch git branch). In a future release
(probably one release after the upcoming one), this will become much
easier, including in Python.
Also, I would suggest that you start from `demo_timestretch_online.py`,
which is much more memory efficient than `demo_timestretch.py`.
A few notes from from reading your code, I would suggest:
- initializing sink_out as an array, not as a list:
import numpy as np
sink_out = np.ndarray([])
- append each produced frames with numpy.stack (list.append would
create a list of arrays, so it's not really what you want):
if t > warmup: # skip the first few frames to warm up phase vocoder
# write to sink
np.append(sink_out, stretched_samples)
The final conversion of your list to an array needs to be checked. If
you need the output as integers, you most likely want to multiply the
float samples by a constant. With the above modifications, it could
become something like:
sink_out_int = (sink_out * 32768).astype(np.int16)
To debug your code, you could add print statements to each steps to
check the size of the sink_out array, which you should see grow at each
step. Also, make sure to avoid not overwriting local variables by using
the same name (self._samples, samples, samples_proc...).
Let us know how it works out for you,
Best, Paul
On 11/22/2016 08:43 PM, Илья wrote:
>
>
>> Начало переадресованного сообщения:
>>
>> *Отправитель: *Илья <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!
>
>
>
> _______________________________________________
> aubio-user mailing list
> aubio-user at aubio.org
> https://lists.aubio.org/listinfo/aubio-user
>
More information about the aubio-user
mailing list