Learn R Programming

audio (version 0.1-11)

audioSample: Audio sample class and constructor

Description

audioSample is a class encapsulating digitalized (sampled) audio data. Essentiually it tags numeric vectors and matrices with additional audio information (most importantly sample rate).

audioSample is the designated constructor of such objects.

Instances of the audioSample are numeric vectors or matrices with the following additional attributes:

  • ratesample rate (in Hz), mandatory

  • bitsresolution of the source (in bits), optional

If the object itself is a vector, it contains only one channel. Otherwise it is a matrix with as many rows as there are channels (hence 2 for stereo).

as.audioSample generic converts an object into an audio sample object. The default method is very similar to the constructor except that it attempts to infer the parameters from the object's attributes if they are not specified. Thus they are optional although they don't have visible defaults.

Usage

audioSample(x, rate=44100, bits=16, clip = TRUE)
  as.audioSample(x, ...)
  # S3 method for default
as.audioSample(x, rate, bits, clip, ...)
  # S3 method for Sample
as.audioSample(x, ...)

Value

audioSample and as.audioSample return an audio sample object.

Arguments

x

object to convert or initilize with

rate

sample rate

bits

resolution of the source. It doesn't affect the data itself and is only used for playback and export.

clip

boolean value determining whether the source should be clipped to a range between -1 and 1. Values outside this range result in undefined behavior.

...

parameters passed to the object-specific method

Examples

Run this code
x <- audioSample(sin(1:8000/10), 8000)
# \donttest{
play(x)
# }

Run the code above in your browser using DataLab