music.mix

music.mix(first_sonic_vector, second_sonic_vector)[source]

Mixes two sonic vectors.

This function mixes two sonic vectors of different lengths. It creates a new sonic vector by summing the samples of the input sonic vectors. If one of the input sonic vectors is shorter than the other, it is padded with zeros to match the length of the longer sonic vector before mixing.

Parameters:
first_sonic_vectorndarray

The first sonic vector.

second_sonic_vectorndarray

The second sonic vector.

Returns:
ndarray

A mixed sonic vector containing the sum of the input sonic vectors.

Raises:
ValueError

If either sound is not one-dimensional. This pads to the longer of the two, and len() of a stereo array counts its channels rather than its samples, so a stereo argument reached numpy as a two-element length and failed there with a message about broadcasting. Mix the channels separately, or use mix_stereo().

Parameters:
Return type:

ndarray

See also

mix_stereo

the same sum for two-channel sounds.

mix_many

the same sum over a list of sounds of any lengths, with per-sound offsets and a choice of aligning their starts or their ends.

Examples

>>> both = mix(note(freq=220, duration=1), note(freq=330, duration=1))
>>> len(both) == len(note(freq=220, duration=1))
True
>>> float(abs(both).max()) > 1.0   # two notes sum past full scale
True