Skip to contents

Method to play PTSamples or all such samples from PTModule objects as audio.

Usage

# S4 method for PTSample
playSample(x, silence = 0, wait = T, note = "C-3", loop = 1, ...)

# S4 method for PTModule
playSample(x, silence = 0, wait = T, note = "C-3", loop = 1, ...)

Arguments

x

Either a PTSample or a PTModule object. In the latter case, all samples in the module will be played in order.

silence

Especially for short samples, the audio::play routine can be a bit buggy: playing audible noise, ticks or parts from other samples at the end of the sample. By adding silence after the sample, this problem is evaded. Use this argument to specify the duration of this silence in seconds. When, x is a PTModule object, the silence will also be inserted in between samples.

wait

A logical value. When set to TRUE the playing routine will wait with executing any code until the playing is finished. When set to FALSE, subsequent R code will be executed while playing.

note

A character string specifying the note to be used for calculating the playback sample rate (using noteToSampleRate). It should start with the note (ranging from A' up to G') optionally followed by a hash sign (#') if a note is sharp (or a dash (-') if it's not) and finally the octave number (ranging from 1 up to 3). A valid notation would for instance be 'F#3'. The fineTune as specified for the sample will also be used as an argument for calculating the playback rate. A custom finetune can also be passed as an argument to noteToSampleRate.

loop

A positive numeric indicating the duration of a looped sample in seconds. A looped sample will be played at least once, even if the specified duration is less than the sum of loopStart position and the loopLength. See loopStart and loopLength for details on how to set (or disable) a loop.

...

Further arguments passed on to noteToSampleRate. Can be used to change the video mode, or finetune argument for the call to that method.

Value

Returns nothing but plays the sample(s) as audio.

Details

This method plays PTSamples and such samples from PTModule objects, using the audio::play method from the audio package. Default fineTune and volume as specified for the PTSample will be applied when playing the sample.

See also

Other sample.operations: PTSample-class, PTSample-method, fineTune(), loopLength(), loopSample(), loopStart(), loopState(), name, read.sample(), sampleLength(), volume(), waveform(), write.sample()

Other sample.rate.operations: sampleRate

Other play.audio.routines: playMod(), playWave()

Author

Pepijn de Vries

Examples

if (FALSE) {
data("mod.intro")

## play all samples in mod.intro:
playSample(mod.intro, 0.2, loop = 0.5)

## play a chromatic scale using sample number 3:
for (note in c("A-2", "A#2", "B-2", "C-3", "C#3",
               "D-3", "D#3", "E-3", "F-3", "F#3",
               "G-3", "G#3"))
{
  playSample(PTSample(mod.intro, 3), note = note, silence = 0.05, loop = 0.4)
}

## play the sample at a rate based on a specific
## video mode and finetune:
playSample(PTSample(mod.intro, 3), video = "NTSC", finetune = -5)
}