LMMS
Loading...
Searching...
No Matches
lpc.h
Go to the documentation of this file.
1/* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000-2009 Josh Coalson
3 * Copyright (C) 2011-2014 Xiph.Org Foundation
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of the Xiph.org Foundation nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef FLAC__PRIVATE__LPC_H
34#define FLAC__PRIVATE__LPC_H
35
36#ifdef HAVE_CONFIG_H
37#include <config.h>
38#endif
39
40#include "cpu.h"
41#include "float.h"
42#include "../../../format.h"
43
44#ifndef FLAC__INTEGER_ONLY_LIBRARY
45
46/*
47 * FLAC__lpc_window_data()
48 * --------------------------------------------------------------------
49 * Applies the given window to the data.
50 * OPT: asm implementation
51 *
52 * IN in[0,data_len-1]
53 * IN window[0,data_len-1]
54 * OUT out[0,lag-1]
55 * IN data_len
56 */
57void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
58
59/*
60 * FLAC__lpc_compute_autocorrelation()
61 * --------------------------------------------------------------------
62 * Compute the autocorrelation for lags between 0 and lag-1.
63 * Assumes data[] outside of [0,data_len-1] == 0.
64 * Asserts that lag > 0.
65 *
66 * IN data[0,data_len-1]
67 * IN data_len
68 * IN 0 < lag <= data_len
69 * OUT autoc[0,lag-1]
70 */
71void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
72#ifndef FLAC__NO_ASM
73# ifdef FLAC__CPU_IA32
74# ifdef FLAC__HAS_NASM
75void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
76void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
77void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
78void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
79void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_16(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
80# endif
81# endif
82# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
83# ifdef FLAC__SSE_SUPPORTED
84void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
85void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
86void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
87void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
88# endif
89# endif
90#endif
91
92/*
93 * FLAC__lpc_compute_lp_coefficients()
94 * --------------------------------------------------------------------
95 * Computes LP coefficients for orders 1..max_order.
96 * Do not call if autoc[0] == 0.0. This means the signal is zero
97 * and there is no point in calculating a predictor.
98 *
99 * IN autoc[0,max_order] autocorrelation values
100 * IN 0 < max_order <= FLAC__MAX_LPC_ORDER max LP order to compute
101 * OUT lp_coeff[0,max_order-1][0,max_order-1] LP coefficients for each order
102 * *** IMPORTANT:
103 * *** lp_coeff[0,max_order-1][max_order,FLAC__MAX_LPC_ORDER-1] are untouched
104 * OUT error[0,max_order-1] error for each order (more
105 * specifically, the variance of
106 * the error signal times # of
107 * samples in the signal)
108 *
109 * Example: if max_order is 9, the LP coefficients for order 9 will be
110 * in lp_coeff[8][0,8], the LP coefficients for order 8 will be
111 * in lp_coeff[7][0,7], etc.
112 */
113void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
114
115/*
116 * FLAC__lpc_quantize_coefficients()
117 * --------------------------------------------------------------------
118 * Quantizes the LP coefficients. NOTE: precision + bits_per_sample
119 * must be less than 32 (sizeof(FLAC__int32)*8).
120 *
121 * IN lp_coeff[0,order-1] LP coefficients
122 * IN order LP order
123 * IN FLAC__MIN_QLP_COEFF_PRECISION < precision
124 * desired precision (in bits, including sign
125 * bit) of largest coefficient
126 * OUT qlp_coeff[0,order-1] quantized coefficients
127 * OUT shift # of bits to shift right to get approximated
128 * LP coefficients. NOTE: could be negative.
129 * RETURN 0 => quantization OK
130 * 1 => coefficients require too much shifting for *shift to
131 * fit in the LPC subframe header. 'shift' is unset.
132 * 2 => coefficients are all zero, which is bad. 'shift' is
133 * unset.
134 */
135int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
136
137/*
138 * FLAC__lpc_compute_residual_from_qlp_coefficients()
139 * --------------------------------------------------------------------
140 * Compute the residual signal obtained from sutracting the predicted
141 * signal from the original.
142 *
143 * IN data[-order,data_len-1] original signal (NOTE THE INDICES!)
144 * IN data_len length of original signal
145 * IN qlp_coeff[0,order-1] quantized LP coefficients
146 * IN order > 0 LP order
147 * IN lp_quantization quantization of LP coefficients in bits
148 * OUT residual[0,data_len-1] residual signal
149 */
150void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
151void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
152#ifndef FLAC__NO_ASM
153# ifdef FLAC__CPU_IA32
154# ifdef FLAC__HAS_NASM
155void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
156void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
157void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
158# endif
159# endif
160# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
161# ifdef FLAC__SSE2_SUPPORTED
162void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
163void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
164# endif
165# ifdef FLAC__SSE4_1_SUPPORTED
166void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
167void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
168# endif
169# ifdef FLAC__AVX2_SUPPORTED
170void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
171void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
172void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
173# endif
174# endif
175#endif
176
177#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
178
179/*
180 * FLAC__lpc_restore_signal()
181 * --------------------------------------------------------------------
182 * Restore the original signal by summing the residual and the
183 * predictor.
184 *
185 * IN residual[0,data_len-1] residual signal
186 * IN data_len length of original signal
187 * IN qlp_coeff[0,order-1] quantized LP coefficients
188 * IN order > 0 LP order
189 * IN lp_quantization quantization of LP coefficients in bits
190 * *** IMPORTANT: the caller must pass in the historical samples:
191 * IN data[-order,-1] previously-reconstructed historical samples
192 * OUT data[0,data_len-1] original signal
193 */
194void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
195void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
196#ifndef FLAC__NO_ASM
197# ifdef FLAC__CPU_IA32
198# ifdef FLAC__HAS_NASM
199void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
200void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
201void FLAC__lpc_restore_signal_wide_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
202# endif /* FLAC__HAS_NASM */
203# endif /* FLAC__CPU_IA32 */
204# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
205# ifdef FLAC__SSE2_SUPPORTED
206void FLAC__lpc_restore_signal_16_intrin_sse2(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
207# endif
208# ifdef FLAC__SSE4_1_SUPPORTED
209void FLAC__lpc_restore_signal_wide_intrin_sse41(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
210# endif
211# endif
212#endif /* FLAC__NO_ASM */
213
214#ifndef FLAC__INTEGER_ONLY_LIBRARY
215
216/*
217 * FLAC__lpc_compute_expected_bits_per_residual_sample()
218 * --------------------------------------------------------------------
219 * Compute the expected number of bits per residual signal sample
220 * based on the LP error (which is related to the residual variance).
221 *
222 * IN lpc_error >= 0.0 error returned from calculating LP coefficients
223 * IN total_samples > 0 # of samples in residual signal
224 * RETURN expected bits per sample
225 */
228
229/*
230 * FLAC__lpc_compute_best_order()
231 * --------------------------------------------------------------------
232 * Compute the best order from the array of signal errors returned
233 * during coefficient computation.
234 *
235 * IN lpc_error[0,max_order-1] >= 0.0 error returned from calculating LP coefficients
236 * IN max_order > 0 max LP order
237 * IN total_samples > 0 # of samples in residual signal
238 * IN overhead_bits_per_order # of bits overhead for each increased LP order
239 * (includes warmup sample size and quantized LP coefficient)
240 * RETURN [1,max_order] best order
241 */
242unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
243
244#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
245
246#endif
FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
Definition lpc_flac.c:1315
void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
Definition lpc_flac.c:73
void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
Definition lpc_flac.c:122
void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
Definition lpc_flac.c:66
int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
Definition lpc_flac.c:166
FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
Definition lpc_flac.c:1304
unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
Definition lpc_flac.c:1332
void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
float FLAC__real
Definition float.h:58
double FLAC__double
Definition float.h:52
#define FLAC__MAX_LPC_ORDER
Definition format.h:131
JSAMPIMAGE data
Definition jpeglib.h:945
float in
Definition lilv_test.c:1460
float out
Definition lilv_test.c:1461
int32_t FLAC__int32
Definition ordinals.h:62
int error
Definition extract.c:1038