summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/demac/libdemac/parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/demac/libdemac/parser.h')
-rw-r--r--lib/rbcodec/codecs/demac/libdemac/parser.h137
1 files changed, 137 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/demac/libdemac/parser.h b/lib/rbcodec/codecs/demac/libdemac/parser.h
new file mode 100644
index 0000000000..6f07deac12
--- /dev/null
+++ b/lib/rbcodec/codecs/demac/libdemac/parser.h
@@ -0,0 +1,137 @@
1/*
2
3libdemac - A Monkey's Audio decoder
4
5$Id$
6
7Copyright (C) Dave Chapman 2007
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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#include "demac_config.h"
30
31/* The earliest and latest file formats supported by this library */
32#define APE_MIN_VERSION 3970
33#define APE_MAX_VERSION 3990
34
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)
41
42
43/* Special frame codes:
44
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
49
50*/
51
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
57
58#define PREDICTOR_ORDER 8
59/* Total size of all predictor histories - 50 * sizeof(int32_t) */
60#define PREDICTOR_SIZE 50
61
62
63/* NOTE: This struct is used in predictor-arm.S - any updates need to
64 be reflected there. */
65
66struct predictor_t
67{
68 /* Filter histories */
69 int32_t* buf;
70
71 int32_t YlastA;
72 int32_t XlastA;
73
74 /* NOTE: The order of the next four fields is important for
75 predictor-arm.S */
76 int32_t YfilterB;
77 int32_t XfilterA;
78 int32_t XfilterB;
79 int32_t YfilterA;
80
81 /* Adaption co-efficients */
82 int32_t YcoeffsA[4];
83 int32_t XcoeffsA[4];
84 int32_t YcoeffsB[5];
85 int32_t XcoeffsB[5];
86 int32_t historybuffer[PREDICTOR_HISTORY_SIZE + PREDICTOR_SIZE];
87};
88
89struct ape_ctx_t
90{
91 /* Derived fields */
92 uint32_t junklength;
93 uint32_t firstframe;
94 uint32_t totalsamples;
95
96 /* Info from Descriptor Block */
97 char magic[4];
98 int16_t fileversion;
99 int16_t padding1;
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;
107 uint8_t md5[16];
108
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;
115 uint16_t bps;
116 uint16_t channels;
117 uint32_t samplerate;
118
119 /* Seektable */
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 */
124
125 /* Decoder state */
126 uint32_t CRC;
127 int frameflags;
128 int currentframeblocks;
129 int blocksdecoded;
130 struct predictor_t predictor;
131};
132
133int ape_parseheader(int fd, struct ape_ctx_t* ape_ctx);
134int ape_parseheaderbuf(unsigned char* buf, struct ape_ctx_t* ape_ctx);
135void ape_dumpinfo(struct ape_ctx_t* ape_ctx);
136
137#endif