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:
- Returns:
ndarrayA mixed sonic vector containing the sum of the input sonic vectors.
- Raises:
ValueErrorIf 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 usemix_stereo().
- Parameters:
- Return type:
See also
mix_stereothe same sum for two-channel sounds.
mix_manythe 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