Mercurial > SDL_sound_CoreAudio
annotate decoders/mpglib/mpglib_common.c @ 377:cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 02 Jul 2002 03:58:24 +0000 |
parents | 31cc49d7d0ce |
children | fb519e6028e3 |
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) { | |
73 Sound_SetError("MPGLIB: Corrupted header"); | |
74 return 0; | |
75 } | |
76 if(fr->mpeg25) { | |
77 fr->sampling_frequency = 6 + ((newhead>>10)&0x3); | |
78 } | |
79 else | |
80 fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3); | |
81 fr->error_protection = ((newhead>>16)&0x1)^0x1; | |
82 | |
83 if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */ | |
84 fr->bitrate_index = ((newhead>>12)&0xf); | |
85 | |
86 fr->bitrate_index = ((newhead>>12)&0xf); | |
87 fr->padding = ((newhead>>9)&0x1); | |
88 fr->extension = ((newhead>>8)&0x1); | |
89 fr->mode = ((newhead>>6)&0x3); | |
90 fr->mode_ext = ((newhead>>4)&0x3); | |
91 fr->copyright = ((newhead>>3)&0x1); | |
92 fr->original = ((newhead>>2)&0x1); | |
93 fr->emphasis = newhead & 0x3; | |
94 | |
95 fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2; | |
96 | |
97 if(!fr->bitrate_index) | |
98 { | |
99 Sound_SetError("MPGLIB: Free format not supported."); | |
100 return (0); | |
101 } | |
102 | |
103 switch(fr->lay) | |
104 { | |
105 case 1: | |
106 #ifdef LAYER1 | |
107 #if 0 | |
108 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? | |
109 (fr->mode_ext<<2)+4 : 32; | |
110 #endif | |
111 fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000; | |
112 fr->framesize /= mpglib_freqs[fr->sampling_frequency]; | |
113 fr->framesize = ((fr->framesize+fr->padding)<<2)-4; | |
114 #else | |
115 Sound_SetError("MPGLIB: Not supported!"); | |
116 #endif | |
117 break; | |
118 case 2: | |
119 #ifdef LAYER2 | |
120 #if 0 | |
121 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? | |
122 (fr->mode_ext<<2)+4 : fr->II_sblimit; | |
123 #endif | |
124 fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000; | |
125 fr->framesize /= mpglib_freqs[fr->sampling_frequency]; | |
126 fr->framesize += fr->padding - 4; | |
127 #else | |
128 Sound_SetError("MPGLIB: Not supported!"); | |
129 #endif | |
130 break; | |
131 case 3: | |
132 #if 0 | |
133 fr->do_layer = do_layer3; | |
134 if(fr->lsf) | |
135 ssize = (fr->stereo == 1) ? 9 : 17; | |
136 else | |
137 ssize = (fr->stereo == 1) ? 17 : 32; | |
138 #endif | |
139 | |
140 #if 0 | |
141 if(fr->error_protection) | |
142 ssize += 2; | |
143 #endif | |
144 fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000; | |
145 fr->framesize /= mpglib_freqs[fr->sampling_frequency]<<(fr->lsf); | |
146 fr->framesize = fr->framesize + fr->padding - 4; | |
147 break; | |
148 default: | |
149 Sound_SetError("MPGLIB: Unknown layer type."); | |
150 return (0); | |
151 } | |
152 return 1; | |
153 } | |
154 | |
155 #if 0 | |
156 void print_header(struct frame *fr) | |
157 { | |
158 static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" }; | |
159 static char *layers[4] = { "Unknown" , "I", "II", "III" }; | |
160 | |
161 fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", | |
162 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), | |
163 layers[fr->lay],mpglib_freqs[fr->sampling_frequency], | |
164 modes[fr->mode],fr->mode_ext,fr->framesize+4); | |
165 fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n", | |
166 fr->stereo,fr->copyright?"Yes":"No", | |
167 fr->original?"Yes":"No",fr->error_protection?"Yes":"No", | |
168 fr->emphasis); | |
169 fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n", | |
170 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension); | |
171 } | |
172 | |
173 void print_header_compact(struct frame *fr) | |
174 { | |
175 static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" }; | |
176 static char *layers[4] = { "Unknown" , "I", "II", "III" }; | |
177 | |
178 fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n", | |
179 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), | |
180 layers[fr->lay], | |
181 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index], | |
182 mpglib_freqs[fr->sampling_frequency], modes[fr->mode]); | |
183 } | |
184 | |
185 #endif | |
186 | |
187 unsigned int getbits(int number_of_bits) | |
188 { | |
189 unsigned long rval; | |
190 | |
191 if(!number_of_bits) | |
192 return 0; | |
193 | |
194 { | |
195 rval = wordpointer[0]; | |
196 rval <<= 8; | |
197 rval |= wordpointer[1]; | |
198 rval <<= 8; | |
199 rval |= wordpointer[2]; | |
200 rval <<= bitindex; | |
201 rval &= 0xffffff; | |
202 | |
203 bitindex += number_of_bits; | |
204 | |
205 rval >>= (24-number_of_bits); | |
206 | |
207 wordpointer += (bitindex>>3); | |
208 bitindex &= 7; | |
209 } | |
210 return rval; | |
211 } | |
212 | |
213 unsigned int getbits_fast(int number_of_bits) | |
214 { | |
215 unsigned long rval; | |
216 | |
217 { | |
218 rval = wordpointer[0]; | |
219 rval <<= 8; | |
220 rval |= wordpointer[1]; | |
221 rval <<= bitindex; | |
222 rval &= 0xffff; | |
223 bitindex += number_of_bits; | |
224 | |
225 rval >>= (16-number_of_bits); | |
226 | |
227 wordpointer += (bitindex>>3); | |
228 bitindex &= 7; | |
229 } | |
230 return rval; | |
231 } | |
232 | |
233 unsigned int get1bit(void) | |
234 { | |
235 unsigned char rval; | |
236 rval = *wordpointer << bitindex; | |
237 | |
238 bitindex++; | |
239 wordpointer += (bitindex>>3); | |
240 bitindex &= 7; | |
241 | |
242 return rval>>7; | |
243 } | |
244 | |
245 | |
246 |