diff --git a/configure.ac b/configure.ac index ca526f414cdfe4af519d681895c68fceb7cfaef8..2dd3734794ae9e8d0fb04cb46f32542781b99055 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ AM_CONFIG_HEADER([config.h]) CELT_MAJOR_VERSION=0 CELT_MINOR_VERSION=8 CELT_MICRO_VERSION=0 -CELT_EXTRA_VERSION=-git +CELT_EXTRA_VERSION= CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION LIBCELT_SUFFIX=0 diff --git a/libcelt/Makefile.am b/libcelt/Makefile.am index f34b451fa038cd793f355342e1556af6256f06d9..086fe11180507df0b94e475c7df4a33f99db4a83 100644 --- a/libcelt/Makefile.am +++ b/libcelt/Makefile.am @@ -16,7 +16,7 @@ lib_LTLIBRARIES = libcelt@LIBCELT_SUFFIX@.la # Sources for compilation in the library libcelt@LIBCELT_SUFFIX@_la_SOURCES = bands.c celt.c cwrs.c ecintrin.h entcode.c \ entdec.c entenc.c header.c kiss_fft.c laplace.c mdct.c \ - modes.c pitch.c quant_bands.c rangedec.c rangeenc.c rate.c \ + modes.c pitch.c plc.c quant_bands.c rangedec.c rangeenc.c rate.c \ vq.c libcelt@LIBCELT_SUFFIX@_la_LDFLAGS = -version-info @CELT_LT_CURRENT@:@CELT_LT_REVISION@:@CELT_LT_AGE@ @@ -25,7 +25,7 @@ noinst_HEADERS = _kiss_fft_guts.h arch.h bands.h fixed_c5x.h fixed_c6x.h \ cwrs.h ecintrin.h entcode.h entdec.h entenc.h fixed_generic.h float_cast.h \ kfft_double.h kiss_fft.h laplace.h mdct.h mfrngcod.h \ mathops.h modes.h os_support.h pitch.h \ - quant_bands.h rate.h stack_alloc.h vq.h plc.c + quant_bands.h rate.h stack_alloc.h vq.h plc.h noinst_PROGRAMS = testcelt dump_modes testcelt_SOURCES = testcelt.c diff --git a/libcelt/celt.c b/libcelt/celt.c index cdf2c062a8ccab5df77ba77b123bd00050d646bd..7ed5c11dd7486d221f971e6204cdf165d2f32e8c 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -51,12 +51,7 @@ #include "mathops.h" #include "float_cast.h" #include <stdarg.h> - -#define LPC_ORDER 24 -#define NEW_PLC -#if !defined(FIXED_POINT) || defined(NEW_PLC) -#include "plc.c" -#endif +#include "plc.h" static const celt_word16 preemph = QCONST16(0.8f,15); @@ -1296,11 +1291,7 @@ bad_request: /* DECODER */ /* */ /**********************************************************************/ -#ifdef NEW_PLC #define DECODE_BUFFER_SIZE 2048 -#else -#define DECODE_BUFFER_SIZE MAX_PERIOD -#endif #define DECODERVALID 0x4c434454 #define DECODERPARTIAL 0x5444434c @@ -1326,9 +1317,7 @@ struct CELTDecoder { celt_word16 *oldBandE; -#ifdef NEW_PLC celt_word16 *lpc; -#endif int last_pitch_index; int loss_count; @@ -1395,16 +1384,12 @@ CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error) st->preemph_memD = (celt_sig*)celt_alloc(C*sizeof(celt_sig)); -#ifdef NEW_PLC st->lpc = (celt_word16*)celt_alloc(C*LPC_ORDER*sizeof(celt_word16)); -#endif st->loss_count = 0; if ((st->decode_mem!=NULL) && (st->out_mem!=NULL) && (st->oldBandE!=NULL) && -#ifdef NEW_PLC (st->lpc!=NULL) && -#endif (st->preemph_memD!=NULL)) { if (error) @@ -1447,10 +1432,7 @@ void celt_decoder_destroy(CELTDecoder *st) celt_free(st->decode_mem); celt_free(st->oldBandE); celt_free(st->preemph_memD); - -#ifdef NEW_PLC celt_free(st->lpc); -#endif st->marker = DECODERFREED; @@ -1495,19 +1477,6 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p fade = 0; } -#ifndef NEW_PLC - offset = MAX_PERIOD-pitch_index; - ALLOC(freq,C*N, celt_sig); /**< Interleaved signal MDCTs */ - while (offset+len >= MAX_PERIOD) - offset -= pitch_index; - compute_mdcts(st->mode, 0, st->out_mem+offset*C, freq, C, LM); - for (i=0;i<C*N;i++) - freq[i] = ADD32(VERY_SMALL, MULT16_32_Q15(fade,freq[i])); - - CELT_MOVE(st->out_mem, st->out_mem+C*N, C*(MAX_PERIOD+st->mode->overlap-N)); - /* Compute inverse MDCTs */ - compute_inv_mdcts(st->mode, 0, freq, -1, 0, st->out_mem, C, LM); -#else for (c=0;c<C;c++) { /* FIXME: This is more memory than necessary */ @@ -1624,7 +1593,6 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p for (i=0;i<N-overlap;i++) st->out_mem[C*(MAX_PERIOD-N+overlap+i)+c] = MULT16_32_Q15(fade, e[overlap+i]); } -#endif deemphasis(st->out_mem, pcm, N, C, preemph, st->preemph_memD); @@ -1935,9 +1903,7 @@ int celt_decoder_ctl(CELTDecoder * restrict st, int request, ...) st->loss_count = 0; -#ifdef NEW_PLC CELT_MEMSET(st->lpc, 0, C*LPC_ORDER); -#endif } break; default: diff --git a/libcelt/mathops.h b/libcelt/mathops.h index 412f7fa4868c3460927deb2c0d74cf956d2f063b..75198daf599bf80e8fb0f16363ab7fce9ab6f2f7 100644 --- a/libcelt/mathops.h +++ b/libcelt/mathops.h @@ -42,6 +42,8 @@ #include "entcode.h" #include "os_support.h" + + #ifndef OVERRIDE_FIND_MAX16 static inline int find_max16(celt_word16 *x, int len) { @@ -108,6 +110,7 @@ static inline celt_int16 bitexact_cos(celt_int16 x) #define celt_atan atan #define celt_rcp(x) (1.f/(x)) #define celt_div(a,b) ((a)/(b)) +#define frac_div32(a,b) ((float)(a)/(b)) #ifdef FLOAT_APPROX @@ -377,6 +380,21 @@ static inline celt_word32 celt_rcp(celt_word32 x) #define celt_div(a,b) MULT32_32_Q31((celt_word32)(a),celt_rcp(b)) +static celt_word32 frac_div32(celt_word32 a, celt_word32 b) +{ + celt_word16 rcp; + celt_word32 result, rem; + int shift = 30-celt_ilog2(b); + a = SHL32(a,shift); + b = SHL32(b,shift); + + /* 16-bit reciprocal */ + rcp = ROUND16(celt_rcp(ROUND16(b,16)),2); + result = SHL32(MULT16_32_Q15(rcp, a),1); + rem = a-MULT32_32_Q31(result, b); + result += SHL32(MULT16_32_Q15(rcp, rem),1); + return result; +} #define M1 32767 #define M2 -21 diff --git a/libcelt/plc.c b/libcelt/plc.c index 888f48d975b33aa941f64adfdfe15f84c6821ad9..2204c02c31471efb6302a34d5947f78c0e7c21f2 100644 --- a/libcelt/plc.c +++ b/libcelt/plc.c @@ -1,28 +1,44 @@ +/* Copyright (c) 2009-2010 Xiph.Org Foundation + Written by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: -#ifndef NEW_PLC -#define NEW_PLC -#endif + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. -#ifdef FIXED_POINT -static celt_word32 frac_div32(celt_word32 a, celt_word32 b) -{ - celt_word16 rcp; - celt_word32 result, rem; - int shift = 30-celt_ilog2(b); - a = SHL32(a,shift); - b = SHL32(b,shift); - - /* 16-bit reciprocal */ - rcp = ROUND16(celt_rcp(ROUND16(b,16)),2); - result = SHL32(MULT16_32_Q15(rcp, a),1); - rem = a-MULT32_32_Q31(result, b); - result += SHL32(MULT16_32_Q15(rcp, rem),1); - return result; -} -#else -#define frac_div32(a,b) ((float)(a)/(b)) + - 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. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif +#include "plc.h" +#include "stack_alloc.h" +#include "mathops.h" + + + void _celt_lpc( celt_word16 *_lpc, /* out: [0...p-1] LPC coefficients */ diff --git a/libcelt/plc.h b/libcelt/plc.h new file mode 100644 index 0000000000000000000000000000000000000000..3beb55c3f95b4ba54c597a7a3681a3d0d5745a2c --- /dev/null +++ b/libcelt/plc.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2009-2010 Xiph.Org Foundation + Written by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - 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 PLC_H +#define PLC_H + +#include "arch.h" + +#define LPC_ORDER 24 + +void _celt_lpc(celt_word16 *_lpc, const celt_word32 *ac, int p); + +void fir(const celt_word16 *x, + const celt_word16 *num, + celt_word16 *y, + int N, + int ord, + celt_word16 *mem); + +void iir(const celt_word32 *x, + const celt_word16 *den, + celt_word32 *y, + int N, + int ord, + celt_word16 *mem); + + +void _celt_autocorr(const celt_word16 *x, celt_word32 *ac, const celt_word16 *window, int overlap, int lag, int n); + + +#endif /* PLC_H */ diff --git a/tests/mathops-test.c b/tests/mathops-test.c index 5f086ae8607479725db201e3269c4b53f5528c51..dd48baa42e0a98693f8e26aca0f61b30202cb533 100644 --- a/tests/mathops-test.c +++ b/tests/mathops-test.c @@ -122,7 +122,7 @@ void testlog2(void) celt_word32 x; for (x=8;x<1073741824;x+=(x>>3)) { - float error = fabs((1.442695040888963387*log(x/16384.0))-celt_log2(x)/256.0); + float error = fabs((1.442695040888963387*log(x/16384.0))-celt_log2(x)/1024.0); if (error>0.003) { fprintf (stderr, "celt_log2 failed: x = %ld, error = %f\n", (long)x,error);