music.stretches

music.stretches(x, durations=(1, 4, 8, 12), sample_rate=44100)[source]

Makes a sequence of squeezes of the fragment in x.

Parameters:
xarray_like

The samples made to repeat as original or squeezed. Assumed to be in the form (channels, samples), i.e. x[1][120] is the 120th sample of the second channel.

durationslist of numbers

Durations in seconds for each repeat of x.

sample_rateinteger

The sample rate in Hertz, used to read the length of x as a duration and so to work out how much each repeat is squeezed.

Returns:
ndarray

The repeats concatenated, mono or (2, nsamples) stereo according to x, each int(duration * sample_rate) samples long. An empty x gives an empty result.

Raises:
ValueError

If any entry of durations is zero or negative. A duration of zero squeezes the fragment into no samples and a negative one reverses the step, so neither produces the repeat the caller asked for.

Notes

This function is useful to render musical sequences given any material. PS: not clear if this function is already useful.

Examples

>>> asound = horizontal_stack(*[note_with_vibrato(freq=i, vibrato_freq=j)
...                           for i, j in zip([220,440,330,440,330],
...                                           [.5,15,6,5,30])])
>>> s = stretches(asound)
>>> s = stretches(asound,
...               durations=[.2, .3] * 10 + [.1, .2, .3, .4] * 8 +
...               [.5, 1.5, .5, 1., 5., .5, .25, .25, .5, 1., .5] * 2)
>>> write_wav_mono(s, 'stretches.wav')