crossFade: Join two waveforms by cross-fading

Description Usage Arguments Value Examples

Description

crossFade joins two input vectors (waveforms) by cross-fading. It truncates both input vectors, so that ampl1 ends with a zero crossing and ampl2 starts with a zero crossing, both on an upward portion of the soundwave. Then it cross-fades both vectors linearly with an overlap of crossLen or crossLenPoints. If the input vectors are too short for the specified length of cross-faded region, the two vectors are concatenated at zero crossings instead of cross-fading. Soundgen uses crossFade for gluing together epochs with different regimes of pitch effects (see the vignette on sound generation), but it can also be useful for joining two separately generated sounds without audible artifacts.

Usage

1
crossFade(ampl1, ampl2, samplingRate, crossLen = 15, crossLenPoints = NULL)

Arguments

ampl1, ampl2

two numeric vectors (waveforms) to be joined

samplingRate

the sampling rate of input vectors, Hz

crossLen

the length of overlap, in ms (doesn't need to be specified if crossLenPoints is not NULL)

crossLenPoints

(optional) the length of overlap, in points (defaults to NULL)

Value

Returns a numeric vector.

Examples

1
2
3
4
5
6
7
8
9
sound1 = sin(1:100 / 9)
sound2 = sin(7:107 / 3)
plot(c(sound1, sound2), type = 'b')
# an ugly discontinuity at 100 that will make an audible click

sound = crossFade(sound1, sound2, crossLenPoints = 5)
plot(sound, type = 'b') # a nice, smooth transition
length(sound) # but note that cross-fading costs us ~60 points
#  because of trimming to zero crossings

tatters/soundgen_beta documentation built on May 14, 2019, 9 a.m.