Learn R Programming

sound (version 1.4.6)

Ops.Sample: Basic Operations for Sample Objects

Description

These functions apply the basic operations pointwise to the waveforms of the samples.

Usage

e1 + e2
# S3 method for Sample
Ops(e1,e2)
e1 - e2
# S3 method for Sample
sum(e1, e2, ...)
# S3 method for Sample
prod(e1, e2, ...)

Value

a Sample object.

Arguments

e1, e2, ...

For +,-,*,/, Sample objects. For prod.Sample and sum.Sample, Sample objects or strings giving the names of wav files.

Author

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

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

Details

The sum of two Sample objects corresponds to the sound when both samples are played at a time. The product of two samples causes an effect called ringmodulation, but it can also be used to add some vibrato to a sound (see the examples).

If the samples have different sample parameters (bits, rate and channels), the system uses the command fitSampleParameters to adjust them before the waveforms are combined.

Be careful to make sure that the resulting waveform does not exceed the interval [-1,1] when it is played or saved to disk, otherwise you will lose information and hear cracks in the sound. To avoid this, you can use const * s or the normalize command.

In prod and sum also the names of wavefiles can be used. Other forms like e1+e2 do not accept filenames as arguments. If the first argument e1 is a filename, the explicit forms sum.Sample and prod.Sample must be used.

See Also

normalize, center

Examples

Run this code
if (FALSE) {
const <- 2.0
e1 <- Sine(440,1)
e2 <- Sine(220,1)
play((e1+e2)/2) # both samples at a time
play(Sine(440,1)*Sine(5,1)) # vibrato

e1 * e2
const * e1
e1 * const
e2 / const

}

Run the code above in your browser using DataLab