3 libdemac - A Monkey's Audio decoder
7 Copyright (C) Dave Chapman 2007
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.
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.
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
29 #include "demac_config.h"
31 /* The earliest and latest file formats supported by this library */
32 #define APE_MIN_VERSION 3970
33 #define APE_MAX_VERSION 3990
35 #define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE]
36 #define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE]
37 #define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE]
38 #define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE]
39 #define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level
40 #define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored)
43 /* Special frame codes:
45 MONO_SILENCE - All PCM samples in frame are zero (mono streams only)
46 LEFT_SILENCE - All PCM samples for left channel in frame are zero (stereo streams)
47 RIGHT_SILENCE - All PCM samples for left channel in frame are zero (stereo streams)
48 PSEUDO_STEREO - Left and Right channels are identical
52 #define APE_FRAMECODE_MONO_SILENCE 1
53 #define APE_FRAMECODE_LEFT_SILENCE 1 /* same as mono */
54 #define APE_FRAMECODE_RIGHT_SILENCE 2
55 #define APE_FRAMECODE_STEREO_SILENCE 3 /* combined */
56 #define APE_FRAMECODE_PSEUDO_STEREO 4
58 #define PREDICTOR_ORDER 8
59 /* Total size of all predictor histories - 50 * sizeof(int32_t) */
60 #define PREDICTOR_SIZE 50
63 /* NOTE: This struct is used in predictor-arm.S - any updates need to
64 be reflected there. */
68 /* Filter histories */
74 /* NOTE: The order of the next four fields is important for
81 /* Adaption co-efficients */
86 int32_t historybuffer
[PREDICTOR_HISTORY_SIZE
+ PREDICTOR_SIZE
];
94 uint32_t totalsamples
;
96 /* Info from Descriptor Block */
100 uint32_t descriptorlength
;
101 uint32_t headerlength
;
102 uint32_t seektablelength
;
103 uint32_t wavheaderlength
;
104 uint32_t audiodatalength
;
105 uint32_t audiodatalength_high
;
106 uint32_t wavtaillength
;
109 /* Info from Header Block */
110 uint16_t compressiontype
;
111 uint16_t formatflags
;
112 uint32_t blocksperframe
;
113 uint32_t finalframeblocks
;
114 uint32_t totalframes
;
120 uint32_t* seektable
; /* Seektable buffer */
121 uint32_t maxseekpoints
; /* Max seekpoints we can store (size of seektable buffer) */
122 uint32_t numseekpoints
; /* Number of seekpoints */
123 int seektablefilepos
; /* Location in .ape file of seektable */
128 int currentframeblocks
;
130 struct predictor_t predictor
;
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
);