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.
Arguments
- x
Object (any of class
tuneR::Wave, avectorofrawdata, or of classPTModule) that needs to be coerced to aPTSampleobject. In the latter case, the object can also be replaced.- index
A positive
integerindex of the sample inPTModulexthat needs to be returned or replaced.- value
An object of
PTSamplewith which thePTSampleobject at the specifiedindexin objectxneeds to 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.
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 exceeding
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.
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