music.mix_with_offset

music.mix_with_offset(first_sonic_vector, second_sonic_vector, duration=0, number_of_samples=0, sample_rate=44100)[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

The offset in samples, taken instead of duration when given.

sample_rateint

The sample rate in Hertz.

Returns:
ndarray

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

Parameters:
  • first_sonic_vector (ArrayLike)

  • second_sonic_vector (ArrayLike)

  • duration (float)

  • number_of_samples (int)

  • sample_rate (int)

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 duration must satisfy -duration * sample_rate < first_sonic_vector.shape[-1]: the second sound cannot begin before the first one does.

The description of duration above was truncated mid-sentence, and its last line sat at column zero, so numpydoc read “s1 ends.” as a parameter of this function and rendered it as one.

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