Set version to 1.3.0 and update coyprights throughout.
[platform/upstream/flac.git] / src / libFLAC / include / private / lpc.h
index 069d459..34bca4b 100644 (file)
@@ -1,28 +1,59 @@
 /* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2000,2001  Josh Coalson
+ * Copyright (C) 2000-2009  Josh Coalson
+ * Copyright (C) 2011-2013  Xiph.Org Foundation
  *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
  *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA  02111-1307, USA.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Xiph.org Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef FLAC__PRIVATE__LPC_H
 #define FLAC__PRIVATE__LPC_H
 
-#include "FLAC/ordinals.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "private/float.h"
+#include "FLAC/format.h"
 
-#define FLAC__MAX_LPC_ORDER (32u)
+#ifndef FLAC__INTEGER_ONLY_LIBRARY
+
+/*
+ *     FLAC__lpc_window_data()
+ *     --------------------------------------------------------------------
+ *     Applies the given window to the data.
+ *  OPT: asm implementation
+ *
+ *     IN in[0,data_len-1]
+ *     IN window[0,data_len-1]
+ *     OUT out[0,lag-1]
+ *     IN data_len
+ */
+void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
 
 /*
  *     FLAC__lpc_compute_autocorrelation()
  *     IN 0 < lag <= data_len
  *     OUT autoc[0,lag-1]
  */
-void FLAC__lpc_compute_autocorrelation(const real data[], unsigned data_len, unsigned lag, real autoc[]);
+void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+#ifndef FLAC__NO_ASM
+#  ifdef FLAC__CPU_IA32
+#    ifdef FLAC__HAS_NASM
+void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+#    endif
+#  endif
+#endif
 
 /*
  *     FLAC__lpc_compute_lp_coefficients()
@@ -50,26 +92,28 @@ void FLAC__lpc_compute_autocorrelation(const real data[], unsigned data_len, uns
  *     OUT lp_coeff[0,max_order-1][0,max_order-1] LP coefficients for each order
  *     *** IMPORTANT:
  *     *** lp_coeff[0,max_order-1][max_order,FLAC__MAX_LPC_ORDER-1] are untouched
- *     OUT error[0,max_order-1]                   error for each order
- *     
+ *     OUT error[0,max_order-1]                   error for each order (more
+ *                                                specifically, the variance of
+ *                                                the error signal times # of
+ *                                                samples in the signal)
+ *
  *     Example: if max_order is 9, the LP coefficients for order 9 will be
  *              in lp_coeff[8][0,8], the LP coefficients for order 8 will be
  *                      in lp_coeff[7][0,7], etc.
  */
-void FLAC__lpc_compute_lp_coefficients(const real autoc[], unsigned max_order, real lp_coeff[][FLAC__MAX_LPC_ORDER], real error[]);
+void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
 
 /*
  *     FLAC__lpc_quantize_coefficients()
  *     --------------------------------------------------------------------
  *     Quantizes the LP coefficients.  NOTE: precision + bits_per_sample
- *     must be less than 32 (sizeof(int32)*8).
+ *     must be less than 32 (sizeof(FLAC__int32)*8).
  *
  *     IN lp_coeff[0,order-1]    LP coefficients
  *     IN order                  LP order
  *     IN FLAC__MIN_QLP_COEFF_PRECISION < precision
  *                               desired precision (in bits, including sign
  *                               bit) of largest coefficient
- *     IN bits_per_sample > 0    bits per sample of the originial signal
  *     OUT qlp_coeff[0,order-1]  quantized coefficients
  *     OUT shift                 # of bits to shift right to get approximated
  *                               LP coefficients.  NOTE: could be negative.
@@ -79,7 +123,7 @@ void FLAC__lpc_compute_lp_coefficients(const real autoc[], unsigned max_order, r
  *         2 => coefficients are all zero, which is bad.  'shift' is
  *              unset.
  */
-int FLAC__lpc_quantize_coefficients(const real lp_coeff[], unsigned order, unsigned precision, unsigned bits_per_sample, int32 qlp_coeff[], int *shift);
+int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
 
 /*
  *     FLAC__lpc_compute_residual_from_qlp_coefficients()
@@ -94,7 +138,18 @@ int FLAC__lpc_quantize_coefficients(const real lp_coeff[], unsigned order, unsig
  *     IN lp_quantization         quantization of LP coefficients in bits
  *     OUT residual[0,data_len-1] residual signal
  */
-void FLAC__lpc_compute_residual_from_qlp_coefficients(const int32 data[], unsigned data_len, const int32 qlp_coeff[], unsigned order, int lp_quantization, int32 residual[]);
+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_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[]);
+#ifndef FLAC__NO_ASM
+#  ifdef FLAC__CPU_IA32
+#    ifdef FLAC__HAS_NASM
+void 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[]);
+void 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[]);
+#    endif
+#  endif
+#endif
+
+#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
 
 /*
  *     FLAC__lpc_restore_signal()
@@ -111,7 +166,21 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const int32 data[], unsign
  *     IN  data[-order,-1]        previously-reconstructed historical samples
  *     OUT data[0,data_len-1]     original signal
  */
-void FLAC__lpc_restore_signal(const int32 residual[], unsigned data_len, const int32 qlp_coeff[], unsigned order, int lp_quantization, int32 data[]);
+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_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+#ifndef FLAC__NO_ASM
+#  ifdef FLAC__CPU_IA32
+#    ifdef FLAC__HAS_NASM
+void 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[]);
+void 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[]);
+#    endif /* FLAC__HAS_NASM */
+#  elif defined FLAC__CPU_PPC
+void FLAC__lpc_restore_signal_asm_ppc_altivec_16(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+#  endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
+#endif /* FLAC__NO_ASM */
+
+#ifndef FLAC__INTEGER_ONLY_LIBRARY
 
 /*
  *     FLAC__lpc_compute_expected_bits_per_residual_sample()
@@ -123,7 +192,8 @@ void FLAC__lpc_restore_signal(const int32 residual[], unsigned data_len, const i
  *     IN total_samples > 0  # of samples in residual signal
  *     RETURN                expected bits per sample
  */
-real FLAC__lpc_compute_expected_bits_per_residual_sample(real lpc_error, unsigned total_samples);
+FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
+FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
 
 /*
  *     FLAC__lpc_compute_best_order()
@@ -134,9 +204,12 @@ real FLAC__lpc_compute_expected_bits_per_residual_sample(real lpc_error, unsigne
  *     IN lpc_error[0,max_order-1] >= 0.0  error returned from calculating LP coefficients
  *     IN max_order > 0                    max LP order
  *     IN total_samples > 0                # of samples in residual signal
- *     IN bits_per_signal_sample           # of bits per sample in the original signal
+ *     IN overhead_bits_per_order          # of bits overhead for each increased LP order
+ *                                         (includes warmup sample size and quantized LP coefficient)
  *     RETURN [1,max_order]                best order
  */
-unsigned FLAC__lpc_compute_best_order(const real lpc_error[], unsigned max_order, unsigned total_samples, unsigned bits_per_signal_sample);
+unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
+
+#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
 
 #endif