soundgen (version 1.5.0)

findZeroCrossing: Find zero crossing

Description

Internal soundgen function.

Usage

findZeroCrossing(ampl, location)

Arguments

ampl

a vector of amplitudes oscillating around zero, such as a sound waveform

location

the index indicating the desired location of a zero crossing

Value

Returns the index of the last negative value before zero crossing closest to specified location.

Details

findZeroCrossing looks for the last negative point before a zero crossing as close as possible to the specified location. Since this is primarily intended for joining waveforms without a click, this function only looks at upward segments of a waveform (see example).

Examples

Run this code
# NOT RUN {
ampl = sin(1:100/2)
plot(ampl, type = 'b')
lines(1:100, rep(0,100), lty = 2)
zc = vector()
for (i in 1:length(ampl)){
  zc[i] = soundgen:::findZeroCrossing (ampl, i)
  # find zc closest to each of 100 points
}
for (z in unique(zc)){
  points(z, ampl[z], col = 'red', pch = 17)
  # only on upward segments
}
zc # see which zc is closest to each point
# }

Run the code above in your browser using DataLab