home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / sound / soundstruct.h < prev    next >
Text File  |  1992-03-16  |  5KB  |  124 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. typedef struct {
  20.     int magic;          /* must be equal to SND_MAGIC */
  21.     int dataLocation;   /* Offset or pointer to the raw data */
  22.     int dataSize;       /* Number of bytes of data in the raw data */
  23.     int dataFormat;     /* The data format code */
  24.     int samplingRate;   /* The sampling rate */
  25.     int channelCount;   /* The number of channels */
  26.     char info[4];       /* Textual information relating to the sound. */
  27. } SNDSoundStruct;
  28.  
  29.  
  30. /*
  31.  * The magic number must appear at the beginning of every SNDSoundStruct.
  32.  * It is used for type checking and byte ordering information.
  33.  */
  34. #define SND_MAGIC ((int)0x2e736e64)
  35.  
  36. /*
  37.  * NeXT data format codes. User-defined formats should be greater than 255.
  38.  * Negative format numbers are reserved.
  39.  */
  40. #define SND_FOBSP_UNSPECIFIED          (0)
  41. #define SND_FORMAT_MULAW_8              (1)
  42. #define SND_FORMAT_LINEAR_8             (2)
  43. #define SND_FORMAT_LINEAR_16            (3)
  44. #define SND_FORMAT_LINEAR_24            (4)
  45. #define SND_FORMAT_LINEAR_32            (5)
  46. #define SND_FORMAT_FLOAT                (6)
  47. #define SND_FORMAT_DOUBLE               (7)
  48. #define SND_FORMAT_INDIRECT             (8)
  49. #define SND_FORMAT_NESTED               (9)
  50. #define SND_FORMAT_DSP_CORE             (10)
  51. #define SND_FORMAT_DSP_DATA_8           (11)
  52. #define SND_FORMAT_DSP_DATA_16          (12)
  53. #define SND_FORMAT_DSP_DATA_24          (13)
  54. #define SND_FORMAT_DSP_DATA_32          (14)
  55. #define SND_FORMAT_DISPLAY              (16)
  56. #define SND_FORMAT_MULAW_SQUELCH        (17)
  57. #define SND_FORMAT_EMPHASIZED           (18)
  58. #define SND_FORMAT_COMPRESSED           (19)
  59. #define SND_FORMAT_COMPRESSED_EMPHASIZED (20)
  60. #define SND_FORMAT_DSP_COMMANDS         (21)
  61. #define SND_FORMAT_DSP_COMMANDS_SAMPLES (22)
  62. #define SND_FORMAT_ADPCM_G721           (23)
  63. #define SND_FORMAT_ADPCM_G722           (24)
  64. #define SND_FORMAT_ADPCM_G723_3         (25)
  65. #define SND_FORMAT_ADPCM_G723_5         (26)
  66. #define SND_FORMAT_ALAW_8               (27)
  67.  
  68. /*
  69.  * Compression subheader which appears at the beginning of the data 
  70.  * (after the SNDSoundStruct header) in a compressed sound.
  71.  */
  72. typedef struct {
  73.     int originalSize;           /* in bytes */
  74.     int method;                 /* e.g. SND_CFORMAT_ATC (below) */
  75.     int numDropped;             /* for SND_CFORMAT_BITS_DROPPED */
  76.     int encodeLength;           /* uncompressed samples per encoded block */
  77.     int reserved;
  78. } SNDCompressionSubheader;
  79.  
  80. /*
  81.  * Compression types
  82.  */
  83. #define SND_CFORMAT_BITS_DROPPED        (0)
  84. #define SND_CFORMAT_BIT_FAITHFUL        (1)
  85. #define SND_CFORMAT_ATC                 (2) /* Audio Transform Compression*/
  86.  
  87. /* 
  88.  * After the compression subheader, each frame of an ATC-format soundfile
  89.  * begins with two bytes which characterize the frame as follows:
  90.  * 
  91.  * Byte     Contents
  92.  * -----    --------
  93.  *   0        Frame length in bytes, including these 2 leading bytes
  94.  *   1        Peak level for the frame, in a log-base-2 relative to 0dB.
  95.  *
  96.  * With these two bytes, an amplitude envelope can be constructed as follows:
  97.  * 
  98.  *    SNDCompressionSubheader *subheader = ((unsigned char *)soundPtr) 
  99.  *                    + soundPtr->dataLocation;
  100.  *     BSQigned char *fp = ((unsigned char *)subheader)
  101.  *                    + sizeof(SNDCompressionSubheader);
  102.  *      for (sample=0; sample < subheader->originalSize;) {
  103.  *          frameSize = *fp;
  104.  *          frameExponent = *(fp+1);
  105.  *          frameAmplitude = (32767 >> frameExponent); // approx amplitude
  106.  *          fp += frameSize;
  107.  *          sample += ATC_FRAME_SIZE;  // samples represented by frame
  108.  *          ...
  109.  *      }
  110.  *
  111.  * where ATC_FRAME_SIZE is the number of samples of the original sound
  112.  * which were compressed to create each frame, defined below.
  113.  *
  114.  */
  115. #define ATC_FRAME_SIZE (256)
  116.  
  117. /*
  118.  * Sampling rates directly supported in hardware.
  119.  */
  120. #define SND_RATE_CODEC          (8012.8210513)
  121. #define SND_RATE_LOW            (22050.0)
  122. #define SND_RATE_HIGH           (44100.0)
  123.  
  124.