diff options
Diffstat (limited to 'apps/codecs/wav.c')
-rw-r--r-- | apps/codecs/wav.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c index 8576ddda41..f4e7f778fd 100644 --- a/apps/codecs/wav.c +++ b/apps/codecs/wav.c | |||
@@ -155,7 +155,6 @@ enum codec_status codec_main(void) | |||
155 | { | 155 | { |
156 | int status = CODEC_OK; | 156 | int status = CODEC_OK; |
157 | uint32_t decodedsamples; | 157 | uint32_t decodedsamples; |
158 | uint32_t i; | ||
159 | size_t n; | 158 | size_t n; |
160 | int bufcount; | 159 | int bufcount; |
161 | int endofstream; | 160 | int endofstream; |
@@ -163,6 +162,7 @@ enum codec_status codec_main(void) | |||
163 | uint8_t *wavbuf; | 162 | uint8_t *wavbuf; |
164 | off_t firstblockposn; /* position of the first block in file */ | 163 | off_t firstblockposn; /* position of the first block in file */ |
165 | const struct pcm_codec *codec; | 164 | const struct pcm_codec *codec; |
165 | uint32_t size; | ||
166 | 166 | ||
167 | /* Generic codec initialisation */ | 167 | /* Generic codec initialisation */ |
168 | ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH); | 168 | ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH); |
@@ -218,11 +218,11 @@ next_track: | |||
218 | } | 218 | } |
219 | 219 | ||
220 | /* chunkSize */ | 220 | /* chunkSize */ |
221 | i = (buf[4]|(buf[5]<<8)|(buf[6]<<16)|(buf[7]<<24)); | 221 | size = (buf[4]|(buf[5]<<8)|(buf[6]<<16)|(buf[7]<<24)); |
222 | if (memcmp(buf, "fmt ", 4) == 0) { | 222 | if (memcmp(buf, "fmt ", 4) == 0) { |
223 | if (i < 16) { | 223 | if (size < 16) { |
224 | DEBUGF("CODEC_ERROR: 'fmt ' chunk size=%lu < 16\n", | 224 | DEBUGF("CODEC_ERROR: 'fmt ' chunk size=%lu < 16\n", |
225 | (unsigned long)i); | 225 | (unsigned long)size); |
226 | status = CODEC_ERROR; | 226 | status = CODEC_ERROR; |
227 | goto done; | 227 | goto done; |
228 | } | 228 | } |
@@ -231,26 +231,26 @@ next_track: | |||
231 | /* wChannels */ | 231 | /* wChannels */ |
232 | format.channels=buf[10]|(buf[11]<<8); | 232 | format.channels=buf[10]|(buf[11]<<8); |
233 | /* skipping dwSamplesPerSec */ | 233 | /* skipping dwSamplesPerSec */ |
234 | /* dwAvgBytesPerSec */ | 234 | /* skipping dwAvgBytesPerSec */ |
235 | format.avgbytespersec = buf[16]|(buf[17]<<8)|(buf[18]<<16)|(buf[19]<<24); | ||
236 | /* wBlockAlign */ | 235 | /* wBlockAlign */ |
237 | format.blockalign=buf[20]|(buf[21]<<8); | 236 | format.blockalign=buf[20]|(buf[21]<<8); |
238 | /* wBitsPerSample */ | 237 | /* wBitsPerSample */ |
239 | format.bitspersample=buf[22]|(buf[23]<<8); | 238 | format.bitspersample=buf[22]|(buf[23]<<8); |
240 | if (format.formattag != WAVE_FORMAT_PCM) { | 239 | if (format.formattag != WAVE_FORMAT_PCM) { |
241 | if (i < 18) { | 240 | if (size < 18) { |
242 | /* this is not a fatal error with some formats, | 241 | /* this is not a fatal error with some formats, |
243 | * we'll see later if we can't decode it */ | 242 | * we'll see later if we can't decode it */ |
244 | DEBUGF("CODEC_WARNING: non-PCM WAVE (formattag=0x%x) " | 243 | DEBUGF("CODEC_WARNING: non-PCM WAVE (formattag=0x%x) " |
245 | "doesn't have ext. fmt descr (chunksize=%d<18).\n", | 244 | "doesn't have ext. fmt descr (chunksize=%d<18).\n", |
246 | (unsigned int)format.formattag, (int)i); | 245 | (unsigned int)format.formattag, (int)size); |
247 | } | 246 | } |
248 | else | 247 | else |
249 | { | 248 | { |
250 | format.size = buf[24]|(buf[25]<<8); | ||
251 | if (format.formattag != WAVE_FORMAT_EXTENSIBLE) | 249 | if (format.formattag != WAVE_FORMAT_EXTENSIBLE) |
252 | format.samplesperblock = buf[26]|(buf[27]<<8); | 250 | format.samplesperblock = buf[26]|(buf[27]<<8); |
253 | else { | 251 | else |
252 | { | ||
253 | format.size = buf[24]|(buf[25]<<8); | ||
254 | if (format.size < 22) { | 254 | if (format.size < 22) { |
255 | DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is " | 255 | DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is " |
256 | "missing extension\n"); | 256 | "missing extension\n"); |
@@ -297,26 +297,26 @@ next_track: | |||
297 | goto done; | 297 | goto done; |
298 | } | 298 | } |
299 | } else if (memcmp(buf, "data", 4) == 0) { | 299 | } else if (memcmp(buf, "data", 4) == 0) { |
300 | format.numbytes = i; | 300 | format.numbytes = size; |
301 | /* advance to start of data */ | 301 | /* advance to start of data */ |
302 | ci->advance_buffer(8); | 302 | ci->advance_buffer(8); |
303 | firstblockposn += 8; | 303 | firstblockposn += 8; |
304 | break; | 304 | break; |
305 | } else if (memcmp(buf, "fact", 4) == 0) { | 305 | } else if (memcmp(buf, "fact", 4) == 0) { |
306 | /* dwSampleLength */ | 306 | /* dwSampleLength */ |
307 | if (i >= 4) | 307 | if (size >= 4) |
308 | format.totalsamples = | 308 | format.totalsamples = |
309 | (buf[8]|(buf[9]<<8)|(buf[10]<<16)|(buf[11]<<24)); | 309 | (buf[8]|(buf[9]<<8)|(buf[10]<<16)|(buf[11]<<24)); |
310 | } else { | 310 | } else { |
311 | DEBUGF("unknown WAVE chunk: '%c%c%c%c', size=%lu\n", | 311 | DEBUGF("unknown WAVE chunk: '%c%c%c%c', size=%lu\n", |
312 | buf[0], buf[1], buf[2], buf[3], (unsigned long)i); | 312 | buf[0], buf[1], buf[2], buf[3], (unsigned long)size); |
313 | } | 313 | } |
314 | 314 | ||
315 | /* go to next chunk (even chunk sizes must be padded) */ | 315 | /* go to next chunk (even chunk sizes must be padded) */ |
316 | if (i & 0x01) | 316 | size += 8 + (size & 0x01); |
317 | i++; | 317 | |
318 | ci->advance_buffer(i+8); | 318 | ci->advance_buffer(size); |
319 | firstblockposn += i + 8; | 319 | firstblockposn += size; |
320 | } | 320 | } |
321 | 321 | ||
322 | if (!codec) | 322 | if (!codec) |
@@ -340,7 +340,7 @@ next_track: | |||
340 | if (format.blockalign == 0) | 340 | if (format.blockalign == 0) |
341 | { | 341 | { |
342 | DEBUGF("CODEC_ERROR: 'fmt ' chunk not found or 0-blockalign file\n"); | 342 | DEBUGF("CODEC_ERROR: 'fmt ' chunk not found or 0-blockalign file\n"); |
343 | i = CODEC_ERROR; | 343 | status = CODEC_ERROR; |
344 | goto done; | 344 | goto done; |
345 | } | 345 | } |
346 | if (format.numbytes == 0) { | 346 | if (format.numbytes == 0) { |
@@ -356,7 +356,7 @@ next_track: | |||
356 | if (format.chunksize == 0) | 356 | if (format.chunksize == 0) |
357 | { | 357 | { |
358 | DEBUGF("CODEC_ERROR: chunksize is 0\n"); | 358 | DEBUGF("CODEC_ERROR: chunksize is 0\n"); |
359 | i = CODEC_ERROR; | 359 | status = CODEC_ERROR; |
360 | goto done; | 360 | goto done; |
361 | } | 361 | } |
362 | 362 | ||