modToWave: Convert a PTModule object into an audio Wave object

modToWaveR Documentation

Convert a PTModule object into an audio Wave object

Description

Converts a PTModule object into a Wave object, which can be played, further analysed, modified and saved.

Usage

## S4 method for signature 'PTModule'
modToWave(
  mod,
  video = c("PAL", "NTSC"),
  target.rate = 44100,
  target.bit = 16,
  stereo.separation = 1,
  low.pass.filter = TRUE,
  tracks = 1:4,
  mix = TRUE,
  ...
)

Arguments

mod

An object of class PTModule

video

The video mode of a Commodore Amiga affects timing routines and the playback sample rate. This mode can be specified with this argument and is represented by a character string that can have either the value 'PAL' or 'NTSC'. PAL is used by default.

target.rate

A positive integer sample rate for the target Wave. Should be at least 2000. Default value is 44100 Hz, which is conform CD quality. 22050 Hz will also produce a decent sound quality and saves you some working memory.

target.bit

Number of bits for the target Wave. Should be a numeric value of either 8, 16, 24 or 32. Default is 16, which is conform CD quality (the quality doesn't really improve at higher bit values, as the original samples are of 8 bit quality).

stereo.separation

A numeric value between 0 and 1. When set to 1 (default), stereo channels (Amiga channels 1 and 4 on left, and channels 2 and 3 on right) are completely separated. When set to less than 1, stereo channels are mixed, where the number gives the fraction of separation of the channels. When set to 0, both channels are completely mixed and a mono Wave is returned.

low.pass.filter

A logical value indicating whether low pass filters should be applied when generating wave data. The Commodore Amiga had hardware audio filters. One (low pass 6 db/Oct tuned at 4.9 kHz) that filters all audio and one (low pass 12 db/Oct tuned at approximately 3.3 kHz) that can be turned on and off at will with effect command E00/E01 (see also ProTrackR documentation, section on effect commands). These filters are only applied when the low.pass.filter argument is set to TRUE and the target.rate is set to values > 4.9 kHz. If you don't want to simulate this typical Amiga sound, turn the filters off to save processing time.

tracks

Either logical or numeric values indicating which of the 4 PTTracks are to be converted. By default all 4 tracks are selected.

mix

A logical value indicating whether the 4 Amiga channels should be mixed to the 2 (stereo) output channels. When set to TRUE (default) a stereo Wave object is returned. When set to FALSE a multi-channel WaveMC object is returned. The stereo.separation argument is ignored in the latter case.

...

Additional arguments that are passed to playingtable.

Details

Before the PTModule object can be converted into a Wave object, the rows of the PTPattern objects in the module need to be put in the right order. This method does that by calling playingtable.

Once the rows of the pattern tables are in the right order, all selected PTTrack objects of the module are looped by this function and the routines described below are applied to each track.

On the Commodore Amiga the chip responsible for audio output (Paula), the audio playback of samples can be controlled by the user in two ways: the playback rate of the sample can be changed by specifying ‘period’ values (see e.g. periodToSampleRate) and specifying a volume which is linearly scaled between 0 (silent) and 64 (maximum).

So, for each track, the correct period and volume values are determined based on the note, effect command and sample information in the module.

Then, the PTSample objects are resampled, using the period values and volume values as determined in the previous step.

Next audio filters are applied to mimic original Commodore Amiga sound. Finaly, the wave data for each separate track is mixed to one (mono) or two (stereo) of the output channels.

Converting ProTracker modules into wave objects can be time consuming. The time required to convert an object obviously depends on your machine's capacities and the length of the module but also the complexity of the module. To speed up the conversion you could reduce the target sample rate or turn off the low pass filter. On modern machines, the time required for conversion should generally be less than the playback time of the module.

You can save the resulting Wave object by calling writeWave.

Value

A Wave object, generated from the mod object is returned. A WaveMC object is returned when the mix argument is set to FALSE.

Note

As audio can be mixed with this package at frequencies much greater than the Commodore Amiga's audio output rate, some aliasing of the sound could occur. This results in high frequency audio, that would not be produced on an Amiga. The current version of this package does not filter out these artefacts. This should not be a problem if you're not concerned with producing an accurate Amiga timbre.

Author(s)

Pepijn de Vries

See Also

Other module.operations: PTModule-class, appendPattern(), clearSamples(), clearSong(), deletePattern(), fix.PTModule(), moduleSize(), patternLength(), patternOrderLength(), patternOrder(), playMod(), playingtable(), rawToPTModule(), read.module(), trackerFlag(), write.module()

Examples

## Not run: 
data(mod.intro)
wav <- modToWave(mod.intro)

## End(Not run)

ProTrackR documentation built on Aug. 23, 2023, 1:07 a.m.