R/data2Wave.R

Defines functions data2Wave

Documented in data2Wave

#' Convert data into a Wave object
#'
#' Make a sequence of data into a normalised Wave object.
#'
#' @param left Data for  audio channel
#' @param samp.rate Sampling rate for Wave object
#' @param bit Bit depth of Wave object
#' @param remove.offset If TRUE any DC offset is removed
#' @param normalise IF TRUE the output Wave is normalised using tuneR
#' @return A mono Wave object.
#' @examples
#' pattern <- seq(from=-1, to=1, length.out=100)
#' data <- rep.int(pattern, 100)
#' w <- data2Wave(data)
#' @export
#'
data2Wave <- function(left, samp.rate=44100, bit=16, remove.offset=TRUE, normalise=TRUE) {
  if (!is.numeric(left)) {
    stop("Data must be numeric.")
  }
  if (remove.offset == TRUE) {
    a <- mean(left)
    left <- left-a
  }
  wave <- tuneR::Wave(left=left, right = numeric(0), samp.rate=samp.rate, bit=bit)
  if (normalise == TRUE) {
    wave <- tuneR::normalize(wave)
  }
  return(wave)
}

Try the sonicscrewdriver package in your browser

Any scripts or data that you put into this service are public.

sonicscrewdriver documentation built on May 2, 2021, 5:06 p.m.