sound (version 1.4.5)

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)

Value

For sampleLength, the number of columns in the waveform matrix of the sample.

For setSampleLength, a Sample object with the new length.

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).

Author

Author: tools:::Rd_package_author("sound")

Maintainer: tools:::Rd_package_maintainer("sound")

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
if (FALSE) {
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