annotate src/demac/ape.h @ 2260:b71d8bee8882

OSS: use SNDCTL_DSP_SYNC, as not all OSS versions have SNDCTL_DSP_RESET. Reported by Michal on the forums.
author William Pitcock <nenolod@atheme.org>
date Fri, 21 Dec 2007 12:17:25 -0600
parents 58c69f2f2b60
children 292636e718c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2182
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
1 /*
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
2 * Monkey's Audio lossless audio decoder, common header,
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
3 * some libav* compatibility stuff
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
4 * Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
5 * based upon libdemac from Dave Chapman.
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
6 * Copyright (c) 2007 Eugene Zagidullin <e.asphyx@gmail.com>
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
7 * Cleanup libav* depending code, Audacious stuff.
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
8 *
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
12 * (at your option) any later version.
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
13 *
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
17 * GNU General Public License for more details.
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
18 *
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
22 */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
23
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
24 #ifndef APE_H
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
25 #define APE_H
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
26
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
27 #define FFMIN(a,b) ((a) < (b) ? (a) : (b))
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
28
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
29 #ifdef DEBUG
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
30 #define av_log(a, b, ...) fprintf(stderr, __VA_ARGS__)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
31 #else
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
32 #define av_log(a, b, ...) ;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
33 #endif
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
34
2193
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
35 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
36 #define MKTAG64(a,b,c,d,e,f,g,h) ((uint64_t)a | ((uint64_t)b << 8) | ((uint64_t)c << 16) | ((uint64_t)d << 24) | \
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
37 ((uint64_t)e << 32) | ((uint64_t)f << 40) | ((uint64_t)g << 48) | ((uint64_t)h << 56))
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
38
2182
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
39 #define AV_TIME_BASE 1000
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
40 #define AV_WL16(a,b) { \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
41 ((uint8_t*)(a))[0] = (uint16_t)(b) & 0x00ff; \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
42 ((uint8_t*)(a))[1] = ((uint16_t)(b) & 0xff00) >> 8; \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
43 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
44 #define AV_WL32(a,b) { \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
45 ((uint8_t*)(a))[0] = ((uint32_t)(b) & 0x000000ff); \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
46 ((uint8_t*)(a))[1] = ((uint32_t)(b) & 0x0000ff00) >> 8; \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
47 ((uint8_t*)(a))[2] = ((uint32_t)(b) & 0x00ff0000) >> 16; \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
48 ((uint8_t*)(a))[3] = ((uint32_t)(b) & 0xff000000) >> 24; \
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
49 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
50
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
51 #ifndef MAX
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
52 #define MAX(a,b) ((a) > (b) ? (a) : (b))
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
53 #endif
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
54
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
55 #define BLOCKS_PER_LOOP 4608
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
56 #define MAX_CHANNELS 2
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
57 //#define MAX_BYTESPERSAMPLE 3
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
58
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
59 #define APE_FRAMECODE_MONO_SILENCE 1
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
60 #define APE_FRAMECODE_STEREO_SILENCE 3
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
61 #define APE_FRAMECODE_PSEUDO_STEREO 4
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
62
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
63 #define HISTORY_SIZE 512
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
64 #define PREDICTOR_ORDER 8
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
65 /** Total size of all predictor histories */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
66 #define PREDICTOR_SIZE 50
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
67
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
68 #define YDELAYA (18 + PREDICTOR_ORDER*4)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
69 #define YDELAYB (18 + PREDICTOR_ORDER*3)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
70 #define XDELAYA (18 + PREDICTOR_ORDER*2)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
71 #define XDELAYB (18 + PREDICTOR_ORDER)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
72
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
73 #define YADAPTCOEFFSA 18
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
74 #define XADAPTCOEFFSA 14
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
75 #define YADAPTCOEFFSB 10
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
76 #define XADAPTCOEFFSB 5
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
77
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
78 #define APE_FILTER_LEVELS 3
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
79
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
80 #define AVERROR_IO -1
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
81 #define AVERROR_NOMEM -1
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
82
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
83 typedef struct {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
84 int64_t pos;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
85 int nblocks;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
86 int size;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
87 int skip;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
88 int64_t pts;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
89 } APEFrame;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
90
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
91 typedef struct {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
92 /* Derived fields */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
93 uint32_t junklength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
94 uint32_t firstframe;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
95 uint32_t totalsamples;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
96 int currentframe;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
97 APEFrame *frames;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
98
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
99 /* Info from Descriptor Block */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
100 char magic[4];
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
101 int16_t fileversion;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
102 int16_t padding1;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
103 uint32_t descriptorlength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
104 uint32_t headerlength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
105 uint32_t seektablelength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
106 uint32_t wavheaderlength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
107 uint32_t audiodatalength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
108 uint32_t audiodatalength_high;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
109 uint32_t wavtaillength;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
110 uint8_t md5[16];
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
111
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
112 /* Info from Header Block */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
113 uint16_t compressiontype;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
114 uint16_t formatflags;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
115 uint32_t blocksperframe;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
116 uint32_t finalframeblocks;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
117 uint32_t totalframes;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
118 uint16_t bps;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
119 uint16_t channels;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
120 uint32_t samplerate;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
121
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
122 /* Seektable */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
123 uint32_t *seektable;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
124
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
125 /* Added by Eugene: */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
126 uint32_t frame_size;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
127 //uint64_t total_blocks;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
128 uint64_t duration;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
129 uint32_t max_packet_size;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
130 } APEContext;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
131
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
132 /** Filters applied to the decoded data */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
133 typedef struct APEFilter {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
134 int16_t *coeffs; ///< actual coefficients used in filtering
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
135 int16_t *adaptcoeffs; ///< adaptive filter coefficients used for correcting of actual filter coefficients
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
136 int16_t *historybuffer; ///< filter memory
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
137 int16_t *delay; ///< filtered values
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
138
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
139 int avg;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
140 } APEFilter;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
141
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
142 typedef struct APERice {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
143 uint32_t k;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
144 uint32_t ksum;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
145 } APERice;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
146
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
147 typedef struct APERangecoder {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
148 uint32_t low; ///< low end of interval
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
149 uint32_t range; ///< length of interval
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
150 uint32_t help; ///< bytes_to_follow resp. intermediate value
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
151 unsigned int buffer; ///< buffer for input/output
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
152 } APERangecoder;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
153
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
154 /** Filter histories */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
155 typedef struct APEPredictor {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
156 int32_t *buf;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
157
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
158 int32_t lastA[2];
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
159
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
160 int32_t filterA[2];
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
161 int32_t filterB[2];
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
162
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
163 int32_t coeffsA[2][4]; ///< adaption coefficients
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
164 int32_t coeffsB[2][5]; ///< adaption coefficients
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
165 int32_t historybuffer[HISTORY_SIZE + PREDICTOR_SIZE];
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
166 } APEPredictor;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
167
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
168 /** Decoder context */
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
169 typedef struct APEDecoderContext {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
170 //AVCodecContext *avctx;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
171 APEContext *apectx;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
172 //DSPContext dsp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
173 int channels;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
174 int samples; ///< samples left to decode in current frame
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
175
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
176 int fileversion; ///< codec version, very important in decoding process
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
177 int compression_level; ///< compression levels
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
178 int fset; ///< which filter set to use (calculated from compression level)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
179 int flags; ///< global decoder flags
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
180
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
181 uint32_t CRC; ///< frame CRC
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
182 int frameflags; ///< frame flags
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
183 int currentframeblocks; ///< samples (per channel) in current frame
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
184 int blocksdecoded; ///< count of decoded samples in current frame
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
185 APEPredictor predictor; ///< predictor used for final reconstruction
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
186
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
187 int32_t decoded0[BLOCKS_PER_LOOP]; ///< decoded data for the first channel
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
188 int32_t decoded1[BLOCKS_PER_LOOP]; ///< decoded data for the second channel
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
189
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
190 int16_t* filterbuf[APE_FILTER_LEVELS]; ///< filter memory
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
191
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
192 APERangecoder rc; ///< rangecoder used to decode actual values
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
193 APERice riceX; ///< rice code parameters for the second channel
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
194 APERice riceY; ///< rice code parameters for the first channel
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
195 APEFilter filters[APE_FILTER_LEVELS][2]; ///< filters used for reconstruction
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
196
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
197 uint8_t *data; ///< current frame data
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
198 uint8_t *data_end; ///< frame data end
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
199 uint8_t *ptr; ///< current position in frame data
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
200 uint8_t *last_ptr; ///< position where last 4608-sample block ended
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
201 /*Eugene:*/
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
202 unsigned int max_packet_size; // Avoid multiply realloc calls
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
203 } APEDecoderContext;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
204
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
205
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
206 static inline uint8_t bytestream_get_byte(uint8_t** ptr) {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
207 uint8_t tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
208 tmp = **ptr;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
209 *ptr += 1;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
210 return tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
211 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
212
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
213 /*static inline uint32_t bytestream_get_be32(uint8_t** ptr) {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
214 uint32_t tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
215 tmp = *((uint32_t*)*ptr);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
216 *ptr += 4;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
217 return tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
218 }*/
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
219
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
220 static inline uint32_t bytestream_get_be32(uint8_t** ptr) {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
221 uint32_t tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
222 tmp = (*ptr)[3] | ((*ptr)[2] << 8) | ((*ptr)[1] << 16) | ((*ptr)[0] << 24);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
223 *ptr += 4;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
224 return tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
225 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
226
2224
58c69f2f2b60 forgotten macros
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2199
diff changeset
227 #ifdef ARCH_X86_64
58c69f2f2b60 forgotten macros
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2199
diff changeset
228 # define LEGACY_REGS "=Q"
58c69f2f2b60 forgotten macros
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2199
diff changeset
229 #else
58c69f2f2b60 forgotten macros
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2199
diff changeset
230 # define LEGACY_REGS "=q"
58c69f2f2b60 forgotten macros
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2199
diff changeset
231 #endif
58c69f2f2b60 forgotten macros
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2199
diff changeset
232
2182
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
233 static inline uint32_t bswap_32(uint32_t x)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
234 {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
235 #if defined(ARCH_X86)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
236 #if __CPU__ != 386
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
237 __asm("bswap %0":
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
238 "=r" (x) :
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
239 #else
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
240 __asm("xchgb %b0,%h0\n"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
241 " rorl $16,%0\n"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
242 " xchgb %b0,%h0":
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
243 LEGACY_REGS (x) :
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
244 #endif
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
245 "0" (x));
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
246 #elif defined(ARCH_SH4)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
247 __asm__(
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
248 "swap.b %0,%0\n"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
249 "swap.w %0,%0\n"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
250 "swap.b %0,%0\n"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
251 :"=r"(x):"0"(x));
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
252 #elif defined(ARCH_ARM)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
253 uint32_t t;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
254 __asm__ (
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
255 "eor %1, %0, %0, ror #16 \n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
256 "bic %1, %1, #0xFF0000 \n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
257 "mov %0, %0, ror #8 \n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
258 "eor %0, %0, %1, lsr #8 \n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
259 : "+r"(x), "+r"(t));
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
260 #elif defined(ARCH_BFIN)
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
261 unsigned tmp;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
262 asm("%1 = %0 >> 8 (V);\n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
263 "%0 = %0 << 8 (V);\n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
264 "%0 = %0 | %1;\n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
265 "%0 = PACK(%0.L, %0.H);\n\t"
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
266 : "+d"(x), "=&d"(tmp));
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
267 #else
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
268 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
269 x= (x>>16) | (x<<16);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
270 #endif
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
271 return x;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
272 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
273
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
274 static inline void bswap_buf(uint32_t *dst, uint32_t *src, int w){
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
275 int i;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
276
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
277 for(i=0; i+8<=w; i+=8){
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
278 dst[i+0]= bswap_32(src[i+0]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
279 dst[i+1]= bswap_32(src[i+1]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
280 dst[i+2]= bswap_32(src[i+2]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
281 dst[i+3]= bswap_32(src[i+3]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
282 dst[i+4]= bswap_32(src[i+4]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
283 dst[i+5]= bswap_32(src[i+5]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
284 dst[i+6]= bswap_32(src[i+6]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
285 dst[i+7]= bswap_32(src[i+7]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
286 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
287 for(;i<w; i++){
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
288 dst[i+0]= bswap_32(src[i+0]);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
289 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
290 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
291
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
292 static inline int16_t av_clip_int16(int a) {
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
293 if ((a+32768) & ~65535) return (a>>31) ^ 32767;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
294 else return a;
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
295 }
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
296
2193
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
297 uint16_t get_le16(VFSFile *vfd);
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
298 uint32_t get_le32(VFSFile *vfd);
2199
8b3c2fe608c9 APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2193
diff changeset
299 int put_le32(uint32_t val, VFSFile *vfd);
2193
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
300 uint64_t get_le64(VFSFile *vfd);
80d7ab8f2ec5 removed some duplicated code
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2182
diff changeset
301
2182
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
302 int ape_read_header(APEContext *ape, VFSFile *pb, int probe_only);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
303 int ape_read_packet(APEContext *ape, VFSFile *pb, uint8_t *pkt, int *pkt_size);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
304 int ape_read_close(APEContext *ape);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
305
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
306 int ape_decode_init(APEDecoderContext *s, APEContext *ctx);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
307 int ape_decode_frame(APEDecoderContext *s,
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
308 void *data, int *data_size,
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
309 uint8_t * buf, int buf_size);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
310
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
311 int ape_decode_close(APEDecoderContext *s);
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
312
cc5e9ec110a4 Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff changeset
313 #endif // APE_H