annotate decoders/mpglib/mpglib_common.c @ 474:c66080364dff

Most decoders now report total sample play time, now. Technically, this breaks binary compatibility with the 1.0 branch, since it extends the Sound_Sample struct, but most (all?) programs are just passing pointers allocated by SDL_sound around, and might be okay. Source-level compatibility is not broken...yet! :) --ryan. -------- Original Message -------- Subject: SDL_sound patch: Finding total length of time of sound file. Date: Sun, 26 Jan 2003 09:31:17 -0800 (PST) Hi Ryan, I am working with Eric Wing and helping him modify SDL_sound. AS part of our efforts in improving and enhancing SDL_sound, we like to submit this patch. We modified the codecs to find the total time of a sound file. Below is the explanation of the patch. The patch is appended as an attachment to this email. * MOTIVATION: We needed the ability to get the total play time of a sample (And we noticed that we're not the only ones). Since SDL_sound blocks direct access to the specific decoders, there is no way for a user to know this information short of decoding the whole thing. Because of this, we believe this will be a useful addition, even though the accuracy may not be perfect (subject to each decoder) or the information may not always be available. * CONTRIBUTORS: Wesley Leong (modified the majority of the codecs and verified the results) Eric Wing (showed everyone how to do modify codec, modified mikmod) Wang Lam (modified a handful of codecs, researched into specs and int overflow) Ahilan Anantha (modified a few codecs and helped with integer math) * GENERAL ISSUES: We chose the value to be milliseconds as an Sint32. Milliseconds because that's what Sound_Seek takes as a parameter and -1 to allow for instances/codecs where the value could not be determined. We are not sure if this is the final convention you want, so we are willing to work with you on this. We also expect the total_time field to be set on open and never again modified by SDL_sound. Users may access it directly much like the sample buffer and buffer_size. We thought about recomputing the time on DecodeAll, but since users may seek or decode small chunks first, not all the data may be there. So this is better done by the user. This may be good information to document. Currently, all the main codecs are implemented except for QuickTime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 08 May 2004 08:19:50 +0000
parents fb519e6028e3
children
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
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 #include <ctype.h>
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 #include <stdlib.h>
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 #include "SDL_sound.h"
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 #define __SDL_SOUND_INTERNAL__
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 #include "SDL_sound_internal.h"
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 #include "mpg123_sdlsound.h"
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 struct parameter param = { 1 , 1 , 0 , 0 };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 int tabsel_123[2][3][16] = {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 long mpglib_freqs[9] = { 44100, 48000, 32000,
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 22050, 24000, 16000 ,
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 11025 , 12000 , 8000 };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 int bitindex;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 unsigned char *wordpointer;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 unsigned char *pcm_sample;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 int pcm_point = 0;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #define HDRCMPMASK 0xfffffd00
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #if 0
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 int head_check(unsigned long head)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 if( (head & 0xffe00000) != 0xffe00000)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 return FALSE;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 if(!((head>>17)&3))
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 return FALSE;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 if( ((head>>12)&0xf) == 0xf)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 return FALSE;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 if( ((head>>10)&0x3) == 0x3 )
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 return FALSE;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 return TRUE;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 /*
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 * the code a header and write the information
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 * into the frame structure
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 */
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 int decode_header(struct frame *fr,unsigned long newhead)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 if( newhead & (1<<20) ) {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 fr->mpeg25 = 0;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 else {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 fr->lsf = 1;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 fr->mpeg25 = 1;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 fr->lay = 4-((newhead>>17)&3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 if(fr->mpeg25) {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 else
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 fr->error_protection = ((newhead>>16)&0x1)^0x1;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 fr->bitrate_index = ((newhead>>12)&0xf);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 fr->bitrate_index = ((newhead>>12)&0xf);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 fr->padding = ((newhead>>9)&0x1);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 fr->extension = ((newhead>>8)&0x1);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 fr->mode = ((newhead>>6)&0x3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 fr->mode_ext = ((newhead>>4)&0x3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 fr->copyright = ((newhead>>3)&0x1);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 fr->original = ((newhead>>2)&0x1);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 fr->emphasis = newhead & 0x3;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 if(!fr->bitrate_index)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 switch(fr->lay)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 case 1:
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 #ifdef LAYER1
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 #if 0
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 (fr->mode_ext<<2)+4 : 32;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 fr->framesize /= mpglib_freqs[fr->sampling_frequency];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 break;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 case 2:
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 #ifdef LAYER2
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 #if 0
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 (fr->mode_ext<<2)+4 : fr->II_sblimit;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 fr->framesize /= mpglib_freqs[fr->sampling_frequency];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 fr->framesize += fr->padding - 4;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 break;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 case 3:
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 #if 0
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 fr->do_layer = do_layer3;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 if(fr->lsf)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 ssize = (fr->stereo == 1) ? 9 : 17;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 else
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 ssize = (fr->stereo == 1) ? 17 : 32;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 #if 0
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 if(fr->error_protection)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 ssize += 2;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 fr->framesize /= mpglib_freqs[fr->sampling_frequency]<<(fr->lsf);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 fr->framesize = fr->framesize + fr->padding - 4;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 break;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 }
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
149
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
150 fr->bitrate = (int) tabsel_123[fr->lsf][(fr->lay - 1)][fr->bitrate_index];
298
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 return 1;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 #if 0
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 void print_header(struct frame *fr)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 static char *layers[4] = { "Unknown" , "I", "II", "III" };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 layers[fr->lay],mpglib_freqs[fr->sampling_frequency],
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 modes[fr->mode],fr->mode_ext,fr->framesize+4);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 fr->stereo,fr->copyright?"Yes":"No",
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 fr->emphasis);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n",
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 void print_header_compact(struct frame *fr)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 static char *layers[4] = { "Unknown" , "I", "II", "III" };
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 layers[fr->lay],
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 mpglib_freqs[fr->sampling_frequency], modes[fr->mode]);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 #endif
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 unsigned int getbits(int number_of_bits)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 unsigned long rval;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 if(!number_of_bits)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 return 0;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 rval = wordpointer[0];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 rval <<= 8;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 rval |= wordpointer[1];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 rval <<= 8;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 rval |= wordpointer[2];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 rval <<= bitindex;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 rval &= 0xffffff;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 bitindex += number_of_bits;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 rval >>= (24-number_of_bits);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 wordpointer += (bitindex>>3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 bitindex &= 7;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 return rval;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 unsigned int getbits_fast(int number_of_bits)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 unsigned long rval;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 rval = wordpointer[0];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 rval <<= 8;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 rval |= wordpointer[1];
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 rval <<= bitindex;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 rval &= 0xffff;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 bitindex += number_of_bits;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 rval >>= (16-number_of_bits);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 wordpointer += (bitindex>>3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 bitindex &= 7;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 return rval;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 unsigned int get1bit(void)
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 {
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 unsigned char rval;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 rval = *wordpointer << bitindex;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 bitindex++;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 wordpointer += (bitindex>>3);
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 bitindex &= 7;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 return rval>>7;
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 }
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244
c92c07e07636 Renamed from common.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245