00001 /* 00002 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 00003 * 00004 * @APPLE_LICENSE_HEADER_START@ 00005 * 00006 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights 00007 * Reserved. This file contains Original Code and/or Modifications of 00008 * Original Code as defined in and that are subject to the Apple Public 00009 * Source License Version 1.0 (the 'License'). You may not use this file 00010 * except in compliance with the License. Please obtain a copy of the 00011 * License at http://www.apple.com/publicsource and read it before using 00012 * this file. 00013 * 00014 * The Original Code and all software distributed under the License are 00015 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 00016 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 00017 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 00018 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 00019 * License for the specific language governing rights and limitations 00020 * under the License." 00021 * 00022 * @APPLE_LICENSE_HEADER_END@ 00023 */ 00024 /* 00025 * soundstruct.h 00026 * Copyright 1988-94 NeXT, Inc. 00027 * 00028 * SNDSoundStruct - This data format for sound is used as the soundfile 00029 * format, and also the "NeXT sound pasteboard type". It consists of a header 00030 * and two variable length quantities: textual information (the info string) 00031 * and raw data. The raw data starts past the info; the dataLocation is 00032 * normally used to specify an offset from the beginning of the SNDSoundStruct 00033 * structure to this data. The dataSize is the length of the raw data in bytes. 00034 * The dataFormat, samplingRate, and channelCount further describe the data. 00035 * The data itself may be anything; the format determines what the data 00036 * actually means (i.e. sample data, dsp core structure). 00037 * The magic number value may be used to determine the byte order of the data. 00038 * The info string is any null-terminated data that the application may need 00039 * (i.e. copyright information, textual description). The four bytes allocated 00040 * are a minimum; the info string may extend any length beyond the structure. 00041 */ 00042 00043 #ifndef __SOUNDSTRUCT__ 00044 #define __SOUNDSTRUCT__ 00045 00046 typedef struct { 00047 int magic; /* must be equal to SND_MAGIC */ 00048 int dataLocation; /* Offset or pointer to the raw data */ 00049 int dataSize; /* Number of bytes of data in the raw data */ 00050 int dataFormat; /* The data format code */ 00051 int samplingRate; /* The sampling rate */ 00052 int channelCount; /* The number of channels */ 00053 char info[4]; /* Textual information relating to the sound. */ 00054 } SndSoundStruct; 00055 00056 00057 /* 00058 * The magic number must appear at the beginning of every SNDSoundStruct. 00059 * It is used for type checking and byte ordering information. 00060 */ 00061 #define SND_MAGIC ((int)0x2e736e64) 00062 00063 /* 00064 * NeXT data format codes. User-defined formats should be greater than 255. 00065 * Negative format numbers are reserved. 00066 */ 00067 #define SND_FORMAT_UNSPECIFIED (0) 00068 #define SND_FORMAT_MULAW_8 (1) 00069 #define SND_FORMAT_LINEAR_8 (2) 00070 #define SND_FORMAT_LINEAR_16 (3) 00071 #define SND_FORMAT_LINEAR_24 (4) 00072 #define SND_FORMAT_LINEAR_32 (5) 00073 #define SND_FORMAT_FLOAT (6) 00074 #define SND_FORMAT_DOUBLE (7) 00075 #define SND_FORMAT_INDIRECT (8) 00076 #define SND_FORMAT_NESTED (9) 00077 #define SND_FORMAT_DSP_CORE (10) 00078 #define SND_FORMAT_DSP_DATA_8 (11) 00079 #define SND_FORMAT_DSP_DATA_16 (12) 00080 #define SND_FORMAT_DSP_DATA_24 (13) 00081 #define SND_FORMAT_DSP_DATA_32 (14) 00082 #define SND_FORMAT_DISPLAY (16) 00083 #define SND_FORMAT_MULAW_SQUELCH (17) 00084 #define SND_FORMAT_EMPHASIZED (18) 00085 #define SND_FORMAT_COMPRESSED (19) 00086 #define SND_FORMAT_COMPRESSED_EMPHASIZED (20) 00087 #define SND_FORMAT_DSP_COMMANDS (21) 00088 #define SND_FORMAT_DSP_COMMANDS_SAMPLES (22) 00089 #define SND_FORMAT_ADPCM_G721 (23) 00090 #define SND_FORMAT_ADPCM_G722 (24) 00091 #define SND_FORMAT_ADPCM_G723_3 (25) 00092 #define SND_FORMAT_ADPCM_G723_5 (26) 00093 #define SND_FORMAT_ALAW_8 (27) 00094 #define SND_FORMAT_AES (28) 00095 #define SND_FORMAT_DELTA_MULAW_8 (29) 00096 00097 /* 00098 * Compression subheader which appears at the beginning of the data 00099 * (after the SNDSoundStruct header) in a compressed sound. 00100 */ 00101 typedef struct { 00102 int originalSize; /* in bytes */ 00103 int method; /* e.g. SND_CFORMAT_ATC (below) */ 00104 int numDropped; /* for SND_CFORMAT_BITS_DROPPED */ 00105 int encodeLength; /* uncompressed samples per encoded block */ 00106 int reserved; 00107 } SNDCompressionSubheader; 00108 00109 /* 00110 * Compression types 00111 */ 00112 #define SND_CFORMAT_BITS_DROPPED (0) 00113 #define SND_CFORMAT_BIT_FAITHFUL (1) 00114 #define SND_CFORMAT_ATC (2) /* Audio Transform Compression*/ 00115 00116 /* 00117 * After the compression subheader, each frame of an ATC-format soundfile 00118 * begins with two bytes which characterize the frame as follows: 00119 * 00120 * Byte Contents 00121 * ----- -------- 00122 * 0 Frame length in bytes, including these 2 leading bytes 00123 * 1 Peak level for the frame, in log-base-2 relative to 0dB. 00124 * 00125 * With these two bytes, an amplitude envelope can be constructed as follows: 00126 * 00127 * SNDCompressionSubheader *subheader = ((unsigned char *)soundPtr) 00128 * + soundPtr->dataLocation; 00129 * unsigned char *fp = ((unsigned char *)subheader) 00130 * + sizeof(SNDCompressionSubheader); 00131 * for (sample=0; sample < subheader->originalSize/sizeof(short);) { 00132 * frameSize = *fp; 00133 * frameExponent = *(fp+1); 00134 * frameAmplitude = (32767 >> frameExponent); // approx amplitude 00135 * fp += frameSize; 00136 * sample += ATC_FRAME_SIZE; // sample count represented by frame 00137 * ... 00138 * } 00139 * 00140 * where ATC_FRAME_SIZE is the number of samples of the original sound 00141 * which were compressed to create each frame, defined below. 00142 * 00143 * For stereo sounds, left and right channels are frame-interleaved. 00144 * The first frame is a left-channel frame, the second is right, and so on. 00145 * 00146 * For mono sounds, and for each channel of a stereo sound, the frames 00147 * are best handled in successive pairs. For example, to modify the playback 00148 * speed of a sound by repeating or deleting frames, adjacent pairs of frames 00149 * should be repeated or deleted. Similarly, playing a sound from an interior 00150 * point should begin on an "even" frame boundary, where frame 0 is the first. 00151 * This restriction is because ATC alternates the discrete sine transform (DST) 00152 * with the discrete cosine transform (DCT) on a frame by frame basis. 00153 * 00154 */ 00155 #define ATC_FRAME_SIZE (256) 00156 00157 /* 00158 * Sampling rates directly supported in hardware. 00159 */ 00160 #define SND_RATE_CODEC (8012.8210513) 00161 #define SND_RATE_LOW (22050.0) 00162 #define SND_RATE_HIGH (44100.0) 00163 #define SND_RATE_LOW_PC (11025.0) 00164 00165 #endif __SOUNDSTRUCT__