MusicKit  0.0.0
MKSamples Class Reference

A MKSamples object represents one complete cycle of a sound waveform as a series of samples. More...

#include <MKSamples.h>


Detailed Description

A MKSamples object represents one complete cycle of a sound waveform as a series of samples.

The data for a MKSamples object is established through association with a Snd object, defined by the SndKit. Two methods are provided to create this association:

The Snd object or soundfile must be one channel of 16-bit linear data (SND_FORMAT_LINEAR_16). The sampling rate is ignored; MKSamples objects are designed to be used as lookup tables for oscillator MKUnitGenerators in which use the sampling rate of the original data is of no consequence.

You can create a MKSamples object from a scorefile by quoting the name of a soundfile within curly brackets which are themselves enclosed by square brackets. The object can be given a name in a waveTable statement:

waveTable mySamples = [ {"samplesFile.snd" }];

A MKSamples object that's written to a soundfile is referred to by the name of the soundfile from which it was created. If a Snd object is used, a soundfile is created and the object is written to it, as explained in the method writeScorefileStream:. You should always name your MKSamples objects by calling the MKNameObject() C function.

MKSamples' sister class, MKPartials, lets you define a waveform by its sine wave components.

MKSamples objects are automatically created by the Music Kit in a number of circumstances, such as when reading a Scorefile. The function MKSetSamplesClass() allows you to specify that your own subclass of MKSamples be used when MKSamples objects are automatically created. You retrieve the MKSamples class with MKGetSamplesClass().

Note that most of the MusicKit DSP oscillators require tables to be of a length that is a power of 2. Note also that the length of a Sample load to the DSP is limited by the amount of DSP memory.

MKSamples can be used in two contexts - to provide wavetables for oscillators and to provide tables for periodic excitation table (PET) synthesis. The access methods inherited from the MKWaveTable class (such as -dataDSP) provide the data in oscillator table format. In this case the MKPartials tableTypeinternal instance varaible is set to MK_oscTable. Alternatively, you can retrieve the data in excitation table format. To do this, use one of the methods of the form accessMethodAsExcitationTablearguments. For example, to get the data for the DSP with the default table length and scaling, use -dataDSPAsExcitationTable. In this case the MKPartials tableType instance varaible is set to MK_excitationTable. For symmetry, a set of methods of the form dataDSPAsOscTable is provided. These methods are synonyms for the inherited methods.

Actually, excitationTable and oscTable formats are the same when the length requested is the same as the length of the Snd. However, the two behave differently when asked for a length that differs from the length of the Snd. For a excitationTable, samples are omitted from the end of the Snd (if the Snd is longer) or zeros are appended to the end of the Snd (if the Snd is shorter.) For an oscTable, if the requested length evenly divides the actualy length, the Snd is downsampled by simply omitting samples. Note that non-integer resampling is not currently supported.

See also:
MKWaveTable, MKPartials

The documentation for this class was generated from the following file: