diff options
author | Yoshihisa Uchida <uchida@rockbox.org> | 2010-03-01 10:37:52 +0000 |
---|---|---|
committer | Yoshihisa Uchida <uchida@rockbox.org> | 2010-03-01 10:37:52 +0000 |
commit | f7533cceaa0b53ded2fe997e9bd8a11571ea84d1 (patch) | |
tree | 3c9d37c57ae73252a89d607c7f57745fb329ac59 /apps/metadata | |
parent | d586fa1e7cf56e0d9aea75e400d34e6be1e6082e (diff) | |
download | rockbox-f7533cceaa0b53ded2fe997e9bd8a11571ea84d1.tar.gz rockbox-f7533cceaa0b53ded2fe997e9bd8a11571ea84d1.zip |
au metadata parser: optimize just a little.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24982 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata')
-rw-r--r-- | apps/metadata/au.c | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/apps/metadata/au.c b/apps/metadata/au.c index edd72375b7..0639bd11e6 100644 --- a/apps/metadata/au.c +++ b/apps/metadata/au.c | |||
@@ -30,15 +30,16 @@ | |||
30 | #include "metadata_parsers.h" | 30 | #include "metadata_parsers.h" |
31 | #include "logf.h" | 31 | #include "logf.h" |
32 | 32 | ||
33 | /* table of bits per sample / 8 */ | ||
33 | static const unsigned char bitspersamples[28] = { | 34 | static const unsigned char bitspersamples[28] = { |
34 | 0, | 35 | 0, |
35 | 8, /* G.711 MULAW */ | 36 | 1, /* G.711 MULAW */ |
36 | 8, /* 8bit */ | 37 | 1, /* 8bit */ |
37 | 16, /* 16bit */ | 38 | 2, /* 16bit */ |
38 | 24, /* 24bit */ | 39 | 3, /* 24bit */ |
39 | 32, /* 32bit */ | 40 | 4, /* 32bit */ |
40 | 32, /* 32bit */ | 41 | 4, /* 32bit */ |
41 | 64, /* 64bit */ | 42 | 8, /* 64bit */ |
42 | 0, /* Fragmented sample data */ | 43 | 0, /* Fragmented sample data */ |
43 | 0, /* DSP program */ | 44 | 0, /* DSP program */ |
44 | 0, /* 8bit fixed point */ | 45 | 0, /* 8bit fixed point */ |
@@ -58,10 +59,10 @@ static const unsigned char bitspersamples[28] = { | |||
58 | 0, /* G.722 */ | 59 | 0, /* G.722 */ |
59 | 0, /* G.723 3bit */ | 60 | 0, /* G.723 3bit */ |
60 | 0, /* G.723 5bit */ | 61 | 0, /* G.723 5bit */ |
61 | 8, /* G.711 ALAW */ | 62 | 1, /* G.711 ALAW */ |
62 | }; | 63 | }; |
63 | 64 | ||
64 | static int get_au_bitspersample(unsigned int encoding) | 65 | static inline unsigned char get_au_bitspersample(unsigned int encoding) |
65 | { | 66 | { |
66 | if (encoding > 27) | 67 | if (encoding > 27) |
67 | return 0; | 68 | return 0; |
@@ -72,26 +73,30 @@ bool get_au_metadata(int fd, struct mp3entry* id3) | |||
72 | { | 73 | { |
73 | /* Use the trackname part of the id3 structure as a temporary buffer */ | 74 | /* Use the trackname part of the id3 structure as a temporary buffer */ |
74 | unsigned char* buf = (unsigned char *)id3->path; | 75 | unsigned char* buf = (unsigned char *)id3->path; |
75 | unsigned long totalsamples = 0; | ||
76 | unsigned long channels = 0; | ||
77 | unsigned long bitspersample = 0; | ||
78 | unsigned long numbytes = 0; | 76 | unsigned long numbytes = 0; |
79 | int read_bytes; | 77 | int read_bytes; |
80 | int offset; | 78 | int offset; |
79 | unsigned char bits_ch; /* bitspersample * channels */ | ||
81 | 80 | ||
82 | id3->vbr = false; /* All Sun audio files are CBR */ | 81 | id3->vbr = false; /* All Sun audio files are CBR */ |
83 | id3->filesize = filesize(fd); | 82 | id3->filesize = filesize(fd); |
83 | id3->length = 0; | ||
84 | 84 | ||
85 | if ((lseek(fd, 0, SEEK_SET) < 0) || ((read_bytes = read(fd, buf, 24)) < 0)) | 85 | if ((lseek(fd, 0, SEEK_SET) < 0) || ((read_bytes = read(fd, buf, 24)) < 0)) |
86 | return false; | 86 | return false; |
87 | 87 | ||
88 | if (read_bytes < 24 || (memcmp(buf, ".snd", 4) != 0)) | 88 | if (read_bytes < 24 || (memcmp(buf, ".snd", 4) != 0)) |
89 | { | 89 | { |
90 | /* no header */ | 90 | /* |
91 | * no header | ||
92 | * | ||
93 | * frequency: 8000 Hz | ||
94 | * bits per sample: 8 bit | ||
95 | * channel: mono | ||
96 | */ | ||
91 | numbytes = id3->filesize; | 97 | numbytes = id3->filesize; |
92 | bitspersample = 8; | ||
93 | id3->frequency = 8000; | 98 | id3->frequency = 8000; |
94 | channels = 1; | 99 | bits_ch = 1; |
95 | } | 100 | } |
96 | else | 101 | else |
97 | { | 102 | { |
@@ -106,17 +111,14 @@ bool get_au_metadata(int fd, struct mp3entry* id3) | |||
106 | numbytes = get_long_be(buf + 8); | 111 | numbytes = get_long_be(buf + 8); |
107 | if (numbytes == (uint32_t)0xffffffff) | 112 | if (numbytes == (uint32_t)0xffffffff) |
108 | numbytes = id3->filesize - offset; | 113 | numbytes = id3->filesize - offset; |
109 | /* bitspersample */ | 114 | |
110 | bitspersample = get_au_bitspersample(get_long_be(buf + 12)); | 115 | bits_ch = get_au_bitspersample(get_long_be(buf + 12)) * get_long_be(buf + 20); |
111 | /* sample rate */ | ||
112 | id3->frequency = get_long_be(buf + 16); | 116 | id3->frequency = get_long_be(buf + 16); |
113 | channels = get_long_be(buf + 20); | ||
114 | } | 117 | } |
115 | 118 | ||
116 | totalsamples = numbytes / ((((bitspersample - 1) / 8) + 1) * channels); | 119 | /* Calculate track length [ms] */ |
117 | 120 | if (bits_ch) | |
118 | /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ | 121 | id3->length = ((int64_t)numbytes * 1000LL) / (bits_ch * id3->frequency); |
119 | id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; | ||
120 | 122 | ||
121 | return true; | 123 | return true; |
122 | } | 124 | } |