Learn R Programming

soundgen (version 1.7.0)

upsamplePitchContour: Upsample pitch contour

Description

Internal soundgen function

Usage

upsamplePitchContour(pitch, len, plot = FALSE)

Arguments

pitch

numeric vector of pitch values, including NAs (as returned by pitch_app)

len

required length

plot

if TRUE, plots the old and new pitch contours

Details

Intended to up- or downsample pitch contours containing NA values using linear interpolation ("approx"). The problem is that NA segments should also be expanded when upsampling, and approx() doesn't do that. Algorithm: when upsampling, first interpolates NAs (constant at beg/end, linear in the middle), then runs approx(), and finally puts NAs back in where they belong.

Examples

Run this code
# NOT RUN {
pitchManual = c(130, 150, 250, 290, 320, 300, 280, 270, 220)
soundgen:::upsamplePitchContour(pitchManual, len = 5, plot = TRUE)
soundgen:::upsamplePitchContour(pitchManual, len = 25, plot = TRUE)

pitchManual = c(NA, 150, 250, NA, NA, 300, 280, 270, NA)
soundgen:::upsamplePitchContour(pitchManual, len = 5, plot = TRUE)
soundgen:::upsamplePitchContour(pitchManual, len = 25, plot = TRUE)

soundgen:::upsamplePitchContour(c(NA, NA), len = 5)
# }

Run the code above in your browser using DataLab