music.mix_many

music.mix_many(sonic_vectors, end=False, offset=0, sample_rate=None)[source]

Mix sonic vectors of arbitrary lengths.

The operation consists in summing sample by sample [1]. This function helps when the sonic_vectors are not of the same size.

Parameters:
sonic_vectorslist of sonic_arrays

The sonic vectors to be summed, mono or stereo. If any is stereo, each mono one is put in both channels.

endbool

If True, sync the final samples. If False (default) sync the initial samples.

offsetlist of scalars

A list of the offsets for each sonic vectors in seconds.

sample_rateinteger or None

The sample rate. Only used if offset is supplied. None, the default, is the rate music.get_sample_rate() returns.

Returns:
Sndarray

A numpy array where each value is a PCM sample of the resulting sound. No sounds mix to no samples.

Notes

Cite the following article whenever you use this function.

References

[1]

Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)

Examples

>>> mixed = mix_many([note(220, 2), note(440, 1)])
>>> write_wav_mono(mixed)  # writes a WAV of the two notes summed