Learn R Programming

sound (version 1.1)

sampleLength: Length of a Sample Object

Description

Get or set the length (number of columns in the waveform matrix) of a Sample object or a wav file.

Usage

sampleLength(s)
sampleLength(s) <- value
setSampleLength(s,value)

Arguments

s
a Sample object, or a string giving the name of a wav file.
value
an integer giving the sample length (number of columns in the waveform matrix).

Value

  • For sampleLength, the number of columns in the waveform matrix of the sample. For setSampleLength, a Sample object with the new length.

Details

The replacement form can be used to reset the sample length (here, filenames are not accepted). If a Sample object is shortened, extra values are discarded. When a Sample object is lengthened, it is padded out to its new length with zeros (silence).

See Also

duration

Examples

Run this code
s <- Sine(440,3,rate=44100,bits=16,channels=2)
sampleLength(s)  # 132300 samples ( = 3 sec * 44100 samples/sec )
sampleLength(s) <- 22050  # sample is now .5 sec long
play(setSampleLength(s,44100)) # plays a .5 sec sine wave and then .5 sec silence

Run the code above in your browser using DataLab