Learn R Programming

soundgen (version 1.0.0)

getSmoothContour: Smooth contour from anchors

Description

Returns a smooth contour based on an arbitrary number of anchors. Used by soundgen for generating intonation contour, mouth opening, etc. Note that pitch contours are treated as a special case: values are log-transformed prior to smoothing, so that with 2 anchors we get a linear transition on a log scale (as if we were operating with musical notes rather than frequencies in Hz). Pitch plots have two Y axes: one showing Hz and the other showing musical notation.

Usage

getSmoothContour(anchors = data.frame(time = c(0, 1), value = c(0, 1)),
  len = NULL, thisIsPitch = FALSE, method = c("spline", "loess")[2],
  valueFloor = NULL, valueCeiling = NULL, plot = FALSE, main = "",
  xlim = NULL, ylim = NULL, samplingRate = 16000, voiced = NULL,
  contourLabel = NULL, ...)

Arguments

anchors

a dataframe of anchors with specified time and amplitude. achors$time can be in ms (with len=NULL) or in arbitrary units, eg 0 to 1 (with duration determined by len, which must then be provided in ms). So anchors$time is assumed to be in ms if len=NULL and relative if len is specified. anchors$value can be on any scale.

len

the required length of the output contour. If NULL, it will be calculated based on the maximum time value (in ms) and samplingRate

thisIsPitch

(boolean) is this a pitch contour? If true, log-transforms before smoothing and plots in both Hz and musical notation

method

smoothing method: 'spline' or 'loess' (default). Consider 'spline' if you have a lot of anchors and not much patience, since it is much faster than 'loess', but it may produce weird results when there are only a few anchors

valueFloor, valueCeiling

lower/upper bounds for the contour

plot

(boolean) produce a plot?

main, xlim, ylim

plotting options

samplingRate

sampling rate used to convert time values to points (Hz)

voiced, contourLabel

graphical pars for plotting breathing contours (see examples below)

...

other plotting options passed to plot()

Value

Returns a numeric vector.

Examples

Run this code
# NOT RUN {
a = getSmoothContour(anchors = data.frame(
  time = c(50, 137, 300), value = c(0.03, 0.78, 0.5)),
  voiced = 200, valueFloor = 0, plot = TRUE, main = '',
  samplingRate = 16000) # breathing

a = getSmoothContour(anchors = data.frame(
  time = c(0, .1), value = c(350, 800)),
  len = 5500, thisIsPitch = TRUE, plot = TRUE,
  samplingRate = 3500) # pitch

# a single anchor gives constant pitch
a = getSmoothContour(anchors = data.frame(time = 0, value = 800),
  len = 500, thisIsPitch = TRUE, plot = TRUE, samplingRate = 500)

# two anchors give loglinear pitch change
a = getSmoothContour(anchors = data.frame(
  time = c(0, 1), value = c(220, 440)),
  len = 500, thisIsPitch = TRUE, plot = TRUE, samplingRate = 500)
# }

Run the code above in your browser using DataLab