summaryrefslogtreecommitdiff
path: root/apps/metadata/aiff.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata/aiff.c')
-rw-r--r--apps/metadata/aiff.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/apps/metadata/aiff.c b/apps/metadata/aiff.c
index 67fb43b8c6..aba327f8c8 100644
--- a/apps/metadata/aiff.c
+++ b/apps/metadata/aiff.c
@@ -29,6 +29,9 @@
29#include "metadata_common.h" 29#include "metadata_common.h"
30#include "metadata_parsers.h" 30#include "metadata_parsers.h"
31 31
32/* compressionType: AIFC QuickTime IMA ADPCM */
33#define AIFC_FORMAT_QT_IMA_ADPCM "ima4"
34
32bool get_aiff_metadata(int fd, struct mp3entry* id3) 35bool get_aiff_metadata(int fd, struct mp3entry* id3)
33{ 36{
34 /* Use the trackname part of the id3 structure as a temporary buffer */ 37 /* Use the trackname part of the id3 structure as a temporary buffer */
@@ -40,6 +43,7 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
40 unsigned long numbytes = 0; 43 unsigned long numbytes = 0;
41 int read_bytes; 44 int read_bytes;
42 int i; 45 int i;
46 bool is_aifc = false;
43 47
44 if ((lseek(fd, 0, SEEK_SET) < 0) 48 if ((lseek(fd, 0, SEEK_SET) < 0)
45 || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54)) 49 || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54))
@@ -47,10 +51,15 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
47 return false; 51 return false;
48 } 52 }
49 53
50 if ((memcmp(buf, "FORM",4) != 0) 54 if (memcmp(buf, "FORM",4) != 0)
51 || ((memcmp(&buf[8], "AIFF", 4) !=0) && (memcmp(&buf[8], "AIFC", 4) !=0)))
52 {
53 return false; 55 return false;
56
57 if (memcmp(&buf[8], "AIFF", 4) != 0)
58 {
59 if (memcmp(&buf[8], "AIFC", 4) != 0)
60 return false;
61
62 is_aifc = true;
54 } 63 }
55 64
56 buf += 12; 65 buf += 12;
@@ -75,7 +84,13 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
75 /* save format infos */ 84 /* save format infos */
76 id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; 85 id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000;
77 id3->frequency = sampleRate; 86 id3->frequency = sampleRate;
78 id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency; 87 if (!is_aifc || memcmp(&buf[26], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0)
88 id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency;
89 else
90 {
91 /* QuickTime IMA ADPCM is 1block = 64 data for each channel */
92 id3->length = (int64_t)(numSampleFrames * 64000LL) / id3->frequency;
93 }
79 94
80 id3->vbr = false; /* AIFF files are CBR */ 95 id3->vbr = false; /* AIFF files are CBR */
81 id3->filesize = filesize(fd); 96 id3->filesize = filesize(fd);