[libav-devel] [PATCH] Experimental DCA encoder
From: Alexander E. Patrakov --- Changelog |1 + doc/general.texi |2 +- libavcodec/Makefile|1 + libavcodec/allcodecs.c |2 +- libavcodec/dcaenc.c| 587 libavcodec/dcaenc.h| 544 6 files changed, 1135 insertions(+), 2 deletions(-) create mode 100644 libavcodec/dcaenc.c create mode 100644 libavcodec/dcaenc.h diff --git a/Changelog b/Changelog index 4bc6d31..d446c64 100644 --- a/Changelog +++ b/Changelog @@ -86,6 +86,7 @@ version : - AAC encoding via libvo-aacenc - AMR-WB encoding via libvo-amrwbenc - xWMA demuxer +- Experimental DCA encoder version 0.6: diff --git a/doc/general.texi b/doc/general.texi index 423402c..f290aca 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -602,7 +602,7 @@ following image formats are supported: @tab Codec used in Delphine Software International games. @item COOK @tab @tab X @tab All versions except 5.1 are supported. -@item DCA (DTS Coherent Acoustics) @tab @tab X +@item DCA (DTS Coherent Acoustics) @tab X @tab X @item DPCM id RoQ@tab X @tab X @tab Used in Quake III, Jedi Knight 2, other computer games. @item DPCM Interplay @tab @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1cdae2c..058c6f9 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -104,6 +104,7 @@ OBJS-$(CONFIG_COOK_DECODER)+= cook.o OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o +OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o OBJS-$(CONFIG_DFA_DECODER) += dfa.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 40a7e23..1d969cd 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -238,7 +238,7 @@ void avcodec_register_all(void) REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); REGISTER_DECODER (COOK, cook); -REGISTER_DECODER (DCA, dca); +REGISTER_ENCDEC (DCA, dca); REGISTER_DECODER (DSICINAUDIO, dsicinaudio); REGISTER_DECODER (EAC3, eac3); REGISTER_ENCDEC (FLAC, flac); diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c new file mode 100644 index 000..6d8694f --- /dev/null +++ b/libavcodec/dcaenc.c @@ -0,0 +1,587 @@ +/* + * DCA encoder + * Copyright (C) 2008 Alexander E. Patrakov + * 2010 Benjamin Larsson + * 2011 Xiang Wang + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/avassert.h" +#include "libavutil/audioconvert.h" +#include "avcodec.h" +#include "get_bits.h" +#include "put_bits.h" +#include "dcaenc.h" +#include "dcadata.h" + +#undef NDEBUG + +#define MAX_CHANNELS 6 +#define DCA_SUBBANDS_32 32 +#define DCA_MAX_FRAME_SIZE 16383 +#define DCA_HEADER_SIZE 13 + +#define DCA_SUBBANDS 32 ///< Subband activity count +#define QUANTIZER_BITS 16 +#define SUBFRAMES 1 +#define SUBSUBFRAMES 4 +#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8) +#define LFE_BITS 8 +#define LFE_INTERPOLATION 64 +#define LFE_PRESENT 2 +#define LFE_MISSING 0 + +static const int8_t dca_lfe_index[] = { +1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 +}; + +static const int8_t dca_channel_reorder_lfe[][9] = { +{ 0, -1, -1, -1, -1, -1, -1, -1, -1 }, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1 }, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1 }, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1 }, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1 }, +{ 1, 2, 0, -1, -1, -1, -1, -1, -1 }, +{ 0, 1, -1, 2, -1, -1, -1, -1, -1 }, +{ 1, 2, 0, -1, 3, -1, -1, -1, -1 }, +{ 0, 1, -1, 2, 3, -1, -1, -1, -1 }, +{ 1, 2, 0, -1, 3, 4, -1, -1, -1 }, +{ 2, 3, -1, 0, 1, 4, 5, -1, -1 }, +{ 1, 2, 0, -1, 3, 4, 5, -1, -1 }, +{ 0, -1, 4, 5, 2, 3, 1, -1, -1 }, +{ 3, 4, 1, -1, 0, 2, 5, 6, -1 }, +{ 2, 3, -1, 5, 7, 0, 1, 4, 6 }, +{ 3, 4, 1, -1, 0,
Re: [libav-devel] [PATCH] Experimental DCA encoder
On Fri, Apr 15, 2011 at 04:39:48PM +0200, Diego Biurrun wrote: > From: Alexander E. Patrakov Patch updated to apply against HEAD and prettified. Benjamin, rebase any review comments on top of this one :) Diego ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH] Experimental DCA encoder
From: Alexander E. Patrakov --- Changelog |1 + doc/general.texi |2 +- libavcodec/Makefile|1 + libavcodec/allcodecs.c |2 +- libavcodec/dcaenc.c| 587 libavcodec/dcaenc.h| 544 6 files changed, 1135 insertions(+), 2 deletions(-) create mode 100644 libavcodec/dcaenc.c create mode 100644 libavcodec/dcaenc.h diff --git a/Changelog b/Changelog index 4bc6d31..d446c64 100644 --- a/Changelog +++ b/Changelog @@ -86,6 +86,7 @@ version : - AAC encoding via libvo-aacenc - AMR-WB encoding via libvo-amrwbenc - xWMA demuxer +- Experimental DCA encoder version 0.6: diff --git a/doc/general.texi b/doc/general.texi index 423402c..f290aca 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -602,7 +602,7 @@ following image formats are supported: @tab Codec used in Delphine Software International games. @item COOK @tab @tab X @tab All versions except 5.1 are supported. -@item DCA (DTS Coherent Acoustics) @tab @tab X +@item DCA (DTS Coherent Acoustics) @tab X @tab X @item DPCM id RoQ@tab X @tab X @tab Used in Quake III, Jedi Knight 2, other computer games. @item DPCM Interplay @tab @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1cdae2c..058c6f9 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -104,6 +104,7 @@ OBJS-$(CONFIG_COOK_DECODER)+= cook.o OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o +OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o OBJS-$(CONFIG_DFA_DECODER) += dfa.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 40a7e23..1d969cd 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -238,7 +238,7 @@ void avcodec_register_all(void) REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); REGISTER_DECODER (COOK, cook); -REGISTER_DECODER (DCA, dca); +REGISTER_ENCDEC (DCA, dca); REGISTER_DECODER (DSICINAUDIO, dsicinaudio); REGISTER_DECODER (EAC3, eac3); REGISTER_ENCDEC (FLAC, flac); diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c new file mode 100644 index 000..4734524 --- /dev/null +++ b/libavcodec/dcaenc.c @@ -0,0 +1,587 @@ +/* + * DCA encoder + * Copyright (C) 2008 Alexander E. Patrakov + * 2010 Benjamin Larsson + * 2011 Xiang Wang + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/avassert.h" +#include "libavutil/audioconvert.h" +#include "avcodec.h" +#include "get_bits.h" +#include "put_bits.h" +#include "dcaenc.h" +#include "dcadata.h" + +#undef NDEBUG + +#define MAX_CHANNELS 6 +#define DCA_SUBBANDS_32 32 +#define DCA_MAX_FRAME_SIZE 16383 +#define DCA_HEADER_SIZE 13 + +#define DCA_SUBBANDS 32 ///< Subband activity count +#define QUANTIZER_BITS 16 +#define SUBFRAMES 1 +#define SUBSUBFRAMES 4 +#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8) +#define LFE_BITS 8 +#define LFE_INTERPOLATION 64 +#define LFE_PRESENT 2 +#define LFE_MISSING 0 + +static const int8_t dca_lfe_index[] = { +1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 +}; + +static const int8_t dca_channel_reorder_lfe[][9] = { +{ 0, -1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, 2, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, 3, -1, -1, -1, -1}, +{ 0, 1, -1, 2, 3, -1, -1, -1, -1}, +{ 1, 2, 0, -1, 3, 4, -1, -1, -1}, +{ 2, 3, -1, 0, 1, 4, 5, -1, -1}, +{ 1, 2, 0, -1, 3, 4, 5, -1, -1}, +{ 0, -1, 4, 5, 2, 3, 1, -1, -1}, +{ 3, 4, 1, -1, 0, 2, 5, 6, -1}, +{ 2, 3, -1, 5, 7, 0, 1, 4, 6}, +{ 3, 4, 1, -1, 0, 2, 5, 7, 6}, +
Re: [libav-devel] [PATCH] Experimental DCA encoder
On Fri, Apr 08, 2011 at 01:33:21AM +0200, Alexander E. Patrakov wrote: > --- > Changelog |1 + > doc/general.texi |2 +- > libavcodec/Makefile|1 + > libavcodec/allcodecs.c |2 +- > libavcodec/dcaenc.c| 587 > > libavcodec/dcaenc.h| 544 > 6 files changed, 1135 insertions(+), 2 deletions(-) > create mode 100644 libavcodec/dcaenc.c > create mode 100644 libavcodec/dcaenc.h > [...] > diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c > new file mode 100644 > index 000..670cc3e > --- /dev/null > +++ b/libavcodec/dcaenc.c > @@ -0,0 +1,587 @@ > +/* > + * DCA encoder > + * Copyright (C) 2008 Alexander E. Patrakov > + * 2010 Benjamin Larsson > + * 2011 Xiang Wang > + * This file is part of Libav. > + * > + * Libav is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * Libav 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 > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with Libav; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + */ > + > +#include "libavutil/common.h" > +#include "libavutil/avassert.h" > +#include "libavutil/audioconvert.h" > +#include "avcodec.h" > +#include "get_bits.h" > +#include "put_bits.h" > +#include "dcaenc.h" > +#include "dcadata.h" > + > +#undef NDEBUG > + > +#define MAX_CHANNELS 6 > +#define DCA_SUBBANDS_32 32 > +#define DCA_MAX_FRAME_SIZE 16383 > +#define DCA_HEADER_SIZE 13 > + > +#define DCA_SUBBANDS 32 ///< Subband activity count > +#define QUANTIZER_BITS 16 > +#define SUBFRAMES 1 > +#define SUBSUBFRAMES 4 > +#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8) > +#define LFE_BITS 8 > +#define LFE_INTERPOLATION 64 > +#define LFE_PRESENT 2 > +#define LFE_MISSING 0 have you considered sharing some of these with decoder? > +static const int8_t dca_lfe_index[] = { > +1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 > +}; this table too > +static const int8_t dca_channel_reorder_lfe[][9] = { > +{ 0, -1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 1, 2, 0, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, 2, -1, -1, -1, -1, -1}, > +{ 1, 2, 0, -1, 3, -1, -1, -1, -1}, > +{ 0, 1, -1, 2, 3, -1, -1, -1, -1}, > +{ 1, 2, 0, -1, 3, 4, -1, -1, -1}, > +{ 2, 3, -1, 0, 1, 4, 5, -1, -1}, > +{ 1, 2, 0, -1, 3, 4, 5, -1, -1}, > +{ 0, -1, 4, 5, 2, 3, 1, -1, -1}, > +{ 3, 4, 1, -1, 0, 2, 5, 6, -1}, > +{ 2, 3, -1, 5, 7, 0, 1, 4, 6}, > +{ 3, 4, 1, -1, 0, 2, 5, 7, 6}, > +}; > + > +static const int8_t dca_channel_reorder_nolfe[][9] = { > +{ 0, -1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, > +{ 1, 2, 0, -1, -1, -1, -1, -1, -1}, > +{ 0, 1, 2, -1, -1, -1, -1, -1, -1}, > +{ 1, 2, 0, 3, -1, -1, -1, -1, -1}, > +{ 0, 1, 2, 3, -1, -1, -1, -1, -1}, > +{ 1, 2, 0, 3, 4, -1, -1, -1, -1}, > +{ 2, 3, 0, 1, 4, 5, -1, -1, -1}, > +{ 1, 2, 0, 3, 4, 5, -1, -1, -1}, > +{ 0, 4, 5, 2, 3, 1, -1, -1, -1}, > +{ 3, 4, 1, 0, 2, 5, 6, -1, -1}, > +{ 2, 3, 5, 7, 0, 1, 4, 6, -1}, > +{ 3, 4, 1, 0, 2, 5, 7, 6, -1}, > +}; please add a not on _how_ these tables remap channels (and why they do it in different way from decoder) > +typedef struct { > +PutBitContext pb; > +int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */ > +int start[MAX_CHANNELS]; > +int frame_size; > +int prim_channels; > +int lfe_channel; > +int sample_rate_code; > +int scale_factor[MAX_CHANNELS][DCA_SUBBANDS_32]; > +int lfe_scale_factor; > +int lfe_data[SUBFRAMES*SUBSUBFRAMES*4]; > + > +int a_mode; ///< audio channels arrangement > +int num_channel; > +int lfe_state; > +int lfe_offset; > +const int8_t* channel_order_tab;///< channel reordering table, lfe > and non lfe > + > +int32_t pcm[FFMAX(LFE_INTERPOLATION, DCA_SUBBANDS_32)]; > +int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]; /* > [sample][channel][subband] */ > +} DCAContext; > + > +static i
Re: [libav-devel] [PATCH] Experimental DCA encoder v2
Ping MvH Benjamin Larsson ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH] Experimental DCA encoder v2
Fixed some things but not others. MvH Benjamin Larsson >From 20a2180193d0fcfaaf71fb1d9f3bb4cd90a1ce0f Mon Sep 17 00:00:00 2001 From: Alexander E. Patrakov Date: Fri, 8 Apr 2011 01:33:21 +0200 Subject: [PATCH] Experimental DCA encoder --- Changelog |1 + doc/general.texi |2 +- libavcodec/Makefile|1 + libavcodec/allcodecs.c |2 +- libavcodec/dcaenc.c| 587 libavcodec/dcaenc.h| 544 6 files changed, 1135 insertions(+), 2 deletions(-) create mode 100644 libavcodec/dcaenc.c create mode 100644 libavcodec/dcaenc.h diff --git a/Changelog b/Changelog index ec09c28..045c3f5 100644 --- a/Changelog +++ b/Changelog @@ -83,6 +83,7 @@ version : - Linux framebuffer input device added - Chronomaster DFA decoder - Mobotix MxPEG decoder +- Experimental DCA encoder version 0.6: diff --git a/doc/general.texi b/doc/general.texi index 5d66e42..2eeb609 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -599,7 +599,7 @@ following image formats are supported: @tab Codec used in Delphine Software International games. @item COOK @tab @tab X @tab All versions except 5.1 are supported. -@item DCA (DTS Coherent Acoustics) @tab @tab X +@item DCA (DTS Coherent Acoustics) @tab X @tab X @item DPCM id RoQ@tab X @tab X @tab Used in Quake III, Jedi Knight 2, other computer games. @item DPCM Interplay @tab @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 837f7e2..195469d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -104,6 +104,7 @@ OBJS-$(CONFIG_COOK_DECODER)+= cook.o OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o +OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o OBJS-$(CONFIG_DFA_DECODER) += dfa.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 7636392..9530358 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -238,7 +238,7 @@ void avcodec_register_all(void) REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); REGISTER_DECODER (COOK, cook); -REGISTER_DECODER (DCA, dca); +REGISTER_ENCDEC (DCA, dca); REGISTER_DECODER (DSICINAUDIO, dsicinaudio); REGISTER_DECODER (EAC3, eac3); REGISTER_ENCDEC (FLAC, flac); diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c new file mode 100644 index 000..670cc3e --- /dev/null +++ b/libavcodec/dcaenc.c @@ -0,0 +1,587 @@ +/* + * DCA encoder + * Copyright (C) 2008 Alexander E. Patrakov + * 2010 Benjamin Larsson + * 2011 Xiang Wang + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/avassert.h" +#include "libavutil/audioconvert.h" +#include "avcodec.h" +#include "get_bits.h" +#include "put_bits.h" +#include "dcaenc.h" +#include "dcadata.h" + +#undef NDEBUG + +#define MAX_CHANNELS 6 +#define DCA_SUBBANDS_32 32 +#define DCA_MAX_FRAME_SIZE 16383 +#define DCA_HEADER_SIZE 13 + +#define DCA_SUBBANDS 32 ///< Subband activity count +#define QUANTIZER_BITS 16 +#define SUBFRAMES 1 +#define SUBSUBFRAMES 4 +#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8) +#define LFE_BITS 8 +#define LFE_INTERPOLATION 64 +#define LFE_PRESENT 2 +#define LFE_MISSING 0 + +static const int8_t dca_lfe_index[] = { +1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 +}; + +static const int8_t dca_channel_reorder_lfe[][9] = { +{ 0, -1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, 2, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, 3, -1, -1, -1, -1}, +{ 0, 1, -1, 2, 3, -1, -1, -1, -1}, +{ 1, 2, 0, -1, 3, 4, -1, -1, -1}, +{ 2, 3, -1, 0, 1, 4, 5, -1, -1}, +
Re: [libav-devel] [PATCH] Experimental DCA encoder
"Ronald S. Bultje" writes: > Hi, > > 2011/4/7 Benjamin Larsson : >> +static inline int32_t mul32(int32_t a, int32_t b) >> +{ >> +/* on >=i686, gcc compiles this into a single "imull" instruction */ >> +int64_t r = (int64_t)a * b; >> +/* round the result before truncating - improves accuracy */ >> +return (r + 0x8000) >> 32; >> +} > > I believe this is what the MUL64() macro is for, then it works on > non-x86 archs also, but that doesn't round... ARM has a rounding version of that instruction FWIW. -- Måns Rullgård m...@mansr.com ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH] Experimental DCA encoder
On Fri, Apr 08, 2011 at 07:53:32AM -0400, Ronald S. Bultje wrote: > Hi, [...] > > Ah, that's what the fixme is for I guess. Sounds ok to me then. > (Didn't Mans just implement fixed-point FFT or something like that? Or > was that "just" MDCT?) MDCT is often implemented via FFT. P.S. And if somebody gets crazy idea of implementing DTS-MA he should implement bitexact fixedpoint DCT32 they use inside QMF (and which is not given in DTS specs IIRC). ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH] Experimental DCA encoder
Hi, On Fri, Apr 8, 2011 at 5:02 AM, Benjamin Larsson wrote: > On 04/08/2011 03:58 AM, Ronald S. Bultje wrote: >> 2011/4/7 Benjamin Larsson : >>> +static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32], >>> int channel) >>> +{ >>> + int band, i, j, k; >>> + int32_t resp; >>> + int32_t accum[DCA_SUBBANDS_32]; >>> + >>> + add_new_samples(c, in, DCA_SUBBANDS_32, channel); >>> + >>> + /* Calculate the dot product of the signal with the (possibly inverted) >>> + reference decoder's response to this vector: >>> + (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0) >>> + so that -1.0 cancels 1.0 from the previous step */ >>> + >>> + memset(accum,0,sizeof(accum)); >>> + >>> + for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++) >>> + accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += >>> mul32(c->history[channel][i], UnQMF[j]); >>> + for (i = 0; i < c->start[channel]; k++, j++, i++) >>> + accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += >>> mul32(c->history[channel][i], UnQMF[j]); >>> + >>> + resp = 0; >>> + /* TODO: implement FFT instead of this naive calculation */ >>> + for (band = 0; band < DCA_SUBBANDS_32; band++) { >>> + for (j = 0; j < 32; j++) >>> + resp += mul32(accum[j], band_delta_factor(band, j)); >>> + >>> + out[band] = (band & 2) ? (-resp) : resp; >>> + } >>> +} >> >> I'll probably sound very naive, but what does this piece of the code do? > > Decomposes the signal into bands. Time domain -> frequency domain. Ah, that's what the fixme is for I guess. Sounds ok to me then. (Didn't Mans just implement fixed-point FFT or something like that? Or was that "just" MDCT?) Ronald ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH] Experimental DCA encoder
On Fri, Apr 08, 2011 at 01:41:37AM +0200, Benjamin Larsson wrote: > [...] Please make sure this compiles with --disable-everything --enable-encoder=dca. Diego ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH] Experimental DCA encoder
On Fri, Apr 08, 2011 at 01:41:37AM +0200, Benjamin Larsson wrote: > > --- > libavcodec/Makefile|1 + > libavcodec/allcodecs.c |2 +- > libavcodec/dcaenc.c| 581 > > libavcodec/dcaenc.h| 544 + > 4 files changed, 1127 insertions(+), 1 deletions(-) changelog, docs update, minor bump > --- /dev/null > +++ b/libavcodec/dcaenc.c > @@ -0,0 +1,581 @@ > +/* > + * DCA encoder > + * Copyright (C) 2008 Alexander E. Patrakov > + * 2010 Benjamin Larsson > + * 2011 Xiang Wang > + * This file is part of Libav. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg 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 > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA That still contains some FFmpeg references, please fix. > +static void add_new_samples(DCAContext *c, const int32_t *in, int count, int > channel){ { on next line, long line > +static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32], > int channel) long line > +int band, i, j, k; > +int32_t resp; > +int32_t accum[DCA_SUBBANDS_32]; > + > +memset(accum,0,sizeof(accum)); Just initialize to 0 > +static int32_t lfe_fir_64i[512]; > +static int lfe_downsample(DCAContext *c, int32_t in[LFE_INTERPOLATION]){ { on next line > +static void init_lfe_fir(void){ ditto > +static int initialized; > +int i; > +if(initialized) if ( > +for(i=0; i<512; i++) for ( .. and please give those operators some room to breathe .. > +static void put_primary_audio_header(DCAContext *c) > +{ > +/* From dca.c */ > +static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; > +static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; That comment makes me suspicious - are these duplicated? > +/* Subband activity count */ > +for (ch=0; chprim_channels; ch++) { > + > +/* High frequency VQ start subband */ > +for (ch=0; chprim_channels; ch++) { > + > +/* Joint intensity coding index: 0, 0 */ > +for (ch=0; chprim_channels; ch++) { > + > +/* Transient mode codebook: A4, A4 (arbitrary) */ > +for (ch=0; chprim_channels; ch++) { > + > +/* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each > channel) */ > +for (ch=0; chprim_channels; ch++) { > + > +/* Bit allocation quantizer select: linear 5-bit */ > +for (ch=0; chprim_channels; ch++) { > + > +/* Quantization index codebook select: dummy data > + to avoid transmission of scale factor adjustment */ > +for (i=1; i<11; i++) { > +for (ch=0; chprim_channels; ch++) { .. more operators in need of elbow room .. :) There are more instances below, same for 'if(' and 'for(', { on the wrong line and excessively long lines that could be shortened easily. Fixing would be appreciated. You could also drop (or not) some {} around if/for blocks. > +/** > + * 8-23 bits quantization > + * @param sample > + * @param bits > + */ > +static inline uint32_t quantize(int32_t sample, int bits) These Doxygen parameter comments are pretty useless. > +switch(avctx->channel_layout) { > + case AV_CH_LAYOUT_STEREO: c->a_mode = 2; c->num_channel = 2; break; switch ( > + case AV_CH_LAYOUT_5POINT0: c->a_mode = 9; c->num_channel = 9; break; > + case AV_CH_LAYOUT_5POINT1: c->a_mode = 9; c->num_channel = 9; break; > + case AV_CH_LAYOUT_5POINT0_BACK: c->a_mode = 9; c->num_channel = 9; > break; > + case AV_CH_LAYOUT_5POINT1_BACK: c->a_mode = 9; c->num_channel = 9; > break; > + default: > +av_log(avctx, AV_LOG_ERROR, "Only stereo, 5.1, 5.0, 5.0back and > 5.0front channel layouts supported at the moment!\n"); > +return AVERROR_PATCHWELCOME; > +} Indent the case statements at the same depth as the switch and fix that instance of 2-space indentation. > +AVCodec ff_dca_encoder = { > +.name = "dca", > +.type = CODEC_TYPE_AUDIO, > +.id = CODEC_ID_DTS, > +.priv_data_size = sizeof(DCAContext), > +.init = DCA_encode_init, > +.encode = DCA_encode_frame, > +.capabilities = CODEC_CAP_EXPERIMENTAL, > +.sample_fmts = (const enum > AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, > +NULL, > +NULL, > +}; pointless trailing NULLs, long_name missing > --- /dev/null > +++ b
Re: [libav-devel] [PATCH] Experimental DCA encoder
On 04/08/2011 03:58 AM, Ronald S. Bultje wrote: > Hi, > > 2011/4/7 Benjamin Larsson : >> +static inline int32_t mul32(int32_t a, int32_t b) >> +{ >> +/* on >=i686, gcc compiles this into a single "imull" instruction */ >> +int64_t r = (int64_t)a * b; >> +/* round the result before truncating - improves accuracy */ >> +return (r + 0x8000) >> 32; >> +} > I believe this is what the MUL64() macro is for, then it works on > non-x86 archs also, but that doesn't round... Ok >> +static int32_t cos_table[128]; > [..] >> +static void qmf_init(void) > There should probably be a static inited = 0; that you set after > succesful init, since this function only has to run once, not every > time the codec re-inits. Ok >> +int i; >> +int32_t c[17], s[17]; >> +s[0] = 0; /* sin(index * PI / 64) * 0x7fff */ >> +c[0] = 0x7fff; /* cos(index * PI / 64) * 0x7fff */ >> + >> +for (i = 1; i <= 16; i++) { >> +s[i] = 2 * (mul32(c[i-1], 105372028) + mul32(s[i-1], 2144896908)); >> +c[i] = 2 * (mul32(c[i-1], 2144896908) - mul32(s[i-1], 105372028)); >> +} >> + >> +for (i = 0; i < 16; i++) { >> +cos_table[i] = c[i] >> 3; /* so that the output doesn't overflow */ >> +cos_table[i+16] = s[16-i] >> 3; >> +cos_table[i+32] = -s[i] >> 3; >> +cos_table[i+48] = -c[16-i] >> 3; >> +cos_table[i+64] = -c[i] >> 3; >> +cos_table[i+80] = -s[16-i] >> 3; >> +cos_table[i+96] = s[i] >> 3;ut >> +cos_table[i+112] = c[16-i] >> 3; >> +} > For the cos-table, can you use libavcodec/sinewin.h functions? If not, > does this look like a proper int-implementation of the same thing that > we might want to share? E.g. does acenc_fixed.c have fixed-point cos > table generation also? > > (I know, this is minor, ignore for now, not critical.) The costable is custom. And there is a float based transform in the decoder already. >> +static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32], >> int channel) >> +{ >> +int band, i, j, k; >> +int32_t resp; >> +int32_t accum[DCA_SUBBANDS_32]; >> + >> +add_new_samples(c, in, DCA_SUBBANDS_32, channel); >> + >> +/* Calculate the dot product of the signal with the (possibly inverted) >> + reference decoder's response to this vector: >> + (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0) >> + so that -1.0 cancels 1.0 from the previous step */ >> + >> +memset(accum,0,sizeof(accum)); >> + >> +for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++) >> +accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += >> mul32(c->history[channel][i], UnQMF[j]); >> +for (i = 0; i < c->start[channel]; k++, j++, i++) >> +accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += >> mul32(c->history[channel][i], UnQMF[j]); >> + >> +resp = 0; >> +/* TODO: implement FFT instead of this naive calculation */ >> +for (band = 0; band < DCA_SUBBANDS_32; band++) { >> +for (j = 0; j < 32; j++) >> +resp += mul32(accum[j], band_delta_factor(band, j)); >> + >> +out[band] = (band & 2) ? (-resp) : resp; >> +} >> +} > I'll probably sound very naive, but what does this piece of the code do? Decomposes the signal into bands. Time domain -> frequency domain. >> +static void init_lfe_fir(void){ >> +static int initialized; >> +int i; >> +if(initialized) >> +return; >> +for(i=0; i<512; i++) >> +lfe_fir_64i[i] = lfe_fir_64[i] * (1<<25); //float -> int32_t >> +initialized = 1; >> +} > This kind of stuff, along with cos tables, FFT etc, raises the > question why this wasn't implemented in float... Realistically, if > !CONFIG_SMALL, the table should be hardcoded. Don't really know but I'd like to keep the fixed-point code path for reg test purposes. > The bitstream stuff I didn't review because I'm not very familiar with it... > >> +static int DCA_encode_init(AVCodecContext *avctx) { > [..] >> +for(i=0; i<16; i++){ >> +if(dca_sample_rates[i] == avctx->sample_rate) >> +break; >> +} >> +if(i==16){ >> +av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported\n", >> avctx->sample_rate); >> +return -1; >> +} >> +c->sample_rate_code = i; > That is pretty unhelpful. What samplerates _are_ supported? Better > yet, how would the user accomplish the resampling within ffmpeg? It's the same as with every other libav encoder. But I guess it could print all the 16 supported sample rates. >> diff --git a/libavcodec/dcaenc.h b/libavcodec/dcaenc.h > [..] >> +/* This is a scaled version of the response of the reference decoder to >> + this vector of subband samples: ( 1.0 0.0 0.0 ... 0.0 ) >> + */ >> + >> +static const int32_t UnQMF[512] = { > ??? What is that? The decomposition filter. > Ronald MvH Benjamin Larsson ___ libav-devel mailing list libav-devel@libav.org https:
Re: [libav-devel] [PATCH] Experimental DCA encoder
Hi, 2011/4/7 Benjamin Larsson : > +static inline int32_t mul32(int32_t a, int32_t b) > +{ > +/* on >=i686, gcc compiles this into a single "imull" instruction */ > +int64_t r = (int64_t)a * b; > +/* round the result before truncating - improves accuracy */ > +return (r + 0x8000) >> 32; > +} I believe this is what the MUL64() macro is for, then it works on non-x86 archs also, but that doesn't round... > +static int32_t cos_table[128]; [..] > +static void qmf_init(void) There should probably be a static inited = 0; that you set after succesful init, since this function only has to run once, not every time the codec re-inits. > +int i; > +int32_t c[17], s[17]; > +s[0] = 0; /* sin(index * PI / 64) * 0x7fff */ > +c[0] = 0x7fff; /* cos(index * PI / 64) * 0x7fff */ > + > +for (i = 1; i <= 16; i++) { > +s[i] = 2 * (mul32(c[i-1], 105372028) + mul32(s[i-1], 2144896908)); > +c[i] = 2 * (mul32(c[i-1], 2144896908) - mul32(s[i-1], 105372028)); > +} > + > +for (i = 0; i < 16; i++) { > +cos_table[i] = c[i] >> 3; /* so that the output doesn't overflow */ > +cos_table[i+16] = s[16-i] >> 3; > +cos_table[i+32] = -s[i] >> 3; > +cos_table[i+48] = -c[16-i] >> 3; > +cos_table[i+64] = -c[i] >> 3; > +cos_table[i+80] = -s[16-i] >> 3; > +cos_table[i+96] = s[i] >> 3; > +cos_table[i+112] = c[16-i] >> 3; > +} For the cos-table, can you use libavcodec/sinewin.h functions? If not, does this look like a proper int-implementation of the same thing that we might want to share? E.g. does acenc_fixed.c have fixed-point cos table generation also? (I know, this is minor, ignore for now, not critical.) > +static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32], > int channel) > +{ > +int band, i, j, k; > +int32_t resp; > +int32_t accum[DCA_SUBBANDS_32]; > + > +add_new_samples(c, in, DCA_SUBBANDS_32, channel); > + > +/* Calculate the dot product of the signal with the (possibly inverted) > + reference decoder's response to this vector: > + (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0) > + so that -1.0 cancels 1.0 from the previous step */ > + > +memset(accum,0,sizeof(accum)); > + > +for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++) > +accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += > mul32(c->history[channel][i], UnQMF[j]); > +for (i = 0; i < c->start[channel]; k++, j++, i++) > +accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += > mul32(c->history[channel][i], UnQMF[j]); > + > +resp = 0; > +/* TODO: implement FFT instead of this naive calculation */ > +for (band = 0; band < DCA_SUBBANDS_32; band++) { > +for (j = 0; j < 32; j++) > +resp += mul32(accum[j], band_delta_factor(band, j)); > + > +out[band] = (band & 2) ? (-resp) : resp; > +} > +} I'll probably sound very naive, but what does this piece of the code do? > +static void init_lfe_fir(void){ > +static int initialized; > +int i; > +if(initialized) > +return; > +for(i=0; i<512; i++) > +lfe_fir_64i[i] = lfe_fir_64[i] * (1<<25); //float -> int32_t > +initialized = 1; > +} This kind of stuff, along with cos tables, FFT etc, raises the question why this wasn't implemented in float... Realistically, if !CONFIG_SMALL, the table should be hardcoded. The bitstream stuff I didn't review because I'm not very familiar with it... > +static int DCA_encode_init(AVCodecContext *avctx) { [..] > +for(i=0; i<16; i++){ > +if(dca_sample_rates[i] == avctx->sample_rate) > +break; > +} > +if(i==16){ > +av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported\n", > avctx->sample_rate); > +return -1; > +} > +c->sample_rate_code = i; That is pretty unhelpful. What samplerates _are_ supported? Better yet, how would the user accomplish the resampling within ffmpeg? > diff --git a/libavcodec/dcaenc.h b/libavcodec/dcaenc.h [..] > +/* This is a scaled version of the response of the reference decoder to > + this vector of subband samples: ( 1.0 0.0 0.0 ... 0.0 ) > + */ > + > +static const int32_t UnQMF[512] = { ??? What is that? Ronald ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH] Experimental DCA encoder
MvH Benjamin Larsson >From 72e6371e0c98e344275173452cec98940a33ef39 Mon Sep 17 00:00:00 2001 From: Alexander E. Patrakov Date: Fri, 8 Apr 2011 01:33:21 +0200 Subject: [PATCH] Experimental DCA encoder --- libavcodec/Makefile|1 + libavcodec/allcodecs.c |2 +- libavcodec/dcaenc.c| 581 libavcodec/dcaenc.h| 544 + 4 files changed, 1127 insertions(+), 1 deletions(-) create mode 100644 libavcodec/dcaenc.c create mode 100644 libavcodec/dcaenc.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 837f7e2..195469d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -104,6 +104,7 @@ OBJS-$(CONFIG_COOK_DECODER)+= cook.o OBJS-$(CONFIG_CSCD_DECODER)+= cscd.o OBJS-$(CONFIG_CYUV_DECODER)+= cyuv.o OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o +OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o OBJS-$(CONFIG_DFA_DECODER) += dfa.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 7636392..9530358 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -238,7 +238,7 @@ void avcodec_register_all(void) REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); REGISTER_DECODER (COOK, cook); -REGISTER_DECODER (DCA, dca); +REGISTER_ENCDEC (DCA, dca); REGISTER_DECODER (DSICINAUDIO, dsicinaudio); REGISTER_DECODER (EAC3, eac3); REGISTER_ENCDEC (FLAC, flac); diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c new file mode 100644 index 000..0362485 --- /dev/null +++ b/libavcodec/dcaenc.c @@ -0,0 +1,581 @@ +/* + * DCA encoder + * Copyright (C) 2008 Alexander E. Patrakov + * 2010 Benjamin Larsson + * 2011 Xiang Wang + * This file is part of Libav. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/avassert.h" +#include "libavutil/audioconvert.h" +#include "avcodec.h" +#include "get_bits.h" +#include "put_bits.h" +#include "dcaenc.h" +#include "dcadata.h" + +#undef NDEBUG + +#define MAX_CHANNELS 6 +#define DCA_SUBBANDS_32 32 +#define DCA_MAX_FRAME_SIZE 16383 +#define DCA_HEADER_SIZE 13 + +#define DCA_SUBBANDS 32 ///< Subband activity count +#define QUANTIZER_BITS 16 +#define SUBFRAMES 1 +#define SUBSUBFRAMES 4 +#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8) +#define LFE_BITS 8 +#define LFE_INTERPOLATION 64 +#define LFE_PRESENT 2 +#define LFE_MISSING 0 + +static const int8_t dca_lfe_index[] = { +1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 +}; + +static const int8_t dca_channel_reorder_lfe[][9] = { +{ 0, -1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, 2, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, 3, -1, -1, -1, -1}, +{ 0, 1, -1, 2, 3, -1, -1, -1, -1}, +{ 1, 2, 0, -1, 3, 4, -1, -1, -1}, +{ 2, 3, -1, 0, 1, 4, 5, -1, -1}, +{ 1, 2, 0, -1, 3, 4, 5, -1, -1}, +{ 0, -1, 4, 5, 2, 3, 1, -1, -1}, +{ 3, 4, 1, -1, 0, 2, 5, 6, -1}, +{ 2, 3, -1, 5, 7, 0, 1, 4, 6}, +{ 3, 4, 1, -1, 0, 2, 5, 7, 6}, +}; + +static const int8_t dca_channel_reorder_nolfe[][9] = { +{ 0, -1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 0, 1, -1, -1, -1, -1, -1, -1, -1}, +{ 1, 2, 0, -1, -1, -1, -1, -1, -1}, +{ 0, 1, 2, -1, -1, -1, -1, -1, -1}, +{ 1, 2, 0, 3, -1, -1, -1, -1, -1}, +{ 0, 1, 2, 3, -1, -1, -1, -1, -1}, +{ 1, 2, 0, 3, 4, -1, -1, -1, -1}, +{ 2, 3, 0, 1, 4, 5, -1, -1, -1}, +{ 1, 2, 0, 3, 4, 5, -1, -1, -1}, +{ 0, 4, 5, 2, 3, 1, -1, -1, -1}, +{ 3, 4, 1, 0, 2, 5, 6, -1, -1}, +{ 2, 3, 5, 7, 0, 1, 4, 6, -1}, +{ 3, 4, 1, 0, 2, 5, 7, 6, -1}, +}; + +type