• Keine Ergebnisse gefunden

A handful of attributes are common to all musical notes: pitch, loudness, begin time, and duration. Special methods and values are used to set the parameters that represent these attributes, as explained in the following sections.

Frequency and Pitch

Frequency and pitch are two terms that refer to the most fundamental aspect of a musical sound: its register or tonal height. Frequency is the exact measurement of the periodicity of an acoustical waveform expressed in hertz. Pitch, on the other hand, is an inexact representation expressed in musical names such as F sharp, A flat, or G natural.

When the DSP synthesizes a musical note, it produces a tone at a specified frequency.

However, musicians think in terms of pitch. To bridge the gap between frequency and pitch, the Music Kit defines sets of pitch variables and key numbers that represent particular frequencies.

3-8 Chapter 3: Representing Music Data

Pitch Variables

A pitch variable takes the following form:

pitchLetter[sharpOrFlat] octave

pitchLetter is a lowercase letter from a to g. As in standard music notation, the Music Kit's pitch variables are organized within an octave such that c is the lowest pitch and b is the highest.

The optional sharpOrFlat is s for sharp and ffor flat. They raise or lower by a semitone the pitch indicated by pitchLetter.

octave is 00 or an integer from 0 to 9. The octave component of the pitch name variable places the pitch class within a particular octave, where 00 is the lowest octave and 9 is the highest. Octaves are numbered such that c4 is middle C.

Some examples of pitch variables are:

Pitch Variable ef4 gs3 fOO

Pitch

E flat above middle C G sharp below middle C

F natural in the fifth octave below middle C

bs8 B sharp five octaves above middle C (the same as c9)

Notice that the natural sign isn't represented in the pitch variables. If neither the sharp nor the flat sign is present, the pitch is automatically natural. In addition, key signatures aren't represented; the accidentals that define a key must be present in each pitch that they affect.

Correspondence Between Pitch Variables and Frequencies

Each pitch variable represents a predefined frequency. By default, the frequencies that correspond to the pitch variables define a twelve-tone equal-tempered tuning system, with a4 equal to 440.0 Hz:

• Twelve-tone means that there are twelve discrete tones within an octave.

• Equal-tempered means that the frequency ratio between any pair of successive tones is always the same.

This is the tuning system used to tune modern fixed-pitch instruments, most notably the piano. The complete table of pitch variables and the corresponding default frequencies is given in Appendix B of Reference.

The Note Class 3-9

Key Numbers

Another way to specify the pitch is to use a key number. Key numbers are integers that correspond to the keys of a MIDI keyboard. As a MIDI standard, 60 is the key number for the middle C of the keyboard. The Music Kit provides constants to represent key numbers.

The form of these constants is like that of the pitch variables, but with the letter k appended;

for example:

Key numbers are provided primarily to accommodate MIDI instruments. If you record a MIDI performance (using a Midi object), the pitch specifications will all be represented as key numbers. When you realize Notes on a MIDI synthesizer, the actual frequency represented by a particular key number is controlled by the synthesizer itself. The standard of "60 equals middle C" simply means that key number 60 creates a tone at whatever frequency the synthesizer'S middle C key is tuned to produce.

Specifying Pitch in a Note

You can specify the pitch of Note objects as a frequency or pitch variable (a double), or as a key number (an int). These are represented by the parameter tags MK_freq and MK keyNum. Regardless of how it's synthesized (on the DSP or on a MIDI instrument), the appropriate value is converted from whichever parameter is present.

To set a Note's pitch, you use the methods described earlier:

/* You must import this file when using pitch variables. */

#import <musickit/pitches.h>

/* Set the Note's pitch to middle C as a frequency. */

[aNote setPar:MK_freq toDouble:26l.625];

/* The same using a pitch variable. */

[aNote setPar:MK_freq toDouble:c4];

/* And as a key number. */

[aNote setPar:MK_keyNum toDouble:c4k];

The conversion between frequencies or pitch variables and key numbers allows you to create Note objects that can be played on both the DSP and on a MIDI instrument using the same pitch parameter.

3-10 Chapter 3: Representing Music Data

Retrieving Pitch from a Note

Special methods are provided to retrieve pitch:

freq: returns a double value as a frequency.

keyNum: returns an iot as a key number.

If the MK _ freq parameter isn't present but MK _key N urn is, the freq: method returns a frequency value converted from the MK _ keyNum parameter. Similarly, keyNum: returns a key number value converted from MK Jreq in the absence of MK _ keyNum.

The Music Kit SynthPatches use freq: to retrieve pitch information; Midi uses keyNum:.

Keep in mind that either retrieval method converts a value from the opposite parameter only if its own parameter isn't set. In addition, you can set MK _freq and MK _ keyNum independently of each other: Setting one doesn't reset the other.

Since frequencies are continuous and key numbers are discrete, the correspondence between them isn't exact; conversion from frequency to key number sometimes requires approximation. The pitch table in Appendix B of Reference gives the frequency range that corresponds to particular key numbers (in the default tuning system).

Loudness

The perceived loudness of a musical note depends on a number of factors, the most important being the amplitude of the waveform and its spectral energy, or brightness. All the Music Kit SynthPatches use the amplitude parameter, MK _amp; most also use MK _bright, the brightness parameter.

Amplitude

Amplitude is fairly straightforward: The value of the amplitude parameter determines the strength of the signal produced by the DSP. The value of MK _amp is retrieved as a double. Its value must be between 0.0 and 1.0, where 0.0 is inaudibly soft and 1.0 is a fully saturated signal. Perceived amplitude increases logarithmically: Successive Notes with incrementally increasing amplitude values are perceived to get louder by successively smaller amounts. For instance, the difference in loudness between amplitudes of 0.1 and 0.2 sounds much greater than the difference between 0.8 and 0.9.

The Note Class 3-11

Amplitude is set and retrieved through the normal methods; for example:

/* Set the amplitude of a Note. */

[aNote setPar:MK_amp toDouble:O.2];

/* Retrieve amplitude. */

double myAmp = [aNote parAsDouble:MK_amp];

/* Set the amplitude of a Note. */

[aNote setPar:MK_amp toDouble:MKdB(-15.0)];

The range ofthe decibel scale extends from negative infinity (inaudible) to 0.0 (maximally loud). Decibel scaling creates a linear correspondence between increasing value and perceived loudness: The perceived increase in loudness from -20.0 to -15.0 is the same as that from -15.0 to -10.0 (as well as from -10.0 to -5.0 and from -5.0 to 0.0).

Brightness

Brightness can be thought of as a tone control. The greater the value of MK _bright, the brighter the synthesized sound. As you decrease brightness, the sound becomes darker.

MK _bright is used differently by the various SynthPatch subclasses; usually it's used to modify the values of other timbre-related parameters. Some SynthPatches, such as those that perform WaveTable synthesis, don't use MK _bright at all.

Brightness values are usually set and retrieved through setPar:toDouble: and

par AsDouble: (the Music Kit SynthPatches always retrieve the value of MK _bright as a double). The range of valid brightness values is, in general, 0.0 to 1.0; you can actually set MK _bright to a value in excess of 1.0, although this may cause distortion in some SynthPatches. Specifying brightness in decibels is possible, but the scale tends to have less meaning here than it does for amplitude.