annotate sonic.c @ 4478:ca8c6efd00d3 libavcodec

cosmetic: indent sensibly so code can be read at all
author mru
date Mon, 05 Feb 2007 19:35:36 +0000
parents c8c591fe26f8
children 9bf957e669f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
1 /*
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
2 * Simple free lossless/lossy audio codec
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
3 * Copyright (c) 2004 Alex Beregszaszi
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
15 * Lesser General Public License for more details.
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
16 *
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3777
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
20 */
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
21 #include "avcodec.h"
2398
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2205
diff changeset
22 #include "bitstream.h"
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
23 #include "golomb.h"
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
24
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
25 /**
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
26 * @file sonic.c
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
27 * Simple free lossless/lossy audio codec
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
28 * Based on Paul Francis Harrison's Bonk (http://www.logarithmic.net/pfh/bonk)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
29 * Written and designed by Alex Beregszaszi
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
30 *
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
31 * TODO:
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
32 * - CABAC put/get_symbol
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
33 * - independent quantizer for channels
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
34 * - >2 channels support
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
35 * - more decorrelation types
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
36 * - more tap_quant tests
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
37 * - selectable intlist writers/readers (bonk-style, golomb, cabac)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
38 */
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
39
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
40 #define MAX_CHANNELS 2
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
41
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
42 #define MID_SIDE 0
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
43 #define LEFT_SIDE 1
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
44 #define RIGHT_SIDE 2
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
45
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
46 typedef struct SonicContext {
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
47 int lossless, decorrelation;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
48
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
49 int num_taps, downsampling;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
50 double quantization;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
51
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
52 int channels, samplerate, block_align, frame_size;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
53
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
54 int *tap_quant;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
55 int *int_samples;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
56 int *coded_samples[MAX_CHANNELS];
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
57
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
58 // for encoding
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
59 int *tail;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
60 int tail_size;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
61 int *window;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
62 int window_size;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
63
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
64 // for decoding
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
65 int *predictor_k;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
66 int *predictor_state[MAX_CHANNELS];
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
67 } SonicContext;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
68
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
69 #define LATTICE_SHIFT 10
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
70 #define SAMPLE_SHIFT 4
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
71 #define LATTICE_FACTOR (1 << LATTICE_SHIFT)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
72 #define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
73
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
74 #define BASE_QUANT 0.6
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
75 #define RATE_VARIATION 3.0
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
76
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
77 static inline int divide(int a, int b)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
78 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
79 if (a < 0)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
80 return -( (-a + b/2)/b );
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
81 else
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
82 return (a + b/2)/b;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
83 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
84
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
85 static inline int shift(int a,int b)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
86 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
87 return (a+(1<<(b-1))) >> b;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
88 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
89
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
90 static inline int shift_down(int a,int b)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
91 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
92 return (a>>b)+((a<0)?1:0);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
93 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
94
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
95 #if 1
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
96 static inline int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
97 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
98 int i;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
99
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
100 for (i = 0; i < entries; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
101 set_se_golomb(pb, buf[i]);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
102
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
103 return 1;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
104 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
105
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
106 static inline int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
107 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
108 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
109
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
110 for (i = 0; i < entries; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
111 buf[i] = get_se_golomb(gb);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
112
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
113 return 1;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
114 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
115
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
116 #else
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
117
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
118 #define ADAPT_LEVEL 8
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
119
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
120 static int bits_to_store(uint64_t x)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
121 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
122 int res = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
123
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
124 while(x)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
125 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
126 res++;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
127 x >>= 1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
128 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
129 return res;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
130 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
131
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
132 static void write_uint_max(PutBitContext *pb, unsigned int value, unsigned int max)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
133 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
134 int i, bits;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
135
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
136 if (!max)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
137 return;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
138
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
139 bits = bits_to_store(max);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
140
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
141 for (i = 0; i < bits-1; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
142 put_bits(pb, 1, value & (1 << i));
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
143
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
144 if ( (value | (1 << (bits-1))) <= max)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
145 put_bits(pb, 1, value & (1 << (bits-1)));
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
146 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
147
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
148 static unsigned int read_uint_max(GetBitContext *gb, int max)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
149 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
150 int i, bits, value = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
151
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
152 if (!max)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
153 return 0;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
154
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
155 bits = bits_to_store(max);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
156
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
157 for (i = 0; i < bits-1; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
158 if (get_bits1(gb))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
159 value += 1 << i;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
160
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
161 if ( (value | (1<<(bits-1))) <= max)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
162 if (get_bits1(gb))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
163 value += 1 << (bits-1);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
164
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
165 return value;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
166 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
167
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
168 static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
169 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
170 int i, j, x = 0, low_bits = 0, max = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
171 int step = 256, pos = 0, dominant = 0, any = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
172 int *copy, *bits;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
173
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
174 copy = av_mallocz(4* entries);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
175 if (!copy)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
176 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
177
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
178 if (base_2_part)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
179 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
180 int energy = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
181
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
182 for (i = 0; i < entries; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
183 energy += abs(buf[i]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
184
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
185 low_bits = bits_to_store(energy / (entries * 2));
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
186 if (low_bits > 15)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
187 low_bits = 15;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
188
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
189 put_bits(pb, 4, low_bits);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
190 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
191
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
192 for (i = 0; i < entries; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
193 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
194 put_bits(pb, low_bits, abs(buf[i]));
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
195 copy[i] = abs(buf[i]) >> low_bits;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
196 if (copy[i] > max)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
197 max = abs(copy[i]);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
198 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
199
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
200 bits = av_mallocz(4* entries*max);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
201 if (!bits)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
202 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
203 // av_free(copy);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
204 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
205 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
206
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
207 for (i = 0; i <= max; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
208 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
209 for (j = 0; j < entries; j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
210 if (copy[j] >= i)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
211 bits[x++] = copy[j] > i;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
212 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
213
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
214 // store bitstream
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
215 while (pos < x)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
216 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
217 int steplet = step >> 8;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
218
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
219 if (pos + steplet > x)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
220 steplet = x - pos;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
221
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
222 for (i = 0; i < steplet; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
223 if (bits[i+pos] != dominant)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
224 any = 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
225
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
226 put_bits(pb, 1, any);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
227
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
228 if (!any)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
229 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
230 pos += steplet;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
231 step += step / ADAPT_LEVEL;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
232 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
233 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
234 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
235 int interloper = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
236
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
237 while (((pos + interloper) < x) && (bits[pos + interloper] == dominant))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
238 interloper++;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
239
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
240 // note change
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
241 write_uint_max(pb, interloper, (step >> 8) - 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
242
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
243 pos += interloper + 1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
244 step -= step / ADAPT_LEVEL;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
245 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
246
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
247 if (step < 256)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
248 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
249 step = 65536 / step;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
250 dominant = !dominant;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
251 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
252 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
253
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
254 // store signs
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
255 for (i = 0; i < entries; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
256 if (buf[i])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
257 put_bits(pb, 1, buf[i] < 0);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
258
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
259 // av_free(bits);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
260 // av_free(copy);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
261
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
262 return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
263 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
264
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
265 static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
266 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
267 int i, low_bits = 0, x = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
268 int n_zeros = 0, step = 256, dominant = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
269 int pos = 0, level = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
270 int *bits = av_mallocz(4* entries);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
271
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
272 if (!bits)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
273 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
274
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
275 if (base_2_part)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
276 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
277 low_bits = get_bits(gb, 4);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
278
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
279 if (low_bits)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
280 for (i = 0; i < entries; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
281 buf[i] = get_bits(gb, low_bits);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
282 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
283
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
284 // av_log(NULL, AV_LOG_INFO, "entries: %d, low bits: %d\n", entries, low_bits);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
285
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
286 while (n_zeros < entries)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
287 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
288 int steplet = step >> 8;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
289
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
290 if (!get_bits1(gb))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
291 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
292 for (i = 0; i < steplet; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
293 bits[x++] = dominant;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
294
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
295 if (!dominant)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
296 n_zeros += steplet;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
297
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
298 step += step / ADAPT_LEVEL;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
299 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
300 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
301 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
302 int actual_run = read_uint_max(gb, steplet-1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
303
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
304 // av_log(NULL, AV_LOG_INFO, "actual run: %d\n", actual_run);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
305
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
306 for (i = 0; i < actual_run; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
307 bits[x++] = dominant;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
308
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
309 bits[x++] = !dominant;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
310
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
311 if (!dominant)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
312 n_zeros += actual_run;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
313 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
314 n_zeros++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
315
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
316 step -= step / ADAPT_LEVEL;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
317 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
318
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
319 if (step < 256)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
320 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
321 step = 65536 / step;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
322 dominant = !dominant;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
323 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
324 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
325
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
326 // reconstruct unsigned values
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
327 n_zeros = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
328 for (i = 0; n_zeros < entries; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
329 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
330 while(1)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
331 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
332 if (pos >= entries)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
333 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
334 pos = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
335 level += 1 << low_bits;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
336 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
337
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
338 if (buf[pos] >= level)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
339 break;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
340
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
341 pos++;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
342 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
343
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
344 if (bits[i])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
345 buf[pos] += 1 << low_bits;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
346 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
347 n_zeros++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
348
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
349 pos++;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
350 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
351 // av_free(bits);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
352
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
353 // read signs
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
354 for (i = 0; i < entries; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
355 if (buf[i] && get_bits1(gb))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
356 buf[i] = -buf[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
357
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
358 // av_log(NULL, AV_LOG_INFO, "zeros: %d pos: %d\n", n_zeros, pos);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
359
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
360 return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
361 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
362 #endif
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
363
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
364 static void predictor_init_state(int *k, int *state, int order)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
365 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
366 int i;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
367
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
368 for (i = order-2; i >= 0; i--)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
369 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
370 int j, p, x = state[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
371
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
372 for (j = 0, p = i+1; p < order; j++,p++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
373 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
374 int tmp = x + shift_down(k[j] * state[p], LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
375 state[p] += shift_down(k[j]*x, LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
376 x = tmp;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
377 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
378 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
379 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
380
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
381 static int predictor_calc_error(int *k, int *state, int order, int error)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
382 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
383 int i, x = error - shift_down(k[order-1] * state[order-1], LATTICE_SHIFT);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
384
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
385 #if 1
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
386 int *k_ptr = &(k[order-2]),
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
387 *state_ptr = &(state[order-2]);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
388 for (i = order-2; i >= 0; i--, k_ptr--, state_ptr--)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
389 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
390 int k_value = *k_ptr, state_value = *state_ptr;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
391 x -= shift_down(k_value * state_value, LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
392 state_ptr[1] = state_value + shift_down(k_value * x, LATTICE_SHIFT);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
393 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
394 #else
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
395 for (i = order-2; i >= 0; i--)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
396 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
397 x -= shift_down(k[i] * state[i], LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
398 state[i+1] = state[i] + shift_down(k[i] * x, LATTICE_SHIFT);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
399 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
400 #endif
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
401
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
402 // don't drift too far, to avoid overflows
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
403 if (x > (SAMPLE_FACTOR<<16)) x = (SAMPLE_FACTOR<<16);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
404 if (x < -(SAMPLE_FACTOR<<16)) x = -(SAMPLE_FACTOR<<16);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
405
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
406 state[0] = x;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
407
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
408 return x;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
409 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
410
3777
20545fbb6f7c add some #ifdef CONFIG_ENCODERS/DECODERS
mru
parents: 3036
diff changeset
411 #ifdef CONFIG_ENCODERS
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
412 // Heavily modified Levinson-Durbin algorithm which
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
413 // copes better with quantization, and calculates the
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
414 // actual whitened result as it goes.
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
415
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
416 static void modified_levinson_durbin(int *window, int window_entries,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
417 int *out, int out_entries, int channels, int *tap_quant)
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
418 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
419 int i;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
420 int *state = av_mallocz(4* window_entries);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
421
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
422 memcpy(state, window, 4* window_entries);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
423
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
424 for (i = 0; i < out_entries; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
425 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
426 int step = (i+1)*channels, k, j;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
427 double xx = 0.0, xy = 0.0;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
428 #if 1
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
429 int *x_ptr = &(window[step]), *state_ptr = &(state[0]);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
430 j = window_entries - step;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
431 for (;j>=0;j--,x_ptr++,state_ptr++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
432 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
433 double x_value = *x_ptr, state_value = *state_ptr;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
434 xx += state_value*state_value;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
435 xy += x_value*state_value;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
436 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
437 #else
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
438 for (j = 0; j <= (window_entries - step); j++);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
439 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
440 double stepval = window[step+j], stateval = window[j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
441 // xx += (double)window[j]*(double)window[j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
442 // xy += (double)window[step+j]*(double)window[j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
443 xx += stateval*stateval;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
444 xy += stepval*stateval;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
445 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
446 #endif
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
447 if (xx == 0.0)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
448 k = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
449 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
450 k = (int)(floor(-xy/xx * (double)LATTICE_FACTOR / (double)(tap_quant[i]) + 0.5));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
451
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
452 if (k > (LATTICE_FACTOR/tap_quant[i]))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
453 k = LATTICE_FACTOR/tap_quant[i];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
454 if (-k > (LATTICE_FACTOR/tap_quant[i]))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
455 k = -(LATTICE_FACTOR/tap_quant[i]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
456
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
457 out[i] = k;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
458 k *= tap_quant[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
459
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
460 #if 1
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
461 x_ptr = &(window[step]);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
462 state_ptr = &(state[0]);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
463 j = window_entries - step;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
464 for (;j>=0;j--,x_ptr++,state_ptr++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
465 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
466 int x_value = *x_ptr, state_value = *state_ptr;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
467 *x_ptr = x_value + shift_down(k*state_value,LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
468 *state_ptr = state_value + shift_down(k*x_value, LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
469 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
470 #else
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
471 for (j=0; j <= (window_entries - step); j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
472 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
473 int stepval = window[step+j], stateval=state[j];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
474 window[step+j] += shift_down(k * stateval, LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
475 state[j] += shift_down(k * stepval, LATTICE_SHIFT);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
476 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
477 #endif
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
478 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
479
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
480 av_free(state);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
481 }
3777
20545fbb6f7c add some #ifdef CONFIG_ENCODERS/DECODERS
mru
parents: 3036
diff changeset
482 #endif /* CONFIG_ENCODERS */
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
483
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
484 static int samplerate_table[] =
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
485 { 44100, 22050, 11025, 96000, 48000, 32000, 24000, 16000, 8000 };
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
486
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
487 #ifdef CONFIG_ENCODERS
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
488
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
489 static inline int code_samplerate(int samplerate)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
490 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
491 switch (samplerate)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
492 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
493 case 44100: return 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
494 case 22050: return 1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
495 case 11025: return 2;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
496 case 96000: return 3;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
497 case 48000: return 4;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
498 case 32000: return 5;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
499 case 24000: return 6;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
500 case 16000: return 7;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
501 case 8000: return 8;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
502 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
503 return -1;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
504 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
505
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
506 static int sonic_encode_init(AVCodecContext *avctx)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
507 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
508 SonicContext *s = avctx->priv_data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
509 PutBitContext pb;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
510 int i, version = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
511
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
512 if (avctx->channels > MAX_CHANNELS)
2183
6d40885b03ad ffmpeg short conversion got fixed somewhere, no need to workaround it - fixes amplitude bug
alex
parents: 2182
diff changeset
513 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
514 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
515 return -1; /* only stereo or mono for now */
2183
6d40885b03ad ffmpeg short conversion got fixed somewhere, no need to workaround it - fixes amplitude bug
alex
parents: 2182
diff changeset
516 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
517
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
518 if (avctx->channels == 2)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
519 s->decorrelation = MID_SIDE;
2183
6d40885b03ad ffmpeg short conversion got fixed somewhere, no need to workaround it - fixes amplitude bug
alex
parents: 2182
diff changeset
520
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
521 if (avctx->codec->id == CODEC_ID_SONIC_LS)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
522 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
523 s->lossless = 1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
524 s->num_taps = 32;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
525 s->downsampling = 1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
526 s->quantization = 0.0;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
527 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
528 else
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
529 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
530 s->num_taps = 128;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
531 s->downsampling = 2;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
532 s->quantization = 1.0;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
533 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
534
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
535 // max tap 2048
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
536 if ((s->num_taps < 32) || (s->num_taps > 1024) ||
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
537 ((s->num_taps>>5)<<5 != s->num_taps))
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
538 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
539 av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
540 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
541 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
542
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
543 // generate taps
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
544 s->tap_quant = av_mallocz(4* s->num_taps);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
545 for (i = 0; i < s->num_taps; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
546 s->tap_quant[i] = (int)(sqrt(i+1));
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
547
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
548 s->channels = avctx->channels;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
549 s->samplerate = avctx->sample_rate;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
550
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
551 s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
552 s->frame_size = s->channels*s->block_align*s->downsampling;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
553
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
554 s->tail = av_mallocz(4* s->num_taps*s->channels);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
555 if (!s->tail)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
556 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
557 s->tail_size = s->num_taps*s->channels;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
558
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
559 s->predictor_k = av_mallocz(4 * s->num_taps);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
560 if (!s->predictor_k)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
561 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
562
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
563 for (i = 0; i < s->channels; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
564 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
565 s->coded_samples[i] = av_mallocz(4* s->block_align);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
566 if (!s->coded_samples[i])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
567 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
568 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
569
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
570 s->int_samples = av_mallocz(4* s->frame_size);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
571
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
572 s->window_size = ((2*s->tail_size)+s->frame_size);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
573 s->window = av_mallocz(4* s->window_size);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
574 if (!s->window)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
575 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
576
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
577 avctx->extradata = av_mallocz(16);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
578 if (!avctx->extradata)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
579 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
580 init_put_bits(&pb, avctx->extradata, 16*8);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
581
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
582 put_bits(&pb, 2, version); // version
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
583 if (version == 1)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
584 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
585 put_bits(&pb, 2, s->channels);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
586 put_bits(&pb, 4, code_samplerate(s->samplerate));
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
587 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
588 put_bits(&pb, 1, s->lossless);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
589 if (!s->lossless)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
590 put_bits(&pb, 3, SAMPLE_SHIFT); // XXX FIXME: sample precision
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
591 put_bits(&pb, 2, s->decorrelation);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
592 put_bits(&pb, 2, s->downsampling);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
593 put_bits(&pb, 5, (s->num_taps >> 5)-1); // 32..1024
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
594 put_bits(&pb, 1, 0); // XXX FIXME: no custom tap quant table
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
595
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
596 flush_put_bits(&pb);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
597 avctx->extradata_size = put_bits_count(&pb)/8;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
598
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
599 av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
600 version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
601
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
602 avctx->coded_frame = avcodec_alloc_frame();
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
603 if (!avctx->coded_frame)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
604 return -ENOMEM;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
605 avctx->coded_frame->key_frame = 1;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
606 avctx->frame_size = s->block_align*s->downsampling;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
607
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
608 return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
609 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
610
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
611 static int sonic_encode_close(AVCodecContext *avctx)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
612 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
613 SonicContext *s = avctx->priv_data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
614 int i;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
615
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
616 av_freep(&avctx->coded_frame);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
617
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
618 for (i = 0; i < s->channels; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
619 av_free(s->coded_samples[i]);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
620
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
621 av_free(s->predictor_k);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
622 av_free(s->tail);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
623 av_free(s->tap_quant);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
624 av_free(s->window);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
625 av_free(s->int_samples);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
626
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
627 return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
628 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
629
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
630 static int sonic_encode_frame(AVCodecContext *avctx,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
631 uint8_t *buf, int buf_size, void *data)
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
632 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
633 SonicContext *s = avctx->priv_data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
634 PutBitContext pb;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
635 int i, j, ch, quant = 0, x = 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
636 short *samples = data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
637
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
638 init_put_bits(&pb, buf, buf_size*8);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
639
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
640 // short -> internal
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
641 for (i = 0; i < s->frame_size; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
642 s->int_samples[i] = samples[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
643
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
644 if (!s->lossless)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
645 for (i = 0; i < s->frame_size; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
646 s->int_samples[i] = s->int_samples[i] << SAMPLE_SHIFT;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
647
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
648 switch(s->decorrelation)
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
649 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
650 case MID_SIDE:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
651 for (i = 0; i < s->frame_size; i += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
652 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
653 s->int_samples[i] += s->int_samples[i+1];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
654 s->int_samples[i+1] -= shift(s->int_samples[i], 1);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
655 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
656 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
657 case LEFT_SIDE:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
658 for (i = 0; i < s->frame_size; i += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
659 s->int_samples[i+1] -= s->int_samples[i];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
660 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
661 case RIGHT_SIDE:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
662 for (i = 0; i < s->frame_size; i += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
663 s->int_samples[i] -= s->int_samples[i+1];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
664 break;
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
665 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
666
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
667 memset(s->window, 0, 4* s->window_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
668
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
669 for (i = 0; i < s->tail_size; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
670 s->window[x++] = s->tail[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
671
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
672 for (i = 0; i < s->frame_size; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
673 s->window[x++] = s->int_samples[i];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
674
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
675 for (i = 0; i < s->tail_size; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
676 s->window[x++] = 0;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
677
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
678 for (i = 0; i < s->tail_size; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
679 s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
680
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
681 // generate taps
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
682 modified_levinson_durbin(s->window, s->window_size,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
683 s->predictor_k, s->num_taps, s->channels, s->tap_quant);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
684 if (intlist_write(&pb, s->predictor_k, s->num_taps, 0) < 0)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
685 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
686
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
687 for (ch = 0; ch < s->channels; ch++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
688 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
689 x = s->tail_size+ch;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
690 for (i = 0; i < s->block_align; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
691 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
692 int sum = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
693 for (j = 0; j < s->downsampling; j++, x += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
694 sum += s->window[x];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
695 s->coded_samples[ch][i] = sum;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
696 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
697 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
698
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
699 // simple rate control code
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
700 if (!s->lossless)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
701 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
702 double energy1 = 0.0, energy2 = 0.0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
703 for (ch = 0; ch < s->channels; ch++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
704 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
705 for (i = 0; i < s->block_align; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
706 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
707 double sample = s->coded_samples[ch][i];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
708 energy2 += sample*sample;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
709 energy1 += fabs(sample);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
710 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
711 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
712
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
713 energy2 = sqrt(energy2/(s->channels*s->block_align));
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
714 energy1 = sqrt(2.0)*energy1/(s->channels*s->block_align);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
715
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
716 // increase bitrate when samples are like a gaussian distribution
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
717 // reduce bitrate when samples are like a two-tailed exponential distribution
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
718
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
719 if (energy2 > energy1)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
720 energy2 += (energy2-energy1)*RATE_VARIATION;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
721
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
722 quant = (int)(BASE_QUANT*s->quantization*energy2/SAMPLE_FACTOR);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
723 // av_log(avctx, AV_LOG_DEBUG, "quant: %d energy: %f / %f\n", quant, energy1, energy2);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
724
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
725 if (quant < 1)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
726 quant = 1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
727 if (quant > 65535)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
728 quant = 65535;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
729
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
730 set_ue_golomb(&pb, quant);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
731
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
732 quant *= SAMPLE_FACTOR;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
733 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
734
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
735 // write out coded samples
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
736 for (ch = 0; ch < s->channels; ch++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
737 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
738 if (!s->lossless)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
739 for (i = 0; i < s->block_align; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
740 s->coded_samples[ch][i] = divide(s->coded_samples[ch][i], quant);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
741
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
742 if (intlist_write(&pb, s->coded_samples[ch], s->block_align, 1) < 0)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
743 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
744 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
745
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
746 // av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
747
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
748 flush_put_bits(&pb);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
749 return (put_bits_count(&pb)+7)/8;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
750 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
751 #endif //CONFIG_ENCODERS
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
752
3777
20545fbb6f7c add some #ifdef CONFIG_ENCODERS/DECODERS
mru
parents: 3036
diff changeset
753 #ifdef CONFIG_DECODERS
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
754 static int sonic_decode_init(AVCodecContext *avctx)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
755 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
756 SonicContext *s = avctx->priv_data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
757 GetBitContext gb;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
758 int i, version;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
759
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
760 s->channels = avctx->channels;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
761 s->samplerate = avctx->sample_rate;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
762
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
763 if (!avctx->extradata)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
764 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
765 av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
766 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
767 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
768
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
769 init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
770
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
771 version = get_bits(&gb, 2);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
772 if (version > 1)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
773 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
774 av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
775 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
776 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
777
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
778 if (version == 1)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
779 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
780 s->channels = get_bits(&gb, 2);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
781 s->samplerate = samplerate_table[get_bits(&gb, 4)];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
782 av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n",
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
783 s->channels, s->samplerate);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
784 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
785
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
786 if (s->channels > MAX_CHANNELS)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
787 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
788 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
789 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
790 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
791
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
792 s->lossless = get_bits1(&gb);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
793 if (!s->lossless)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
794 skip_bits(&gb, 3); // XXX FIXME
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
795 s->decorrelation = get_bits(&gb, 2);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
796
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
797 s->downsampling = get_bits(&gb, 2);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
798 s->num_taps = (get_bits(&gb, 5)+1)<<5;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
799 if (get_bits1(&gb)) // XXX FIXME
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
800 av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
801
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
802 s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
803 s->frame_size = s->channels*s->block_align*s->downsampling;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
804 // avctx->frame_size = s->block_align;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
805
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
806 av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
807 version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
808
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
809 // generate taps
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
810 s->tap_quant = av_mallocz(4* s->num_taps);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
811 for (i = 0; i < s->num_taps; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
812 s->tap_quant[i] = (int)(sqrt(i+1));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
813
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
814 s->predictor_k = av_mallocz(4* s->num_taps);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
815
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
816 for (i = 0; i < s->channels; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
817 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
818 s->predictor_state[i] = av_mallocz(4* s->num_taps);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
819 if (!s->predictor_state[i])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
820 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
821 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
822
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
823 for (i = 0; i < s->channels; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
824 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
825 s->coded_samples[i] = av_mallocz(4* s->block_align);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
826 if (!s->coded_samples[i])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
827 return -1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
828 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
829 s->int_samples = av_mallocz(4* s->frame_size);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
830
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
831 return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
832 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
833
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
834 static int sonic_decode_close(AVCodecContext *avctx)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
835 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
836 SonicContext *s = avctx->priv_data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
837 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
838
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
839 av_free(s->int_samples);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
840 av_free(s->tap_quant);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
841 av_free(s->predictor_k);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
842
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
843 for (i = 0; i < s->channels; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
844 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
845 av_free(s->predictor_state[i]);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
846 av_free(s->coded_samples[i]);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
847 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
848
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
849 return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
850 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
851
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
852 static int sonic_decode_frame(AVCodecContext *avctx,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
853 void *data, int *data_size,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
854 uint8_t *buf, int buf_size)
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
855 {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
856 SonicContext *s = avctx->priv_data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
857 GetBitContext gb;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
858 int i, quant, ch, j;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
859 short *samples = data;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
860
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
861 if (buf_size == 0) return 0;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
862
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
863 // av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
864
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
865 init_get_bits(&gb, buf, buf_size*8);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
866
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
867 intlist_read(&gb, s->predictor_k, s->num_taps, 0);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
868
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
869 // dequantize
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
870 for (i = 0; i < s->num_taps; i++)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
871 s->predictor_k[i] *= s->tap_quant[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
872
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
873 if (s->lossless)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
874 quant = 1;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
875 else
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
876 quant = get_ue_golomb(&gb) * SAMPLE_FACTOR;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
877
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
878 // av_log(NULL, AV_LOG_INFO, "quant: %d\n", quant);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
879
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
880 for (ch = 0; ch < s->channels; ch++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
881 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
882 int x = ch;
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
883
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
884 predictor_init_state(s->predictor_k, s->predictor_state[ch], s->num_taps);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
885
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
886 intlist_read(&gb, s->coded_samples[ch], s->block_align, 1);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
887
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
888 for (i = 0; i < s->block_align; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
889 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
890 for (j = 0; j < s->downsampling - 1; j++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
891 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
892 s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, 0);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
893 x += s->channels;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
894 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
895
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
896 s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, s->coded_samples[ch][i] * quant);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
897 x += s->channels;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
898 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
899
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
900 for (i = 0; i < s->num_taps; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
901 s->predictor_state[ch][i] = s->int_samples[s->frame_size - s->channels + ch - i*s->channels];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
902 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
903
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
904 switch(s->decorrelation)
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
905 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
906 case MID_SIDE:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
907 for (i = 0; i < s->frame_size; i += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
908 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
909 s->int_samples[i+1] += shift(s->int_samples[i], 1);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
910 s->int_samples[i] -= s->int_samples[i+1];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
911 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
912 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
913 case LEFT_SIDE:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
914 for (i = 0; i < s->frame_size; i += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
915 s->int_samples[i+1] += s->int_samples[i];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
916 break;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
917 case RIGHT_SIDE:
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
918 for (i = 0; i < s->frame_size; i += s->channels)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
919 s->int_samples[i] += s->int_samples[i+1];
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
920 break;
2205
b90828c162f5 more decorrelation types
alex
parents: 2183
diff changeset
921 }
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
922
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
923 if (!s->lossless)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
924 for (i = 0; i < s->frame_size; i++)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
925 s->int_samples[i] = shift(s->int_samples[i], SAMPLE_SHIFT);
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
926
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
927 // internal -> short
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
928 for (i = 0; i < s->frame_size; i++)
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
929 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
930 if (s->int_samples[i] > 32767)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
931 samples[i] = 32767;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
932 else if (s->int_samples[i] < -32768)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
933 samples[i] = -32768;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
934 else
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
935 samples[i] = s->int_samples[i];
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
936 }
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
937
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
938 align_get_bits(&gb);
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
939
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
940 *data_size = s->frame_size * 2;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
941
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
942 return (get_bits_count(&gb)+7)/8;
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
943 }
3777
20545fbb6f7c add some #ifdef CONFIG_ENCODERS/DECODERS
mru
parents: 3036
diff changeset
944 #endif
2182
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
945
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
946 #ifdef CONFIG_ENCODERS
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
947 AVCodec sonic_encoder = {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
948 "sonic",
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
949 CODEC_TYPE_AUDIO,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
950 CODEC_ID_SONIC,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
951 sizeof(SonicContext),
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
952 sonic_encode_init,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
953 sonic_encode_frame,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
954 sonic_encode_close,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
955 NULL,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
956 };
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
957
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
958 AVCodec sonic_ls_encoder = {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
959 "sonicls",
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
960 CODEC_TYPE_AUDIO,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
961 CODEC_ID_SONIC_LS,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
962 sizeof(SonicContext),
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
963 sonic_encode_init,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
964 sonic_encode_frame,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
965 sonic_encode_close,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
966 NULL,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
967 };
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
968 #endif
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
969
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
970 #ifdef CONFIG_DECODERS
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
971 AVCodec sonic_decoder = {
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
972 "sonic",
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
973 CODEC_TYPE_AUDIO,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
974 CODEC_ID_SONIC,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
975 sizeof(SonicContext),
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
976 sonic_decode_init,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
977 NULL,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
978 sonic_decode_close,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
979 sonic_decode_frame,
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
980 };
113732773bda new opensource lossy/lossless audio codec based on speech compression techniques (actually based on bonk)
alex
parents:
diff changeset
981 #endif