home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / sound / soundstruct.h < prev    next >
C/C++ Source or Header  |  1993-03-18  |  6KB  |  143 lines

  1. /*
  2.  *      soundstruct.h
  3.  *      Copyright 1988-89 NeXT, Inc.
  4.  *
  5.  * SNDSoundStruct - This data format for sound is used as the soundfile
  6.  * format, and also the "NeXT sound pasteboard type". It consists of a header
  7.  * and two variable length quantities: textual information (the info string)
  8.  * and raw data. The raw data starts past the info; the dataLocation is
  9.  * normally used to specify an offset from the beginning of the SNDSoundStruct
  10.  * structure to this data. The dataSize is the length of the raw data in bytes. 
  11.  * The dataFormat, samplingRate, and channelCount further describe the data.
  12.  * The data itself may be anything; the format determines what the data
  13.  * actually means (i.e. sample data, dsp core structure).
  14.  * The magic number value may be used to determine the byte order of the data.
  15.  * The info string is any null-terminated data that the application may need
  16.  * (i.e. copyright information, textual description). The four bytes allocated
  17.  * are a minimum; the info string may extend any length beyond the structure.
  18.  */
  19.  
  20. #ifndef __SOUNDSTRUCT__
  21. #define __SOUNDSTRUCT__
  22.  
  23. typedef struct {
  24.     int magic;          /* must be equal to SND_MAGIC */
  25.     int dataLocation;   /* Offset or pointer to the raw data */
  26.     int dataSize;       /* Number of bytes of data in the raw data */
  27.     int dataFormat;     /* The data format code */
  28.     int samplingRate;   /* The sampling rate */
  29.     int channelCount;   /* The number of channels */
  30.     char info[4];       /* Textual information relating to the sound. */
  31. } SNDSoundStruct;
  32.  
  33.  
  34. /*
  35.  * The magic number must appear at the beginning of every SNDSoundStruct.
  36.  * It is used for type checking and byte ordering information.
  37.  */
  38. #define SND_MAGIC ((int)0x2e736e64)
  39.  
  40. /*
  41.  * NeXT data format codes. User-defined formats should be greater than 255.
  42.  * Negative format numbers are reserved.
  43.  */
  44. #define SND_FORMAT_UNSPECIFIED          (0)
  45. #define SND_FORMAT_MULAW_8              (1)
  46. #define SND_FORMAT_LINEAR_8             (2)
  47. #define SND_FORMAT_LINEAR_16            (3)
  48. #define SND_FORMAT_LINEAR_24            (4)
  49. #define SND_FORMAT_LINEAR_32            (5)
  50. #define SND_FORMAT_FLOAT                (6)
  51. #define SND_FORMAT_DOUBLE               (7)
  52. #define SND_FORMAT_INDIRECT             (8)
  53. #define SND_FORMAT_NESTED               (9)
  54. #define SND_FORMAT_DSP_CORE             (10)
  55. #define SND_FORMAT_DSP_DATA_8           (11)
  56. #define SND_FORMAT_DSP_DATA_16          (12)
  57. #define SND_FORMAT_DSP_DATA_24          (13)
  58. #define SND_FORMAT_DSP_DATA_32          (14)
  59. #define SND_FORMAT_DISPLAY              (16)
  60. #define SND_FORMAT_MULAW_SQUELCH        (17)
  61. #define SND_FORMAT_EMPHASIZED           (18)
  62. #define SND_FORMAT_COMPRESSED           (19)
  63. #define SND_FORMAT_COMPRESSED_EMPHASIZED (20)
  64. #define SND_FORMAT_DSP_COMMANDS         (21)
  65. #define SND_FORMAT_DSP_COMMANDS_SAMPLES (22)
  66. #define SND_FORMAT_ADPCM_G721           (23)
  67. #define SND_FORMAT_ADPCM_G722           (24)
  68. #define SND_FORMAT_ADPCM_G723_3         (25)
  69. #define SND_FORMAT_ADPCM_G723_5         (26)
  70. #define SND_FORMAT_ALAW_8               (27)
  71. #define SND_FORMAT_AES                  (28)
  72. #define SND_FORMAT_DELTA_MULAW_8    (29)
  73.  
  74. /*
  75.  * Compression subheader which appears at the beginning of the data 
  76.  * (after the SNDSoundStruct header) in a compressed sound.
  77.  */
  78. typedef struct {
  79.     int originalSize;           /* in bytes */
  80.     int method;                 /* e.g. SND_CFORMAT_ATC (below) */
  81.     int numDropped;             /* for SND_CFORMAT_BITS_DROPPED */
  82.     int encodeLength;           /* uncompressed samples per encoded block */
  83.     int reserved;
  84. } SNDCompressionSubheader;
  85.  
  86. /*
  87.  * Compression types
  88.  */
  89. #define SND_CFORMAT_BITS_DROPPED        (0)
  90. #define SND_CFORMAT_BIT_FAITHFUL        (1)
  91. #define SND_CFORMAT_ATC                 (2) /* Audio Transform Compression*/
  92.  
  93. /* 
  94.  * After the compression subheader, each frame of an ATC-format soundfile
  95.  * begins with two bytes which characterize the frame as follows:
  96.  * 
  97.  * Byte     Contents
  98.  * -----    --------
  99.  *   0        Frame length in bytes, including these 2 leading bytes
  100.  *   1        Peak level for the frame, in log-base-2 relative to 0dB.
  101.  *
  102.  * With these two bytes, an amplitude envelope can be constructed as follows:
  103.  * 
  104.  *    SNDCompressionSubheader *subheader = ((unsigned char *)soundPtr) 
  105.  *                    + soundPtr->dataLocation;
  106.  *      unsigned char *fp = ((unsigned char *)subheader)
  107.  *                    + sizeof(SNDCompressionSubheader);
  108.  *      for (sample=0; sample < subheader->originalSize/sizeof(short);) {
  109.  *          frameSize = *fp;
  110.  *          frameExponent = *(fp+1);
  111.  *          frameAmplitude = (32767 >> frameExponent); // approx amplitude
  112.  *          fp += frameSize;
  113.  *          sample += ATC_FRAME_SIZE;  // sample count represented by frame
  114.  *          ...
  115.  *      }
  116.  *
  117.  * where ATC_FRAME_SIZE is the number of samples of the original sound
  118.  * which were compressed to create each frame, defined below.
  119.  *
  120.  * For stereo sounds, left and right channels are frame-interleaved.
  121.  * The first frame is a left-channel frame, the second is right, and so on.
  122.  *
  123.  * For mono sounds, and for each channel of a stereo sound, the frames
  124.  * are best handled in successive pairs.  For example, to modify the playback
  125.  * speed of a sound by repeating or deleting frames, adjacent pairs of frames
  126.  * should be repeated or deleted.  Similarly, playing a sound from an interior
  127.  * point should begin on an "even" frame boundary, where frame 0 is the first.
  128.  * This restriction is because ATC alternates the discrete sine transform (DST)
  129.  * with the discrete cosine transform (DCT) on a frame by frame basis.
  130.  *
  131.  */
  132. #define ATC_FRAME_SIZE (256)
  133.  
  134. /*
  135.  * Sampling rates directly supported in hardware.
  136.  */
  137. #define SND_RATE_CODEC          (8012.8210513)
  138. #define SND_RATE_LOW            (22050.0)
  139. #define SND_RATE_HIGH           (44100.0)
  140. #define SND_RATE_LOW_PC         (11025.0)
  141.  
  142. #endif __SOUNDSTRUCT__
  143.