PTSample-method {ProTrackR} | R Documentation |
Coerce to or replace PTSample
Description
This method will coerce a set of objects to a PTSample
object. It can also
be used to select specific samples from PTModule
objects and replace
the selected PTSample
.
Usage
## S4 method for signature 'Wave,missing'
PTSample(x)
## S4 method for signature 'raw,missing'
PTSample(x)
## S4 method for signature 'PTModule,numeric'
PTSample(x, index)
## S4 replacement method for signature 'PTModule,numeric,PTSample'
PTSample(x, index) <- value
Arguments
x |
Object (any of class |
index |
A positive |
value |
An object of |
Details
Method to coerce x
to class PTSample
.
When x
is a tuneR::Wave
object, this method will not
resample it. However, the sample rate will be adjusted and samples exeeding
the maximum length of 2*0xffff
= 131070
will be clipped to this
maximum length. When x
is a stereo sample, it will be converted to
mono, by averaging the left and right channel.
When x
is a vector
of raw
data, it will be truncated
if the maximum length of 2*0xffff
= 131070
is exceeded.
The raw will be converted with rawToSignedInt
in order
to represent an 8 bit mono waveform
.
As samples must have an even length (as per ProTracker specifications), a 0x00 value is appended if the length is odd.
When x
is of class PTModule
, the PTSample
at the
specified index
is returned, or will be replaced.
Value
When PTSample
is used, a PTSample
object
based on x
is returned.
When PTSample<-
is used, object x
is returned in which
the selected PTSample
is replaced with value
.
Author(s)
Pepijn de Vries
See Also
Other sample.operations:
PTSample-class
,
fineTune()
,
loopLength()
,
loopSample()
,
loopStart()
,
loopState()
,
name
,
playSample()
,
read.sample()
,
sampleLength()
,
volume()
,
waveform()
,
write.sample()
Examples
## Create a raw data sine wave:
raw_sine <- signedIntToRaw(round(sin(2*pi*(0:275)/276)*127))
data("mod.intro")
## Replace sample number 1 from mod.intro
## with the sine wave:
PTSample(mod.intro, 1) <-
PTSample(raw_sine)
## Note that the replacement above
## could also (maybe more efficiently)
## be done with the 'waveform' method
## Restore the loop in sample number 1:
loopLength(PTSample(mod.intro, 1)) <- 276