summaryrefslogtreecommitdiff
path: root/apps/codecs/aiff.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/aiff.c')
-rw-r--r--apps/codecs/aiff.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/apps/codecs/aiff.c b/apps/codecs/aiff.c
index 3ad6ecfbbf..18a48a329a 100644
--- a/apps/codecs/aiff.c
+++ b/apps/codecs/aiff.c
@@ -75,7 +75,6 @@ enum codec_status codec_main(void)
75 struct pcm_format format; 75 struct pcm_format format;
76 uint32_t bytesdone, decodedsamples; 76 uint32_t bytesdone, decodedsamples;
77 uint32_t num_sample_frames = 0; 77 uint32_t num_sample_frames = 0;
78 uint32_t i = CODEC_OK;
79 size_t n; 78 size_t n;
80 int bufcount; 79 int bufcount;
81 int endofstream; 80 int endofstream;
@@ -85,13 +84,14 @@ enum codec_status codec_main(void)
85 off_t firstblockposn; /* position of the first block in file */ 84 off_t firstblockposn; /* position of the first block in file */
86 bool is_aifc = false; 85 bool is_aifc = false;
87 const struct pcm_codec *codec; 86 const struct pcm_codec *codec;
87 uint32_t size;
88 88
89 /* Generic codec initialisation */ 89 /* Generic codec initialisation */
90 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH); 90 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
91 91
92next_track: 92next_track:
93 if (codec_init()) { 93 if (codec_init()) {
94 i = CODEC_ERROR; 94 status = CODEC_ERROR;
95 goto exit; 95 goto exit;
96 } 96 }
97 97
@@ -103,14 +103,14 @@ next_track:
103 /* assume the AIFF header is less than 1024 bytes */ 103 /* assume the AIFF header is less than 1024 bytes */
104 buf = ci->request_buffer(&n, 1024); 104 buf = ci->request_buffer(&n, 1024);
105 if (n < 54) { 105 if (n < 54) {
106 i = CODEC_ERROR; 106 status = CODEC_ERROR;
107 goto done; 107 goto done;
108 } 108 }
109 109
110 if (memcmp(buf, "FORM", 4) != 0) 110 if (memcmp(buf, "FORM", 4) != 0)
111 { 111 {
112 DEBUGF("CODEC_ERROR: does not aiff format %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]); 112 DEBUGF("CODEC_ERROR: does not aiff format %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]);
113 i = CODEC_ERROR; 113 status = CODEC_ERROR;
114 goto done; 114 goto done;
115 } 115 }
116 if (memcmp(&buf[8], "AIFF", 4) == 0) 116 if (memcmp(&buf[8], "AIFF", 4) == 0)
@@ -120,7 +120,7 @@ next_track:
120 else 120 else
121 { 121 {
122 DEBUGF("CODEC_ERROR: does not aiff format %c%c%c%c\n", buf[8], buf[9], buf[10], buf[11]); 122 DEBUGF("CODEC_ERROR: does not aiff format %c%c%c%c\n", buf[8], buf[9], buf[10], buf[11]);
123 i = CODEC_ERROR; 123 status = CODEC_ERROR;
124 goto done; 124 goto done;
125 } 125 }
126 126
@@ -138,13 +138,13 @@ next_track:
138 while (format.numbytes == 0 && n >= 8) 138 while (format.numbytes == 0 && n >= 8)
139 { 139 {
140 /* chunkSize */ 140 /* chunkSize */
141 i = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]); 141 size = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]);
142 if (memcmp(buf, "COMM", 4) == 0) { 142 if (memcmp(buf, "COMM", 4) == 0) {
143 if ((!is_aifc && i < 18) || (is_aifc && i < 22)) 143 if ((!is_aifc && size < 18) || (is_aifc && size < 22))
144 { 144 {
145 DEBUGF("CODEC_ERROR: 'COMM' chunk size=%lu < %d\n", 145 DEBUGF("CODEC_ERROR: 'COMM' chunk size=%lu < %d\n",
146 (unsigned long)i, (is_aifc)?22:18); 146 (unsigned long)size, (is_aifc)?22:18);
147 i = CODEC_ERROR; 147 status = CODEC_ERROR;
148 goto done; 148 goto done;
149 } 149 }
150 /* num_channels */ 150 /* num_channels */
@@ -157,7 +157,7 @@ next_track:
157 /* sample_rate (don't use last 4 bytes, only integer fs) */ 157 /* sample_rate (don't use last 4 bytes, only integer fs) */
158 if (buf[16] != 0x40) { 158 if (buf[16] != 0x40) {
159 DEBUGF("CODEC_ERROR: weird sampling rate (no @)\n"); 159 DEBUGF("CODEC_ERROR: weird sampling rate (no @)\n");
160 i = CODEC_ERROR; 160 status = CODEC_ERROR;
161 goto done; 161 goto done;
162 } 162 }
163 format.samplespersec = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21])+1; 163 format.samplespersec = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21])+1;
@@ -184,7 +184,7 @@ next_track:
184 } else if (memcmp(buf, "SSND", 4)==0) { 184 } else if (memcmp(buf, "SSND", 4)==0) {
185 if (format.bitspersample == 0) { 185 if (format.bitspersample == 0) {
186 DEBUGF("CODEC_ERROR: unsupported chunk order\n"); 186 DEBUGF("CODEC_ERROR: unsupported chunk order\n");
187 i = CODEC_ERROR; 187 status = CODEC_ERROR;
188 goto done; 188 goto done;
189 } 189 }
190 /* offset2snd */ 190 /* offset2snd */
@@ -193,35 +193,35 @@ next_track:
193 format.blockalign = ((buf[12]<<24)|(buf[13]<<16)|(buf[14]<<8)|buf[15]) >> 3; 193 format.blockalign = ((buf[12]<<24)|(buf[13]<<16)|(buf[14]<<8)|buf[15]) >> 3;
194 if (format.blockalign == 0) 194 if (format.blockalign == 0)
195 format.blockalign = format.channels * format.bitspersample >> 3; 195 format.blockalign = format.channels * format.bitspersample >> 3;
196 format.numbytes = i - 8 - offset2snd; 196 format.numbytes = size - 8 - offset2snd;
197 i = 8 + offset2snd; /* advance to the beginning of data */ 197 size = 8 + offset2snd; /* advance to the beginning of data */
198 } else if (is_aifc && (memcmp(buf, "FVER", 4)==0)) { 198 } else if (is_aifc && (memcmp(buf, "FVER", 4)==0)) {
199 /* Format Version Chunk (AIFC only chunk) */ 199 /* Format Version Chunk (AIFC only chunk) */
200 /* skip this chunk */ 200 /* skip this chunk */
201 } else { 201 } else {
202 DEBUGF("unsupported AIFF chunk: '%c%c%c%c', size=%lu\n", 202 DEBUGF("unsupported AIFF chunk: '%c%c%c%c', size=%lu\n",
203 buf[0], buf[1], buf[2], buf[3], (unsigned long)i); 203 buf[0], buf[1], buf[2], buf[3], (unsigned long)size);
204 } 204 }
205 205
206 if (i & 0x01) /* odd chunk sizes must be padded */ 206 size += 8 + (size & 0x01); /* odd chunk sizes must be padded */
207 i++; 207
208 buf += i + 8; 208 buf += size;
209 if (n < (i + 8)) { 209 if (n < size) {
210 DEBUGF("CODEC_ERROR: AIFF header size > 1024\n"); 210 DEBUGF("CODEC_ERROR: AIFF header size > 1024\n");
211 i = CODEC_ERROR; 211 status = CODEC_ERROR;
212 goto done; 212 goto done;
213 } 213 }
214 n -= i + 8; 214 n -= size;
215 } /* while 'SSND' */ 215 } /* while 'SSND' */
216 216
217 if (format.channels == 0) { 217 if (format.channels == 0) {
218 DEBUGF("CODEC_ERROR: 'COMM' chunk not found or 0-channels file\n"); 218 DEBUGF("CODEC_ERROR: 'COMM' chunk not found or 0-channels file\n");
219 i = CODEC_ERROR; 219 status = CODEC_ERROR;
220 goto done; 220 goto done;
221 } 221 }
222 if (format.numbytes == 0) { 222 if (format.numbytes == 0) {
223 DEBUGF("CODEC_ERROR: 'SSND' chunk not found or has zero length\n"); 223 DEBUGF("CODEC_ERROR: 'SSND' chunk not found or has zero length\n");
224 i = CODEC_ERROR; 224 status = CODEC_ERROR;
225 goto done; 225 goto done;
226 } 226 }
227 227
@@ -230,13 +230,13 @@ next_track:
230 { 230 {
231 DEBUGF("CODEC_ERROR: AIFC does not support compressionType: 0x%x\n", 231 DEBUGF("CODEC_ERROR: AIFC does not support compressionType: 0x%x\n",
232 (unsigned int)format.formattag); 232 (unsigned int)format.formattag);
233 i = CODEC_ERROR; 233 status = CODEC_ERROR;
234 goto done; 234 goto done;
235 } 235 }
236 236
237 if (!codec->set_format(&format)) 237 if (!codec->set_format(&format))
238 { 238 {
239 i = CODEC_ERROR; 239 status = CODEC_ERROR;
240 goto done; 240 goto done;
241 } 241 }
242 242
@@ -248,20 +248,20 @@ next_track:
248 ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); 248 ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
249 } else { 249 } else {
250 DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n"); 250 DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n");
251 i = CODEC_ERROR; 251 status = CODEC_ERROR;
252 goto done; 252 goto done;
253 } 253 }
254 254
255 if (format.samplesperblock == 0) 255 if (format.samplesperblock == 0)
256 { 256 {
257 DEBUGF("CODEC_ERROR: samplesperblock is 0\n"); 257 DEBUGF("CODEC_ERROR: samplesperblock is 0\n");
258 i = CODEC_ERROR; 258 status = CODEC_ERROR;
259 goto done; 259 goto done;
260 } 260 }
261 if (format.blockalign == 0) 261 if (format.blockalign == 0)
262 { 262 {
263 DEBUGF("CODEC_ERROR: blockalign is 0\n"); 263 DEBUGF("CODEC_ERROR: blockalign is 0\n");
264 i = CODEC_ERROR; 264 status = CODEC_ERROR;
265 goto done; 265 goto done;
266 } 266 }
267 267
@@ -272,7 +272,7 @@ next_track:
272 if (format.chunksize == 0) 272 if (format.chunksize == 0)
273 { 273 {
274 DEBUGF("CODEC_ERROR: chunksize is 0\n"); 274 DEBUGF("CODEC_ERROR: chunksize is 0\n");
275 i = CODEC_ERROR; 275 status = CODEC_ERROR;
276 goto done; 276 goto done;
277 } 277 }
278 278
@@ -329,13 +329,13 @@ next_track:
329 329
330 ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); 330 ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
331 } 331 }
332 i = CODEC_OK; 332 status = CODEC_OK;
333 333
334done: 334done:
335 if (ci->request_next_track()) 335 if (ci->request_next_track())
336 goto next_track; 336 goto next_track;
337 337
338exit: 338exit:
339 return i; 339 return status;
340} 340}
341 341