From f640b89a12eb6a222c0371624fe56a2a6dd6d649 Mon Sep 17 00:00:00 2001 From: Yoshihisa Uchida Date: Sun, 7 Mar 2010 07:15:21 +0000 Subject: wave codec - does not get dwAvgBytesPerSec wave/aiff/smaf/wave64 codec - corrects the problem that codec_main() returns invalid value. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25051 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/aiff.c | 60 ++++++++++++++++++++++++++--------------------------- apps/codecs/smaf.c | 19 ++++++++--------- apps/codecs/wav.c | 38 ++++++++++++++++----------------- apps/codecs/wav64.c | 15 +++++++------- 4 files changed, 65 insertions(+), 67 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) struct pcm_format format; uint32_t bytesdone, decodedsamples; uint32_t num_sample_frames = 0; - uint32_t i = CODEC_OK; size_t n; int bufcount; int endofstream; @@ -85,13 +84,14 @@ enum codec_status codec_main(void) off_t firstblockposn; /* position of the first block in file */ bool is_aifc = false; const struct pcm_codec *codec; + uint32_t size; /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH); next_track: if (codec_init()) { - i = CODEC_ERROR; + status = CODEC_ERROR; goto exit; } @@ -103,14 +103,14 @@ next_track: /* assume the AIFF header is less than 1024 bytes */ buf = ci->request_buffer(&n, 1024); if (n < 54) { - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (memcmp(buf, "FORM", 4) != 0) { DEBUGF("CODEC_ERROR: does not aiff format %c%c%c%c\n", buf[0], buf[1], buf[2], buf[3]); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (memcmp(&buf[8], "AIFF", 4) == 0) @@ -120,7 +120,7 @@ next_track: else { DEBUGF("CODEC_ERROR: does not aiff format %c%c%c%c\n", buf[8], buf[9], buf[10], buf[11]); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -138,13 +138,13 @@ next_track: while (format.numbytes == 0 && n >= 8) { /* chunkSize */ - i = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]); + size = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]); if (memcmp(buf, "COMM", 4) == 0) { - if ((!is_aifc && i < 18) || (is_aifc && i < 22)) + if ((!is_aifc && size < 18) || (is_aifc && size < 22)) { DEBUGF("CODEC_ERROR: 'COMM' chunk size=%lu < %d\n", - (unsigned long)i, (is_aifc)?22:18); - i = CODEC_ERROR; + (unsigned long)size, (is_aifc)?22:18); + status = CODEC_ERROR; goto done; } /* num_channels */ @@ -157,7 +157,7 @@ next_track: /* sample_rate (don't use last 4 bytes, only integer fs) */ if (buf[16] != 0x40) { DEBUGF("CODEC_ERROR: weird sampling rate (no @)\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } format.samplespersec = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21])+1; @@ -184,7 +184,7 @@ next_track: } else if (memcmp(buf, "SSND", 4)==0) { if (format.bitspersample == 0) { DEBUGF("CODEC_ERROR: unsupported chunk order\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } /* offset2snd */ @@ -193,35 +193,35 @@ next_track: format.blockalign = ((buf[12]<<24)|(buf[13]<<16)|(buf[14]<<8)|buf[15]) >> 3; if (format.blockalign == 0) format.blockalign = format.channels * format.bitspersample >> 3; - format.numbytes = i - 8 - offset2snd; - i = 8 + offset2snd; /* advance to the beginning of data */ + format.numbytes = size - 8 - offset2snd; + size = 8 + offset2snd; /* advance to the beginning of data */ } else if (is_aifc && (memcmp(buf, "FVER", 4)==0)) { /* Format Version Chunk (AIFC only chunk) */ /* skip this chunk */ } else { DEBUGF("unsupported AIFF chunk: '%c%c%c%c', size=%lu\n", - buf[0], buf[1], buf[2], buf[3], (unsigned long)i); + buf[0], buf[1], buf[2], buf[3], (unsigned long)size); } - if (i & 0x01) /* odd chunk sizes must be padded */ - i++; - buf += i + 8; - if (n < (i + 8)) { + size += 8 + (size & 0x01); /* odd chunk sizes must be padded */ + + buf += size; + if (n < size) { DEBUGF("CODEC_ERROR: AIFF header size > 1024\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } - n -= i + 8; + n -= size; } /* while 'SSND' */ if (format.channels == 0) { DEBUGF("CODEC_ERROR: 'COMM' chunk not found or 0-channels file\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (format.numbytes == 0) { DEBUGF("CODEC_ERROR: 'SSND' chunk not found or has zero length\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -230,13 +230,13 @@ next_track: { DEBUGF("CODEC_ERROR: AIFC does not support compressionType: 0x%x\n", (unsigned int)format.formattag); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (!codec->set_format(&format)) { - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -248,20 +248,20 @@ next_track: ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); } else { DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (format.samplesperblock == 0) { DEBUGF("CODEC_ERROR: samplesperblock is 0\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (format.blockalign == 0) { DEBUGF("CODEC_ERROR: blockalign is 0\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -272,7 +272,7 @@ next_track: if (format.chunksize == 0) { DEBUGF("CODEC_ERROR: chunksize is 0\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -329,13 +329,13 @@ next_track: ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - i = CODEC_OK; + status = CODEC_OK; done: if (ci->request_next_track()) goto next_track; exit: - return i; + return status; } diff --git a/apps/codecs/smaf.c b/apps/codecs/smaf.c index fccb6cbc64..9309937700 100644 --- a/apps/codecs/smaf.c +++ b/apps/codecs/smaf.c @@ -276,7 +276,6 @@ enum codec_status codec_main(void) { int status = CODEC_OK; uint32_t decodedsamples; - uint32_t i = CODEC_OK; size_t n; int bufcount; int endofstream; @@ -289,7 +288,7 @@ enum codec_status codec_main(void) next_track: if (codec_init()) { - i = CODEC_ERROR; + status = CODEC_ERROR; goto exit; } @@ -307,7 +306,7 @@ next_track: if (!parse_header(&format, &n)) { - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -315,13 +314,13 @@ next_track: if (codec == 0) { DEBUGF("CODEC_ERROR: unsupport audio format: 0x%x\n", (int)format.formattag); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (!codec->set_format(&format)) { - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -339,7 +338,7 @@ next_track: if (format.blockalign == 0) { DEBUGF("CODEC_ERROR: 'fmt ' chunk not found or 0-blockalign file\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (format.numbytes == 0) { @@ -355,7 +354,7 @@ next_track: if (format.chunksize == 0) { DEBUGF("CODEC_ERROR: chunksize is 0\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -367,7 +366,7 @@ next_track: ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); } else { DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } @@ -423,13 +422,13 @@ next_track: ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - i = CODEC_OK; + status = CODEC_OK; done: if (ci->request_next_track()) goto next_track; exit: - return i; + return status; } 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) { int status = CODEC_OK; uint32_t decodedsamples; - uint32_t i; size_t n; int bufcount; int endofstream; @@ -163,6 +162,7 @@ enum codec_status codec_main(void) uint8_t *wavbuf; off_t firstblockposn; /* position of the first block in file */ const struct pcm_codec *codec; + uint32_t size; /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH); @@ -218,11 +218,11 @@ next_track: } /* chunkSize */ - i = (buf[4]|(buf[5]<<8)|(buf[6]<<16)|(buf[7]<<24)); + size = (buf[4]|(buf[5]<<8)|(buf[6]<<16)|(buf[7]<<24)); if (memcmp(buf, "fmt ", 4) == 0) { - if (i < 16) { + if (size < 16) { DEBUGF("CODEC_ERROR: 'fmt ' chunk size=%lu < 16\n", - (unsigned long)i); + (unsigned long)size); status = CODEC_ERROR; goto done; } @@ -231,26 +231,26 @@ next_track: /* wChannels */ format.channels=buf[10]|(buf[11]<<8); /* skipping dwSamplesPerSec */ - /* dwAvgBytesPerSec */ - format.avgbytespersec = buf[16]|(buf[17]<<8)|(buf[18]<<16)|(buf[19]<<24); + /* skipping dwAvgBytesPerSec */ /* wBlockAlign */ format.blockalign=buf[20]|(buf[21]<<8); /* wBitsPerSample */ format.bitspersample=buf[22]|(buf[23]<<8); if (format.formattag != WAVE_FORMAT_PCM) { - if (i < 18) { + if (size < 18) { /* this is not a fatal error with some formats, * we'll see later if we can't decode it */ DEBUGF("CODEC_WARNING: non-PCM WAVE (formattag=0x%x) " "doesn't have ext. fmt descr (chunksize=%d<18).\n", - (unsigned int)format.formattag, (int)i); + (unsigned int)format.formattag, (int)size); } else { - format.size = buf[24]|(buf[25]<<8); if (format.formattag != WAVE_FORMAT_EXTENSIBLE) format.samplesperblock = buf[26]|(buf[27]<<8); - else { + else + { + format.size = buf[24]|(buf[25]<<8); if (format.size < 22) { DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is " "missing extension\n"); @@ -297,26 +297,26 @@ next_track: goto done; } } else if (memcmp(buf, "data", 4) == 0) { - format.numbytes = i; + format.numbytes = size; /* advance to start of data */ ci->advance_buffer(8); firstblockposn += 8; break; } else if (memcmp(buf, "fact", 4) == 0) { /* dwSampleLength */ - if (i >= 4) + if (size >= 4) format.totalsamples = (buf[8]|(buf[9]<<8)|(buf[10]<<16)|(buf[11]<<24)); } else { DEBUGF("unknown WAVE chunk: '%c%c%c%c', size=%lu\n", - buf[0], buf[1], buf[2], buf[3], (unsigned long)i); + buf[0], buf[1], buf[2], buf[3], (unsigned long)size); } /* go to next chunk (even chunk sizes must be padded) */ - if (i & 0x01) - i++; - ci->advance_buffer(i+8); - firstblockposn += i + 8; + size += 8 + (size & 0x01); + + ci->advance_buffer(size); + firstblockposn += size; } if (!codec) @@ -340,7 +340,7 @@ next_track: if (format.blockalign == 0) { DEBUGF("CODEC_ERROR: 'fmt ' chunk not found or 0-blockalign file\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (format.numbytes == 0) { @@ -356,7 +356,7 @@ next_track: if (format.chunksize == 0) { DEBUGF("CODEC_ERROR: chunksize is 0\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } diff --git a/apps/codecs/wav64.c b/apps/codecs/wav64.c index a9e5ca126a..f70fb53ba4 100644 --- a/apps/codecs/wav64.c +++ b/apps/codecs/wav64.c @@ -163,7 +163,6 @@ enum codec_status codec_main(void) { int status = CODEC_OK; uint32_t decodedsamples; - uint32_t i; size_t n; int bufcount; int endofstream; @@ -255,10 +254,10 @@ next_track: } else { - format.size = buf[40]|(buf[41]<<8); if (format.formattag != WAVE_FORMAT_EXTENSIBLE) format.samplesperblock = buf[42]|(buf[43]<<8); else { + format.size = buf[40]|(buf[41]<<8); if (format.size < 22) { DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is " "missing extension\n"); @@ -320,10 +319,10 @@ next_track: } /* go to next chunk (8byte bound) */ - if (size & 0x07) - size += 8 - (size & 0x7); - ci->advance_buffer(size + 24); - firstblockposn += size + 24; + size += 24 + ((1 + ~size) & 0x07); + + ci->advance_buffer(size); + firstblockposn += size; } if (!codec) @@ -347,7 +346,7 @@ next_track: if (format.blockalign == 0) { DEBUGF("CODEC_ERROR: 'fmt ' chunk not found or 0-blockalign file\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } if (format.numbytes == 0) { @@ -363,7 +362,7 @@ next_track: if (format.chunksize == 0) { DEBUGF("CODEC_ERROR: chunksize is 0\n"); - i = CODEC_ERROR; + status = CODEC_ERROR; goto done; } -- cgit v1.2.3