music.mix_with_offset¶
- music.mix_with_offset(first_sonic_vector, second_sonic_vector, duration=0, number_of_samples=None, sample_rate=None)[source]¶
Mix two sonic vector by placing the beginning of the second one a specified number of seconds after the first one.
- Parameters:
- first_sonic_vectornumeric
array A sequence of PCM samples.
- second_sonic_vectornumeric
array Another sequence of PCM samples.
- durationnumeric
The offset of the second sound in seconds: how far after the start of the first the second begins. Negative starts the second sound that many seconds before the first one ends.
- number_of_samples
intorNone The offset in samples, taken instead of
durationwhen given. Zero is an offset of zero samples; None, the default, readsdurationinstead.- sample_rate
intorNone The sample rate in Hertz. None, the default, is the rate
music.get_sample_rate()returns.
- first_sonic_vectornumeric
- Returns:
ndarrayThe two sounds summed at that offset, long enough to hold both.
- Raises:
ValueErrorIf a negative offset reaches back past the start of the first sound: the second cannot begin before the first one does. Such an offset was read from the end of the mix, as a negative index is, and failed in numpy with a message about broadcasting.
- Parameters:
- Return type:
NDArray[float64]
See also
mix_many_with_offsetsthe same, for any number of sounds, each offset from the mix built so far.
mix_manya list of sounds aligned at their starts or their ends.
Notes
A negative offset counts back from the end of the first sound, so it can reach that sound’s first sample,
first_sonic_vector.shape[-1]samples back, and no further.Examples
>>> late = mix_with_offset(note(220, 1), note(330, 1), duration=0.5) >>> len(late) / 44100 # the second note starts half a second in 1.5