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_samplesint or None

The offset in samples, taken instead of duration when given. Zero is an offset of zero samples; None, the default, reads duration instead.

sample_rateint or None

The sample rate in Hertz. None, the default, is the rate music.get_sample_rate() returns.

Returns:
ndarray

The two sounds summed at that offset, long enough to hold both.

Raises:
ValueError

If 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:
  • first_sonic_vector (ArrayLike)

  • second_sonic_vector (ArrayLike)

  • duration (float)

  • number_of_samples (int | None)

  • sample_rate (int | None)

Return type:

NDArray[float64]

See also

mix_many_with_offsets

the same, for any number of sounds, each offset from the mix built so far.

mix_many

a 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