annotate sonic.c @ 2243:b8bad8bbbc64 libavcodec

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