maad.util.crossfade

maad.util.crossfade(s1, s2, fs, fade_len=1)[source]

Add a smooth transition (cross-fade) between two audio signals. The function applies a squared function to apply the transition between signals. The signals must have the same sampling rate.

Parameters:
s1numpy.ndarray

First audio signal.

s2numpy.ndarray

Second audio signal.

fs: int

Sampling frequency of signals.

Returns:
s_out: numpy.ndarray

Signal with the resulting crossfade between s1 and s2. The length in seconds of the resulting signal is: len(s1)/fs + len(s1)/fs - fade_len.

See also

crossfade_list

Examples

>>> from maad import sound, util
>>> s, fs = sound.load('../data/spinetail.wav')
>>> s1 = sound.trim(s, fs, 0, 4)
>>> s2 = sound.trim(s, fs, 15, 19)
>>> s_out = util.crossfade(s1, s2, fs, fade_len=1)