Previous Book Contents Book Index Next

Inside Macintosh: Sound /
Chapter 2 - Sound Manager / Sound Manager Reference
Data Structures


Legacy Documentclose button

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. The SoundHeader 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 to NIL. 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 both loopStart and loopEnd 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}
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. The baseFrequency value allows the Sound Manager to calculate the proper playback rate of the sample when an application uses the freqDurationCmd command. Applications should not alter the baseFrequency field of a sampled sound; to play the sample at different pitches, use freqDurationCmd or freqCmd.
sampleArea
If the value of samplePtr is NIL, 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 the length parameter.
If you need to create a sound header for sampled-sound data that your application has recorded, then you should use the SetupSndHeader function, described in the chapter "Sound Input Manager" in this book.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996