diff options
Diffstat (limited to 'apps/codecs/demac/libdemac/parser.h')
-rw-r--r-- | apps/codecs/demac/libdemac/parser.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/apps/codecs/demac/libdemac/parser.h b/apps/codecs/demac/libdemac/parser.h new file mode 100644 index 0000000000..edf4222fd5 --- /dev/null +++ b/apps/codecs/demac/libdemac/parser.h | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | |||
3 | libdemac - A Monkey's Audio decoder | ||
4 | |||
5 | $Id:$ | ||
6 | |||
7 | Copyright (C) Dave Chapman 2007 | ||
8 | |||
9 | This program is free software; you can redistribute it and/or modify | ||
10 | it under the terms of the GNU General Public License as published by | ||
11 | the Free Software Foundation; either version 2 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | This program is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program; if not, write to the Free Software | ||
21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | ||
22 | |||
23 | */ | ||
24 | |||
25 | #ifndef _APE_PARSER_H | ||
26 | #define _APE_PARSER_H | ||
27 | |||
28 | #include <inttypes.h> | ||
29 | |||
30 | #ifdef ROCKBOX | ||
31 | /* Include the Rockbox Codec API when building for Rockbox */ | ||
32 | #define APE_OUTPUT_DEPTH 29 | ||
33 | #ifndef ROCKBOX_PLUGIN | ||
34 | #include "../lib/codeclib.h" | ||
35 | #include <codecs.h> | ||
36 | #endif | ||
37 | #else | ||
38 | #define APE_OUTPUT_DEPTH (ape_ctx->bps) | ||
39 | #define IBSS_ATTR | ||
40 | #define ICONST_ATTR | ||
41 | #define ICODE_ATTR | ||
42 | #endif | ||
43 | |||
44 | /* The earliest and latest file formats supported by this library */ | ||
45 | #define APE_MIN_VERSION 3970 | ||
46 | #define APE_MAX_VERSION 3990 | ||
47 | |||
48 | #define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE] | ||
49 | #define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE] | ||
50 | #define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE] | ||
51 | #define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE] | ||
52 | #define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level | ||
53 | #define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored) | ||
54 | |||
55 | |||
56 | /* Special frame codes: | ||
57 | |||
58 | MONO_SILENCE - All PCM samples in frame are zero (mono streams only) | ||
59 | LEFT_SILENCE - All PCM samples for left channel in frame are zero (stereo streams) | ||
60 | RIGHT_SILENCE - All PCM samples for left channel in frame are zero (stereo streams) | ||
61 | PSEUDO_STEREO - Left and Right channels are identical | ||
62 | |||
63 | */ | ||
64 | |||
65 | #define APE_FRAMECODE_MONO_SILENCE 1 | ||
66 | #define APE_FRAMECODE_STEREO_SILENCE 3 | ||
67 | #define APE_FRAMECODE_PSEUDO_STEREO 4 | ||
68 | |||
69 | #define HISTORY_SIZE 512 | ||
70 | #define PREDICTOR_ORDER 8 | ||
71 | |||
72 | struct predictor_t | ||
73 | { | ||
74 | /* Adaption co-efficients */ | ||
75 | int32_t coeffsA[4]; | ||
76 | int32_t coeffsB[5]; | ||
77 | |||
78 | /* Filter histories */ | ||
79 | int32_t historybuffer[HISTORY_SIZE + PREDICTOR_ORDER * 4]; | ||
80 | int32_t* delayA; | ||
81 | int32_t* delayB; | ||
82 | int32_t* adaptcoeffsA; | ||
83 | int32_t* adaptcoeffsB; | ||
84 | |||
85 | int32_t lastA; | ||
86 | |||
87 | int32_t filterA; | ||
88 | int32_t filterB; | ||
89 | }; | ||
90 | |||
91 | struct ape_ctx_t | ||
92 | { | ||
93 | /* Derived fields */ | ||
94 | uint32_t junklength; | ||
95 | uint32_t firstframe; | ||
96 | uint32_t totalsamples; | ||
97 | |||
98 | /* Info from Descriptor Block */ | ||
99 | char magic[4]; | ||
100 | int16_t fileversion; | ||
101 | int16_t padding1; | ||
102 | uint32_t descriptorlength; | ||
103 | uint32_t headerlength; | ||
104 | uint32_t seektablelength; | ||
105 | uint32_t wavheaderlength; | ||
106 | uint32_t audiodatalength; | ||
107 | uint32_t audiodatalength_high; | ||
108 | uint32_t wavtaillength; | ||
109 | uint8_t md5[16]; | ||
110 | |||
111 | /* Info from Header Block */ | ||
112 | uint16_t compressiontype; | ||
113 | uint16_t formatflags; | ||
114 | uint32_t blocksperframe; | ||
115 | uint32_t finalframeblocks; | ||
116 | uint32_t totalframes; | ||
117 | uint16_t bps; | ||
118 | uint16_t channels; | ||
119 | uint32_t samplerate; | ||
120 | |||
121 | /* Seektable */ | ||
122 | uint32_t* seektable; | ||
123 | |||
124 | /* Decoder state */ | ||
125 | uint32_t CRC; | ||
126 | int frameflags; | ||
127 | int currentframeblocks; | ||
128 | int blocksdecoded; | ||
129 | struct predictor_t predictorY; | ||
130 | struct predictor_t predictorX; | ||
131 | }; | ||
132 | |||
133 | int ape_parseheader(int fd, struct ape_ctx_t* ape_ctx); | ||
134 | int ape_parseheaderbuf(unsigned char* buf, struct ape_ctx_t* ape_ctx); | ||
135 | void ape_dumpinfo(struct ape_ctx_t* ape_ctx); | ||
136 | |||
137 | #endif | ||