• Keine Ergebnisse gefunden

WaveTable objects are used exclusively in DSP synthesis to describe and create musical timbres. While Wave Table synthesis has limitations, it's a particularly easy and direct way to create a library of sounds. However, to intelligently define a Wave Table, you need to be familiar with a few basic concepts of musical acoustics. The section "What is Sound?" in Chapter 2 introduces some of these fundamentals; the cogent points from Chapter 2 are summarized and new concepts that pertain to WaveTables are introduced in the next section.

Summary of Musical Acoustics

When matter vibrates, a pressure disturbance is created in the surrounding air. The pressure disturbance travels as a wave to your ears and you hear a sound. A sound, particularly if it's a musical sound, can be characterized by its waveform, the shape of the air pressure's rise and fall. Waveforms created by musical instruments are generally periodic; this means that the pressure rises and falls in a cyclical pattern.

The Note Class 3-31

A periodic waveform has two basic characteristics, frequency and amplitude:

• The number of pattern repetitions, or periods, within a given amount of time determines a sound's frequency (pitch). Frequency is measured in hertz (abbreviated Hz), or cycles per second. For example, a musical sound with a period that repeats itself 440 times a second produces a tone at 440 Hz (A above middle C).

• The amplitude of a sound wave is the amount of energy in the air pressure disturbance.

Amplitude is heard as loudness-the greater the energy, the louder the sound. (There are other factors that contribute to the loudness of a sound, but amplitude is generally the most important.) A number of different methods are used to measure loudness; of greatest use for musical purposes is to describe the loudness of a sound (or, as we shall see, a component of a sound) in comparison with another sound (or sound component).

A special waveform is the sine wave: Sine waves are important to musical acoustics in that they define the basic component used to describe musical sounds: Any periodic waveform can be broken down into one or more sine waves. The sine waves that make up a musical sound have frequencies that are (usually) integer multiples of a basic frequency called the fundamental. For example, if you pluck the B string on a guitar, it produces a fundamental

frequency of approximately 494 Hz. However, the sound that's produced contains sine waves with frequencies that are integer multiples of 494:

494

*

1

=

494 494

*

2

=

988

494

*

3

=

1482 494

*

4

=

1976

and so on

Sine wave components, or partials, that are related to each other as integer multiples of a fundamental frequency are said to make up a harmonic series. A musical sound can also have partials that are inharmonically related to the fundamental; for example, the shimmer and pungency of a bell's tone is created by the abundance of inharmonic partials. However, as explained later, a WaveTable object is best suited to represent timbres that are created from a harmonic series.

The partials in a sound have amplitudes that are measured in relation to each other. For the guitar, the amplitude of each successive sine wave is generally less than that of the previous partial.

The fundamental (the partial at the fundamental frequency) needn't have the greatest amplitUde of all the partials, nor must successive partials decrease in amplitude. Some instruments, such as the bassoon, have very little energy at the fundamental. Nonetheless, your ears decode the information in a harmonic series such that there is rarely confusion about the frequency of the fundamental; in other words, we almost always hear the fundamental as the frequency that's the least common denominator of the partials that make up the sound.

3-32 Chapter 3: Representing Music Data

Constructing a Wave Table

A Wave Table object represents one complete period of a musical waveform. There are two ways to create a WaveTable, as embodied by WaveTable's subclasses, Partials and Samples:

With a Partials object, you can define a WaveTable by specifying the individual partials that make up the waveform.

• A Samples object represents a waveform as a series of sound samples. It uses a Sound object (defined by the Sound Kit) as its data.

The Partials Class

You define a Partials object by supplying the frequency, amplitude, and phase information for a series of partials. This is done through the method

setPartiaICount:freqRatios:ampRatios:phases:orDefauItPhase:. The first argument is the number of partials; the next three arguments are arrays of double data that specify the frequency ratios, amplitude ratios, and initial phases of the partials, respectively. You can also set the phase as a constant by passing a double as the argument to the orDefaultPhase:

keyword. In this case, you must pass NULL as the argument to phases:.

In the following example, a waveform is created from a series of partials that are integer multiples of a fundamental frequency; the partials decrease in amplitude as they increase in frequency.

/* Create the Partials object. */

id aPartials = [Partials new];

double freqs[] = {1.O,2.0,3.0,4.0,5.0,6.0};

double amps[] = {1.O,O.5,O.25,O.12,O.06,O.03};

/* Fill the object with data. */

Note: Phase is generally unimportant in creating musical timbres, although it can

drastically affect a waveform that's used as a low-frequency control signal, such as vibrato.

The frequencies in a Partials object are specified as ratios, or multiples, of a fundamental frequency (the fundamental is represented by a frequency ratio of 1.0). The actual (fundamental) frequency of the waveform created from a Partials depends on the how the object is used by the SynthPatch that synthesizes it. In general, the waveform is

"transposed" to produce the frequency specified in a Note's frequency parameter, MK_freq. Similarly, the amplitude of each partial is relative to the value of another parameter, usually MK_amp.

The Note Class 3-33

The Samples Class

The Samples class lets you create a WaveTable through association with a Sound object (an instance of the Sound Kit's Sound class). This is done by invoking the Samples' setSound:

method:

/* You must import the Sound Kit's header file. */

#import <soundkit/soundkit.h>

/* Create a Samples object and a Sound object. */

id aSamples = [Samples new];

id aSound = [Sound new];

/* Fill the Sound with data. */

/* Associate the Sound with the Samples. */

[aSamples setSound:aSound];

A copy of the Sound object is created and stored in the Samples object when setSound: is invoked, so it's important that you fill the Sound with data before invoking the method.

Chapter 2 describes ways to create Sound data.

You can also associate a Samples with a Sound by reading a soundfile, through the readSoundfile: method. The Samples object creates a Sound object and then reads the soundfile by sending newFromSoundfile: to the Sound. The argument is a UNIX pathname that must include the soundfile-identifying ".snd" extension.

A Samples' Sound object must contain one channel of 16-bit linear, sampled data. The length of the data (the number of samples) must be a power of two.

Setting a Wave Table in a Note

To hear the timbre represented by a WaveTable object, you set the Wave Table as a parameter of a Note and then play the Note using a SynthPatch that recognizes the

parameter. Most of the Music Kit SynthPatches recognize the MK _waveform parameter:

/* Create a Note. */

id aNote [Note new];

/* Set its MK waveform value. */

[aNote setPar:MK_waveform toWaveTable:aPartials];

In this example, the value of MK _waveform is set to the previously defined Partials object, aPartials. The manner in which the Partials object is used during synthesis depends on the SynthPatch to which the Note is sent.

3-34 Chapter 3: Representing Music Data