/src/ffmpeg/libavcodec/wavpack.h
Line | Count | Source |
1 | | /* |
2 | | * WavPack decoder/encoder common code |
3 | | * Copyright (c) 2006,2011 Konstantin Shishkov |
4 | | * |
5 | | * This file is part of FFmpeg. |
6 | | * |
7 | | * FFmpeg is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * FFmpeg is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public |
18 | | * License along with FFmpeg; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | | */ |
21 | | |
22 | | #ifndef AVCODEC_WAVPACK_H |
23 | | #define AVCODEC_WAVPACK_H |
24 | | |
25 | | #include <limits.h> |
26 | | #include <stdint.h> |
27 | | #include "libavutil/attributes.h" |
28 | | #include "libavutil/intmath.h" |
29 | | |
30 | 207k | #define MAX_TERMS 16 |
31 | 0 | #define MAX_TERM 8 |
32 | | |
33 | 490k | #define WV_HEADER_SIZE 32 |
34 | | |
35 | 124k | #define WV_MONO 0x00000004 |
36 | 124k | #define WV_JOINT_STEREO 0x00000010 |
37 | 0 | #define WV_CROSS_DECORR 0x00000020 |
38 | 23.1k | #define WV_FLOAT_DATA 0x00000080 |
39 | 0 | #define WV_INT32_DATA 0x00000100 |
40 | 124k | #define WV_FALSE_STEREO 0x40000000 |
41 | 254k | #define WV_DSD_DATA 0x80000000 |
42 | | |
43 | 124k | #define WV_HYBRID_MODE 0x00000008 |
44 | | #define WV_HYBRID_SHAPE 0x00000008 |
45 | 124k | #define WV_HYBRID_BITRATE 0x00000200 |
46 | | #define WV_HYBRID_BALANCE 0x00000400 |
47 | 249k | #define WV_INITIAL_BLOCK 0x00000800 |
48 | 249k | #define WV_FINAL_BLOCK 0x00001000 |
49 | | |
50 | 0 | #define WV_MONO_DATA (WV_MONO | WV_FALSE_STEREO) |
51 | | |
52 | 249k | #define WV_SINGLE_BLOCK (WV_INITIAL_BLOCK | WV_FINAL_BLOCK) |
53 | | |
54 | 471k | #define WV_FLT_SHIFT_ONES 0x01 |
55 | 383k | #define WV_FLT_SHIFT_SAME 0x02 |
56 | 76.2k | #define WV_FLT_SHIFT_SENT 0x04 |
57 | 272k | #define WV_FLT_ZERO_SENT 0x08 |
58 | 143k | #define WV_FLT_ZERO_SIGN 0x10 |
59 | | |
60 | | #define WV_MAX_CHANNELS (1 << 12) |
61 | 137k | #define WV_MAX_SAMPLES 150000 |
62 | | |
63 | | enum WP_ID_Flags { |
64 | | WP_IDF_MASK = 0x3F, |
65 | | WP_IDF_IGNORE = 0x20, |
66 | | WP_IDF_ODD = 0x40, |
67 | | WP_IDF_LONG = 0x80 |
68 | | }; |
69 | | |
70 | | enum WP_ID { |
71 | | WP_ID_DUMMY = 0, |
72 | | WP_ID_ENCINFO, |
73 | | WP_ID_DECTERMS, |
74 | | WP_ID_DECWEIGHTS, |
75 | | WP_ID_DECSAMPLES, |
76 | | WP_ID_ENTROPY, |
77 | | WP_ID_HYBRID, |
78 | | WP_ID_SHAPING, |
79 | | WP_ID_FLOATINFO, |
80 | | WP_ID_INT32INFO, |
81 | | WP_ID_DATA, |
82 | | WP_ID_CORR, |
83 | | WP_ID_EXTRABITS, |
84 | | WP_ID_CHANINFO, |
85 | | WP_ID_DSD_DATA, |
86 | | WP_ID_SAMPLE_RATE = 0x27, |
87 | | }; |
88 | | |
89 | | typedef struct Decorr { |
90 | | int delta; |
91 | | int value; |
92 | | int weightA; |
93 | | int weightB; |
94 | | int samplesA[MAX_TERM]; |
95 | | int samplesB[MAX_TERM]; |
96 | | int sumA; |
97 | | int sumB; |
98 | | } Decorr; |
99 | | |
100 | | typedef struct WvChannel { |
101 | | int median[3]; |
102 | | int slow_level, error_limit; |
103 | | unsigned bitrate_acc, bitrate_delta; |
104 | | } WvChannel; |
105 | | |
106 | | // macros for manipulating median values |
107 | 3.75M | #define GET_MED(n) ((c->median[n] >> 4) + 1) |
108 | 2.80M | #define DEC_MED(n) c->median[n] -= ((int)(c->median[n] + (128U >> (n)) - 2) / (128 >> (n))) * 2U |
109 | 907k | #define INC_MED(n) c->median[n] += ((int)(c->median[n] + (128U >> (n)) ) / (128 >> (n))) * 5U |
110 | | |
111 | | // macros for applying weight |
112 | | #define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \ |
113 | 9.21M | if ((samples) && (in)) { \ |
114 | 2.12M | if (((samples) ^ (in)) < 0) { \ |
115 | 593k | (weight) -= (delta); \ |
116 | 593k | if ((weight) < -1024) \ |
117 | 593k | (weight) = -1024; \ |
118 | 1.53M | } else { \ |
119 | 1.53M | (weight) += (delta); \ |
120 | 1.53M | if ((weight) > 1024) \ |
121 | 1.53M | (weight) = 1024; \ |
122 | 1.53M | } \ |
123 | 2.12M | } |
124 | | |
125 | | static const int wv_rates[16] = { |
126 | | 6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
127 | | 32000, 44100, 48000, 64000, 88200, 96000, 192000, 0 |
128 | | }; |
129 | | |
130 | | // exponent table copied from WavPack source |
131 | | extern const uint8_t ff_wp_exp2_table[256]; |
132 | | extern const uint8_t ff_wp_log2_table[256]; |
133 | | |
134 | | static av_always_inline int wp_exp2(int16_t val) |
135 | 518k | { |
136 | 518k | int res, neg = 0; |
137 | | |
138 | 518k | if (val < 0) { |
139 | 39.4k | val = -val; |
140 | 39.4k | neg = 1; |
141 | 39.4k | } |
142 | | |
143 | 518k | res = ff_wp_exp2_table[val & 0xFF] | 0x100; |
144 | 518k | val >>= 8; |
145 | 518k | if (val > 31U) |
146 | 51.8k | return INT_MIN; |
147 | 467k | res = (val > 9) ? (res << (val - 9)) : (res >> (9 - val)); |
148 | 467k | return neg ? -res : res; |
149 | 518k | } Unexecuted instantiation: wavpackenc.c:wp_exp2 Unexecuted instantiation: wavpackdata.c:wp_exp2 Line | Count | Source | 135 | 518k | { | 136 | 518k | int res, neg = 0; | 137 | | | 138 | 518k | if (val < 0) { | 139 | 39.4k | val = -val; | 140 | 39.4k | neg = 1; | 141 | 39.4k | } | 142 | | | 143 | 518k | res = ff_wp_exp2_table[val & 0xFF] | 0x100; | 144 | 518k | val >>= 8; | 145 | 518k | if (val > 31U) | 146 | 51.8k | return INT_MIN; | 147 | 467k | res = (val > 9) ? (res << (val - 9)) : (res >> (9 - val)); | 148 | 467k | return neg ? -res : res; | 149 | 518k | } |
|
150 | | |
151 | | static av_always_inline int wp_log2(uint32_t val) |
152 | 2.70M | { |
153 | 2.70M | int bits; |
154 | | |
155 | 2.70M | if (!val) |
156 | 635k | return 0; |
157 | 2.06M | if (val == 1) |
158 | 50.6k | return 256; |
159 | 2.01M | val += val >> 9; |
160 | 2.01M | bits = av_log2(val) + 1; |
161 | 2.01M | if (bits < 9) |
162 | 263k | return (bits << 8) + ff_wp_log2_table[(val << (9 - bits)) & 0xFF]; |
163 | 1.75M | else |
164 | 1.75M | return (bits << 8) + ff_wp_log2_table[(val >> (bits - 9)) & 0xFF]; |
165 | 2.01M | } Unexecuted instantiation: wavpackenc.c:wp_log2 Unexecuted instantiation: wavpackdata.c:wp_log2 Line | Count | Source | 152 | 2.70M | { | 153 | 2.70M | int bits; | 154 | | | 155 | 2.70M | if (!val) | 156 | 635k | return 0; | 157 | 2.06M | if (val == 1) | 158 | 50.6k | return 256; | 159 | 2.01M | val += val >> 9; | 160 | 2.01M | bits = av_log2(val) + 1; | 161 | 2.01M | if (bits < 9) | 162 | 263k | return (bits << 8) + ff_wp_log2_table[(val << (9 - bits)) & 0xFF]; | 163 | 1.75M | else | 164 | 1.75M | return (bits << 8) + ff_wp_log2_table[(val >> (bits - 9)) & 0xFF]; | 165 | 2.01M | } |
|
166 | | |
167 | | #endif /* AVCODEC_WAVPACK_H */ |