Previous Book Contents Book Index Next

Inside Macintosh: Sound /
Chapter 2 - Sound Manager


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.

Summary of the Sound Manager

Pascal Summary

Constants

CONST
   {Gestalt sound attributes selector and response bits}
   gestaltSoundAttr           = 'snd ';{sound attributes selector}
   gestaltStereoCapability    = 0;     {built-in hw can play stereo sounds}
   gestaltStereoMixing        = 1;     {built-in hw mixes stereo to mono}
   gestaltSoundIOMgrPresent   = 3;     {sound input routines available}
   gestaltBuiltInSoundInput   = 4;     {built-in input hw available}
   gestaltHasSoundInputDevice = 5;     {sound input device available}
   gestaltPlayAndRecord       = 6;     {built-in hw can play while recording}
   gestalt16BitSoundIO        = 7;     {built-in hw can handle 16-bit data}
   gestaltStereoInput         = 8;     {built-in hw can record stereo sounds}
   gestaltLineLevelInput      = 9;     {built-in input hw needs line level}
   gestaltSndPlayDoubleBuffer = 10;    {play from disk routines available}
   gestaltMultiChannels       = 11;    {multiple channels of sound supported}
   gestalt16BitAudioSupport   = 12;    {16-bit audio data supported}
   
   {channel initialization parameters}
   initChanLeft               = $0002; {left stereo channel}
   initChanRight              = $0003; {right stereo channel}
   waveInitChannel0           = $0004; {wave-table channel 0}
   waveInitChannel1           = $0005; {wave-table channel 1}
   waveInitChanne12           = $0006; {wave-table channel 2}
   waveInitChannel3           = $0007; {wave-table channel 3}
   initMono                   = $0080; {monophonic channel}
   initStereo                 = $00C0; {stereo channel}
   initMACE3                  = $0300; {3:1 compression}
   initMACE6                  = $0400; {6:1 compression}
   initNoInterp               = $0004; {no linear interpolation}
   initNoDrop                 = $0008; {no drop-sample conversion}
   
   {masks for channel attributes}
   initPanMask             = $0003;    {mask for right/left pan values}
   initSRateMask           = $0030;    {mask for sample rate values}
   initStereoMask          = $00C0;    {mask for mono/stereo values}
   initCompMask            = $FF00;    {mask for compression IDs}
   {sound data types}
   squareWaveSynth         = 1;        {square-wave data}
   waveTableSynth          = 3;        {wave-table data}
   sampledSynth            = 5;        {sampled-sound data}
   
   {sound command numbers}
   nullCmd                 = 0;        {do nothing}
   quietCmd                = 3;        {stop a sound that is playing}
   flushCmd                = 4;        {flush a sound channel}
   reInitCmd               = 5;        {reinitialize a sound channel}
   waitCmd                 = 10;       {suspend processing in a channel}
   pauseCmd                = 11;       {pause processing in a channel}
   resumeCmd               = 12;       {resume processing in a channel}
   callBackCmd             = 13;       {execute a callback procedure}
   syncCmd                 = 14;       {synchronize channels}
   availableCmd            = 24;       {see if initialization options }
                                       { are supported}
   versionCmd              = 25;       {determine version}
   totalLoadCmd            = 26;       {report total CPU load}
   loadCmd                 = 27;       {report CPU load for a new channel}
   freqDurationCmd         = 40;       {play a note for a duration}
   restCmd                 = 41;       {rest a channel for a duration}
   freqCmd                 = 42;       {change the pitch of a sound
   ampCmd                  = 43;       {change the amplitude of a sound}
   timbreCmd               = 44;       {change the timbre of a sound}
   getAmpCmd               = 45;       {get the amplitude of a sound}
   volumeCmd               = 46;       {set volume}
   getVolumeCmd            = 47;       {get volume}
   waveTableCmd            = 60;       {install a wave table as a voice}
   soundCmd                = 80;       {install a sampled sound as a voice}
   bufferCmd               = 81;       {play a sampled sound}
   rateCmd                 = 82;       {set the pitch of a sampled sound}
   getRateCmd              = 85;       {get the pitch of a sampled sound}
   
   {sampled sound header encoding options}
   stdSH                   = $00;      {standard sound header}
   extSH                   = $FF;      {extended sound header}
   cmpSH                   = $FE;      {compressed sound header}
   
   {size of data structures}
   stdQLength              = 128;      {default size of standard sound }
                                       { channel}
   
   {sound resource formats}
   firstSoundFormat        = $0001;    {format 1 'snd ' resource}
   secondSoundFormat       = $0002;    {format 2 'snd ' resource}
   {sound command mask}
   dataOffsetFlag          = $8000;    {sound command data offset bit}
   {system beep states}
   sysBeepDisable          = $0000;    {system alert sound disabled}
   sysBeepEnable           = $0001;    {system alert sound enabled}
   {values for the unitType field in AudioSelection}
   unitTypeSeconds         = $0000;    {seconds}
   unitTypeNoSelection     = $FFFF;    {no selection}
   
   {double buffer status flags}
   dbBufferReady           = $00000001;{double buffer is filled}
   dbLastBuffer            = $00000004;{last double buffer to play}
   {values for the compressionID field of CmpSoundHeader}
   variableCompression     = -2;       {variable-ratio compression}
   fixedCompression        = -1;       {fixed-ratio compression}
   notCompressed           = 0;        {noncompressed samples}
   threeToOne              = 3;        {3:1 compressed samples}
   sixToOne                = 4;        {6:1 compressed samples}
   
   {values for the packetSize field of CmpSoundHeader}
   sixToOnePacketSize      = 8;        {packet size in bits for 6:1}
   threeToOnePacketSize    = 16;       {packet size in bits for 3:1}
   
   {compression names and types}
   NoneName                = 'not compressed';
   ACE2to1Name             = 'ACE 2-to-1';
   ACE8to3Name             = 'ACE 8-to-3';
   MACE3to1Name            = 'MACE 3-to-1';
   MACE6to1Name            = 'MACE 6-to-1';
   NoneType                = 'NONE';
   ACE2Type                = 'ACE2';
   ACE8Type                = 'ACE8';
   MACE3Type               = 'MAC3';
   MACE6Type               = 'MAC6'
   
   {IDs for AIFF and AIFF-C files}
   AIFFID                  = 'AIFF';   {AIFF file}
   AIFCID                  = 'AIFC';   {AIFF-C file}
   
   {IDs for AIFF and AIFF-C file chunks}
   FormID                  = 'FORM';   {ID for Form Chunk}
   FormatVersionID         = 'FVER';   {ID for Format Version Chunk}
   CommonID                = 'COMM';   {ID for Common Chunk}
   SoundDataID             = 'SSND';   {ID for Sound Data Chunk}
   MarkerID                = 'MARK';   {ID for Marker Chunk}
   InstrumentID            = 'INST';   {ID for Instrument Chunk}
   MIDIDataID              = 'MIDI';   {ID for MIDI Data Chunk}
   AudioRecordingID        = 'AESD';   {ID for Recording Chunk}
   ApplicationSpecificID   = 'APPL';   {ID for Application Chunk}
   CommentID               = 'COMT';   {ID for Comment Chunk}
   NameID                  = 'NAME';   {ID for Name Chunk}
   AuthorID                = 'AUTH';   {ID for Author Chunk}
   CopyrightID             = '(c) ';   {ID for Copyright Chunk}
   AnnotationID            = 'ANNO';   {ID for Annotation Chunk}
   
   {version of AIFC format specification}
   AIFCVersion1            = $A2805140;{date of version creation}
   
   {MIDI note value for middle C}
   kMiddleC                = 60;
   
   {ratio between frequencies of MIDI note values}
   twelfthRootTwo          = 1.05946309434;
   
   {standard sampling rates}
   rate44khz               = $AC440000;   {44100.00000 in fixed-point}
   rate22khz               = $56EE8BA3;   {22254.54545 in fixed-point}
   rate22050hz             = $56220000;   {22050.00000 in fixed-point}
   rate11khz               = $2B7745D1;   {11127.27273 in fixed-point}
   rate11025hz             = $2B110000;   {11025.00000 in fixed-point}
   
   {constant for synth parameter of SndNewChannel}
   kUseOptionalOutputDevice      = -1;
   
   {volumes}
   kFullVolume                   = $0100;
   kNoVolume                     = 0;
   
   {development stages}
   developStage            = $20;         {prealpha release}
   alphaStage              = $40;         {alpha release}
   betaStage               = $60;         {beta release}
   finalStage              = $80;         {final release}
   
   {sizes of data buffers}
   stateBlockSize          = 64;          {size of state block buffer}
   leftOverBlockSize       = 32;          {size of leftover block buffer}

Data Types

Unsigned Fixed-Point Numbers

TYPE
   UnsignedFixed = LongInt;            {unsigned fixed-point number}

Times

TYPE
   Time = LongInt;                     {in half-milliseconds}

Sound Command Record

   SndCommand =
   PACKED RECORD
      cmd:              Integer;       {command number}
      param1:           Integer;       {first parameter}
      param2:           LongInt;       {second parameter}
   END;

Audio Selection Record

   AudioSelection = 
   PACKED RECORD
      unitType:         LongInt;       {type of time unit}
      selStart:         Fixed;         {starting point of selection}
      selEnd:           Fixed;         {ending point of selection}
   END;
   AudioSelectionPtr = ^AudioSelection;

Sound Channel Status Record

   SCStatus =
   RECORD
      scStartTime:         Fixed;      {starting time for play from disk}
      scEndTime:           Fixed;      {ending time for play from disk}
      scCurrentTime:       Fixed;      {current time for play from disk}
      scChannelBusy:       Boolean;    {TRUE if channel is processing cmds}
      scChannelDisposed:   Boolean;    {reserved}
      scChannelPaused:     Boolean;    {TRUE if play from disk is paused}
      scUnused:            Boolean;    {unused}
      scChannelAttributes: LongInt;    {attributes of this channel}
      scCPULoad:           LongInt;    {CPU load for this channel}
   END;
   SCStatusPtr = ^SCStatus;

Sound Manager Status Record

   SMStatus =
   PACKED RECORD
      smMaxCPULoad:     Integer;       {maximum load on all channels}
      smNumChannels:    Integer;       {number of allocated channels}
      smCurCPULoad:     Integer;       {current load on all channels}
   END;
   SMStatusPtr = ^SMStatus;

Sound Channel Record

   SndChannel =
   PACKED RECORD
      nextChan:         SndChannelPtr; {pointer to next channel}
      firstMod:         Ptr;           {used internally}
      callBack:         ProcPtr;       {pointer to callback procedure}
      userInfo:         LongInt;       {free for application's use}
      wait:             LongInt;       {used internally}
      cmdInProgress:    SndCommand;    {used internally}
      flags:            Integer;       {used internally}
      qLength:          Integer;       {used internally}
      qHead:            Integer;       {used internally}
      qTail:            Integer;       {used internally}
      queue:            ARRAY[0..stdQLength-1] OF SndCommand;
   END;
   SndChannelPtr = ^SndChannel;

Sound Header Record

   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;
   SoundHeaderPtr = ^SoundHeader;

Extended Sound Header Record

   ExtSoundHeader =
   PACKED RECORD
      samplePtr:        Ptr;           {if NIL, samples in sampleArea}
      numChannels:      LongInt;       {number of channels in sample}
      sampleRate:       Fixed;         {rate of original sample}
      loopStart:        LongInt;       {loop point beginning}
      loopEnd:          LongInt;       {loop point ending}
      encode:           Byte;          {sample's encoding option}
      baseFrequency:    Byte;          {base frequency of sample}
      numFrames:        LongInt;       {total number of frames}
      AIFFSampleRate:   Extended80;    {rate of original sample}
      markerChunk:      Ptr;           {reserved}
      instrumentChunks: Ptr;           {pointer to instrument info}
      AESRecording:     Ptr;           {pointer to audio info}
      sampleSize:       Integer;       {number of bits per sample}
      futureUse1:       Integer;       {reserved}
      futureUse2:       LongInt;       {reserved}
      futureUse3:       LongInt;       {reserved}
      futureUse4:       LongInt;       {reserved}
      sampleArea:       PACKED ARRAY[0..0] OF Byte;
   END;
   ExtSoundHeaderPtr = ^ExtSoundHeader;

Compressed Sound Header Record

   CmpSoundHeader =
   PACKED RECORD
      samplePtr:        Ptr;           {if NIL, samples in sampleArea}
      numChannels:      LongInt;       {number of channels in sample}
      sampleRate:       Fixed;         {rate of original sample}
      loopStart:        LongInt;       {loop point beginning}
      loopEnd:          LongInt;       {loop point ending}
      encode:           Byte;          {sample's encoding option}
      baseFrequency:    Byte;          {base freq. of original sample}
      numFrames:        LongInt;       {length of sample in frames}
      AIFFSampleRate:   Extended80;    {rate of original sample}
      markerChunk:      Ptr;           {reserved}
      format:           OSType;        {data format type}
      futureUse2:       LongInt;       {reserved}
      stateVars:        StateBlockPtr; {pointer to StateBlock}
      leftOverSamples:  LeftOverBlockPtr; 
                                       {pointer to LeftOverBlock}
      compressionID:    Integer;       {ID of compression algorithm}
      packetSize:       Integer;       {number of bits per packet}
      snthID:           Integer;       {unused}
      sampleSize:       Integer;       {bits in each sample point}
      sampleArea:       PACKED ARRAY[0..0] OF Byte;
   END;
   CmpSoundHeaderPtr = ^CmpSoundHeader;

Sound Double Buffer Header Record

   SndDoubleBufferHeader =
   PACKED RECORD
      dbhNumChannels:   Integer;       {number of sound channels}
      dbhSampleSize:    Integer;       {sample size, if noncompressed}
      dbhCompressionID: Integer;       {ID of compression algorithm}
      dbhPacketSize:    Integer;       {number of bits per packet}
      dbhSampleRate:    Fixed;         {sample rate}
      dbhBufferPtr:     ARRAY[0..1] OF SndDoubleBufferPtr;
                                       {pointers to SndDoubleBuffer}
      dbhDoubleBack:    ProcPtr;       {pointer to doubleback procedure}
   END;
   SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
   SndDoubleBufferHeader2 =
   PACKED RECORD
      dbhNumChannels:   Integer;       {number of sound channels}
      dbhSampleSize:    Integer;       {sample size, if noncompressed}
      dbhCompressionID: Integer;       {ID of compression algorithm}
      dbhPacketSize:    Integer;       {number of bits per packet}
      dbhSampleRate:    Fixed;         {sample rate}
      dbhBufferPtr:     ARRAY[0..1] OF SndDoubleBufferPtr;
                                       {pointers to SndDoubleBuffer}
      dbhDoubleBack:    ProcPtr;       {pointer to doubleback procedure}
      dbhFormat:        OSType;        {signature of codec}
   END;
   SndDoubleBufferHeaderPtr2 = ^SndDoubleBufferHeader2;

Sound Double Buffer Record

   SndDoubleBuffer =
   PACKED RECORD
      dbNumFrames:      LongInt;       {number of frames in buffer}
      dbFlags:          LongInt;       {buffer status flags}
      dbUserInfo:       ARRAY[0..1] OF LongInt;
                                       {for application's use}
      dbSoundData:      PACKED ARRAY[0..0] OF Byte;
                                       {array of data}
   END;
   SndDoubleBufferPtr = ^SndDoubleBuffer;

Chunk Header

   ID = LongInt;                       {chunk ID type}
   ChunkHeader =
   RECORD
      ckID:             ID;            {chunk type ID}
      ckSize:           LongInt;       {number of bytes of data}
   END;

Form Chunk

   ContainerChunk =
   RECORD
      ckID:             ID;            {'FORM'}
      ckSize:           LongInt;       {number of bytes of data}
      formType:         ID;            {type of file}
   END;

Format Version Chunk

   FormatVersionChunk =
   RECORD
      ckID:             ID;            {'FVER'}
      ckSize:           LongInt;       {4 bytes}
      timestamp:        LongInt;       {date of format version}
   END;

Common Chunk

   CommonChunk =
   RECORD
      ckID:             ID;            {'COMM'}
      ckSize:           LongInt;       {18 bytes}
      numChannels:      Integer;       {number of channels}
      numSampleFrames:  LongInt;       {number of sample frames}
      sampleSize:       Integer;       {number of bits per sample}
      sampleRate:       Extended;      {number of frames per second}
   END;

Extended Common Chunk

   ExtCommonChunk =
   RECORD
      ckID:             ID;            {'COMM'}
      ckSize:           LongInt;       {22 bytes + compression name}
      numChannels:      Integer;       {number of channels}
      numSampleFrames:  LongInt;       {number of sample frames}
      sampleSize:       Integer;       {number of bits per sample}
      sampleRate:       Extended;      {number of frames per second}
      compressionType:  ID;            {compression type ID}
      compressionName:  PACKED ARRAY[0..0] OF Byte;
                                       {compression type name}
   END;

Sound Data Chunk

   SoundDataChunk =
   RECORD
      ckID:       ID;         {'SSND'}
      ckSize:     LongInt;    {size of chunk data}
      offset:     LongInt;    {offset to sound data}
      blockSize:  LongInt;    {size of alignment blocks}
   END;

Version Record

   NumVersion = 
   PACKED RECORD
   CASE INTEGER OF
    0:
      (majorRev:        SignedByte;    {major revision level in BCD}
      minorAndBugRev:   SignedByte;    {minor revision level}
      stage:            SignedByte;    {development stage}
      nonRelRev:        SignedByte);   {nonreleased revision level}
    1:
      (version:         LongInt);      {all 4 fields together}
   END;

Leftover Block

   LeftOverBlock = 
   RECORD
      count:         LongInt;
      sampleArea:    PACKED ARRAY[0..leftOverBlockSize - 1] OF Byte;
   END;
   LeftOverBlockPtr = ^LeftOverBlock;

State Block

   StateBlock = 
   RECORD
      stateVar:      ARRAY[0..stateBlockSize - 1] OF Integer;
   END;
   StateBlockPtr = ^StateBlock;

Sound Manager Routines

Playing Sound Resources

PROCEDURE	SysBeep		(duration: Integer);
FUNCTION	SndPlay		(chan: SndChannelPtr; sndHdl: Handle; 
				async: Boolean): OSErr;

Playing From Disk

FUNCTION    SndStartFilePlay    (chan: SndChannelPtr; fRefNum: Integer; 
                                resNum: Integer; bufferSize: LongInt; 
                                theBuffer: Ptr; 
                                theSelection: AudioSelectionPtr; 
                                theCompletion: ProcPtr; async: Boolean): OSErr;
FUNCTION    SndPauseFilePlay    (chan: SndChannelPtr): OSErr;
FUNCTION    SndStopFilePlay     (chan: SndChannelPtr; quietNow: Boolean): OSErr;

Allocating and Releasing Sound Channels

FUNCTION    SndNewChannel       (VAR chan: SndChannelPtr; synth: Integer; 
                                init: LongInt; userRoutine: ProcPtr): OSErr;
FUNCTION    SndDisposeChannel   (chan: SndChannelPtr; quietNow: Boolean): OSErr;

Sending Commands to a Sound Channel

FUNCTION    SndDoCommand    (chan: SndChannelPtr; cmd: SndCommand; 
                            noWait: Boolean): OSErr;
FUNCTION    SndDoImmediate  (chan: SndChannelPtr; cmd: SndCommand): OSErr;

Obtaining Information

FUNCTION    SndSoundManagerVersion
                              : NumVersion;
FUNCTION    MACEVersion       : NumVersion;
FUNCTION    SndControl        (id: Integer; VAR cmd: SndCommand): OSErr;
FUNCTION    SndChannelStatus  (chan: SndChannelPtr; theLength: Integer; 
                              theStatus: SCStatusPtr): OSErr;
FUNCTION    SndManagerStatus  (theLength: Integer; theStatus: SMStatusPtr): 
                    OSErr;
PROCEDURE   SndGetSysBeepState
                              (VAR sysBeepState: Integer);
FUNCTION    SndSetSysBeepState
                              (sysBeepState: Integer): OSErr;
FUNCTION    GetSoundHeaderOffset
                              (sndHdl: Handle; VAR offset: LongInt): OSErr;

Controlling Volume Levels

FUNCTION    GetSysBeepVolume  (VAR level: LongInt): OSErr;
FUNCTION    SetSysBeepVolume  (level: LongInt): OSErr;
FUNCTION    GetDefaultOutputVolume
                              (VAR level: LongInt): OSErr;
FUNCTION    SetDefaultOutputVolume
                              (level: LongInt): OSErr;

Compressing and Expanding Audio Data

PROCEDURE   Comp3to1        (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt; 
                            inState: Ptr; outState: Ptr; 
                            numChannels: LongInt; whichChannel: LongInt);
PROCEDURE   Comp6to1        (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt; 
                            inState: Ptr; outState: Ptr; 
                            numChannels: LongInt; whichChannel: LongInt);
PROCEDURE   Exp1to3         (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt; 
                            inState: Ptr; outState: Ptr; 
                            numChannels: LongInt; whichChannel: LongInt);
PROCEDURE   Exp1to6         (inBuffer: Ptr; outBuffer: Ptr; cnt: LongInt; 
                            inState: Ptr; outState: Ptr; 
                            numChannels: LongInt; whichChannel: LongInt);

Managing Double Buffers

FUNCTION    SndPlayDoubleBuffer
                    (chan: SndChannelPtr; 
                    theParams: SndDoubleBufferHeaderPtr): OSErr;

Performing Unsigned Fixed-Point Arithmetic

FUNCTION    UnsignedFixMulDiv  (value: UnsignedFixed; 
                               multiplier: UnsignedFixed; 
                               divisor: UnsignedFixed): UnsignedFixed;

Linking Modifiers to Sound Channels

FUNCTION    SndAddModifier  (chan: SndChannelPtr; modifier: ProcPtr; 
                            id: Integer; init: LongInt): OSErr;

Application-Defined Routines

PROCEDURE   MyFilePlayCompletionRoutine
                                  (chan: SndChannelPtr);
PROCEDURE   MyCallback            (chan: SndChannelPtr; cmd: SndCommand);
PROCEDURE   MyDoubleBackProc      (chan: SndChannelPtr; 
                                  doubleBufferPtr: SndDoubleBufferPtr);

C Summary

Constants

/*Gestalt sound attributes selector and response bits*/
#define gestaltSoundAttr    'snd '  /*sound attributes selector*/
enum {
   gestaltStereoCapability    = 0,  /*built-in hw can play stereo sounds*/
   gestaltStereoMixing        = 1,  /*built-in hw mixes stereo to mono*/
   gestaltSoundIOMgrPresent   = 3,  /*sound input routines available*/
   gestaltBuiltInSoundInput   = 4,  /*built-in input hw available*/
   gestaltHasSoundInputDevice = 5,  /*sound input device available*/
   gestaltPlayAndRecord       = 6,  /*built-in hw can play while recording*/
   gestalt16BitSoundIO        = 7,  /*built-in hw can handle 16-bit data*/
   gestaltStereoInput         = 8,  /*built-in hw can record stereo sounds*/
   gestaltLineLevelInput      = 9,  /*built-in input hw needs line level*/
   gestaltSndPlayDoubleBuffer = 10, /*play from disk routines available*/
   gestaltMultiChannels       = 11, /*multiple channels of sound supported*/
   gestalt16BitAudioSupport   = 12  /*16-bit audio data supported*/
};
/*channel initialization parameters*/
enum {
   initChanLeft            = 0x0002,   /*left stereo channel*/
   initChanRight           = 0x0003,   /*right stereo channel*/
   initMono                = 0x0080,   /*monophonic channel*/
   initStereo              = 0x00C0,   /*stereo channel*/
   initMACE3               = 0x0300,   /*3:1 compression*/
   initMACE6               = 0x0400,   /*6:1 compression*/
   initNoInterp            = 0x0004,   /*no linear interpolation*/
   initNoDrop              = 0x0008    /*no drop-sample conversion*/
};
/*wave channel initialization parameters*/
enum {
   waveInitChannel0        = 0x04,     /*wave-table channel 0*/
   waveInitChannel1        = 0x05,     /*wave-table channel 1*/
   waveInitChannel2        = 0x06,     /*wave-table channel 2*/
   waveInitChannel3        = 0x07,     /*wave-table channel 3*/
   waveInitChannelMask     = 0x07      /*mask for wave-table parameters*/
};
/*masks for channel attributes*/
enum {
   initPanMask             = 0x0003,   /*mask for left/right pan values*/
   initSRateMask           = 0x0030,   /*mask for sample rate values*/
   initStereoMask          = 0x00C0,   /*mask for mono/stereo values*/
   initCompMask            = 0xFF00    /*mask for compression IDs*/
};
/*sound data types*/
enum {
   squareWaveSynth         = 1,        /*square-wave data*/
   waveTableSynth          = 3,        /*wave-table data*/
   sampledSynth            = 5         /*sampled-sound data*/
};
/*sound command numbers*/
enum {
   nullCmd                 = 0,        /*do nothing*/
   quietCmd                = 3,        /*stop a sound that is playing*/
   flushCmd                = 4,        /*flush a sound channel*/
   reInitCmd               = 5,        /*reinitialize a sound channel*/
   waitCmd                 = 10,       /*suspend processing in a channel*/
   pauseCmd                = 11,       /*pause processing in a channel*/
   resumeCmd               = 12,       /*resume processing in a channel*/
   callBackCmd             = 13,       /*execute a callback procedure*/
   syncCmd                 = 14,       /*synchronize channels*/
   availableCmd            = 24,       /*see if initialization options */
                                       /* are supported*/
   versionCmd              = 25,       /*determine version*/
   totalLoadCmd            = 26,       /*report total CPU load*/
   loadCmd                 = 27,       /*report CPU load for a new channel*/
   freqDurationCmd         = 40,       /*play a note for a duration*/
   restCmd                 = 41,       /*rest a channel for a duration*/
   freqCmd                 = 42,       /*change the pitch of a sound*/
   ampCmd                  = 43,       /*change the amplitude of a sound*/
   timbreCmd               = 44,       /*change the timbre of a sound*/
   getAmpCmd               = 45,       /*get the amplitude of a sound*/
   volumeCmd               = 46,       /*set volume*/
   getVolumeCmd            = 47,       /*get volume*/
   waveTableCmd            = 60,       /*install a wave table as a voice*/
   soundCmd                = 80,       /*install a sampled sound as a voice*/
   bufferCmd               = 81,       /*play a sampled sound*/
   rateCmd                 = 82,       /*set the pitch of a sampled sound*/
   getRateCmd              = 85        /*get the pitch of a sampled sound*/
};
/*sampled sound header encoding options*/
enum {
   stdSH                   = 0x00,     /*standard sound header*/
   extSH                   = 0xFF,     /*extended sound header*/
   cmpSH                   = 0xFE      /*compressed sound header*/
};
/*size of data structures*/
enum {
   stdQLength              = 128       /*default size of sound channel*/
};
/*sound resource formats*/
enum {
   firstSoundFormat        = 0x0001,   /*format 1 'snd ' resource*/
   secondSoundFormat       = 0x0002    /*format 2 'snd ' resource*/
};
/*sound command mask*/
enum {
   dataOffsetFlag          = 0x8000    /*sound command data offset bit*/
};
/*system beep states*/
enum {
   sysBeepDisable          = 0x0000,   /*system alert sound disabled*/
   sysBeepEnable           = 0x0001    /*system alert sound enabled*/
};
/*values for the unitType field in AudioSelection*/
enum {
   unitTypeSeconds         = 0x0000,   /*seconds*/
   unitTypeNoSelection     = 0xFFFF    /*no selection*/
};
/*double buffer status flags*/
enum {
   dbBufferReady           = 0x00000001,  /*double buffer is filled*/
   dbLastBuffer            = 0x00000004   /*last double buffer to play*/
};
/*values for the compressionID field of CmpSoundHeader*/
enum {
   variableCompression     = -2,       /*variable-ratio compression*/
   fixedCompression        = -1,       /*fixed-ratio compression*/
   notCompressed           = 0,        /*noncompressed samples*/
   threeToOne              = 3,        /*3:1 compressed samples*/
   sixToOne                = 4         /*6:1 compressed samples*/
};
/*values for the packetSize field of CmpSoundHeader*/
enum {
   sixToOnePacketSize      = 8,        /*packet size in bits for 6:1*/
   threeToOnePacketSize    = 16        /*packet size in bits for 3:1*/
};
/*compression names and types*/
#define NoneName              "\pnot compressed"
#define ACE2to1Name           "\pACE 2-to-1"
#define ACE8to3Name           "\pACE 8-to-3"
#define MACE3to1Name          "\pMACE 3-to-1"
#define MACE6to1Name          "\pMACE 6-to-1"
#define NoneType              'NONE'
#define ACE2Type              'ACE2'
#define ACE8Type              'ACE8'
#define MACE3Type             'MAC3'
#define MACE6Type             'MAC6'
/*IDs for AIFF and AIFF-C files*/
#define AIFFID                'AIFF'   /*AIFF file*/
#define AIFCID                'AIFC'   /*AIFF-C file*/
/*IDs for AIFF and AIFF-C file chunks*/
#define FORMID                'FORM'   /*ID for Form Chunk*/
#define FormatVersionID       'FVER'   /*ID for Format Version Chunk*/
#define CommonID              'COMM'   /*ID for Common Chunk*/
#define SoundDataID           'SSND'   /*ID for Sound Data Chunk*/
#define MarkerID              'MARK'   /*ID for Marker Chunk*/
#define InstrumentID          'INST'   /*ID for Instrument Chunk*/
#define MIDIDataID            'MIDI'   /*ID for MIDI Data Chunk*/
#define AudioRecordingID      'AESD'   /*ID for Recording Chunk*/
#define ApplicationSpecificID 'APPL'   /*ID for Application Chunk*/
#define CommentID             'COMT'   /*ID for Comment Chunk*/
#define NameID                'NAME'   /*ID for Name Chunk*/
#define AuthorID              'AUTH'   /*ID for Author Chunk*/
#define CopyrightID           '(c) '   /*ID for Copyright Chunk*/
#define AnnotationID          'ANNO'   /*ID for Annotation Chunk*/
/*version of AIFC format specification*/
#define AIFCVersion1          0xA2805140
                                       /*date of version creation*/
/*MIDI note value for middle C*/
enum {
   kMiddleC                = 60
};
/*ratio between frequencies of MIDI note values*/
#define twelfthRootTwo        1.05946309434
/*standard sampling rates*/
#define rate44khz          0xAC440000     /*44100.00000 in fixed-point*/
#define rate22khz          0x56EE8BA3     /*22254.54545 in fixed-point*/
#define rate22050hz        0x56220000     /*22050.00000 in fixed-point*/
#define rate11khz          0x2B7745D1     /*11127.27273 in fixed-point*/
#define rate11025hz        0x2B110000     /*11025.00000 in fixed-point*/
/*constant for synth parameter of SndNewChannel*/
enum {
   kUseOptionalOutputDevice      = -1
};
/*volumes*/
enum {
   kFullVolume                   = 0x0100,
   kNoVolume                     = 0
};
/*development stages*/
enum {
   developStage         = 0x20,        /*prealpha release*/
   alphaStage           = 0x40,        /*alpha release*/
   betaStage            = 0x60,        /*beta release*/
   finalStage           = 0x80         /*final release*/
};
/*sizes of data buffers*/
enum {
   stateBlockSize       = 64,          /*size of state block buffer*/
   leftOverBlockSize    = 32           /*size of leftover block buffer*/
};

Data Types

Unsigned Fixed-Point Numbers

typedef unsigned long UnsignedFixed;   /*unsigned fixed-point number*/

Times

typedef long Time;                     /*in half-milliseconds*/

Sound Command Record

struct SndCommand {
   unsigned short       cmd;           /*command number*/
   short                param1;        /*first parameter*/
   long                 param2;        /*second parameter*/
};
typedef struct SndCommand SndCommand;

Audio Selection Record

struct AudioSelection {
   long                 unitType;      /*type of time unit*/
   Fixed                selStart;      /*starting point of selection*/
   Fixed                selEnd;        /*ending point of selection/*
};
typedef struct AudioSelection AudioSelection;
typedef AudioSelection *AudioSelectionPtr;

Sound Channel Status Record

struct SCStatus {
   Fixed                scStartTime;   /*starting time for play from disk*/
   Fixed                scEndTime;     /*ending time for play from disk*/
   Fixed                scCurrentTime; /*current time for play from disk*/
   Boolean              scChannelBusy; /*TRUE if channel is processing cmds*/
   Boolean              scChannelDisposed;
                                       /*reserved*/
   Boolean              scChannelPaused;
                                       /*TRUE if play from disk is paused*/
   Boolean              scUnused;      /*unused*/
   unsigned long        scChannelAttributes;
                                       /*attributes of this channel*/
   long                 scCPULoad;     /*CPU load for this channel*/
};
typedef struct SCStatus SCStatus;
typedef SCStatus *SCStatusPtr;

Sound Manager Status Record

struct SMStatus {
   short                smMaxCPULoad;  /*maximum load on all channels*/
   short                smNumChannels; /*number of allocated channels*/
   short                smCurCPULoad;  /*current load on all channels*/
};
typedef struct SMStatus SMStatus;
typedef SMStatus *SMStatusPtr;

Sound Channel Record

struct SndChannel {
   struct SndChannel    *nextChan;     /*pointer to next channel*/
   Ptr                  firstMod;      /*used internally*/
   SndCallBackProcPtr   callBack;      /*pointer to callback procedure*/
   long                 userInfo;      /*free for application's use*/
   long                 wait;          /*used internally*/
   SndCommand           cmdInProgress; /*used internally*/
   short                flags;         /*used internally*/
   short                qLength;       /*used internally*/
   short                qHead;         /*used internally*/
   short                qTail;         /*used internally*/
   SndCommand           queue[stdQLength];
};
typedef struct SndChannel SndChannel;
typedef SndChannel *SndChannelPtr;

Sound Header Record

struct SoundHeader {
   Ptr                  samplePtr;     /*if NIL, samples in sampleArea*/
   unsigned long        length;        /*number of samples in array*/
   Fixed                sampleRate;    /*sample rate for this sound*/
   unsigned long        loopStart;     /*loop point beginning*/
   unsigned long        loopEnd;       /*loop point ending*/
   unsigned char        encode;        /*sample's encoding option*/
   unsigned char        baseFrequency; /*base frequency of sample*/
   unsigned char        sampleArea[1];
};
typedef struct SoundHeader SoundHeader;
typedef SoundHeader *SoundHeaderPtr;

Extended Sound Header Record

struct ExtSoundHeader {
   Ptr                  samplePtr;     /*if NIL, samples in sampleArea*/
   unsigned long        numChannels;   /*number of channels in sample*/
   Fixed                sampleRate;    /*rate of original sample*/
   unsigned long        loopStart;     /*loop point beginning*/
   unsigned long        loopEnd;       /*loop point ending*/
   unsigned char        encode;        /*sample's encoding option*/
   unsigned char        baseFrequency; /*base frequency of sample*/
   unsigned long        numFrames;     /*total number of frames*/
   extended80           AIFFSampleRate;/*rate of original sample*/
   Ptr                  markerChunk;   /*reserved*/
   Ptr                  instrumentChunks;
                                       /*pointer to instrument info*/
   Ptr                  AESRecording;  /*pointer to audio info*/
   unsigned short       sampleSize;    /*number of bits per sample*/
   unsigned short       futureUse1;    /*reserved*/
   unsigned long        futureUse2;    /*reserved*/
   unsigned long        futureUse3;    /*reserved*/
   unsigned long        futureUse4;    /*reserved*/
   unsigned char        sampleArea[1];
};
typedef struct ExtSoundHeader ExtSoundHeader;
typedef ExtSoundHeader *ExtSoundHeaderPtr;

Compressed Sound Header Record

struct CmpSoundHeader {
   Ptr                  samplePtr;     /*if NIL, samples in sampleArea*/
   unsigned long        numChannels;   /*number of channels in sample*/
   Fixed                sampleRate;    /*rate of original sample*/
   unsigned long        loopStart;     /*loop point beginning*/
   unsigned long        loopEnd;       /*loop point ending*/
   unsigned char        encode;        /*sample's encoding option*/
   unsigned char        baseFrequency; /*base frequency of original sample*/
   unsigned long        numFrames;     /*length of sample in frames*/
   extended80           AIFFSampleRate;/*rate of original sample*/
   Ptr                  markerChunk;   /*reserved*/
   OSType               format;        /*data format type*/
   unsigned long        futureUse2;    /*reserved*/
   StateBlockPtr        stateVars;     /*pointer to StateBlock*/
   LeftOverBlockPtr     leftOverSamples;
                                       /*pointer to LeftOverBlock*/
   unsigned short       compressionID; /*ID of compression algorithm*/
   unsigned short       packetSize;    /*number of bits per packet*/
   unsigned short       snthID;        /*unused*/
   unsigned short       sampleSize;    /*bits in each sample point*/
   unsigned char        sampleArea[1];
};
typedef struct CmpSoundHeader CmpSoundHeader;
typedef CmpSoundHeader *CmpSoundHeaderPtr;

Sound Double Buffer Header Record

struct SndDoubleBufferHeader {
   short                dbhNumChannels;/*number of sound channels*/
   short                dbhSampleSize; /*sample size, if noncompressed*/
   short                dbhCompressionID;
                                       /*ID of compression algorithm*/
   short                dbhPacketSize; /*number of bits per packet*/
   Fixed                dbhSampleRate; /*sample rate*/
   SndDoubleBufferPtr   dbhBufferPtr[2];
                                       /*pointers to SndDoubleBuffer*/
   SndDoubleBackProcPtr dbhDoubleBack; /*pointer to doubleback procedure*/
};
typedef struct SndDoubleBufferHeader SndDoubleBufferHeader;
typedef SndDoubleBufferHeader *SndDoubleBufferHeaderPtr;
struct SndDoubleBufferHeader2 {
   short                dbhNumChannels;/*number of sound channels*/
   short                dbhSampleSize; /*sample size, if noncompressed*/
   short                dbhCompressionID;
                                       /*ID of compression algorithm*/
   short                dbhPacketSize; /*number of bits per packet*/
   Fixed                dbhSampleRate; /*sample rate*/
   SndDoubleBufferPtr   dbhBufferPtr[2];
                                       /*pointers to SndDoubleBuffer*/
   SndDoubleBackProcPtr dbhDoubleBack; /*pointer to doubleback procedure*/
   OSType               dbhFormat;     /*signature of codec*/
};
typedef struct SndDoubleBufferHeader2 SndDoubleBufferHeader2;
typedef SndDoubleBufferHeader2 *SndDoubleBufferHeaderPtr2;

Sound Double Buffer Record

struct SndDoubleBuffer {
   long                 dbNumFrames;   /*number of frames in buffer*/
   long                 dbFlags;       /*buffer status flags*/
   long                 dbUserInfo[2]; /*for application's use*/
   char                 dbSoundData[1];/*array of data*/
};
typedef struct SndDoubleBuffer SndDoubleBuffer;
typedef SndDoubleBuffer *SndDoubleBufferPtr;

Chunk Headers

typedef unsigned long ID;              /*chunk ID type*/

struct ChunkHeader {
   ID                   ckID;          /*chunk type ID*/
   long                 ckSize;        /*number of bytes of data*/
};
typedef struct ChunkHeader ChunkHeader;

Form Chunk

struct ContainerChunk {
   ID                   ckID;          /*'FORM'*/
   long                 ckSize;        /*number of bytes of data*/
   ID                   formType;      /*type of file*/
};
typedef struct ContainerChunk ContainerChunk;

Format Version Chunk

struct FormatVersionChunk {
   ID                   ckID;          /*'FVER'*/
   long                 ckSize;        /*4 bytes*/
   unsigned long        timestamp;     /*date of format version*/
};
typedef struct FormatVersionChunk FormatVersionChunk;

Common Chunk

struct CommonChunk {
   ID                   ckID;          /*'COMM'*/
   long                 ckSize;        /*18 bytes*/
   short                numChannels;   /*number of channels*/
   unsigned long        numSampleFrames;
                                       /*number of sample frames*/
   short                sampleSize;    /*number of bits per sample*/
   extended80           sampleRate;    /*number of frames per second*/
};

typedef struct CommonChunk CommonChunk;

Extended Common Chunk

struct ExtCommonChunk {
   ID                   ckID;          /*'COMM'*/
   long                 ckSize;        /*22 bytes + compression name*/
   short                numChannels;   /*number of channels*/
   unsigned long        numSampleFrames;  
                                       /*number of sample frames*/
   short                sampleSize;    /*number of bits per sample*/
   extended80           sampleRate;    /*number of frames per second*/
   ID                   compressionType;  
                                       /*compression type ID*/
   char                 compressionName[1];
                                       /*compression type name*/
};
typedef struct ExtCommonChunk ExtCommonChunk;

Sound Data Chunk

struct SoundDataChunk {
   ID                   ckID;          /*'SSND'*/
   long                 ckSize;        /*size of chunk data*/
   unsigned long        offset;        /*offset to sound data*/
   unsigned long        blockSize;     /*size of alignment blocks*/
};
typedef struct SoundDataChunk SoundDataChunk;

Version Record

struct NumVersion {
   unsigned char        majorRev;      /*major revision level in BCD*/
   unsigned char        minorAndBugRev;/*minor revision level*/
   unsigned char        stage;         /*development stage*/
   unsigned char        nonRelRev;     /*nonreleased version revision level*/
};
typedef struct NumVersion NumVersion;

Leftover Block

struct LeftOverBlock {
   unsigned long        count;
   char                 sampleArea[leftOverBlockSize];
};
typedef struct LeftOverBlock LeftOverBlock;
typedef LeftOverBlock *LeftOverBlockPtr;

State Block

struct StateBlock {
   short                stateVar[stateBlockSize];
};
typedef struct StateBlock StateBlock;
typedef StateBlock *StateBlockPtr;

Procedure Types

typedef pascal void (*FilePlayCompletionProcPtr)
                    (SndChannelPtr chan);
typedef pascal void (*SndCallBackProcPtr)
                    (SndChannelPtr chan, SndCommand *cmd);
typedef pascal void (*SndDoubleBackProcPtr)
                    (SndChannelPtr chan,
                    SndDoubleBufferPtr doubleBufferPtr);

Sound Manager Routines

Playing Sound Resources

pascal void SysBeep     (short duration);
pascal OSErr SndPlay    (SndChannelPtr chan, Handle sndHdl, 
                         Boolean async);

Playing From Disk

pascal OSErr SndStartFilePlay
                (SndChannelPtr chan, short fRefNum,
                 short resNum, long bufferSize, void *theBuffer,
                 AudioSelectionPtr theSelection,
                 FilePlayCompletionProcPtr theCompletion, Boolean async);
pascal OSErr SndPauseFilePlay
                (SndChannelPtr chan);
pascal OSErr SndStopFilePlay
                (SndChannelPtr chan, Boolean quietNow);

Allocating and Releasing Sound Channels

pascal OSErr SndNewChannel  (SndChannelPtr *chan, short synth, long init,
                             SndCallBackProcPtr userRoutine);
pascal OSErr SndDisposeChannel
                            (SndChannelPtr chan, Boolean quietNow);

Sending Commands to a Sound Channel

pascal OSErr SndDoCommand   (SndChannelPtr chan, const SndCommand *cmd,
                             Boolean noWait);
pascal OSErr SndDoImmediate
                            (SndChannelPtr chan, const SndCommand *cmd);

Obtaining Information

pascal NumVersion SndSoundManagerVersion
                            (void);
pascal NumVersion MACEVersion
                            (void);
pascal OSErr SndControl     (short id, SndCommand *cmd);
pascal OSErr SndChannelStatus
                            (SndChannelPtr chan, short theLength,
                             SCStatusPtr theStatus);
pascal OSErr SndManagerStatus
                            (short theLength, SMStatusPtr theStatus);
pascal void SndGetSysBeepState
                            (short *sysBeepState);
pascal OSErr SndSetSysBeepState
                            (short sysBeepState);
pascal OSErr GetSoundHeaderOffset
                            (Handle sndHandle, long *offset);

Controlling Volume Levels

pascal OSErr GetSysBeepVolume
                    (long *level);
pascal OSErr SetSysBeepVolume
                    (long level);
pascal OSErr GetDefaultOutputVolume
                    (long *level);
pascal OSErr SetDefaultOutputVolume
                    (long level);

Compressing and Expanding Audio Data

pascal void Comp3to1   (const void *inBuffer, void *outBuffer, 
                        unsigned long cnt, const void *inState, 
                        void *outState, unsigned long numChannels, 
                        unsigned long whichChannel);
pascal void Comp6to1   (const void *inBuffer, void *outBuffer, 
                        unsigned long cnt, const void *inState, 
                        void *outState, unsigned long numChannels, 
                        unsigned long whichChannel);
pascal void Exp1to3    (const void *inBuffer, void *outBuffer, 
                        unsigned long cnt, const void *inState, 
                        void *outState, unsigned long numChannels, 
                        unsigned long whichChannel);
pascal void Exp1to6    (const void *inBuffer, void *outBuffer, 
                        unsigned long cnt, const void *inState, 
                        void *outState, unsigned long numChannels, 
                        unsigned long whichChannel);

Managing Double Buffers

pascal OSErr SndPlayDoubleBuffer
                    (SndChannelPtr chan, 
                     SndDoubleBufferHeaderPtr theParams);

Performing Unsigned Fixed-Point Arithmetic

pascal UnsignedFixed UnsignedFixMulDiv
                    (UnsignedFixed value, UnsignedFixed multiplier, UnsignedFixed divisor);

Linking Modifiers to Sound Channels

pascal OSErr SndAddModifier
                    (SndChannelPtr chan, Ptr modifier, short id, long init);

Application-Defined Routines

pascal void MyFilePlayCompletionRoutine
                            (SndChannelPtr chan);
pascal void MyCallback      (SndChannelPtr chan, SndCommand *cmd);
pascal void MyDoubleBackProc
                            (SndChannelPtr chan, 
                             SndDoubleBufferPtr doubleBufferPtr);

Assembly-Language Summary

Data Structures

SndCommand Data Structure
0cmdwordcommand number
2param1wordfirst parameter
4param2longsecond parameter

AudioSelection Data Structure
0unitTypelongtype of time unit
4selStart4 bytesstarting point of selection (Fixed)
8selEnd4 bytesending point of selection (Fixed)

SCStatus Data Structure
0scStartTime4 bytesstarting time for play from disk (Fixed)
4scEndTime4 bytesending time for play from disk (Fixed)
8scCurrentTime4 bytescurrent time for play from disk (Fixed)
12scChannelBusybytechannel playing sampled sound flag
13scChannelDisposedbytereserved
14scChannelPausedbyteplay from disk is paused flag
15scUnusedbyteunused
16scChannelAttributeslongattributes of channel
20scCPULoadlongCPU load for channel

SMStatus Data Structure
0smMaxCPULoadwordmaximum load on all channels
2smNumChannelswordnumber of allocated channels
4smCurCPULoadwordcurrent load on all channels

SndChannel Data Structure
0nextChanlongpointer to next channel
4firstModlongused internally
8callBacklongpointer to callback procedure
12userInfolongfree for application's use
16waitlongused internally
20cmdInProgress8 bytesused internally
28flagswordused internally
30qLengthwordused internally
32qHeadwordused internally
34qTailwordused internally
36queuevariablequeue of sound commands

SoundHeader Data Structure
0samplePtrlongpointer to samples (or NIL if samples follow data structure)
4lengthlongnumber of samples in array
8sampleRate4 bytessample rate (Fixed)
12loopStartlongloop point beginning
16loopEndlongloop point ending
20encodebytesample's encoding option
21baseFrequencybytebase frequency of sample
22sampleAreavariablesampled-sound data

ExtSoundHeader Data Structure
0samplePtrlongpointer to samples (or NIL if samples follow data structure)
4numChannelslongnumber of channels in sample
8sampleRate4 bytessample rate (Fixed)
12loopStartlongloop point beginning
16loopEndlongloop point ending
20encodebytesample's encoding option
21baseFrequencybytebase frequency of sample
22numFrameslongtotal number of frames
26AIFFSampleRate10 bytesrate of original sample (Extended80)
36markerChunklongreserved
40instrumentChunkslongpointer to instrument info
44AESRecordinglongpointer to audio info
48sampleSizewordnumber of bits per sample
50futureUse1wordreserved
52futureUse2longreserved
56futureUse3longreserved
60futureUse4longreserved
64sampleAreavariablesampled-sound data

CmpSoundHeader Data Structure
0samplePtrlongpointer to samples (or NIL if samples follow data structure)
4numChannelslongnumber of channels in sample
8sampleRate4 bytessample rate (Fixed)
12loopStartlongloop point beginning
16loopEndlongloop point ending
20encodebytesample's encoding option
21baseFrequencybytebase frequency of original sample
22numFrameslonglength of sample in frames
26AIFFSampleRate10 bytesrate of original sample (Extended80)
36markerChunklongreserved
40formatOSTypedata format type
44futureUse2longreserved
48stateVarslongpointer to StateBlock
52leftOverSampleslongpointer to LeftOverBlock
56compressionIDwordID of compression algorithm
58packetSizewordnumber of bits per packet
60snthIDwordunused
62sampleSizewordbits in each sample point
64sampleAreavariablecompressed sound data

SndDoubleBufferHeader Data Structure
0dbhNumChannelswordnumber of sound channels
2dbhSampleSizewordsample size, if noncompressed
4dbhCompressionIDwordID of compression algorithm
6dbhPacketSizewordnumber of bits per packet
8dbhSampleRate4 bytessample rate (Fixed)
12dbhBufferPtr2 longspointers to SndDoubleBuffer data structures
20dbhDoubleBacklongpointer to doubleback procedure

SndDoubleBuffer Data Structure
0dbNumFrameslongnumber of frames in buffer
4dbFlagslongbuffer status flags
8dbUserInfo2 longsfor application's use
16dbSoundDatavariablearray of data

ChunkHeader Data Structure
0ckIDlongchunk type ID
4ckSizelongnumber of bytes of data

ContainerChunk Data Structure
0ckIDlongchunk type ID ('FORM')
4ckSizelongnumber of bytes of data
8formTypelongtype of file

FormatVersionChunk Data Structure
0ckIDlongchunk type ID ('FVER')
4ckSizelongnumber of bytes of data (4)
8timestamplongdate of format version

CommonChunk Data Structure
0ckIDlongchunk type ID ('COMM')
4ckSizelongnumber of bytes of data (18)
8numChannelswordnumber of channels
10numSampleFrameslongnumber of sample frames
14sampleSizewordnumber of bits per sample
16sampleRate10 bytesnumber of frames per second (Extended80)

ExtCommonChunk Data Structure
0ckIDlongchunk type ID ('COMM')
4ckSizelongnumber of bytes of data (22 + length of compression name)
8numChannelswordnumber of channels
10numSampleFrameslongnumber of sample frames
14sampleSizewordnumber of bits per sample
16sampleRate10 bytesnumber of frames per second (Extended80)
26compressionTypelongcompression type ID
30compressionNamevariablecompression type name

SoundDataChunk
0ckIDlongchunk type ID ('SSND')
4ckSizelongnumber of bytes of data
8offsetlongoffset to sound data
12blockSizelongsize of alignment blocks

Trap Macros

Trap Macro Requiring Routine Selectors

_SoundDispatch
SelectorRoutine
$00000010MACEVersion
$00040010Comp3to1
$00080010Exp1to3
$000C0008SndSoundManagerVersion
$000C0010Comp6to1
$00100008SndChannelStatus
$00100010Exp1to6
$00140008SndManagerStatus
$00180008SndGetSysBeepState
$001C0008SndSetSysBeepState
$00200008SndPlayDoubleBuffer
$02040008SndPauseFilePlay
$02240024GetSysBeepVolume
$02280024SetSysBeepVolume
$022C0024GetDefaultOutputVolume
$02300024SetDefaultOutputVolume
$03080008SndStopFilePlay
$0D000008SndStartFilePlay
$04040024GetSoundHeaderOffset

Result Codes
noErr0No error
paramErr-50A parameter is incorrect
noHardwareErr-200Required sound hardware not available
notEnoughHardwareErr-201Insufficient hardware available
queueFull-203No room in the queue
resProblem-204Problem loading the resource
badChannel-205Channel is corrupt or unusable
badFormat-206Resource is corrupt or unusable
notEnoughBufferSpace-207Insufficient memory available
badFileFormat-208File is corrupt or unusable, or not AIFF or AIFF-C
channelBusy-209Channel is busy
buffersTooSmall-210Buffer is too small
channelNotBusy-211Channel not currently used
noMoreRealTime-212Not enough CPU time available
siInvalidCompression-223Invalid compression type


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996