Mercurial > SDL_sound_CoreAudio
annotate decoders/mpglib/mpglib_common.c @ 414:eb7878e07dba
Added borland.zip to EXTRA_DIST.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 22 Aug 2002 09:48:56 +0000 |
parents | fb519e6028e3 |
children | c66080364dff |
rev | line source |
---|---|
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
1 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
2 #if HAVE_CONFIG_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
3 # include <config.h> |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
4 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
5 |
298 | 6 #include <ctype.h> |
7 #include <stdlib.h> | |
8 | |
9 #include "SDL_sound.h" | |
10 | |
11 #define __SDL_SOUND_INTERNAL__ | |
12 #include "SDL_sound_internal.h" | |
13 | |
14 #include "mpg123_sdlsound.h" | |
15 | |
16 struct parameter param = { 1 , 1 , 0 , 0 }; | |
17 | |
18 int tabsel_123[2][3][16] = { | |
19 { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,}, | |
20 {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,}, | |
21 {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} }, | |
22 | |
23 { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,}, | |
24 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}, | |
25 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} } | |
26 }; | |
27 | |
28 long mpglib_freqs[9] = { 44100, 48000, 32000, | |
29 22050, 24000, 16000 , | |
30 11025 , 12000 , 8000 }; | |
31 | |
32 int bitindex; | |
33 unsigned char *wordpointer; | |
34 unsigned char *pcm_sample; | |
35 int pcm_point = 0; | |
36 | |
37 | |
38 #define HDRCMPMASK 0xfffffd00 | |
39 | |
40 #if 0 | |
41 int head_check(unsigned long head) | |
42 { | |
43 if( (head & 0xffe00000) != 0xffe00000) | |
44 return FALSE; | |
45 if(!((head>>17)&3)) | |
46 return FALSE; | |
47 if( ((head>>12)&0xf) == 0xf) | |
48 return FALSE; | |
49 if( ((head>>10)&0x3) == 0x3 ) | |
50 return FALSE; | |
51 return TRUE; | |
52 } | |
53 #endif | |
54 | |
55 | |
56 /* | |
57 * the code a header and write the information | |
58 * into the frame structure | |
59 */ | |
60 int decode_header(struct frame *fr,unsigned long newhead) | |
61 { | |
62 if( newhead & (1<<20) ) { | |
63 fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1; | |
64 fr->mpeg25 = 0; | |
65 } | |
66 else { | |
67 fr->lsf = 1; | |
68 fr->mpeg25 = 1; | |
69 } | |
70 | |
71 fr->lay = 4-((newhead>>17)&3); | |
72 if( ((newhead>>10)&0x3) == 0x3) { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
73 BAIL_MACRO("MPGLIB: Corrupted header", 0); |
298 | 74 } |
75 if(fr->mpeg25) { | |
76 fr->sampling_frequency = 6 + ((newhead>>10)&0x3); | |
77 } | |
78 else | |
79 fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3); | |
80 fr->error_protection = ((newhead>>16)&0x1)^0x1; | |
81 | |
82 if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */ | |
83 fr->bitrate_index = ((newhead>>12)&0xf); | |
84 | |
85 fr->bitrate_index = ((newhead>>12)&0xf); | |
86 fr->padding = ((newhead>>9)&0x1); | |
87 fr->extension = ((newhead>>8)&0x1); | |
88 fr->mode = ((newhead>>6)&0x3); | |
89 fr->mode_ext = ((newhead>>4)&0x3); | |
90 fr->copyright = ((newhead>>3)&0x1); | |
91 fr->original = ((newhead>>2)&0x1); | |
92 fr->emphasis = newhead & 0x3; | |
93 | |
94 fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2; | |
95 | |
96 if(!fr->bitrate_index) | |
97 { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
98 BAIL_MACRO("MPGLIB: Free format not supported.", 0); |
298 | 99 } |
100 | |
101 switch(fr->lay) | |
102 { | |
103 case 1: | |
104 #ifdef LAYER1 | |
105 #if 0 | |
106 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? | |
107 (fr->mode_ext<<2)+4 : 32; | |
108 #endif | |
109 fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000; | |
110 fr->framesize /= mpglib_freqs[fr->sampling_frequency]; | |
111 fr->framesize = ((fr->framesize+fr->padding)<<2)-4; | |
112 #else | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
113 __Sound_SetError("MPGLIB: Not supported!"); |
298 | 114 #endif |
115 break; | |
116 case 2: | |
117 #ifdef LAYER2 | |
118 #if 0 | |
119 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? | |
120 (fr->mode_ext<<2)+4 : fr->II_sblimit; | |
121 #endif | |
122 fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000; | |
123 fr->framesize /= mpglib_freqs[fr->sampling_frequency]; | |
124 fr->framesize += fr->padding - 4; | |
125 #else | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
126 __Sound_SetError("MPGLIB: Not supported!"); |
298 | 127 #endif |
128 break; | |
129 case 3: | |
130 #if 0 | |
131 fr->do_layer = do_layer3; | |
132 if(fr->lsf) | |
133 ssize = (fr->stereo == 1) ? 9 : 17; | |
134 else | |
135 ssize = (fr->stereo == 1) ? 17 : 32; | |
136 #endif | |
137 | |
138 #if 0 | |
139 if(fr->error_protection) | |
140 ssize += 2; | |
141 #endif | |
142 fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000; | |
143 fr->framesize /= mpglib_freqs[fr->sampling_frequency]<<(fr->lsf); | |
144 fr->framesize = fr->framesize + fr->padding - 4; | |
145 break; | |
146 default: | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
147 BAIL_MACRO("MPGLIB: Unknown layer type.", 0); |
298 | 148 } |
149 return 1; | |
150 } | |
151 | |
152 #if 0 | |
153 void print_header(struct frame *fr) | |
154 { | |
155 static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" }; | |
156 static char *layers[4] = { "Unknown" , "I", "II", "III" }; | |
157 | |
158 fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", | |
159 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), | |
160 layers[fr->lay],mpglib_freqs[fr->sampling_frequency], | |
161 modes[fr->mode],fr->mode_ext,fr->framesize+4); | |
162 fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n", | |
163 fr->stereo,fr->copyright?"Yes":"No", | |
164 fr->original?"Yes":"No",fr->error_protection?"Yes":"No", | |
165 fr->emphasis); | |
166 fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n", | |
167 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension); | |
168 } | |
169 | |
170 void print_header_compact(struct frame *fr) | |
171 { | |
172 static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" }; | |
173 static char *layers[4] = { "Unknown" , "I", "II", "III" }; | |
174 | |
175 fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n", | |
176 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), | |
177 layers[fr->lay], | |
178 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index], | |
179 mpglib_freqs[fr->sampling_frequency], modes[fr->mode]); | |
180 } | |
181 | |
182 #endif | |
183 | |
184 unsigned int getbits(int number_of_bits) | |
185 { | |
186 unsigned long rval; | |
187 | |
188 if(!number_of_bits) | |
189 return 0; | |
190 | |
191 { | |
192 rval = wordpointer[0]; | |
193 rval <<= 8; | |
194 rval |= wordpointer[1]; | |
195 rval <<= 8; | |
196 rval |= wordpointer[2]; | |
197 rval <<= bitindex; | |
198 rval &= 0xffffff; | |
199 | |
200 bitindex += number_of_bits; | |
201 | |
202 rval >>= (24-number_of_bits); | |
203 | |
204 wordpointer += (bitindex>>3); | |
205 bitindex &= 7; | |
206 } | |
207 return rval; | |
208 } | |
209 | |
210 unsigned int getbits_fast(int number_of_bits) | |
211 { | |
212 unsigned long rval; | |
213 | |
214 { | |
215 rval = wordpointer[0]; | |
216 rval <<= 8; | |
217 rval |= wordpointer[1]; | |
218 rval <<= bitindex; | |
219 rval &= 0xffff; | |
220 bitindex += number_of_bits; | |
221 | |
222 rval >>= (16-number_of_bits); | |
223 | |
224 wordpointer += (bitindex>>3); | |
225 bitindex &= 7; | |
226 } | |
227 return rval; | |
228 } | |
229 | |
230 unsigned int get1bit(void) | |
231 { | |
232 unsigned char rval; | |
233 rval = *wordpointer << bitindex; | |
234 | |
235 bitindex++; | |
236 wordpointer += (bitindex>>3); | |
237 bitindex &= 7; | |
238 | |
239 return rval>>7; | |
240 } | |
241 | |
242 | |
243 |