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.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)
38 unsigned char* buf = (unsigned char *)id3->path; 38 unsigned char* buf = (unsigned char *)id3->path;
39 unsigned long numChannels = 0; 39 unsigned long numChannels = 0;
40 unsigned long numSampleFrames = 0; 40 unsigned long numSampleFrames = 0;
41 unsigned long sampleSize = 0;
42 unsigned long sampleRate = 0;
43 unsigned long numbytes = 0; 41 unsigned long numbytes = 0;
44 int read_bytes; 42 int read_bytes;
45 int i; 43 int i;
46 bool is_aifc = false; 44 bool is_aifc = false;
47 45
48 if ((lseek(fd, 0, SEEK_SET) < 0) 46 if ((lseek(fd, 0, SEEK_SET) < 0) ||
49 || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54)) 47 ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54) ||
48 (memcmp(buf, "FORM", 4) != 0) || (memcmp(buf + 8, "AIF", 3) != 0) ||
49 (!(is_aifc = (buf[11] == 'C')) && buf[11] != 'F'))
50 { 50 {
51 return false; 51 return false;
52 } 52 }
53
54 if (memcmp(buf, "FORM",4) != 0)
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;
63 }
64
65 buf += 12;
66 read_bytes -= 12;
67 53
54 i = 12;
68 while ((numbytes == 0) && (read_bytes >= 8)) 55 while ((numbytes == 0) && (read_bytes >= 8))
69 { 56 {
57 buf += i;
58 read_bytes -= i;
59
70 /* chunkSize */ 60 /* chunkSize */
71 i = get_long_be(&buf[4]); 61 i = get_long_be(&buf[4]);
72 62
@@ -76,20 +66,17 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
76 numChannels = ((buf[8]<<8)|buf[9]); 66 numChannels = ((buf[8]<<8)|buf[9]);
77 /* numSampleFrames */ 67 /* numSampleFrames */
78 numSampleFrames = get_long_be(&buf[10]); 68 numSampleFrames = get_long_be(&buf[10]);
79 /* sampleSize */
80 sampleSize = ((buf[14]<<8)|buf[15]);
81 /* sampleRate */ 69 /* sampleRate */
82 sampleRate = get_long_be(&buf[18]); 70 id3->frequency = get_long_be(&buf[18]);
83 sampleRate = sampleRate >> (16+14-buf[17]); 71 id3->frequency >>= (16+14-buf[17]);
84 /* save format infos */ 72 /* save format infos */
85 id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; 73 id3->bitrate = (((buf[14]<<8)|buf[15]) * numChannels * id3->frequency) / 1000;
86 id3->frequency = sampleRate;
87 if (!is_aifc || memcmp(&buf[26], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0) 74 if (!is_aifc || memcmp(&buf[26], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0)
88 id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency; 75 id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency;
89 else 76 else
90 { 77 {
91 /* QuickTime IMA ADPCM is 1block = 64 data for each channel */ 78 /* QuickTime IMA ADPCM is 1block = 64 data for each channel */
92 id3->length = (int64_t)(numSampleFrames * 64000LL) / id3->frequency; 79 id3->length = ((int64_t) numSampleFrames * 64000LL) / id3->frequency;
93 } 80 }
94 81
95 id3->vbr = false; /* AIFF files are CBR */ 82 id3->vbr = false; /* AIFF files are CBR */
@@ -100,17 +87,9 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3)
100 numbytes = i - 8; 87 numbytes = i - 8;
101 } 88 }
102 89
103 if (i & 0x01) 90 /* odd chunk sizes must be padded */
104 { 91 i += 8 + (i & 0x01);
105 i++; /* odd chunk sizes must be padded */
106 }
107 buf += i + 8;
108 read_bytes -= i + 8;
109 } 92 }
110 93
111 if ((numbytes == 0) || (numChannels == 0)) 94 return ((numbytes != 0) && (numChannels != 0));
112 {
113 return false;
114 }
115 return true;
116} 95}