Sound Designer II File Format
 Sound Designer II files store all sound samples in the data fork and all sound parameters in the resource fork. This is extremely convenient for sound data where the data fork may grow to a hundred megabytes or more. Regardless of the size of the data fork you can add, delete, and modify sound parameters at will without compacting the sound data or moving it around the disk (and extremely time consuming procedure if the file is 100 MB). In addition, you may add your own parameters to a file (as long as their resource types don't conflict with Sound Designer II's) while allowing the file to be read by both Sound Designer and your program. We recommend that developers standardize on the Sound Designer II file format as the primary format due to its ability to be customized. For multi-track operations, we recommend that each track be recorded in a separate single mono Sound Designer II file using stereo Sound Designer II files as the mastering medium.
 
 File Type: 'Sd2f'
 
 Resource Fork
 The resource fork contains many different kinds of resources which specify everything from the sample rate to loop points to graphic eq settings. Most of these are application-specific to Sound Designer II. There are three core parameters/rsrcs in an SDII file:
 
 Type: 'STR ' ID: 1000 Name: 'sample-size'
 Integer numeric string specifying the number of bytes per sample (ie 2 for standard 16 bit samples).
 
 Type: 'STR ' ID: 1001 Name: 'sample-rate'
 Floating point numeric string specifying the sample rate in hertz of the file (ie '44100.0000' for a standard 44.1kHz sample rate file).
 
 Type: 'STR ' ID: 1002 Name: 'channels'
 Integer numeric string specifying the number of channels in the file (ie 2 for stereo).
 
 The above resources are all that are specifically required in an SDII file. Given only these three parameters, Sound Designer II can read in and play the file. If your program modifies the sound data or above 'STR ' resources in any way, it is your responsibility to delete any other resources that may have become out of sync with the file. This can happen if you delete a large section of the file without updating the playlist pointers. Notice that the length of the file is not stored. This is because you can derive the length given the sample size, number of channels, and the length in bytes of the data fork (using file system calls) using the following formulas:
 
 Length of file (in sample frames) = Length of data fork /(number of channels * sample size)
 
 Length of file (in seconds) = (Length of data fork /(number of channels * sample size)) / sample rate
 
 The following resources store file information used by Sound Designer II for various advanced playback and processing. Unlike the above core parameters, these are stored as Pascal RECORD structures written out to resources. Therefore they are defined by the associated Pascal RECORD definitions below. Default values are given in ( ) within the comment next to a field. Byte offsets are indicated to the left at various offsets. Fields with the comment DO NOT USE are for Sound Designer internal use and should not be changed except when initializing the file. The size of the data types are detailed in Inside Macintosh, Volume 1, page 86.
 
 Type: 'sdDD' ID: 1000
 Stores general document information such as comments. A DocumentDataRecord as defined below.
 
 typedef struct EditRecord
 {
  long HiAddr; // DO NOT USE (0).
  long LoAddr; // DO NOT USE (0).
  enum SideType ExtendSide; // DO NOT USE (0).
 } EditRecord;
 
 typedef struct ZoomType
 {
  short v; // Vertical scale factor: positive = magnification
    // negative = reduction (-256).
  long h; // Horizontal scale factor: positive = magnification
    // negative = reduction (1).
 } ZoomType;
 
 typedef struct ScaleType
 {
  long VFactor; // Scale factor for vertical axis tick units:    // positive = magnification
    // negative = reduction (327)
  enum ScaleNames VType; // Type of vertical axis tick mark unit (4).  
  char VString[34]; // Vertical axis tick units string ("%Scale").
  long HFactor; // Scale factor for horizontal axis tick units:


   // positive = magnification
    // negative = reduction (1).
  enum ScaleNames HType; // Type of horizontal axis tick mark unit (0).
  char HString[34]; // Horizontal axis tick units string:
    // sec,msec,sec,samples ("sec").
 } ScaleType;
 
 typedef struct DocumentDataRecord
 {
  short Version; // version/format of this resource(1).
  long BufOffset; // DO NOT USE (0).
  long MarkerOffset; // Offset to get relative time of markers.
  Str255 Comment; // File comment (" ").
  short HDPlayBufMultiple; // HD play buf multiple for this file (8).
  long SMPTEStartTime; // SMPTE start time of this file (0).
  short FramesPerSec; // SMPTE frame rate of this file (30).
  short FilmSize; // 16mm or 35mm film (35).
  long StartBarNum; // Starting Bar Number (0).
  long StartBeatNum; // Starting Beat Number (0).
  long StartFrame; // The sample frame this new entry starts at
  Fixed Tempo; // Tempo in beats/sec.
  Fixed TimeSignature; // HiWord = numerator, LoWord = denominator.
  long CursorPos; // Cursor position relative to window start (0).
  Boolean CursorOn; // (FALSE/0)
  ZoomType Zoom; // See above.
  ScaleType Scale; // See above.
  EditRecord Edit; // See above.
  long VOffset; // Position of vertical center of window in quantization
    // units ie -32768 to 32767 (0).
  long HOffset; // Position of left edge of sample window in #SAMPLES (0).
  Rect CtlWidth; // DO NOT USE (0.
  Point ZoomIndex; // h and v indices in zoom increments.
  short SelectMode; // DO NOT USE (0).
 } DocumentDataRecord;
 
 
 Type: 'sdML' ID: 1000
 Stores a list of text and numeric markers.
 
  short Version; // Version/format of this resource(1).
  long MarkerOffset; // DO NOT USE (0).
  short NumMarkers; // Number of MarkerRecords to follow.
 
 Followed by NumMarkers of the following record.
 
 typedef struct MarkerRecord
 {
  short MarkerType0; // 1 = numbered marker, 2 = text marker (1).
  short MarkerType1; // DUPLICATE of previous value - for historical reasons.
  long Position; // Sample frame in file.
  long Text; // DO NOT USE (0).
  short CursorID; // 24430 = numeric, 3012 = text (24430).
  short MarkerID; // Unique unsigned ID for each marker.
  long TextLength; // length of marker text.
  char TheText[]; // The Text (ie TextLength bytes of ASCII characters).
 } MarkerRecord;
 
 Type: 'sdLL' ID: 1000
 Stores a list of audio loops (commonly used with samplers).
 
  short Version; // Version/format of this resource(1).
  short HScale; // DO NOT USE (1).
  short VScale; // DO NOT USE (9).
  short NumLoops; // number of LoopRecords to follow.
 
 Followed by NumLoops of the following records:
 
 typedef struct LoopRecord
 {
  long LoopStart; // Reference to start sample frame of this loop.
  long LoopEnd; // Reference to end sample frame of this loop.
  short LoopIndex; // Identifies which loop this is (1..NumLoops).
  short LoopSense; // 117=forward loop, 118=backwards/forwards loop.
  short Channel; // Channel which loop is on (0..NumChannels-1).
 } LoopRecord;
 
 Region List Resource Spec
 
 Type: 'ddRL' ID: 1000
  short VersionNumber; // Version of resource: 1 for current.
  long HeaderSize; // Size of the header in bytes NOT-INCLUDING VersionNumber
    // and HeaderSize.
  long RegionSize; // Size of each region in bytes.
  long ResourceDate; // Time stamp for last modification ie ticks since 1904....
    // see IM vol ?
  long NextID; // The next kosher RegionID to be used for the next region
    // created.
 
 Followed by a variable number of RegionRec's of the following format:
 
 typedef struct RegionRec
 {
  long RegionID; // Unique within a file, not necessarily in order.
  long StartFrame; // Number of sample frames into the file that the region
    // starts.
  long StopFrame; // Ditto as above but the frame past the end ie + 1.
  long SynchFrame; // Absolute frame number (ie not relative to region start)
    // for synch.
  long TimeStampMS; // Most significant long of time stamp ie time of day
    // absolute stamp.
  long TimeStampLS; // Least significant long of time stamp ie time of day
    // absolute stamp. Time stamp viewed as one 64 bit
    // number is the number of sample frames since the
    // Macintosh start time ie 1904.


 Str31 RegionName; // 31 character name NOT UNIQUE OR MEANINGFUL.
 } RegionRec;
 
 
 The first RegionRec shall be a special one such that it represents the entire file. Its fields are as follows:
 
 typedef struct RegionRec
 {
  long RegionID; // 0.
  long StartFrame; // 0.
  long StopFrame; // Undefined and not to be used - so the length of a file
    // is never stored...
  long SynchFrame; // As specified above.
  long TimeStampMS; // Current time of day.
  long TimeStampLS; // Current time of day.
  Str31 RegionName; // Same as the filename.
 } RegionRec;
 
 
 Reserved Parameter/Resource Types
 Digidesign reserves all resource types that begin with the letters 'sd' or 'dd' (capital and lower case) ie 'sdPL', 'SDxx', 'DDxx' or 'dDxx', for present and future use by Sound Designer II and other Digidesign programs.
 
 Data Fork
 The data of a Sound Designer II file is stored in Two's Complement encoding. Byte one of the data fork is the first byte of sound data. The sound data is organized as interleaved samples (if more then one channel) of either 8 or 16 bit samples depending on the value of the 'sample-size' STR resource (see below).
 
 For example, a standard 16 bit stereo file would be organized as follows:
 
 Left Channel sample #1
 Right Channel sample #1
 Left Channel sample #2
 Right Channel sample #2
 Left Channel sample #3
 Right Channel sample #3
 etc...
 
 Where each sample is the MSB (most significant byte) followed by the LSB (least significant byte) or better known as little endian format.
 

[ wrong !  its big endian ] 


 A four channel file would be as follows:
 
 Channel 1 sample #1
 Channel 2 sample #1
 Channel 3 sample #1
 Channel 4 sample #1
 Channel 1 sample #2
 Channel 2 sample #2
 Channel 3 sample #2
 Channel 4 sample #2
 etc...
 
 