music.normalize_stereo¶
- music.normalize_stereo(sonic_vector, remove_bias=True, normalize_sep=False)[source]¶
Normalize a stereo sonic vector.
The final array will have values only between -1 and 1.
- Parameters:
- sonic_vectorarray_like
A (2, nsamples) shaped array. A one-dimensional array is taken as mono and given two identical channels.
- remove_biasbool
If True (default), subtract each channel’s mean before scaling. If False, map the sample range affinely onto [-1, 1], using each channel’s range when
normalize_sepis True and the combined range otherwise.- normalize_sepbool
Set to True if each channel should be normalized separately. If False (default), the arrays will be rescaled in the same proportion (preserves loudness proportion).
- Returns:
- sv_normalized
ndarray A numpy array with values between -1 and 1.
- sv_normalized
- Raises:
ValueErrorIf the sonic vector is empty; see
normalize_mono()for what an empty render means.
- Parameters:
- Return type:
NDArray[float64]
Examples
>>> quiet = np.vstack([note(220, 0.1) * 0.1, note(330, 0.1) * 0.4]) >>> loudest = float(abs(normalize_stereo(quiet)).max()) >>> round(loudest, 6) 1.0 >>> apart = normalize_stereo(quiet, normalize_sep=True) >>> [round(float(abs(channel).max()), 6) for channel in apart] [1.0, 1.0]