2 * WavPack decoder/encoder common code
3 * Copyright (c) 2006,2011 Konstantin Shishkov
5 * This file is part of FFmpeg.
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.
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.
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
22 #ifndef AVCODEC_WAVPACK_H
23 #define AVCODEC_WAVPACK_H
27 #include "libavutil/attributes.h"
28 #include "libavutil/intmath.h"
33 #define WV_HEADER_SIZE 32
35 #define WV_MONO 0x00000004
36 #define WV_JOINT_STEREO 0x00000010
37 #define WV_CROSS_DECORR 0x00000020
38 #define WV_FLOAT_DATA 0x00000080
39 #define WV_INT32_DATA 0x00000100
40 #define WV_FALSE_STEREO 0x40000000
41 #define WV_DSD_DATA 0x80000000
43 #define WV_HYBRID_MODE 0x00000008
44 #define WV_HYBRID_SHAPE 0x00000008
45 #define WV_HYBRID_BITRATE 0x00000200
46 #define WV_HYBRID_BALANCE 0x00000400
47 #define WV_INITIAL_BLOCK 0x00000800
48 #define WV_FINAL_BLOCK 0x00001000
50 #define WV_MONO_DATA (WV_MONO | WV_FALSE_STEREO)
52 #define WV_SINGLE_BLOCK (WV_INITIAL_BLOCK | WV_FINAL_BLOCK)
54 #define WV_FLT_SHIFT_ONES 0x01
55 #define WV_FLT_SHIFT_SAME 0x02
56 #define WV_FLT_SHIFT_SENT 0x04
57 #define WV_FLT_ZERO_SENT 0x08
58 #define WV_FLT_ZERO_SIGN 0x10
60 #define WV_MAX_CHANNELS (1 << 12)
61 #define WV_MAX_SAMPLES 150000
86 WP_ID_SAMPLE_RATE
= 0x27,
89 typedef struct Decorr
{
94 int samplesA
[MAX_TERM
];
95 int samplesB
[MAX_TERM
];
100 typedef struct WvChannel
{
102 int slow_level
, error_limit
;
103 unsigned bitrate_acc
, bitrate_delta
;
106 // macros for manipulating median values
107 #define GET_MED(n) ((c->median[n] >> 4) + 1)
108 #define DEC_MED(n) c->median[n] -= ((int)(c->median[n] + (128U >> (n)) - 2) / (128 >> (n))) * 2U
109 #define INC_MED(n) c->median[n] += ((int)(c->median[n] + (128U >> (n)) ) / (128 >> (n))) * 5U
111 // macros for applying weight
112 #define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \
113 if ((samples) && (in)) { \
114 if (((samples) ^ (in)) < 0) { \
115 (weight) -= (delta); \
116 if ((weight) < -1024) \
119 (weight) += (delta); \
120 if ((weight) > 1024) \
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
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];
134 static av_always_inline
int wp_exp2(int16_t val
)
143 res
= ff_wp_exp2_table
[val
& 0xFF] | 0x100;
147 res
= (val
> 9) ? (res
<< (val
- 9)) : (res
>> (9 - val
));
148 return neg
? -res
: res
;
151 static av_always_inline
int wp_log2(uint32_t val
)
160 bits
= av_log2(val
) + 1;
162 return (bits
<< 8) + ff_wp_log2_table
[(val
<< (9 - bits
)) & 0xFF];
164 return (bits
<< 8) + ff_wp_log2_table
[(val
>> (bits
- 9)) & 0xFF];
167 #endif /* AVCODEC_WAVPACK_H */