diff options
author | Dave Chapman <dave@dchapman.com> | 2007-06-06 17:46:49 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-06-06 17:46:49 +0000 |
commit | c995ae8026b4e22159695a7b8c856bc0d8d5328b (patch) | |
tree | 9fec68ba229fbcd9a115de4d7a87a4421e621797 /apps/codecs/demac | |
parent | 6c31a9a9d3611edb811964a80e15449a54634c83 (diff) | |
download | rockbox-c995ae8026b4e22159695a7b8c856bc0d8d5328b.tar.gz rockbox-c995ae8026b4e22159695a7b8c856bc0d8d5328b.zip |
Make v3.97 APE files work in Rockbox
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13571 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/demac')
-rw-r--r-- | apps/codecs/demac/libdemac/parser.c | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/apps/codecs/demac/libdemac/parser.c b/apps/codecs/demac/libdemac/parser.c index bcb542dbb6..4e907308b6 100644 --- a/apps/codecs/demac/libdemac/parser.c +++ b/apps/codecs/demac/libdemac/parser.c | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | libdemac - A Monkey's Audio decoder | 3 | libdemac - A Monkey's Audio decoder |
4 | 4 | ||
5 | $Id:$ | 5 | $Id$ |
6 | 6 | ||
7 | Copyright (C) Dave Chapman 2007 | 7 | Copyright (C) Dave Chapman 2007 |
8 | 8 | ||
@@ -70,39 +70,71 @@ int ape_parseheaderbuf(unsigned char* buf, struct ape_ctx_t* ape_ctx) | |||
70 | 70 | ||
71 | if (ape_ctx->fileversion >= 3980) | 71 | if (ape_ctx->fileversion >= 3980) |
72 | { | 72 | { |
73 | ape_ctx->padding1 = get_int16(buf + 6); | 73 | ape_ctx->padding1 = get_int16(buf + 6); |
74 | ape_ctx->descriptorlength = get_uint32(buf + 8); | 74 | ape_ctx->descriptorlength = get_uint32(buf + 8); |
75 | ape_ctx->headerlength = get_uint32(buf + 12); | 75 | ape_ctx->headerlength = get_uint32(buf + 12); |
76 | ape_ctx->seektablelength = get_uint32(buf + 16); | 76 | ape_ctx->seektablelength = get_uint32(buf + 16); |
77 | ape_ctx->wavheaderlength = get_uint32(buf + 20); | 77 | ape_ctx->wavheaderlength = get_uint32(buf + 20); |
78 | ape_ctx->audiodatalength = get_uint32(buf + 24); | 78 | ape_ctx->audiodatalength = get_uint32(buf + 24); |
79 | ape_ctx->audiodatalength_high = get_uint32(buf + 28); | 79 | ape_ctx->audiodatalength_high = get_uint32(buf + 28); |
80 | ape_ctx->wavtaillength = get_uint32(buf + 32); | 80 | ape_ctx->wavtaillength = get_uint32(buf + 32); |
81 | memcpy(ape_ctx->md5, buf + 36, 16); | 81 | memcpy(ape_ctx->md5, buf + 36, 16); |
82 | 82 | ||
83 | header = buf + ape_ctx->descriptorlength; | 83 | header = buf + ape_ctx->descriptorlength; |
84 | |||
85 | /* Read header data */ | ||
86 | ape_ctx->compressiontype = get_uint16(header + 0); | ||
87 | ape_ctx->formatflags = get_uint16(header + 2); | ||
88 | ape_ctx->blocksperframe = get_uint32(header + 4); | ||
89 | ape_ctx->finalframeblocks = get_uint32(header + 8); | ||
90 | ape_ctx->totalframes = get_uint32(header + 12); | ||
91 | ape_ctx->bps = get_uint16(header + 16); | ||
92 | ape_ctx->channels = get_uint16(header + 18); | ||
93 | ape_ctx->samplerate = get_uint32(header + 20); | ||
94 | 84 | ||
95 | ape_ctx->firstframe = ape_ctx->junklength + ape_ctx->descriptorlength + | 85 | /* Read header data */ |
96 | ape_ctx->headerlength + ape_ctx->seektablelength + | 86 | ape_ctx->compressiontype = get_uint16(header + 0); |
97 | ape_ctx->wavheaderlength; | 87 | ape_ctx->formatflags = get_uint16(header + 2); |
88 | ape_ctx->blocksperframe = get_uint32(header + 4); | ||
89 | ape_ctx->finalframeblocks = get_uint32(header + 8); | ||
90 | ape_ctx->totalframes = get_uint32(header + 12); | ||
91 | ape_ctx->bps = get_uint16(header + 16); | ||
92 | ape_ctx->channels = get_uint16(header + 18); | ||
93 | ape_ctx->samplerate = get_uint32(header + 20); | ||
94 | |||
95 | ape_ctx->firstframe = ape_ctx->junklength + ape_ctx->descriptorlength + | ||
96 | ape_ctx->headerlength + ape_ctx->seektablelength + | ||
97 | ape_ctx->wavheaderlength; | ||
98 | } else { | 98 | } else { |
99 | ape_ctx->headerlength = 32; | ||
99 | ape_ctx->compressiontype = get_uint16(buf + 6); | 100 | ape_ctx->compressiontype = get_uint16(buf + 6); |
100 | ape_ctx->formatflags = get_uint16(buf + 8); | 101 | ape_ctx->formatflags = get_uint16(buf + 8); |
101 | ape_ctx->channels = get_uint16(buf + 10); | 102 | ape_ctx->channels = get_uint16(buf + 10); |
102 | ape_ctx->samplerate = get_uint32(buf + 14); | 103 | ape_ctx->samplerate = get_uint32(buf + 12); |
103 | ape_ctx->wavheaderlength = get_uint32(buf + 18); | 104 | ape_ctx->wavheaderlength = get_uint32(buf + 16); |
104 | ape_ctx->totalframes = get_uint32(buf + 26); | 105 | ape_ctx->totalframes = get_uint32(buf + 24); |
105 | ape_ctx->finalframeblocks = get_uint32(buf + 30); | 106 | ape_ctx->finalframeblocks = get_uint32(buf + 28); |
107 | |||
108 | if (ape_ctx->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) | ||
109 | { | ||
110 | ape_ctx->headerlength += 4; | ||
111 | } | ||
112 | |||
113 | if (ape_ctx->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) | ||
114 | { | ||
115 | ape_ctx->seektablelength = get_uint32(buf + ape_ctx->headerlength); | ||
116 | ape_ctx->seektablelength *= sizeof(int32_t); | ||
117 | ape_ctx->headerlength += 4; | ||
118 | } else { | ||
119 | ape_ctx->seektablelength = ape_ctx->totalframes * sizeof(int32_t); | ||
120 | } | ||
121 | |||
122 | if (ape_ctx->formatflags & MAC_FORMAT_FLAG_8_BIT) | ||
123 | ape_ctx->bps = 8; | ||
124 | else if (ape_ctx->formatflags & MAC_FORMAT_FLAG_24_BIT) | ||
125 | ape_ctx->bps = 24; | ||
126 | else | ||
127 | ape_ctx->bps = 16; | ||
128 | |||
129 | if (ape_ctx->fileversion >= 3950) | ||
130 | ape_ctx->blocksperframe = 73728 * 4; | ||
131 | else if ((ape_ctx->fileversion >= 3900) || (ape_ctx->fileversion >= 3800 && ape_ctx->compressiontype >= 4000)) | ||
132 | ape_ctx->blocksperframe = 73728; | ||
133 | else | ||
134 | ape_ctx->blocksperframe = 9216; | ||
135 | |||
136 | ape_ctx->firstframe = ape_ctx->junklength + ape_ctx->headerlength + | ||
137 | ape_ctx->seektablelength + ape_ctx->wavheaderlength; | ||
106 | } | 138 | } |
107 | 139 | ||
108 | ape_ctx->totalsamples = ape_ctx->finalframeblocks; | 140 | ape_ctx->totalsamples = ape_ctx->finalframeblocks; |