summaryrefslogtreecommitdiff
path: root/apps/metadata/aiff.c
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-03-02 10:59:46 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-03-02 10:59:46 +0000
commit66ebc35c557e27401799e542a6fee8c824364bb2 (patch)
treef762331466af2999329b73618ce071b8d46279fa /apps/metadata/aiff.c
parent04e0d6c12c6ad878b551be79a7c83c8b1784e748 (diff)
Wave/Wave64/vox metadata parser: optimize just a little.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24992 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata/aiff.c')
-rw-r--r--apps/metadata/aiff.c51
1 files changed, 15 insertions, 36 deletions
diff --git a/apps/metadata/aiff.c b/apps/metadata/aiff.c
index aba327f8c8..063e5d56af 100644
--- a/apps/metadata/aiff.c
+++ b/apps/metadata/aiff.c
@@ -38,35 +38,25 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
unsigned char* buf = (unsigned char *)id3->path;
unsigned long numChannels = 0;
unsigned long numSampleFrames = 0;
- unsigned long sampleSize = 0;
- unsigned long sampleRate = 0;
unsigned long numbytes = 0;
int read_bytes;
int i;
bool is_aifc = false;
- if ((lseek(fd, 0, SEEK_SET) < 0)
- || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54))
+ if ((lseek(fd, 0, SEEK_SET) < 0) ||
+ ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54) ||
+ (memcmp(buf, "FORM", 4) != 0) || (memcmp(buf + 8, "AIF", 3) != 0) ||
+ (!(is_aifc = (buf[11] == 'C')) && buf[11] != 'F'))
{
return false;
}
-
- if (memcmp(buf, "FORM",4) != 0)
- return false;
-
- if (memcmp(&buf[8], "AIFF", 4) != 0)
- {
- if (memcmp(&buf[8], "AIFC", 4) != 0)
- return false;
-
- is_aifc = true;
- }
-
- buf += 12;
- read_bytes -= 12;
+ i = 12;
while ((numbytes == 0) && (read_bytes >= 8))
{
+ buf += i;
+ read_bytes -= i;
+
/* chunkSize */
i = get_long_be(&buf[4]);
@@ -76,20 +66,17 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
numChannels = ((buf[8]<<8)|buf[9]);
/* numSampleFrames */
numSampleFrames = get_long_be(&buf[10]);
- /* sampleSize */
- sampleSize = ((buf[14]<<8)|buf[15]);
/* sampleRate */
- sampleRate = get_long_be(&buf[18]);
- sampleRate = sampleRate >> (16+14-buf[17]);
+ id3->frequency = get_long_be(&buf[18]);
+ id3->frequency >>= (16+14-buf[17]);
/* save format infos */
- id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000;
- id3->frequency = sampleRate;
+ id3->bitrate = (((buf[14]<<8)|buf[15]) * numChannels * id3->frequency) / 1000;
if (!is_aifc || memcmp(&buf[26], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0)
id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency;
else
{
/* QuickTime IMA ADPCM is 1block = 64 data for each channel */
- id3->length = (int64_t)(numSampleFrames * 64000LL) / id3->frequency;
+ id3->length = ((int64_t) numSampleFrames * 64000LL) / id3->frequency;
}
id3->vbr = false; /* AIFF files are CBR */
@@ -100,17 +87,9 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
numbytes = i - 8;
}
- if (i & 0x01)
- {
- i++; /* odd chunk sizes must be padded */
- }
- buf += i + 8;
- read_bytes -= i + 8;
+ /* odd chunk sizes must be padded */
+ i += 8 + (i & 0x01);
}
- if ((numbytes == 0) || (numChannels == 0))
- {
- return false;
- }
- return true;
+ return ((numbytes != 0) && (numChannels != 0));
}