annotate decoders/mpglib/interface.c @ 274:9e7f9e09ea0e

Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 10 Mar 2002 19:15:25 +0000
parents e1429f96aded
children 52b9f37998db
rev   line source
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 #include <stdlib.h>
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 #include <stdio.h>
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
5 #include "SDL_sound.h"
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
6
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
7 #define __SDL_SOUND_INTERNAL__
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
8 #include "SDL_sound_internal.h"
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
9
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 #include "mpg123_sdlsound.h"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 #include "mpglib_sdlsound.h"
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 /* Global mp .. it's a hack */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 struct mpstr *gmp;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 BOOL InitMP3(struct mpstr *mp)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 static int init = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 memset(mp,0,sizeof(struct mpstr));
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 mp->framesize = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 mp->fsizeold = -1;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 mp->bsize = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 mp->head = mp->tail = NULL;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 mp->fr.single = -1;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 mp->bsnum = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 mp->synth_bo = 1;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 if(!init) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 init = 1;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 make_decode_tables(32767);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 init_layer2();
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 init_layer3(SBLIMIT);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 return !0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 void ExitMP3(struct mpstr *mp)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 struct buf *b,*bn;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 b = mp->tail;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 while(b) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 free(b->pnt);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 bn = b->next;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 free(b);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 b = bn;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 static struct buf *addbuf(struct mpstr *mp,char *buf,int size)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 struct buf *nbuf;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 nbuf = malloc( sizeof(struct buf) );
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 if(!nbuf) {
274
9e7f9e09ea0e Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents: 273
diff changeset
60 Sound_SetError("MPGLIB: Out of memory!");
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 return NULL;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 nbuf->pnt = malloc(size);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 if(!nbuf->pnt) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 free(nbuf);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 return NULL;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 nbuf->size = size;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 memcpy(nbuf->pnt,buf,size);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 nbuf->next = NULL;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 nbuf->prev = mp->head;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 nbuf->pos = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 if(!mp->tail) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 mp->tail = nbuf;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 else {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 mp->head->next = nbuf;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 mp->head = nbuf;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 mp->bsize += size;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 return nbuf;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 static void remove_buf(struct mpstr *mp)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 struct buf *buf = mp->tail;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 mp->tail = buf->next;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 if(mp->tail)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 mp->tail->prev = NULL;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 else {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 mp->tail = mp->head = NULL;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 free(buf->pnt);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 free(buf);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
103 static int read_buf_byte(struct mpstr *mp, unsigned long *retval)
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 int pos;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 pos = mp->tail->pos;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 while(pos >= mp->tail->size) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 remove_buf(mp);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 pos = mp->tail->pos;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 if(!mp->tail) {
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
112 Sound_SetError("MPGLIB: Fatal error! Short read in read_buf_byte()!");
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
113 return 0;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
117 if (retval != NULL)
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
118 *retval = mp->tail->pnt[pos];
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
119
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 mp->bsize--;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 mp->tail->pos++;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
123 return 1;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
126 static int read_head(struct mpstr *mp)
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 {
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
128 unsigned long val;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 unsigned long head;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
131 if (!read_buf_byte(mp, &val))
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
132 return 0;
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
133
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
134 head = val << 8;
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
135
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
136 if (!read_buf_byte(mp, &val))
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
137 return 0;
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
138
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
139 head |= val;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 head <<= 8;
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
141
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
142 if (!read_buf_byte(mp, &val))
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
143 return 0;
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
144
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
145 head |= val;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 head <<= 8;
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
147
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
148 if (!read_buf_byte(mp, &val))
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
149 return 0;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
151 head |= val;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 mp->header = head;
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
153 return 1;
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 int osize,int *done)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 int len;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 gmp = mp;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 if(osize < 4608) {
274
9e7f9e09ea0e Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents: 273
diff changeset
164 Sound_SetError("MPGLIB: Not enough output space for decoding!");
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 return MP3_ERR;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 if(in) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 if(addbuf(mp,in,isize) == NULL) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 return MP3_ERR;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 /* First decode header */
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 if(mp->framesize == 0) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 if(mp->bsize < 4) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 return MP3_NEED_MORE;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 }
273
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
179
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
180 if (!read_head(mp))
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
181 return MP3_ERR;
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
182
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
183 if (!decode_header(&mp->fr,mp->header))
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
184 return MP3_ERR;
e1429f96aded Replaced exit() calls with proper error reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 261
diff changeset
185
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 mp->framesize = mp->fr.framesize;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 if(mp->fr.framesize > mp->bsize)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 return MP3_NEED_MORE;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 wordpointer = mp->bsspace[mp->bsnum] + 512;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 mp->bsnum = (mp->bsnum + 1) & 0x1;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 bitindex = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 len = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 while(len < mp->framesize) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 int nlen;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 int blen = mp->tail->size - mp->tail->pos;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 if( (mp->framesize - len) <= blen) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 nlen = mp->framesize-len;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 else {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 nlen = blen;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 memcpy(wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 len += nlen;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 mp->tail->pos += nlen;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 mp->bsize -= nlen;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 if(mp->tail->pos == mp->tail->size) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 remove_buf(mp);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 *done = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 if(mp->fr.error_protection)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 getbits(16);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 switch(mp->fr.lay) {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 case 1:
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 do_layer1(&mp->fr,(unsigned char *) out,done);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 break;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 case 2:
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 do_layer2(&mp->fr,(unsigned char *) out,done);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 break;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 case 3:
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 do_layer3(&mp->fr,(unsigned char *) out,done);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 break;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 mp->fsizeold = mp->framesize;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 mp->framesize = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 return MP3_OK;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 int set_pointer(long backstep)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 {
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 unsigned char *bsbufold;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 if(gmp->fsizeold < 0 && backstep > 0) {
274
9e7f9e09ea0e Removed fprintf() calls. Replaced with SNDDBG() and Sound_SetError() calls.
Ryan C. Gordon <icculus@icculus.org>
parents: 273
diff changeset
240 Sound_SetError("MPGLIB: Can't step back!"); /* FIXME: need formatting: %ld!\n",backstep); */
261
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 return MP3_ERR;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 bsbufold = gmp->bsspace[gmp->bsnum] + 512;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 wordpointer -= backstep;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 if (backstep)
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 memcpy(wordpointer,bsbufold+gmp->fsizeold-backstep,backstep);
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 bitindex = 0;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 return MP3_OK;
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 }
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252
9b6e82f7c853 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253