Important: Inside Macintosh: Sound is deprecated as of Mac OS X v10.5. For new audio development in Mac OS X, use Core Audio. See the Audio page in the ADC Reference Library.
Sound Header Records
Sound resources often contain sampled-sound data as well as sound commands. The sound data is contained in the last field of the sound header. You can access a sound header record to find information about sampled-sound data. The standard sound header is used only for simple monophonic sounds. TheSoundHeader
data type defines a sampled sound header record.
TYPE SoundHeader = PACKED RECORD samplePtr: Ptr; {if NIL, samples in sampleArea} length: LongInt; {number of samples in array} sampleRate: Fixed; {sample rate} loopStart: LongInt; {loop point beginning} loopEnd: LongInt; {loop point ending} encode: Byte; {sample's encoding option} baseFrequency: Byte; {base frequency of sample} sampleArea: PACKED ARRAY[0..0] OF Byte; END;
Field Description
samplePtr
- A pointer to the sampled-sound data. If the sampled sound is located in memory immediately after the
baseFrequency
field, then this field should be set toNIL
. Otherwise, this field is a pointer to the memory location of the sampled-sound data. (This might be useful if you want to change some fields of a sound header but do not want to modify a handle to a sound resource directly.)length
- The number of bytes of sound data.
sampleRate
- The rate at which the sample was originally recorded. The Sound Manager can play sounds sampled at any rate up to 64 kHz. The values corresponding to the three most common sample rates (11 kHz, 22 kHz, and 44 kHz) are defined by constants:
CONST rate44khz = $AC440000; {44100.00000 Fixed} rate22khz = $56EE8BA3; {22254.54545 Fixed} rate11khz = $2B7745D1; {11127.27273 Fixed}
- Note that the sample rate is declared as a
Fixed
data type, but the most significant bit is not treated as a sign bit; instead, that bit is interpreted as having the value 32,768.loopStart
- The starting point of the portion of the sampled sound header that is to be used by the Sound Manager when determining the duration of
freqDurationCmd
. These loop points specify the byte numbers in the sampled data to be used as the beginning and end points to cycle through when playing the sound. The loop starting and ending points are 0-based.loopEnd
- The end point of the portion of the sampled sound header that is to be used by the Sound Manager when determining the duration of
freqDurationCmd
. If no looping is desired, set bothloopStart
andloopEnd
to 0.encode
- The method of encoding used to generate the sampled-sound data. The current encoding option values are
CONST stdSH = $00; {standard sound header} extSH = $FF; {extended sound header} cmpSH = $FE; {compressed sound header}If you need to create a sound header for sampled-sound data that your application has recorded, then you should use the
- For a standard sound header, you should specify the constant
stdSH
. Encode option values in the ranges 0 through 63 and 128 to 255 are reserved for use by Apple. You are free to use numbers in the range 64 through 127 for your own encode options.baseFrequency
- The pitch at which the original sample was taken. This value must be in the range 1 through 127. Table 2-2 on page 2-43 lists the possible
baseFrequency
values. ThebaseFrequency
value allows the Sound Manager to calculate the proper playback rate of the sample when an application uses thefreqDurationCmd
command. Applications should not alter thebaseFrequency
field of a sampled sound; to play the sample at different pitches, usefreqDurationCmd
orfreqCmd
.sampleArea
- If the value of
samplePtr
isNIL
, this field is an array of bytes, each of which contains a value similar to the values in a wave-table description. These values are interpreted as offset values, where $80 represents an amplitude of 0. The value $00 is the most negative amplitude, and $FF is the largest positive amplitude. The samples are numbered 1 through the value in thelength
parameter.SetupSndHeader
function, described in the chapter "Sound Input Manager" in this book.