findZeroCrossing: Find zero crossing

View source: R/soundgen_utilities.R

findZeroCrossingR Documentation

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

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).

Value

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

Examples

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

tatters/soundgen documentation built on Aug. 22, 2023, 4:24 p.m.