1 /* $Id: private.h,v 1.22 2007/09/19 12:00:59 toad32767 Exp $ */ 2 3 #if !defined(HAVE_MEMSET) && defined(HAVE_BZERO) 4 #ifdef HAVE_STRINGS_H 5 #include <strings.h> 6 #endif 7 8 #ifdef HAVE_STRING_H 9 #include <string.h> 10 #endif 11 12 #define memset(a, b, c) bzero((a), (c)) 13 14 #endif 15 16 #ifdef MIN 17 #undef MIN 18 #endif 19 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 20 21 #ifdef ASSERT 22 #undef ASSERT 23 #endif 24 25 void AIFFAssertionFailed (const char*, int); 26 27 #define ASSERT(x) if(!(x)) AIFFAssertionFailed(__FILE__, __LINE__) 28 29 /* == Supported formats == */ 30 31 /* File formats */ 32 #define AIFF_TYPE_IFF ARRANGE_BE32(0x464F524D) 33 #define AIFF_TYPE_AIFF ARRANGE_BE32(0x41494646) 34 #define AIFF_TYPE_AIFC ARRANGE_BE32(0x41494643) 35 36 /* Audio encoding formats */ 37 #define AUDIO_FORMAT_LPCM ARRANGE_BE32(0x4E4F4E45) 38 #define AUDIO_FORMAT_lpcm ARRANGE_BE32(0x6C70636D) 39 #define AUDIO_FORMAT_twos ARRANGE_BE32(0x74776F73) 40 #define AUDIO_FORMAT_sowt ARRANGE_LE32(0x74776F73) 41 #define AUDIO_FORMAT_ULAW ARRANGE_BE32(0x554C4157) 42 #define AUDIO_FORMAT_ulaw ARRANGE_BE32(0x756C6177) 43 #define AUDIO_FORMAT_ALAW ARRANGE_BE32(0x414C4157) 44 #define AUDIO_FORMAT_alaw ARRANGE_BE32(0x616C6177) 45 #define AUDIO_FORMAT_FL32 ARRANGE_BE32(0x464c3332) 46 #define AUDIO_FORMAT_fl32 ARRANGE_BE32(0x666c3332) 47 #define AUDIO_FORMAT_UNKNOWN 0xFFFFFFFF 48 49 /* OSTypes */ 50 #define AIFF_FORM 0x464f524d 51 #define AIFF_AIFF 0x41494646 52 #define AIFF_AIFC 0x41494643 53 #define AIFF_FVER 0x46564552 54 #define AIFF_COMM 0x434f4d4d 55 #define AIFF_SSND 0x53534e44 56 #define AIFF_MARK 0x4d41524b 57 #define AIFF_INST 0x494e5354 58 #define AIFF_COMT 0x434f4d54 59 60 /* Standards & specifications */ 61 #define AIFC_STD_DRAFT_082691 2726318400U 62 63 struct s_IFFHeader 64 { 65 IFFType hid ; 66 uint32_t len ; 67 IFFType fid ; 68 } ; 69 typedef struct s_IFFHeader IFFHeader ; 70 71 struct s_IFFChunk 72 { 73 IFFType id ; 74 uint32_t len ; 75 } ; 76 typedef struct s_IFFChunk IFFChunk ; 77 78 /* 79 * WARNING: this struct is not alignment-safe! 80 */ 81 struct s_AIFFCommon 82 { 83 uint16_t numChannels ; 84 uint32_t numSampleFrames ; 85 uint16_t sampleSize ; 86 iext sampleRate ; /* Motorola 80-bit extended */ 87 } ; 88 typedef struct s_AIFFCommon CommonChunk ; 89 90 struct s_AIFFSound 91 { 92 uint32_t offset ; 93 uint32_t blockSize ; 94 } ; 95 typedef struct s_AIFFSound SoundChunk ; 96 97 struct s_Marker 98 { 99 MarkerId id ; 100 uint32_t position ; 101 uint8_t markerNameLen ; 102 char markerName ; 103 } ; 104 typedef struct s_Marker Marker ; 105 106 struct s_AIFFMarker 107 { 108 uint16_t numMarkers ; 109 char markers ; 110 } ; 111 typedef struct s_AIFFMarker MarkerChunk ; 112 113 struct s_AIFFLoop 114 { 115 int16_t playMode ; 116 MarkerId beginLoop ; 117 MarkerId endLoop ; 118 uint16_t garbage ; /* not read (size=6 bytes) */ 119 } ; 120 typedef struct s_AIFFLoop AIFFLoop ; 121 122 123 struct s_Comment 124 { 125 uint32_t timeStamp ; 126 MarkerId marker ; 127 uint16_t count ; 128 char text ; 129 } ; 130 typedef struct s_Comment Comment ; 131 132 struct s_AIFFComment 133 { 134 uint16_t numComments ; 135 char comments ; 136 } ; 137 typedef struct s_AIFFComment CommentChunk ; 138 139 struct decoder { 140 IFFType fmt; 141 int (*construct) (AIFF_Ref); 142 size_t (*read_lpcm)(AIFF_Ref, void *, size_t); 143 int (*read_float32)(AIFF_Ref, float *, int); 144 int (*seek)(AIFF_Ref, uint64_t); 145 void (*delete) (AIFF_Ref); 146 }; 147 148 /* iff.c */ 149 int find_iff_chunk(IFFType, AIFF_Ref, uint32_t *) ; 150 char* get_iff_attribute(AIFF_Ref r,IFFType attrib) ; 151 int set_iff_attribute(AIFF_Ref w,IFFType attrib,char* str) ; 152 int clone_iff_attributes(AIFF_Ref w, AIFF_Ref r) ; 153 154 /* aifx.c */ 155 int init_aifx(AIFF_Ref) ; 156 int read_aifx_marker(AIFF_Ref r,int* id,uint64_t* position,char** name) ; 157 int get_aifx_instrument(AIFF_Ref r,Instrument* inpi) ; 158 int do_aifx_prepare(AIFF_Ref r) ; 159 char * get_aifx_enc_name(IFFType) ; 160 161 /* lpcm.c */ 162 void lpcm_swap_samples(int,int,void*,void*,int); 163 void lpcm_dequant(int segmentSize, void *buffer, float *outFrames, int nFrames); 164 extern struct decoder lpcm; 165 166 /* g711.c */ 167 extern struct decoder ulaw; 168 extern struct decoder alaw; 169 170 /* float32.c */ 171 extern struct decoder float32; 172 173 /* extended.c */ 174 void ieee754_write_extended (double, uint8_t*); 175 double ieee754_read_extended (uint8_t*); 176 177 /* pascal.c */ 178 int PASCALInGetLength (FILE *); 179 char * PASCALInRead (FILE *, int *); 180 int PASCALOutGetLength (char *); 181 int PASCALOutWrite (FILE *, char *); 182 183 184