Ops.Sample: Basic Operations for Sample Objects

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/sound.R

Description

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

Usage

1
2
3
4
5
6
7
8
e1 + e2
## S3 method for class 'Sample'
Ops(e1,e2)
e1 - e2
## S3 method for class 'Sample'
sum(e1, e2, ...)
## S3 method for class 'Sample'
prod(e1, e2, ...)

Arguments

e1, e2, ...

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

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.

Value

a Sample object.

Author(s)

Author: Matthias Heymann <mail@MatthiasHeymann.de>

Maintainer: Stefan Langenberg <langenberg@uni-bonn.de>

See Also

normalize, center

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
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


## End(Not run)

sound documentation built on May 2, 2019, 2:10 a.m.

Related to Ops.Sample in sound...