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 tuneR::Wave, a vector of raw data, or of class PTModule) that needs to be coerced to a PTSample object. In the latter case, the object can also be replaced.

index

A positive integer index of the sample in PTModule x that needs to be returned or replaced.

value

An object of PTSample with which the PTSample object at the specified index in object x needs to be replaced.

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


[Package ProTrackR version 0.4.3 Index]