├── m4 ├── .keep └── pkg.m4 ├── dcaenc.sym ├── AUTHORS ├── NEWS ├── dcaenc.pc.in ├── .gitignore ├── TODO ├── softfloat.h ├── Makefile.am ├── wavfile.h ├── configure.ac ├── math_tables.h ├── dcaenc.h ├── dcaenc_private.h ├── main.c ├── BUGS ├── dca.conf ├── wavfile.c ├── gentables.c ├── int_data.h ├── alsaplugin.c ├── INSTALL ├── README ├── COPYING ├── dcaenc.c └── float_data.h /m4/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dcaenc.sym: -------------------------------------------------------------------------------- 1 | dcaenc_channel_config_to_count 2 | dcaenc_create 3 | dcaenc_input_size 4 | dcaenc_output_size 5 | dcaenc_convert_s32 6 | dcaenc_destroy 7 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Main author: Alexander E. Patrakov 2 | 3 | Other people who contributed at least one line of code: 4 | 5 | Charles Hannum 6 | Colin Guthrie 7 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | dcaenc-2: 2012-01-28 2 | * Minor cleanups 3 | * Support for 5.0 channel encoding 4 | * Fixed infinite loop on too-high bitrates 5 | * Fixed buffer overflow on attempts to encode a 7.1 file 6 | 7 | dcaenc-1: 2011-09-17 8 | * Initial release. 9 | -------------------------------------------------------------------------------- /dcaenc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: dcaenc 7 | Description: dcaenc is an encoder for DTS Coherent Acoustics audio format 8 | Version: @VERSION@ 9 | Requires: 10 | Conflicts: 11 | Libs: -L${libdir} -ldcaenc 12 | Cflags: -I${includedir} 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | m4/*.m4 4 | *.la 5 | *.lo 6 | *.o 7 | .libs/ 8 | .deps/ 9 | autom4te.cache/ 10 | math_tables.c 11 | dcaenc 12 | gentables 13 | Makefile 14 | Makefile.in 15 | dcaenc.pc 16 | aclocal.m4 17 | config.guess 18 | config.h 19 | config.h.in 20 | config.log 21 | config.status 22 | config.sub 23 | configure 24 | *.tar.gz 25 | depcomp 26 | install-sh 27 | libtool 28 | *.wav 29 | *.dts 30 | ltmain.sh 31 | missing 32 | stamp-h1 33 | compile 34 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | The items below are not sorted in any order. 2 | 3 | * Fix bugs. 4 | * Use the standard getopt() interface for parsing command-line options. 5 | Add options for all DCAENC_FLAG_* defines. 6 | * Convert the encoder from fixed point back to floating point. This will 7 | simplify the code. 8 | * Convert the ALSA plugin from extplug to ioplug. This will fix the bug with 9 | incorrect reporting of the supported sample rates. 10 | * Implement the ADPCM part of the DTS specification. This will improve sound 11 | quality. 12 | * Add helper programs for use of the encoder with JACK or OSS4. 13 | -------------------------------------------------------------------------------- /softfloat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef SOFTFLOAT_H 22 | #define SOFTFLOAT_H 23 | 24 | typedef struct { 25 | int32_t m; 26 | int32_t e; 27 | } softfloat; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | AUTOMAKE_OPTIONS=foreign 4 | EXTRA_DIST = dcaenc.sym dca.conf 5 | 6 | pkgconfigdir = $(libdir)/pkgconfig 7 | pkgconfig_DATA = dcaenc.pc 8 | 9 | bin_PROGRAMS = dcaenc 10 | noinst_PROGRAMS = gentables 11 | lib_LTLIBRARIES = libdcaenc.la 12 | 13 | include_HEADERS = dcaenc.h 14 | libdcaenc_la_SOURCES = dcaenc.c \ 15 | dcaenc_private.h int_data.h math_tables.h softfloat.h 16 | nodist_libdcaenc_la_SOURCES = math_tables.c 17 | libdcaenc_la_LDFLAGS = -version-info 0:0:0 \ 18 | -export-symbols $(top_srcdir)/dcaenc.sym 19 | 20 | if HAVE_ALSA 21 | plugin_LTLIBRARIES = libasound_module_pcm_dca.la 22 | plugindir = $(libdir)/alsa-lib 23 | 24 | libasound_module_pcm_dca_la_SOURCES = alsaplugin.c dcaenc.h 25 | libasound_module_pcm_dca_la_LIBADD = libdcaenc.la @ALSA_LIBS@ 26 | libasound_module_pcm_dca_la_LDFLAGS = -no-undefined -avoid-version 27 | 28 | alsaconfdir = $(datadir)/alsa/pcm 29 | alsaconf_DATA = dca.conf 30 | endif 31 | 32 | dcaenc_SOURCES = main.c wavfile.c dcaenc.h wavfile.h 33 | dcaenc_LDADD = libdcaenc.la 34 | 35 | gentables_SOURCES = gentables.c \ 36 | int_data.h float_data.h softfloat.h 37 | 38 | gentables_LDADD = @LIBM@ 39 | 40 | CLEANFILES = math_tables.c 41 | math_tables.c: Makefile gentables$(EXEEXT) 42 | ./gentables$(EXEEXT) >$@ 43 | -------------------------------------------------------------------------------- /wavfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef WAVFILE_H 22 | #define WAVFILE_H 23 | 24 | #include 25 | 26 | typedef struct { 27 | FILE * file; 28 | unsigned int channels; 29 | unsigned int bits_per_sample; 30 | unsigned int sample_rate; 31 | unsigned int samples_left; 32 | } wavfile; 33 | 34 | wavfile * wavfile_open(const char * filename); 35 | int wavfile_read_s32(wavfile * f, int32_t * samples); 36 | void wavfile_close(wavfile * f); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.65]) 5 | AC_INIT([dcaenc],[2],[patrakov@gmail.com],,[http://aepatrakov.narod.ru/dcaenc/]) 6 | AC_CONFIG_SRCDIR([dcaenc.c]) 7 | AC_CONFIG_HEADERS([config.h]) 8 | 9 | AC_CONFIG_MACRO_DIR([m4]) 10 | 11 | AM_INIT_AUTOMAKE([foreign check-news]) 12 | LT_INIT([disable-static]) 13 | 14 | # Checks for programs. 15 | AC_PROG_CC 16 | PKG_PROG_PKG_CONFIG 17 | 18 | # Checks for libraries. 19 | AC_ARG_ENABLE([alsa], 20 | AS_HELP_STRING([--disable-alsa], [disable building of ALSA plugin])) 21 | 22 | ac_save_LIBS="$LIBS" 23 | 24 | if test "x$enable_alsa" != "xno"; then 25 | PKG_CHECK_MODULES([ALSA], [alsa >= 1.0.11], [HAVE_ALSA=yes], [HAVE_ALSA=no]) 26 | AC_CHECK_LIB(asound, snd_pcm_extplug_create,, 27 | [HAVE_ALSA=no], -ldl) 28 | if test "x$enable_alsa" = "xyes" -a "x$HAVE_ALSA" = "xno"; then 29 | AC_MSG_ERROR([ALSA libraries not found]) 30 | fi 31 | fi 32 | AM_CONDITIONAL(HAVE_ALSA, test "x$enable_alsa" != "xno" -a "x$HAVE_ALSA" = "xyes") 33 | LIBS="$ac_save_LIBS" 34 | 35 | # Checks for header files. 36 | AC_HEADER_STDC 37 | 38 | # Checks for typedefs, structures, and compiler characteristics. 39 | AC_C_INLINE 40 | AC_TYPE_INT32_T 41 | AC_TYPE_INT64_T 42 | AC_TYPE_SIZE_T 43 | AC_TYPE_UINT32_T 44 | AC_TYPE_UINT8_T 45 | 46 | # Checks for library functions. 47 | ac_save_LIBS="$LIBS" 48 | LT_LIB_M 49 | LIBS="$ac_save_LIBS" 50 | 51 | AC_CONFIG_FILES([Makefile dcaenc.pc]) 52 | AC_OUTPUT 53 | -------------------------------------------------------------------------------- /math_tables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef MATH_TABLES_H 22 | #define MATH_TABLES_H 23 | 24 | #include 25 | 26 | #define AUBANDS 25 27 | 28 | extern const int32_t lfe_fir[512]; 29 | extern const int32_t band_interpolation[2][512]; 30 | extern const int32_t band_spectrum[2][8]; 31 | 32 | extern const int32_t cos_table[2048]; 33 | extern const int bitrev[256]; 34 | extern const int32_t auf[9][AUBANDS][256]; 35 | extern const int32_t cb_to_level[2048]; 36 | extern const int32_t cb_to_add[256]; 37 | 38 | extern const int quant_levels_cb[27]; 39 | 40 | static inline int32_t cos_t(int x) 41 | { 42 | return cos_table[x & 2047]; 43 | } 44 | 45 | static inline int32_t sin_t(int x) 46 | { 47 | return cos_t(x - 512); 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /dcaenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef DCAENC_H 22 | #define DCAENC_H 23 | 24 | #include 25 | 26 | typedef struct dcaenc_context_s *dcaenc_context; 27 | 28 | #define DCAENC_FLAG_28BIT 1 29 | #define DCAENC_FLAG_BIGENDIAN 2 30 | #define DCAENC_FLAG_LFE 4 31 | #define DCAENC_FLAG_PERFECT_QMF 8 32 | #define DCAENC_FLAG_IEC_WRAP 16 33 | 34 | #define DCAENC_CHANNELS_MONO 0 35 | #define DCAENC_CHANNELS_DUAL_MONO 1 36 | #define DCAENC_CHANNELS_STEREO 2 37 | #define DCAENC_CHANNELS_STEREO_SUMDIFF 3 38 | #define DCAENC_CHANNELS_STEREO_TOTAL 4 39 | #define DCAENC_CHANNELS_3FRONT 5 40 | #define DCAENC_CHANNELS_2FRONT_1REAR 6 41 | #define DCAENC_CHANNELS_3FRONT_1REAR 7 42 | #define DCAENC_CHANNELS_2FRONT_2REAR 8 43 | #define DCAENC_CHANNELS_3FRONT_2REAR 9 44 | #define DCAENC_CHANNELS_4FRONT_2REAR 10 45 | #define DCAENC_CHANNELS_3FRONT_2REAR_1OV 11 46 | #define DCAENC_CHANNELS_3FRONT_3REAR 12 47 | #define DCAENC_CHANNELS_5FRONT_2REAR 13 48 | #define DCAENC_CHANNELS_4FRONT_4REAR 14 49 | #define DCAENC_CHANNELS_5FRONT_3REAR 15 50 | 51 | int dcaenc_channel_config_to_count(int channel_config); 52 | 53 | dcaenc_context dcaenc_create(int sample_rate, int channel_config, int approx_bitrate, int flags); 54 | int dcaenc_bitrate(dcaenc_context c); 55 | int dcaenc_input_size(dcaenc_context c); 56 | int dcaenc_output_size(dcaenc_context c); 57 | int dcaenc_convert_s32(dcaenc_context c, const int32_t *input, uint8_t *output); 58 | int dcaenc_destroy(dcaenc_context c, uint8_t *output); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /dcaenc_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef DCAENC_PRIVATE_H 22 | #define DCAENC_PRIVATE_H 23 | 24 | #include 25 | #include "softfloat.h" 26 | #define DCAENC_MAX_CHANNELS 6 27 | 28 | /* The standard allows up to 4 subsubframes per subframe, 29 | * but more than 2 don't fit in MPEG program stream at 1536 kbps 30 | */ 31 | #define DCAENC_SUBSUBFRAMES 2 32 | #define DCAENC_LFE_SAMPLES 8 33 | #define DCAENC_SUBBAND_SAMPLES 16 34 | 35 | struct dcaenc_context_s { 36 | int samplerate_index; 37 | int channel_config; 38 | int channels; 39 | int fullband_channels; 40 | int flags; 41 | int bitrate_index; 42 | int frame_bits; 43 | const int32_t *band_interpolation; 44 | const int32_t *band_spectrum; 45 | int32_t pcm_history[512][DCAENC_MAX_CHANNELS]; 46 | /* int32_t subband_history[???][???][DCAENC_MAX_CHANNELS]; */ 47 | 48 | /* usage: subband_samples[sample][band][channel], peak[band][channel] */ 49 | int32_t subband_samples[DCAENC_SUBBAND_SAMPLES][32][DCAENC_MAX_CHANNELS]; 50 | int32_t quantized_samples[DCAENC_SUBBAND_SAMPLES][32][DCAENC_MAX_CHANNELS]; 51 | int32_t peak_cb[32][DCAENC_MAX_CHANNELS]; 52 | 53 | int32_t downsampled_lfe[DCAENC_LFE_SAMPLES]; 54 | int32_t lfe_peak_cb; 55 | 56 | int32_t masking_curve_cb[DCAENC_SUBSUBFRAMES][256]; 57 | int abits[32][DCAENC_MAX_CHANNELS]; 58 | int nscale[32][DCAENC_MAX_CHANNELS]; 59 | softfloat quant[32][DCAENC_MAX_CHANNELS]; 60 | int lfe_nscale; 61 | softfloat lfe_quant; 62 | 63 | int32_t eff_masking_curve_cb[256]; 64 | int32_t band_masking_cb[32]; 65 | int32_t worst_quantization_noise; 66 | int32_t worst_noise_ever; 67 | int consumed_bits; 68 | 69 | uint32_t word; 70 | int wbits; 71 | uint8_t *output; 72 | int wrote; 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "config.h" 25 | #include "dcaenc.h" 26 | #include "wavfile.h" 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | dcaenc_context c; 31 | int32_t data[512 * 6]; 32 | uint8_t output[16384]; 33 | wavfile * f; 34 | FILE * outfile; 35 | int bitrate; 36 | int wrote; 37 | int samples_total; 38 | 39 | static const int channel_map[6] = {DCAENC_CHANNELS_MONO, DCAENC_CHANNELS_STEREO, 0, 40 | DCAENC_CHANNELS_2FRONT_2REAR, DCAENC_CHANNELS_3FRONT_2REAR, DCAENC_CHANNELS_3FRONT_2REAR }; 41 | 42 | if (argc != 4) { 43 | if (argc == 2 && !strcmp(argv[1], "--version")) { 44 | fprintf(stderr, PACKAGE_NAME "-" PACKAGE_VERSION "\n"); 45 | fprintf(stderr, PACKAGE_URL "\n\n"); 46 | fprintf(stderr, "Copyrignt (c) 2008-2012 Alexander E. Patrakov \n"); 47 | fprintf(stderr, "License: GNU LGPL version 2.1 or later \n"); 48 | fprintf(stderr, "This is free software: you are free to change and redistribute it.\n"); 49 | fprintf(stderr, "There is NO WARRANTY, to the extent permitted by law.\n"); 50 | return 0; 51 | } else { 52 | fprintf(stderr, "Usage: dcaenc input.wav output.dts bits_per_second\n"); 53 | return 1; 54 | } 55 | } 56 | f = wavfile_open(argv[1]); 57 | if (!f) { 58 | printf("Could not open or parse %s\n", argv[1]); 59 | return 1; 60 | } 61 | bitrate = atoi(argv[3]); 62 | 63 | samples_total = f->samples_left; 64 | c = dcaenc_create(f->sample_rate, channel_map[f->channels - 1], bitrate, f->channels == 6 ? DCAENC_FLAG_LFE : 0); 65 | 66 | if (!c) { 67 | printf("Wrong bitrate or sample rate\n"); 68 | return 1; 69 | } 70 | outfile = fopen(argv[2], "wb"); 71 | if (!outfile) { 72 | printf("Could not open %s\n", argv[2]); 73 | return 1; 74 | } 75 | while (wavfile_read_s32(f, data)) { 76 | wrote = dcaenc_convert_s32(c, data, output); 77 | fwrite(output, 1, wrote, outfile); 78 | } 79 | wrote = dcaenc_destroy(c, output); 80 | fwrite(output, 1, wrote, outfile); 81 | fclose(outfile); 82 | wavfile_close(f); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | These bugs and limitations are known. Please don't report them again. Better, 2 | send a patch (not a git merge request!) to patrakov@gmail.com. 3 | 4 | * Low bitrates (such as 256 kbps for 48 kHz stereo files) are rejected. 5 | Fixing this would require adding support for less than 32 active subbands. 6 | 7 | * High bitrates (i.e. anything above 1536 kbps for 48 kHz files) are 8 | not rejected, even though the version 1.3.1 of the DTS specification 9 | disallows them for DTS Core streams. Such streams are valid according to 10 | earlier versions of this specification. Since there may be users depending 11 | on this functionality, this is scheduled to be dealt with at version 3. 12 | Depending on the user feedback, the functionality of encoding at 13 | higher-than-16bit-pcm-stereo bitrates will be either removed or hidden 14 | behind a dcaenc_create() flag. 15 | 16 | * The quality is not as high as it can be at a given bitrate. To fix this, 17 | one has to add ADPCM, channel coupling, vector quantization, transient 18 | detection and huffman coding. That's a lot of work, but at SPDIF bitrates 19 | nobody will notice the improvement. 20 | 21 | * More than 5.1 channels, or sample rates more than 48 kHz are not supported. 22 | To fix this, one has to implement the whole lot of new techniques described 23 | in the version 1.3.1 of the DTS specification. 24 | 25 | * The psychoacoustical model wants to remove all frequencies above 16 kHz if 26 | there is anything else in the incoming audio. The reason looks quite valid: 27 | there is no filter in the human ear model that responds to such frequencies. 28 | These frequencies are present in the output only at 3 levels per sample 29 | (even though the psychoacoustical model says they should be discarded 30 | completely), just because encoding with less than 32 active subbands is not 31 | implemented yet. However, the future addition of high sample rate support 32 | would require a psychoacoustical model that doesn't throw these frequencies 33 | out completely. 34 | 35 | * Command line syntax is not compatible with the one supported by Lord 36 | Mulder's fork. His changes related to the command line syntax have to be 37 | separated from the rest of changes, amended to not depend on floating point 38 | (and still allow 1411.2 kbps) and applied. 39 | 40 | * There are no command-line parameters to specify endianness of the resulting 41 | stream. See above. 42 | 43 | * Multichannel wav files are not parsed properly. E.g., the channel mask is 44 | not used at all, and floating-point files are mistaken for 32-bit ones. 45 | Someone just has to implement this. Using a library is not really an option, 46 | as neither sndfile nor audiofile libraries export the channel mask. 47 | 48 | * It can be argued that, due to the 4GB length limitation, multichannel wav 49 | files are not a suitable input format: at 5.1, this means the two-hour 50 | length limit with 16-bit samples, or just one hour with 32-bit samples. 51 | Under Windows, professional encoders are fed with 6 mono wav files, not 52 | with one 6-channel file. Again, someone has to implement this. 53 | 54 | * Attempts to open the ALSA plugin with incorrect sample rates are not 55 | rejected. This is because the "extplug" framework doesn't allow this. 56 | Either the functionality has to be added at the alsa-lib side, or this 57 | plugin needs to be rewritten using "ioplug" (even though this means a lot 58 | of boilerplate code). 59 | 60 | * ALSA plugin adds 512 more samples (10 ms) of latency than it should. 61 | Probably fixable by switching to ioplug. 62 | 63 | * Video player applications don't take the latency added by the ALSA plugin 64 | into account when synchronizing audio with video. ALSA bug (no way to export 65 | the required information), not fixable within dcaenc. Anyway, it's just 66 | 30 ms. 67 | 68 | -------------------------------------------------------------------------------- /dca.conf: -------------------------------------------------------------------------------- 1 | defaults.pcm.dca.aes0 0x06 2 | defaults.pcm.dca.aes1 0x82 3 | defaults.pcm.dca.aes2 0x00 4 | defaults.pcm.dca.aes3 0x00 5 | defaults.pcm.dca.iec61937 0 6 | 7 | pcm.!dca { 8 | @args [ CARD DEV AES0 AES1 AES2 AES3 IEC61937 ] 9 | 10 | @args.CARD { 11 | type string 12 | default { 13 | @func getenv 14 | vars [ 15 | ALSA_IEC958_CARD 16 | ALSA_PCM_CARD 17 | ALSA_CARD 18 | ] 19 | default { 20 | @func refer 21 | name defaults.pcm.iec958.card 22 | } 23 | } 24 | } 25 | 26 | @args.DEV { 27 | type integer 28 | default { 29 | @func igetenv 30 | vars [ 31 | ALSA_IEC958_DEVICE 32 | ] 33 | default { 34 | @func refer 35 | name defaults.pcm.iec958.device 36 | } 37 | } 38 | } 39 | 40 | @args.AES0 { 41 | type integer 42 | default { 43 | @func refer 44 | name defaults.pcm.dca.aes0 45 | } 46 | } 47 | 48 | @args.AES1 { 49 | type integer 50 | default { 51 | @func refer 52 | name defaults.pcm.dca.aes1 53 | } 54 | } 55 | 56 | @args.AES2 { 57 | type integer 58 | default { 59 | @func refer 60 | name defaults.pcm.dca.aes2 61 | } 62 | } 63 | 64 | @args.AES3 { 65 | type integer 66 | default { 67 | @func refer 68 | name defaults.pcm.dca.aes3 69 | } 70 | } 71 | 72 | @args.IEC61937 { 73 | type integer; 74 | default { 75 | @func refer 76 | name defaults.pcm.dca.iec61937 77 | } 78 | } 79 | 80 | type dca 81 | slave.pcm { 82 | @func refer 83 | name { 84 | @func concat 85 | strings [ 86 | "cards." 87 | { 88 | @func card_driver 89 | card $CARD 90 | } 91 | ".pcm.iec958." $DEV ":" 92 | "CARD=" $CARD "," 93 | "AES0=" $AES0 "," 94 | "AES1=" $AES1 "," 95 | "AES2=" $AES2 "," 96 | "AES3=" $AES3 97 | ] 98 | } 99 | } 100 | 101 | iec61937 $IEC61937 102 | 103 | hint { 104 | show { 105 | @func refer 106 | name defaults.namehint.basic 107 | } 108 | description "DTS Encoding through IEC958 (S/PDIF)" 109 | device $DEV 110 | } 111 | } 112 | 113 | pcm.!dcahdmi { 114 | @args [ CARD DEV AES0 AES1 AES2 AES3 ] 115 | 116 | @args.CARD { 117 | type string 118 | default { 119 | @func getenv 120 | vars [ 121 | ALSA_IEC958_CARD 122 | ALSA_PCM_CARD 123 | ALSA_CARD 124 | ] 125 | default { 126 | @func refer 127 | name defaults.pcm.iec958.card 128 | } 129 | } 130 | } 131 | 132 | @args.DEV { 133 | type integer 134 | default { 135 | @func igetenv 136 | vars [ 137 | ALSA_IEC958_DEVICE 138 | ] 139 | default { 140 | @func refer 141 | name defaults.pcm.iec958.device 142 | } 143 | } 144 | } 145 | 146 | @args.AES0 { 147 | type integer 148 | default { 149 | @func refer 150 | name defaults.pcm.dca.aes0 151 | } 152 | } 153 | 154 | @args.AES1 { 155 | type integer 156 | default { 157 | @func refer 158 | name defaults.pcm.dca.aes1 159 | } 160 | } 161 | 162 | @args.AES2 { 163 | type integer 164 | default { 165 | @func refer 166 | name defaults.pcm.dca.aes2 167 | } 168 | } 169 | 170 | @args.AES3 { 171 | type integer 172 | default { 173 | @func refer 174 | name defaults.pcm.dca.aes3 175 | } 176 | } 177 | 178 | @args.IEC61937 { 179 | type integer; 180 | default { 181 | @func refer 182 | name defaults.pcm.dca.iec61937 183 | } 184 | } 185 | 186 | type dca 187 | slave.pcm { 188 | @func refer 189 | name { 190 | @func concat 191 | strings [ 192 | "cards." 193 | { 194 | @func card_driver 195 | card $CARD 196 | } 197 | ".pcm.hdmi." $DEV ":" 198 | "CARD=" $CARD "," 199 | "AES0=" $AES0 "," 200 | "AES1=" $AES1 "," 201 | "AES2=" $AES2 "," 202 | "AES3=" $AES3 203 | ] 204 | } 205 | } 206 | 207 | iec61937 $IEC61937 208 | 209 | hint { 210 | show { 211 | @func refer 212 | name defaults.namehint.basic 213 | } 214 | description "DTS Encoding through HDMI" 215 | device $DEV 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /m4/pkg.m4: -------------------------------------------------------------------------------- 1 | # pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- 2 | # serial 1 (pkg-config-0.24) 3 | # 4 | # Copyright © 2004 Scott James Remnant . 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | # 20 | # As a special exception to the GNU General Public License, if you 21 | # distribute this file as part of a program that contains a 22 | # configuration script generated by Autoconf, you may include it under 23 | # the same distribution terms that you use for the rest of that program. 24 | 25 | # PKG_PROG_PKG_CONFIG([MIN-VERSION]) 26 | # ---------------------------------- 27 | AC_DEFUN([PKG_PROG_PKG_CONFIG], 28 | [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) 29 | m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) 30 | m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) 31 | AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) 32 | AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) 33 | AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) 34 | 35 | if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then 36 | AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) 37 | fi 38 | if test -n "$PKG_CONFIG"; then 39 | _pkg_min_version=m4_default([$1], [0.9.0]) 40 | AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) 41 | if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then 42 | AC_MSG_RESULT([yes]) 43 | else 44 | AC_MSG_RESULT([no]) 45 | PKG_CONFIG="" 46 | fi 47 | fi[]dnl 48 | ])# PKG_PROG_PKG_CONFIG 49 | 50 | # PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 51 | # 52 | # Check to see whether a particular set of modules exists. Similar 53 | # to PKG_CHECK_MODULES(), but does not set variables or print errors. 54 | # 55 | # Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 56 | # only at the first occurence in configure.ac, so if the first place 57 | # it's called might be skipped (such as if it is within an "if", you 58 | # have to call PKG_CHECK_EXISTS manually 59 | # -------------------------------------------------------------- 60 | AC_DEFUN([PKG_CHECK_EXISTS], 61 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 62 | if test -n "$PKG_CONFIG" && \ 63 | AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then 64 | m4_default([$2], [:]) 65 | m4_ifvaln([$3], [else 66 | $3])dnl 67 | fi]) 68 | 69 | # _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) 70 | # --------------------------------------------- 71 | m4_define([_PKG_CONFIG], 72 | [if test -n "$$1"; then 73 | pkg_cv_[]$1="$$1" 74 | elif test -n "$PKG_CONFIG"; then 75 | PKG_CHECK_EXISTS([$3], 76 | [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` 77 | test "x$?" != "x0" && pkg_failed=yes ], 78 | [pkg_failed=yes]) 79 | else 80 | pkg_failed=untried 81 | fi[]dnl 82 | ])# _PKG_CONFIG 83 | 84 | # _PKG_SHORT_ERRORS_SUPPORTED 85 | # ----------------------------- 86 | AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], 87 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 88 | if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then 89 | _pkg_short_errors_supported=yes 90 | else 91 | _pkg_short_errors_supported=no 92 | fi[]dnl 93 | ])# _PKG_SHORT_ERRORS_SUPPORTED 94 | 95 | 96 | # PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], 97 | # [ACTION-IF-NOT-FOUND]) 98 | # 99 | # 100 | # Note that if there is a possibility the first call to 101 | # PKG_CHECK_MODULES might not happen, you should be sure to include an 102 | # explicit call to PKG_PROG_PKG_CONFIG in your configure.ac 103 | # 104 | # 105 | # -------------------------------------------------------------- 106 | AC_DEFUN([PKG_CHECK_MODULES], 107 | [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 108 | AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl 109 | AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl 110 | 111 | pkg_failed=no 112 | AC_MSG_CHECKING([for $1]) 113 | 114 | _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) 115 | _PKG_CONFIG([$1][_LIBS], [libs], [$2]) 116 | 117 | m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS 118 | and $1[]_LIBS to avoid the need to call pkg-config. 119 | See the pkg-config man page for more details.]) 120 | 121 | if test $pkg_failed = yes; then 122 | AC_MSG_RESULT([no]) 123 | _PKG_SHORT_ERRORS_SUPPORTED 124 | if test $_pkg_short_errors_supported = yes; then 125 | $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` 126 | else 127 | $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` 128 | fi 129 | # Put the nasty error message in config.log where it belongs 130 | echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD 131 | 132 | m4_default([$4], [AC_MSG_ERROR( 133 | [Package requirements ($2) were not met: 134 | 135 | $$1_PKG_ERRORS 136 | 137 | Consider adjusting the PKG_CONFIG_PATH environment variable if you 138 | installed software in a non-standard prefix. 139 | 140 | _PKG_TEXT])[]dnl 141 | ]) 142 | elif test $pkg_failed = untried; then 143 | AC_MSG_RESULT([no]) 144 | m4_default([$4], [AC_MSG_FAILURE( 145 | [The pkg-config script could not be found or is too old. Make sure it 146 | is in your PATH or set the PKG_CONFIG environment variable to the full 147 | path to pkg-config. 148 | 149 | _PKG_TEXT 150 | 151 | To get pkg-config, see .])[]dnl 152 | ]) 153 | else 154 | $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS 155 | $1[]_LIBS=$pkg_cv_[]$1[]_LIBS 156 | AC_MSG_RESULT([yes]) 157 | $3 158 | fi[]dnl 159 | ])# PKG_CHECK_MODULES 160 | -------------------------------------------------------------------------------- /wavfile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "wavfile.h" 26 | 27 | static uint32_t find_chunk(FILE * file, const uint8_t chunk_id[4]) 28 | { 29 | uint8_t buffer[8]; 30 | while (1) { 31 | size_t chunksize; 32 | size_t s = fread(buffer, 1, 8, file); 33 | if (s < 8) 34 | return 0; 35 | chunksize = (uint32_t)buffer[4] | ((uint32_t)buffer[5] << 8) | 36 | ((uint32_t)buffer[6] << 16) | ((uint32_t)buffer[7] << 24); 37 | if (!memcmp(buffer, chunk_id, 4)) 38 | return chunksize; 39 | fseek(file, chunksize, SEEK_CUR); 40 | } 41 | } 42 | 43 | wavfile * wavfile_open(const char * filename) 44 | { 45 | wavfile *result; 46 | size_t s; 47 | uint8_t buffer[8]; 48 | uint8_t *fmt; 49 | uint32_t v; 50 | uint32_t avg_bps; 51 | uint32_t block_align; 52 | static const uint8_t riff[4] = {'R', 'I', 'F', 'F'}; 53 | static const uint8_t wave[4] = { 'W', 'A', 'V', 'E'}; 54 | static const uint8_t fmt_[4] = {'f', 'm', 't', ' '}; 55 | static const uint8_t data[4] = {'d', 'a', 't', 'a'}; 56 | 57 | result = (wavfile *)calloc(1, sizeof(wavfile)); 58 | if (!result) 59 | goto err0; 60 | 61 | result->file = fopen(filename, "rb"); 62 | if (!result->file) 63 | goto err1; 64 | 65 | s = fread(buffer, 1, 8, result->file); 66 | if (s < 8) 67 | goto err2; 68 | 69 | if (memcmp(buffer, riff, 4)) 70 | goto err2; 71 | 72 | /* TODO: check size (in buffer[4..8]) */ 73 | s = fread(buffer, 1, 4, result->file); 74 | if (s < 4) 75 | goto err2; 76 | 77 | if (memcmp(buffer, wave, 4)) 78 | goto err2; 79 | 80 | s = find_chunk(result->file, fmt_); 81 | if (s != 16 && s != 40) 82 | goto err2; 83 | 84 | fmt = (uint8_t*)malloc(s); 85 | if (!fmt) 86 | goto err2; 87 | 88 | if (fread(fmt, 1, s, result->file) != s) 89 | goto err3; 90 | 91 | /* wFormatTag */ 92 | v = (uint32_t)fmt[0] | ((uint32_t)fmt[1] << 8); 93 | if (v != 1 && v != 0xfffe) 94 | goto err3; 95 | 96 | /* wChannels */ 97 | v = (uint32_t)fmt[2] | ((uint32_t)fmt[3] << 8); 98 | if (v != 1 && v != 2 && v != 4 && v != 5 && v !=6) 99 | goto err3; 100 | result->channels = v; 101 | /* dwSamplesPerSec */ 102 | result->sample_rate = (uint32_t)fmt[4] | ((uint32_t)fmt[5] << 8) | 103 | ((uint32_t)fmt[6] << 16) | ((uint32_t)fmt[7] << 24); 104 | 105 | /* dwAvgBytesPerSec */ 106 | avg_bps = (uint32_t)fmt[8] | ((uint32_t)fmt[9] << 8) | 107 | ((uint32_t)fmt[10] << 16) | ((uint32_t)fmt[11] << 24); 108 | 109 | /* wBlockAlign */ 110 | block_align = (uint32_t)fmt[12] | ((uint32_t)fmt[13] << 8); 111 | 112 | /* wBitsPerSample */ 113 | result->bits_per_sample = (uint32_t)fmt[14] | ((uint32_t)fmt[15] << 8); 114 | if (result->bits_per_sample != 16 && result->bits_per_sample != 32) 115 | goto err3; 116 | 117 | if (block_align != result->channels * (result->bits_per_sample / 8)) 118 | goto err3; 119 | 120 | if (avg_bps != block_align * result->sample_rate) 121 | goto err3; 122 | 123 | v = find_chunk(result->file, data); 124 | if (v == 0 || v % block_align != 0) 125 | goto err3; 126 | 127 | result->samples_left = v / block_align; 128 | free(fmt); 129 | return result; 130 | 131 | err3: 132 | free(fmt); 133 | err2: 134 | fclose(result->file); 135 | err1: 136 | free(result); 137 | err0: 138 | return NULL; 139 | } 140 | 141 | void wavfile_close(wavfile * f) 142 | { 143 | fclose(f->file); 144 | free(f); 145 | } 146 | 147 | static int32_t get_s32_sample(const wavfile * f, const uint8_t *buffer, int sample, int channel) 148 | { 149 | int offset = (f->bits_per_sample / 8) * (f->channels * sample + channel); 150 | uint32_t v; 151 | switch (f->bits_per_sample) { 152 | case 16: 153 | v = (uint32_t)buffer[offset + 0] | ((uint32_t)buffer[offset + 1] << 8); 154 | return v << 16; 155 | break; 156 | case 32: 157 | v = (uint32_t)buffer[offset + 0] | ((uint32_t)buffer[offset + 1] << 8) | 158 | ((uint32_t)buffer[offset + 2] << 16) | ((uint32_t)buffer[offset + 3] << 24); 159 | return v; 160 | break; 161 | default: 162 | return 0; 163 | } 164 | } 165 | 166 | int wavfile_read_s32(wavfile * f, int32_t *samples) 167 | { 168 | uint8_t buffer[512 * 6 * 4]; 169 | int32_t smpte_sample[6]; 170 | int samples_to_read; 171 | int bytes_to_read; 172 | unsigned int i, ch; 173 | 174 | memset(buffer, 0, 512 * 6 * 4); 175 | samples_to_read = f->samples_left < 512 ? f->samples_left : 512; 176 | bytes_to_read = samples_to_read * f->channels * (f->bits_per_sample / 8); 177 | f->samples_left -= samples_to_read; 178 | if (fread(buffer, 1, bytes_to_read, f->file) != bytes_to_read) { 179 | f->samples_left = 0; 180 | } 181 | 182 | for (i = 0; i < 512; i++) { 183 | for (ch = 0; ch < f->channels; ch++) 184 | smpte_sample[ch] = get_s32_sample(f, buffer, i, ch); 185 | switch(f->channels) { 186 | case 1: 187 | case 2: 188 | case 4: 189 | for (ch = 0; ch < f->channels; ch++) 190 | *(samples++) = smpte_sample[ch]; 191 | break; 192 | case 5: 193 | *(samples++) = smpte_sample[2]; 194 | *(samples++) = smpte_sample[0]; 195 | *(samples++) = smpte_sample[1]; 196 | *(samples++) = smpte_sample[3]; 197 | *(samples++) = smpte_sample[4]; 198 | break; 199 | case 6: 200 | *(samples++) = smpte_sample[2]; 201 | *(samples++) = smpte_sample[0]; 202 | *(samples++) = smpte_sample[1]; 203 | *(samples++) = smpte_sample[4]; 204 | *(samples++) = smpte_sample[5]; 205 | *(samples++) = smpte_sample[3]; 206 | break; 207 | } 208 | } 209 | 210 | return f->samples_left; 211 | } 212 | -------------------------------------------------------------------------------- /gentables.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | /* Visual C++ brokenness */ 22 | #define _USE_MATH_DEFINES 23 | 24 | #include 25 | #include 26 | #include 27 | #include "config.h" 28 | #include "int_data.h" 29 | #include "float_data.h" 30 | 31 | #define AUBANDS 25 32 | 33 | /* Dump the table of cosines, scaled to 0x7fffffff 34 | * cos_table[i] == (int32_t)(0x7fffffff * cos(M_PI * i / 1024)) 35 | */ 36 | void print_cos_table(void) 37 | { 38 | int i; 39 | printf("const int32_t cos_table[2048] = {"); 40 | 41 | for (i = 0; i < 2048; i++) { 42 | if (i % 4 == 0) 43 | printf("\n "); 44 | printf(" %d,", (int32_t)(0x7fffffff * cos(M_PI * i / 1024))); 45 | } 46 | printf("\n};\n\n"); 47 | } 48 | 49 | /* Dumps the table that is used to reverse bits of small integers */ 50 | void print_bitrev_table(void) 51 | { 52 | int i, j, k; 53 | int br[256]; 54 | 55 | for (k = 0; k < 256; k++) 56 | br[k] = 0; 57 | 58 | for (i = 128, j = 1; i != 0; i >>= 1, j <<= 1) 59 | for (k = 0; k < 256; k++) 60 | if (k & j) 61 | br[k] += i; 62 | 63 | printf("const int bitrev[256] = {"); 64 | for (k = 0; k < 256; k++) { 65 | if (k % 8 == 0) 66 | printf("\n "); 67 | printf(" %d,", br[k]); 68 | } 69 | printf("\n};\n\n"); 70 | } 71 | 72 | /* Transfer function of outer and middle ear, Hz -> dB */ 73 | static double hom(double f) 74 | { 75 | double f1 = f / 1000; 76 | 77 | return -3.64 * pow(f1, -0.8) 78 | + 6.8 * exp(-0.6 * (f1 - 3.4) * (f1 - 3.4)) 79 | - 6.0 * exp(-0.15 * (f1 - 8.7) * (f1 - 8.7)) 80 | - 0.0006 * (f1 * f1) * (f1 * f1); 81 | } 82 | 83 | /* Auditory filter center frequencies and bandwidths, in Hz. 84 | * The last two are made up, because there is no scientific data. 85 | */ 86 | double fc[AUBANDS] = { 87 | 50, 150, 250, 350, 450, 570, 700, 840, 88 | 1000, 1170, 1370, 1600, 1850, 2150, 2500, 2900, 89 | 3400, 4000, 4800, 5800, 7000, 8500, 10500, 13500, 90 | 17000 91 | }; 92 | 93 | double erb[AUBANDS] = { 94 | 80, 100, 100, 100, 110, 120, 140, 150, 95 | 160, 190, 210, 240, 280, 320, 380, 450, 96 | 550, 700, 900, 1100, 1300, 1800, 2500, 3500, 97 | 4500 98 | }; 99 | 100 | /* transfer function of i-th auditory filter, in dB */ 101 | static double gammafilter(int i, double f) 102 | { 103 | double h = (f - fc[i]) / erb[i]; 104 | h = 1 + h * h; 105 | h = 1 / (h * h); 106 | return 20 * log10(h); 107 | } 108 | 109 | /* Dumps the auditory filter */ 110 | void print_auf(void) 111 | { 112 | int i, j, k; 113 | 114 | printf("const int32_t auf[9][AUBANDS][256] = {\n "); 115 | for (i = 0; i < 9; i++) { 116 | printf(" { /* Sample rate: %d Hz */\n ", sample_rates[i]); 117 | for (j = 0; j < AUBANDS; j++) { 118 | printf(" {"); 119 | for (k = 0; k < 256; k++) { 120 | double freq = sample_rates[i] * (k + 0.5) / 512; 121 | if (k % 8 == 0) 122 | printf("\n "); 123 | printf(" %d,", (int)(10 * (hom(freq) + gammafilter(j, freq)))); 124 | } 125 | printf("\n },"); 126 | } 127 | printf("\n },"); 128 | } 129 | printf("\n};\n\n"); 130 | } 131 | 132 | /* Dumps the exponent table, 133 | * used to convert centibels to 32-bit integer samples 134 | */ 135 | void print_cb_table(void) 136 | { 137 | int i; 138 | printf("const int32_t cb_to_level[2048] = {"); 139 | for (i = 0; i < 2048; i++) { 140 | if (i % 8 == 0) 141 | printf("\n "); 142 | printf(" %d,", (int)(0x7fffffff * pow(10, -0.005 * i))); 143 | } 144 | printf("\n};\n\n"); 145 | } 146 | 147 | /* Dumps the table that is used for addition of centibels */ 148 | void print_cb_add_table(void) 149 | { 150 | int i; 151 | printf("const int32_t cb_to_add[256] = {"); 152 | for (i = 0; i < 256; i++) { 153 | double add = 1 + pow(10, -0.01 * i); 154 | add = 100 * log10(add); 155 | if (i % 8 == 0) 156 | printf("\n "); 157 | printf(" %d,", (int)add); 158 | } 159 | printf("\n};\n\n"); 160 | } 161 | 162 | /* Dumps the integer version of the LFE FIR table */ 163 | void print_lfe_fir(void) 164 | { 165 | int i; 166 | printf("const int32_t lfe_fir[512] = {"); 167 | 168 | for (i = 0; i < 512; i++) { 169 | if (i % 8 == 0) 170 | printf("\n "); 171 | printf(" %d,", (int32_t)(0x01ffffff * lfe_fir_64[i])); 172 | } 173 | 174 | printf("\n};\n\n"); 175 | 176 | } 177 | 178 | /* Dumps the integer version of the subband FIR table and its spectrum */ 179 | void print_subband_fir(void) 180 | { 181 | int i, j, k; 182 | double spectrum[2][8]; 183 | 184 | for (j = 0; j < 2; j++) { 185 | 186 | for (k = 0; k < 8; k++) { 187 | double accum = 0; 188 | for (i = 0; i < 512; i++) { 189 | double reconst = reconstruction_fir[j][i] * ((i & 64) ? (-1) : 1); 190 | accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (k + 0.5) / 512); 191 | } 192 | spectrum[j][k] = accum; 193 | } 194 | } 195 | 196 | printf("const int32_t band_interpolation[2][512] = {\n"); 197 | for (j = 0; j < 2; j++) { 198 | printf(" {"); 199 | for (i = 0; i < 512; i++) { 200 | if (i % 8 == 0) 201 | printf("\n "); 202 | printf(" %d,", (int32_t) (0x1000000000ULL * reconstruction_fir[j][i])); 203 | } 204 | printf("\n },\n"); 205 | } 206 | printf("};\n\n"); 207 | 208 | printf("const int32_t band_spectrum[2][8] = {\n"); 209 | for (j = 0; j < 2; j++) { 210 | printf("\t{ "); 211 | for (i = 0; i < 8; i++) 212 | printf("%d, ", (int32_t) (200 * log10(spectrum[j][i]))); 213 | printf("},\n"); 214 | } 215 | printf("};\n\n"); 216 | 217 | } 218 | 219 | int main(int argc, char *argv[]) 220 | { 221 | printf("/* GENERATED FILE, DO NOT EDIT */\n\n"); 222 | printf("#include \"config.h\"\n"); 223 | printf("#include \"math_tables.h\"\n\n"); 224 | print_lfe_fir(); 225 | print_subband_fir(); 226 | print_cos_table(); 227 | print_bitrev_table(); 228 | print_cb_table(); 229 | print_cb_add_table(); 230 | print_auf(); 231 | 232 | return 0; 233 | } 234 | -------------------------------------------------------------------------------- /int_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef INT_DATA_H 22 | #define INT_DATA_H 23 | 24 | #include "softfloat.h" 25 | 26 | 27 | /* 28 | * Official tables taken from: 29 | * ETSI TS 102 114 V1.2.1 30 | * 31 | * Copyright (C) European Telecommunications Standards Institute 2002. 32 | * Copyright (C) European Broadcasting Union 2002. 33 | * All rights reserved. 34 | */ 35 | 36 | /* 5.4.1 Bit Stream Header, 37 | * Table 5.7: RATE parameter vs. targeted bit-rate 38 | * with "open" replaced by 6144000 39 | * and "variable" and "lossless" by 16144000 (i.e. invalid value) 40 | */ 41 | static const int target_bitrate_table[32] = { 42 | 32000, 56000, 64000, 96000, 112000, 128000, 192000, 224000, 43 | 256000, 320000, 384000, 448000, 512000, 576000, 640000, 768000, 44 | 960000, 1024000, 1152000, 1280000, 1344000, 1408000, 1411200, 1472000, 45 | 1536000, 1920000, 2048000, 3072000, 3840000, 6144000, 16144000, 16144000, 46 | }; 47 | 48 | /* 5.4.1 Bit Stream Header, 49 | * Table 5.4: Audio channel arrangement 50 | * FIXME: more than 5 channels are not supported 51 | */ 52 | static const int channels_table[16] = { 53 | 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 54 | }; 55 | 56 | /* 5.4.1 Bit Stream Header, 57 | * Table 5.5: Core audio sampling frequencies 58 | */ 59 | static const int sample_rates[9] = { 60 | 8000, 16000, 32000, 11025, 22050, 44100, 12000, 24000, 48000, 61 | }; 62 | 63 | static const int bitstream_sfreq[9] = { 64 | 1, 2, 3, 6, 7, 8, 11, 12, 13, 65 | }; 66 | 67 | /* manually derived from 68 | * Table B.5: Selection of quantization levels and codebooks 69 | * Fixme: will become invalid when Huffman codes are introduced. 70 | */ 71 | static const int bit_consumption[27] = { 72 | -8, 28, 40, 48, 52, 60, 68, 76, 80, 96, 73 | 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 74 | 272, 288, 304, 320, 336, 352, 368, 75 | }; 76 | 77 | /* Table B.5: Selection of quantization levels and codebooks */ 78 | static const int quant_levels[27] = { 79 | 1, 3, 5, 7, 9, 13, 17, 25, 32, 64, 80 | 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 81 | 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 82 | }; 83 | 84 | /* D.2.1 Lossy Quantization */ 85 | static const int32_t stepsize[27] = { 86 | 0, 6710886, 4194304, 3355443, 2474639, 2097152, 1761608, 1426063, 796918, 461373, 87 | 251658, 146801, 79692, 46137, 27263, 16777, 10486, 5872, 3355, 1887, 88 | 1258, 713, 336, 168, 84, 42, 21, 89 | }; 90 | 91 | /* Generated table, FIXME: move to math_tables.c */ 92 | /* a / stepsize[i] == mul32(a, stepsize_inv[i].m) >> stepsize_inv[i].e */ 93 | static const softfloat stepsize_inv[27] = { 94 | {0, 0}, {1342177360, 21}, {2147483647, 21}, {1342177360, 20}, 95 | {1819901661, 20}, {2147483647, 20}, {1278263843, 19}, {1579032492, 19}, 96 | {1412817763, 18}, {1220162327, 17}, {1118482133, 16}, {1917391412, 16}, 97 | {1766017772, 15}, {1525212826, 14}, {1290553940, 13}, {2097179000, 13}, 98 | {1677683200, 12}, {1497972244, 11}, {1310893147, 10}, {1165354136, 9}, 99 | {1748031204, 9}, {1542092044, 8}, {1636178017, 7}, {1636178017, 6}, 100 | {1636178017, 5}, {1636178017, 4}, {1636178017, 3}, 101 | }; 102 | 103 | /* D.1.2 7-bit Quantization (Nominal 1.1 dB Step) */ 104 | static const int32_t scalefactor[128] = { 105 | 1, 1, 2, 2, 2, 2, 3, 3, 106 | 3, 4, 4, 5, 6, 7, 7, 8, 107 | 10, 11, 12, 14, 16, 18, 20, 23, 108 | 26, 30, 34, 38, 44, 50, 56, 64, 109 | 72, 82, 93, 106, 120, 136, 155, 176, 110 | 200, 226, 257, 292, 331, 376, 427, 484, 111 | 550, 624, 708, 804, 912, 1035, 1175, 1334, 112 | 1514, 1718, 1950, 2213, 2512, 2851, 3236, 3673, 113 | 4169, 4732, 5370, 6095, 6918, 7852, 8913, 10116, 114 | 11482, 13032, 14791, 16788, 19055, 21627, 24547, 27861, 115 | 31623, 35892, 40738, 46238, 52481, 59566, 67608, 76736, 116 | 87096, 98855, 112202, 127350, 144544, 164059, 186209, 211349, 117 | 239883, 272270, 309030, 350752, 398107, 451856, 512861, 582103, 118 | 660693, 749894, 851138, 966051, 1096478, 1244515, 1412538, 1603245, 119 | 1819701, 2065380, 2344229, 2660725, 3019952, 3427678, 3890451, 4415704, 120 | 5011872, 5688529, 6456542, 7328245, 8317638, 8317638, 8317638, 8317638, 121 | }; 122 | 123 | /* Generated table */ 124 | /* sqrt(2) * a / scalefactor[i] == 4 * mul32(a, scalefactor_inv[i].m) >> scalefactor_inv[i].e */ 125 | static const softfloat scalefactor_inv[128] = { 126 | {2147483647, 1}, {2147483647, 1}, {2147483647, 2}, {2147483647, 2}, 127 | {2147483647, 2}, {2147483647, 2}, {1431655765, 2}, {1431655765, 2}, 128 | {1431655765, 2}, {2147483647, 3}, {2147483647, 3}, {1717986918, 3}, 129 | {1431655765, 3}, {1227133513, 3}, {1227133513, 3}, {2147483647, 4}, 130 | {1717986918, 4}, {1561806289, 4}, {1431655765, 4}, {1227133513, 4}, 131 | {2147483647, 5}, {1908874353, 5}, {1717986918, 5}, {1493901668, 5}, 132 | {1321528398, 5}, {1145324612, 5}, {2021161080, 6}, {1808407282, 6}, 133 | {1561806289, 6}, {1374389534, 6}, {1227133513, 6}, {2147483647, 7}, 134 | {1908874353, 7}, {1676084798, 7}, {1477838209, 7}, {1296593900, 7}, 135 | {1145324612, 7}, {2021161080, 8}, {1773405851, 8}, {1561806289, 8}, 136 | {1374389534, 8}, {1216273924, 8}, {2139127680, 9}, {1882725390, 9}, 137 | {1660893697, 9}, {1462116526, 9}, {1287484341, 9}, {1135859119, 9}, 138 | {1999112050, 10}, {1762037865, 10}, {1552982525, 10}, {1367551775, 10}, 139 | {1205604855, 10}, {2124660150, 11}, {1871509153, 11}, {1648443220, 11}, 140 | {1452459217, 11}, {1279990253, 11}, {1127704233, 11}, {1987368509, 12}, 141 | {1750814693, 12}, {1542632939, 12}, {1359099663, 12}, {1197398995, 12}, 142 | {2109880792, 13}, {1858853132, 13}, {1638006149, 13}, {1443165385, 13}, 143 | {1271479187, 13}, {1120235993, 13}, {1973767086, 14}, {1739045674, 14}, 144 | {1532153461, 14}, {1349922194, 14}, {1189384493, 14}, {2095804865, 15}, 145 | {1846464029, 15}, {1626872524, 15}, {1433347133, 15}, {1262853884, 15}, 146 | {1112619678, 15}, {1960569045, 16}, {1727349015, 16}, {1521881227, 16}, 147 | {1340842289, 16}, {1181357555, 16}, {2081669156, 17}, {1834047752, 17}, 148 | {1615889229, 17}, {1423675973, 17}, {1254322457, 17}, {1105123583, 17}, 149 | {1947330755, 18}, {1715693602, 18}, {1511607799, 18}, {1331801790, 18}, 150 | {1173384427, 18}, {2067616532, 19}, {1821667648, 19}, {1604980024, 19}, 151 | {1414066955, 19}, {1245861410, 19}, {1097665748, 19}, {1934193616, 20}, 152 | {1704119624, 20}, {1501412075, 20}, {1322817107, 20}, {1165466323, 20}, 153 | {2053666205, 21}, {1809379407, 21}, {1594151671, 21}, {1404526328, 21}, 154 | {1237455941, 21}, {1090259329, 21}, {1921143210, 22}, {1692621231, 22}, 155 | {1491281857, 22}, {1313892269, 22}, {1157603482, 22}, {2039810470, 23}, 156 | {1797172644, 23}, {1583396912, 23}, {1395050052, 23}, {1229107276, 23}, 157 | {1082903494, 23}, {1082903494, 23}, {1082903494, 23}, {1082903494, 23}, 158 | }; 159 | #endif 160 | -------------------------------------------------------------------------------- /alsaplugin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "dcaenc.h" 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | struct dcaplug_info { 28 | snd_pcm_extplug_t ext; 29 | int iec61937; 30 | dcaenc_context enc; 31 | int32_t pcm_buffer[6 * 512]; 32 | int16_t dts_buffer[2 * 512]; 33 | snd_pcm_uframes_t bufpos; 34 | }; 35 | 36 | static inline void *area_addr(const snd_pcm_channel_area_t *area, 37 | snd_pcm_uframes_t offset) 38 | { 39 | unsigned int bitofs = area->first + area->step * offset; 40 | return (char *) area->addr + bitofs / 8; 41 | } 42 | 43 | 44 | static inline int32_t get_s32(const snd_pcm_channel_area_t *area, 45 | snd_pcm_uframes_t offset, snd_pcm_format_t format) 46 | { 47 | int32_t* sample32; 48 | int16_t* sample16; 49 | switch (format) { 50 | case SND_PCM_FORMAT_S32: 51 | sample32 = (int32_t*)area_addr(area, offset); 52 | return *sample32; 53 | case SND_PCM_FORMAT_S16: 54 | sample16 = (int16_t*)area_addr(area, offset); 55 | return *sample16 * 0x10000; 56 | } 57 | return 0; 58 | } 59 | 60 | static inline void put_s16(const snd_pcm_channel_area_t *area, 61 | snd_pcm_uframes_t offset, int16_t value) 62 | { 63 | int16_t* sample16 = (int16_t*)area_addr(area, offset); 64 | *sample16 = value; 65 | } 66 | 67 | static snd_pcm_sframes_t dcaplug_transfer(snd_pcm_extplug_t *ext, 68 | const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset, 69 | const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset, 70 | snd_pcm_uframes_t size) 71 | { 72 | struct dcaplug_info *dcaplug = (struct dcaplug_info*)ext; 73 | 74 | /* Force samples to the buffer */ 75 | 76 | snd_pcm_uframes_t remaining = 512 - dcaplug->bufpos; 77 | if (size > remaining) 78 | size = remaining; 79 | 80 | snd_pcm_uframes_t i; 81 | int channel; 82 | int srcbufidx = ext->channels * dcaplug->bufpos; 83 | int dstbufidx = 2 * dcaplug->bufpos; 84 | for (i = 0; i < size; i++) { 85 | if (ext->channels == 4) { 86 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[0], i + src_offset, ext->format); 87 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[1], i + src_offset, ext->format); 88 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[2], i + src_offset, ext->format); 89 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[3], i + src_offset, ext->format); 90 | } else { 91 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[4], i + src_offset, ext->format); 92 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[0], i + src_offset, ext->format); 93 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[1], i + src_offset, ext->format); 94 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[2], i + src_offset, ext->format); 95 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[3], i + src_offset, ext->format); 96 | dcaplug->pcm_buffer[srcbufidx++] = get_s32(&src_areas[5], i + src_offset, ext->format); 97 | } 98 | 99 | put_s16(&dst_areas[0], i + dst_offset, dcaplug->dts_buffer[dstbufidx++]); 100 | put_s16(&dst_areas[1], i + dst_offset, dcaplug->dts_buffer[dstbufidx++]); 101 | } 102 | dcaplug->bufpos += size; 103 | 104 | if (dcaplug->bufpos == 512) { 105 | dcaenc_convert_s32(dcaplug->enc, dcaplug->pcm_buffer, (uint8_t*)dcaplug->dts_buffer); 106 | dcaplug->bufpos = 0; 107 | } 108 | 109 | return size; 110 | } 111 | 112 | static const int32_t zero[512 * 6]; 113 | static int dcaplug_init(snd_pcm_extplug_t *ext) 114 | { 115 | struct dcaplug_info *dcaplug = (struct dcaplug_info*)ext; 116 | 117 | if (ext->rate != 44100 && ext->rate != 48000) { 118 | SNDERR("Wrong sample rate, must be 44100 or 48000 Hz"); 119 | return -EINVAL; 120 | } 121 | 122 | if (ext->channels == 2) { 123 | /* TODO: passthrough? */ 124 | SNDERR("Conversion from stereo to DTS is pointless"); 125 | return -EINVAL; 126 | } 127 | 128 | if (ext->channels != 4 && ext->channels != 6) { 129 | SNDERR("Wrong number of channels"); 130 | return -EINVAL; 131 | } 132 | 133 | if (dcaplug->iec61937) { 134 | dcaplug->enc = dcaenc_create(ext->rate, 135 | (ext->channels == 4) ? DCAENC_CHANNELS_2FRONT_2REAR : DCAENC_CHANNELS_3FRONT_2REAR, 136 | ext->rate * 503 / 16, /* same as DVD */ 137 | ((ext->channels == 4) ? 0 : DCAENC_FLAG_LFE) | DCAENC_FLAG_IEC_WRAP); 138 | } else { 139 | dcaplug->enc = dcaenc_create(ext->rate, 140 | (ext->channels == 4) ? DCAENC_CHANNELS_2FRONT_2REAR : DCAENC_CHANNELS_3FRONT_2REAR, 141 | ext->rate * 32, /* same as S16 stereo on a CD */ 142 | (ext->channels == 4) ? 0 : DCAENC_FLAG_LFE); 143 | } 144 | 145 | if (!dcaplug->enc) { 146 | SNDERR("Failed to create DCA encoder"); 147 | return -ENOMEM; 148 | } 149 | 150 | if (dcaenc_output_size(dcaplug->enc) != 2048) { 151 | SNDERR("The dcaenc library is incompatible"); 152 | return -EINVAL; 153 | } 154 | 155 | /* Create a dummy frame of silence */ 156 | dcaenc_convert_s32(dcaplug->enc, zero, (uint8_t*)dcaplug->dts_buffer); 157 | 158 | return 0; 159 | } 160 | 161 | static int dcaplug_close(snd_pcm_extplug_t *ext) 162 | { 163 | struct dcaplug_info *dcaplug = (struct dcaplug_info*)ext; 164 | 165 | dcaenc_destroy(dcaplug->enc, NULL); 166 | dcaplug->enc = NULL; 167 | return 0; 168 | } 169 | 170 | static const snd_pcm_extplug_callback_t dcaplug_callback = { 171 | .transfer = dcaplug_transfer, 172 | .init = dcaplug_init, 173 | .close = dcaplug_close, 174 | }; 175 | 176 | 177 | SND_PCM_PLUGIN_DEFINE_FUNC(dca) 178 | { 179 | snd_config_iterator_t i, next; 180 | snd_config_t *slave = NULL; 181 | int iec61937 = 0; 182 | struct dcaplug_info *dcaplug; 183 | int err; 184 | 185 | if (stream != SND_PCM_STREAM_PLAYBACK) { 186 | SNDERR("dca is only for playback"); 187 | return -EINVAL; 188 | } 189 | snd_config_for_each(i, next, conf) { 190 | snd_config_t *n = snd_config_iterator_entry(i); 191 | const char *id; 192 | if (snd_config_get_id(n, &id) < 0) 193 | continue; 194 | if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0) 195 | continue; 196 | if (strcmp(id, "slave") == 0) { 197 | slave = n; 198 | continue; 199 | } 200 | if (strcmp(id, "iec61937") == 0) { 201 | if ((err = snd_config_get_bool(n)) < 0) { 202 | SNDERR("Invalid value for %s", id); 203 | return -EINVAL; 204 | } 205 | iec61937 = err; 206 | continue; 207 | } 208 | SNDERR("Unknown field %s", id); 209 | return -EINVAL; 210 | } 211 | 212 | if (!slave) { 213 | SNDERR("No slave defined for dca"); 214 | return -EINVAL; 215 | } 216 | 217 | dcaplug = calloc(1, sizeof(*dcaplug)); 218 | if (dcaplug == NULL) 219 | return -ENOMEM; 220 | 221 | dcaplug->ext.version = SND_PCM_EXTPLUG_VERSION; 222 | dcaplug->ext.name = "DTS Coherent Acoustics encoder"; 223 | dcaplug->ext.callback = &dcaplug_callback; 224 | dcaplug->ext.private_data = dcaplug; 225 | dcaplug->iec61937 = iec61937; 226 | 227 | err = snd_pcm_extplug_create(&dcaplug->ext, name, root, slave, stream, mode); 228 | if (err < 0) { 229 | dcaenc_destroy(dcaplug->enc, NULL); 230 | free(dcaplug); 231 | return err; 232 | } 233 | 234 | static const int channels[2] = {4, 6}; 235 | static const int formats[2] = {SND_PCM_FORMAT_S32, SND_PCM_FORMAT_S16}; 236 | 237 | snd_pcm_extplug_set_param_list(&dcaplug->ext, SND_PCM_EXTPLUG_HW_CHANNELS, 238 | 2, channels); 239 | snd_pcm_extplug_set_slave_param(&dcaplug->ext, SND_PCM_EXTPLUG_HW_CHANNELS, 2); 240 | 241 | snd_pcm_extplug_set_param_list(&dcaplug->ext, SND_PCM_EXTPLUG_HW_FORMAT, 242 | 2, formats); 243 | snd_pcm_extplug_set_slave_param(&dcaplug->ext, SND_PCM_EXTPLUG_HW_FORMAT, SND_PCM_FORMAT_S16); 244 | 245 | *pcmp = dcaplug->ext.pcm; 246 | return 0; 247 | } 248 | 249 | SND_PCM_PLUGIN_SYMBOL(dca); 250 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 5 | 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 6 | 7 | Copying and distribution of this file, with or without modification, 8 | are permitted in any medium without royalty provided the copyright 9 | notice and this notice are preserved. This file is offered as-is, 10 | without warranty of any kind. 11 | 12 | Basic Installation 13 | ================== 14 | 15 | Briefly, the shell commands `./configure; make; make install' should 16 | configure, build, and install this package. The following 17 | more-detailed instructions are generic; see the `README' file for 18 | instructions specific to this package. Some packages provide this 19 | `INSTALL' file but do not implement all of the features documented 20 | below. The lack of an optional feature in a given package is not 21 | necessarily a bug. More recommendations for GNU packages can be found 22 | in *note Makefile Conventions: (standards)Makefile Conventions. 23 | 24 | The `configure' shell script attempts to guess correct values for 25 | various system-dependent variables used during compilation. It uses 26 | those values to create a `Makefile' in each directory of the package. 27 | It may also create one or more `.h' files containing system-dependent 28 | definitions. Finally, it creates a shell script `config.status' that 29 | you can run in the future to recreate the current configuration, and a 30 | file `config.log' containing compiler output (useful mainly for 31 | debugging `configure'). 32 | 33 | It can also use an optional file (typically called `config.cache' 34 | and enabled with `--cache-file=config.cache' or simply `-C') that saves 35 | the results of its tests to speed up reconfiguring. Caching is 36 | disabled by default to prevent problems with accidental use of stale 37 | cache files. 38 | 39 | If you need to do unusual things to compile the package, please try 40 | to figure out how `configure' could check whether to do them, and mail 41 | diffs or instructions to the address given in the `README' so they can 42 | be considered for the next release. If you are using the cache, and at 43 | some point `config.cache' contains results you don't want to keep, you 44 | may remove or edit it. 45 | 46 | The file `configure.ac' (or `configure.in') is used to create 47 | `configure' by a program called `autoconf'. You need `configure.ac' if 48 | you want to change it or regenerate `configure' using a newer version 49 | of `autoconf'. 50 | 51 | The simplest way to compile this package is: 52 | 53 | 1. `cd' to the directory containing the package's source code and type 54 | `./configure' to configure the package for your system. 55 | 56 | Running `configure' might take a while. While running, it prints 57 | some messages telling which features it is checking for. 58 | 59 | 2. Type `make' to compile the package. 60 | 61 | 3. Optionally, type `make check' to run any self-tests that come with 62 | the package, generally using the just-built uninstalled binaries. 63 | 64 | 4. Type `make install' to install the programs and any data files and 65 | documentation. When installing into a prefix owned by root, it is 66 | recommended that the package be configured and built as a regular 67 | user, and only the `make install' phase executed with root 68 | privileges. 69 | 70 | 5. Optionally, type `make installcheck' to repeat any self-tests, but 71 | this time using the binaries in their final installed location. 72 | This target does not install anything. Running this target as a 73 | regular user, particularly if the prior `make install' required 74 | root privileges, verifies that the installation completed 75 | correctly. 76 | 77 | 6. You can remove the program binaries and object files from the 78 | source code directory by typing `make clean'. To also remove the 79 | files that `configure' created (so you can compile the package for 80 | a different kind of computer), type `make distclean'. There is 81 | also a `make maintainer-clean' target, but that is intended mainly 82 | for the package's developers. If you use it, you may have to get 83 | all sorts of other programs in order to regenerate files that came 84 | with the distribution. 85 | 86 | 7. Often, you can also type `make uninstall' to remove the installed 87 | files again. In practice, not all packages have tested that 88 | uninstallation works correctly, even though it is required by the 89 | GNU Coding Standards. 90 | 91 | 8. Some packages, particularly those that use Automake, provide `make 92 | distcheck', which can by used by developers to test that all other 93 | targets like `make install' and `make uninstall' work correctly. 94 | This target is generally not run by end users. 95 | 96 | Compilers and Options 97 | ===================== 98 | 99 | Some systems require unusual options for compilation or linking that 100 | the `configure' script does not know about. Run `./configure --help' 101 | for details on some of the pertinent environment variables. 102 | 103 | You can give `configure' initial values for configuration parameters 104 | by setting variables in the command line or in the environment. Here 105 | is an example: 106 | 107 | ./configure CC=c99 CFLAGS=-g LIBS=-lposix 108 | 109 | *Note Defining Variables::, for more details. 110 | 111 | Compiling For Multiple Architectures 112 | ==================================== 113 | 114 | You can compile the package for more than one kind of computer at the 115 | same time, by placing the object files for each architecture in their 116 | own directory. To do this, you can use GNU `make'. `cd' to the 117 | directory where you want the object files and executables to go and run 118 | the `configure' script. `configure' automatically checks for the 119 | source code in the directory that `configure' is in and in `..'. This 120 | is known as a "VPATH" build. 121 | 122 | With a non-GNU `make', it is safer to compile the package for one 123 | architecture at a time in the source code directory. After you have 124 | installed the package for one architecture, use `make distclean' before 125 | reconfiguring for another architecture. 126 | 127 | On MacOS X 10.5 and later systems, you can create libraries and 128 | executables that work on multiple system types--known as "fat" or 129 | "universal" binaries--by specifying multiple `-arch' options to the 130 | compiler but only a single `-arch' option to the preprocessor. Like 131 | this: 132 | 133 | ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 134 | CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 135 | CPP="gcc -E" CXXCPP="g++ -E" 136 | 137 | This is not guaranteed to produce working output in all cases, you 138 | may have to build one architecture at a time and combine the results 139 | using the `lipo' tool if you have problems. 140 | 141 | Installation Names 142 | ================== 143 | 144 | By default, `make install' installs the package's commands under 145 | `/usr/local/bin', include files under `/usr/local/include', etc. You 146 | can specify an installation prefix other than `/usr/local' by giving 147 | `configure' the option `--prefix=PREFIX', where PREFIX must be an 148 | absolute file name. 149 | 150 | You can specify separate installation prefixes for 151 | architecture-specific files and architecture-independent files. If you 152 | pass the option `--exec-prefix=PREFIX' to `configure', the package uses 153 | PREFIX as the prefix for installing programs and libraries. 154 | Documentation and other data files still use the regular prefix. 155 | 156 | In addition, if you use an unusual directory layout you can give 157 | options like `--bindir=DIR' to specify different values for particular 158 | kinds of files. Run `configure --help' for a list of the directories 159 | you can set and what kinds of files go in them. In general, the 160 | default for these options is expressed in terms of `${prefix}', so that 161 | specifying just `--prefix' will affect all of the other directory 162 | specifications that were not explicitly provided. 163 | 164 | The most portable way to affect installation locations is to pass the 165 | correct locations to `configure'; however, many packages provide one or 166 | both of the following shortcuts of passing variable assignments to the 167 | `make install' command line to change installation locations without 168 | having to reconfigure or recompile. 169 | 170 | The first method involves providing an override variable for each 171 | affected directory. For example, `make install 172 | prefix=/alternate/directory' will choose an alternate location for all 173 | directory configuration variables that were expressed in terms of 174 | `${prefix}'. Any directories that were specified during `configure', 175 | but not in terms of `${prefix}', must each be overridden at install 176 | time for the entire installation to be relocated. The approach of 177 | makefile variable overrides for each directory variable is required by 178 | the GNU Coding Standards, and ideally causes no recompilation. 179 | However, some platforms have known limitations with the semantics of 180 | shared libraries that end up requiring recompilation when using this 181 | method, particularly noticeable in packages that use GNU Libtool. 182 | 183 | The second method involves providing the `DESTDIR' variable. For 184 | example, `make install DESTDIR=/alternate/directory' will prepend 185 | `/alternate/directory' before all installation names. The approach of 186 | `DESTDIR' overrides is not required by the GNU Coding Standards, and 187 | does not work on platforms that have drive letters. On the other hand, 188 | it does better at avoiding recompilation issues, and works well even 189 | when some directory options were not specified in terms of `${prefix}' 190 | at `configure' time. 191 | 192 | Optional Features 193 | ================= 194 | 195 | If the package supports it, you can cause programs to be installed 196 | with an extra prefix or suffix on their names by giving `configure' the 197 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 198 | 199 | Some packages pay attention to `--enable-FEATURE' options to 200 | `configure', where FEATURE indicates an optional part of the package. 201 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 202 | is something like `gnu-as' or `x' (for the X Window System). The 203 | `README' should mention any `--enable-' and `--with-' options that the 204 | package recognizes. 205 | 206 | For packages that use the X Window System, `configure' can usually 207 | find the X include and library files automatically, but if it doesn't, 208 | you can use the `configure' options `--x-includes=DIR' and 209 | `--x-libraries=DIR' to specify their locations. 210 | 211 | Some packages offer the ability to configure how verbose the 212 | execution of `make' will be. For these packages, running `./configure 213 | --enable-silent-rules' sets the default to minimal output, which can be 214 | overridden with `make V=1'; while running `./configure 215 | --disable-silent-rules' sets the default to verbose, which can be 216 | overridden with `make V=0'. 217 | 218 | Particular systems 219 | ================== 220 | 221 | On HP-UX, the default C compiler is not ANSI C compatible. If GNU 222 | CC is not installed, it is recommended to use the following options in 223 | order to use an ANSI C compiler: 224 | 225 | ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" 226 | 227 | and if that doesn't work, install pre-built binaries of GCC for HP-UX. 228 | 229 | On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot 230 | parse its `' header file. The option `-nodtk' can be used as 231 | a workaround. If GNU CC is not installed, it is therefore recommended 232 | to try 233 | 234 | ./configure CC="cc" 235 | 236 | and if that doesn't work, try 237 | 238 | ./configure CC="cc -nodtk" 239 | 240 | On Solaris, don't put `/usr/ucb' early in your `PATH'. This 241 | directory contains several dysfunctional programs; working variants of 242 | these programs are available in `/usr/bin'. So, if you need `/usr/ucb' 243 | in your `PATH', put it _after_ `/usr/bin'. 244 | 245 | On Haiku, software installed for all users goes in `/boot/common', 246 | not `/usr/local'. It is recommended to use the following options: 247 | 248 | ./configure --prefix=/boot/common 249 | 250 | Specifying the System Type 251 | ========================== 252 | 253 | There may be some features `configure' cannot figure out 254 | automatically, but needs to determine by the type of machine the package 255 | will run on. Usually, assuming the package is built to be run on the 256 | _same_ architectures, `configure' can figure that out, but if it prints 257 | a message saying it cannot guess the machine type, give it the 258 | `--build=TYPE' option. TYPE can either be a short name for the system 259 | type, such as `sun4', or a canonical name which has the form: 260 | 261 | CPU-COMPANY-SYSTEM 262 | 263 | where SYSTEM can have one of these forms: 264 | 265 | OS 266 | KERNEL-OS 267 | 268 | See the file `config.sub' for the possible values of each field. If 269 | `config.sub' isn't included in this package, then this package doesn't 270 | need to know the machine type. 271 | 272 | If you are _building_ compiler tools for cross-compiling, you should 273 | use the option `--target=TYPE' to select the type of system they will 274 | produce code for. 275 | 276 | If you want to _use_ a cross compiler, that generates code for a 277 | platform different from the build platform, you should specify the 278 | "host" platform (i.e., that on which the generated programs will 279 | eventually be run) with `--host=TYPE'. 280 | 281 | Sharing Defaults 282 | ================ 283 | 284 | If you want to set default values for `configure' scripts to share, 285 | you can create a site shell script called `config.site' that gives 286 | default values for variables like `CC', `cache_file', and `prefix'. 287 | `configure' looks for `PREFIX/share/config.site' if it exists, then 288 | `PREFIX/etc/config.site' if it exists. Or, you can set the 289 | `CONFIG_SITE' environment variable to the location of the site script. 290 | A warning: not all `configure' scripts look for a site script. 291 | 292 | Defining Variables 293 | ================== 294 | 295 | Variables not defined in a site shell script can be set in the 296 | environment passed to `configure'. However, some packages may run 297 | configure again during the build, and the customized values of these 298 | variables may be lost. In order to avoid this problem, you should set 299 | them in the `configure' command line, using `VAR=value'. For example: 300 | 301 | ./configure CC=/usr/local2/bin/gcc 302 | 303 | causes the specified `gcc' to be used as the C compiler (unless it is 304 | overridden in the site shell script). 305 | 306 | Unfortunately, this technique does not work for `CONFIG_SHELL' due to 307 | an Autoconf bug. Until the bug is fixed you can use this workaround: 308 | 309 | CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash 310 | 311 | `configure' Invocation 312 | ====================== 313 | 314 | `configure' recognizes the following options to control how it 315 | operates. 316 | 317 | `--help' 318 | `-h' 319 | Print a summary of all of the options to `configure', and exit. 320 | 321 | `--help=short' 322 | `--help=recursive' 323 | Print a summary of the options unique to this package's 324 | `configure', and exit. The `short' variant lists options used 325 | only in the top level, while the `recursive' variant lists options 326 | also present in any nested packages. 327 | 328 | `--version' 329 | `-V' 330 | Print the version of Autoconf used to generate the `configure' 331 | script, and exit. 332 | 333 | `--cache-file=FILE' 334 | Enable the cache: use and save the results of the tests in FILE, 335 | traditionally `config.cache'. FILE defaults to `/dev/null' to 336 | disable caching. 337 | 338 | `--config-cache' 339 | `-C' 340 | Alias for `--cache-file=config.cache'. 341 | 342 | `--quiet' 343 | `--silent' 344 | `-q' 345 | Do not print messages saying which checks are being made. To 346 | suppress all normal output, redirect it to `/dev/null' (any error 347 | messages will still be shown). 348 | 349 | `--srcdir=DIR' 350 | Look for the package's source code in directory DIR. Usually 351 | `configure' can determine that directory automatically. 352 | 353 | `--prefix=DIR' 354 | Use DIR as the installation prefix. *note Installation Names:: 355 | for more details, including other options available for fine-tuning 356 | the installation locations. 357 | 358 | `--no-create' 359 | `-n' 360 | Run the configure checks, but stop before creating any output 361 | files. 362 | 363 | `configure' also accepts some other, not widely useful, options. Run 364 | `configure --help' for more details. 365 | 366 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | dcaenc is an open-source implementation of the DTS Coherent Acoustics 5 | lossy audio codec. Only the core part of the encoder is implemented, 6 | even though the full specification (ETSI TS 102 114 V1.3.1) is available 7 | for download. 8 | 9 | The project page is at http://aepatrakov.narod.ru/dcaenc/ 10 | 11 | The latest code can be obtained from git: 12 | 13 | git clone git://gitorious.org/dtsenc/dtsenc.git 14 | 15 | Windows-specific notes 16 | ====================== 17 | 18 | There is a fork of dcaenc specially targetted at Windows users. You can get 19 | it from http://gitorious.org/~mulder/dtsenc/mulders-dtsenc . As compared to 20 | this version, that fork adds a Visual Studio project file, a progress indicator 21 | and support for Unicode file names on Windows. It also breaks Linux support. 22 | Still, the original dcaenc can be compiled for Windows, here is how. 23 | 24 | The recommended compiler for dcaenc on Windows is MinGW. Get it from 25 | http://sourceforge.net/projects/mingw/files/Installer/ . You may want to use 26 | either the mingw-get.exe utility directly (just copy it to c:\mingw\bin, 27 | install nothing else), or use a graphical installer. In the latter case, 28 | install just the C compiler. 29 | 30 | After installation, add c:\mingw\bin and c:\mingw\msys\1.0\bin to the Path 31 | environment variable (right-click My Computer -> Properties -> Advanced -> 32 | Environment Variables) if it is not already there. Then install the required 33 | MinGW components from the command prompt: 34 | 35 | mingw-get install mingw32-base mingw32-autotools 36 | 37 | For autotools to work, you also have to copy or rename the 38 | c:\mingw\msys\1.0\etc\fstab.sample file to c:\mingw\msys\1.0\etc\fstab. 39 | 40 | Installation 41 | ============ 42 | 43 | The dcaenc library has no external dependencies. The optional ALSA plugin 44 | that comes with it, obviously, depends on the ALSA library compiled with 45 | support for external plugins. 46 | 47 | See the file INSTALL for the generic installation instructions. 48 | Quick summary for UNIX-like systems: 49 | 50 | autoreconf -f -i -v # only if building from git 51 | ./configure --prefix=/usr --libdir=??? # see below 52 | make 53 | su -c 'make install' # Or, on Ubuntu: sudo make install 54 | 55 | The --libdir parameter is distribution- and architecture-specific, thus, the 56 | default (/usr/lib) may be wrong for your system. This parameter influences 57 | the shared library and ALSA plugin location. If you specify this parameter 58 | incorrectly, ALSA will not find the plugin. You can verify that the value is 59 | correct by looking if there are already any ALSA plugins for the same 60 | architecture in $libdir/alsa-lib. Here are some values to consider: 61 | 62 | Most 32-bit x86 linux systems: /usr/lib 63 | Most x86-64 linux systems: /usr/lib or /usr/lib64 64 | 32-bit libraries on most x86-64 linux systems: /usr/lib or /usr/lib32 65 | x86 Debian or Ubuntu (new versions): /usr/lib/i386-linux-gnu 66 | x86-64 Debian or Ubuntu (new versions): /usr/lib/x86_64-linux-gnu 67 | 68 | Quick summary for Windows: 69 | 70 | bash 71 | autoreconf -f -i -v # only if building from git 72 | ./configure MAKE=mingw32-make 73 | mingw32-make 74 | 75 | Package contents 76 | ================ 77 | 78 | On UNIX-like systems, the dcaenc package contains the libdcaenc.so shared 79 | library, the corresponding dcaenc.h header, the dcaenc command line tool, 80 | and (optionally, on Linux only) the ALSA plugin. 81 | 82 | On Windows, you only get the command-line tool, even if you use the forked 83 | version. 84 | 85 | The libdcaenc library 86 | ===================== 87 | 88 | The library may be useful if you want to create DTS streams in your own 89 | UNIX application. 90 | 91 | To do so, you have to call the following functions: 92 | 93 | dcaenc_context dcaenc_create( 94 | int sample_rate, 95 | int channel_config, 96 | int approx_bitrate, 97 | int flags); 98 | 99 | This function creates a library context according to its parameters. The 100 | resulting context is an opaque value that should be passed to the other library 101 | functions as the first parameter. 102 | 103 | The sample rate must be one of the following values: 32000, 44100, 48000 or 104 | those divided by 2 or 4. The channel configuration is one of the 105 | DCAENC_CHANNELS_* defines listed in the dcaenc.h header. Note that values 106 | greater than DCAENC_CHANNELS_3FRONT_2REAR always return an error now because 107 | their encoding requires the XCH/XXCH extensions that became documented only in 108 | September 2011 and thus were not implemented. Only non-LFE channels have to be 109 | specified here. The approximate bitrate is specified in bits per second and 110 | may be rounded slightly up or down by the library. 111 | 112 | The flags parameter should be a logical OR of zero or more of the 113 | DCAENC_FLAG_* defines. Their meanings: 114 | 115 | DCAENC_FLAG_28BIT: use only 28 out of 32 bits in each four bytes of output. 116 | This may be useful if the loudness of the hiss resulting from 117 | mis-interpretation of the encoded stream as PCM must be reduced. However, 118 | this also results in the reduction of the effective bitrate by 12.5%. DTS 119 | CDs are usually encoded with this option. 120 | 121 | DCAENC_FLAG_BIGENDIAN: produce a big-endian variant of the DTS bitstream. 122 | This may be useful for writing the stream as a DVD sound track. 123 | 124 | DCAENC_FLAG_LFE: indicates that a separate LFE channel has to be added to the 125 | layout indicated by the channel_config parameter. 126 | 127 | DCAENC_FLAG_PERFECT_QMF: selects a "perfect-reconstruction" version of the 128 | quadrature mirror filter. This reduces distortions inherent in the filterbank 129 | design, but makes the filter output more sensitive to quantization errors 130 | introduced later in the encoder. libdca version 0.0.5 or earlier will not be 131 | able to decode the resulting stream correctly due to a bug (mistyped table) 132 | in it. It makes no sense to use this option for streams with bitrate of 133 | 0.3 Mbps per channel or less. 134 | 135 | DCAENC_FLAG_IEC_WRAP: wraps DTS frames as defined by the IEC 61937-5 standard 136 | for transmission over SPDIF. Namely, the library adds a 8-byte header to each 137 | frame and pads the frame with zeroes to achieve the same bitrate as a stereo 138 | 16-bit PCM stream. 139 | 140 | On any error, dcaenc_create() returns NULL. There is no way to find out the 141 | reason for the error. 142 | 143 | int dcaenc_channel_config_to_count(int channel_config); 144 | 145 | Returns the number of channels used in a given channel configuration, or -1 146 | if the channel configuration is invalid or unsupported. 147 | 148 | int dcaenc_bitrate(dcaenc_context c); 149 | 150 | Returns the actual bitrate that is used by the library. 151 | 152 | int dcaenc_input_size(dcaenc_context c); 153 | 154 | Returns the size of the input buffer that your application has to submit, in 155 | samples. Now this value is always equal to 512. 156 | 157 | int dcaenc_output_size(dcaenc_context c); 158 | 159 | Returns the size of the output buffer that the application should provide, 160 | in bytes. 161 | 162 | int dcaenc_convert_s32( 163 | dcaenc_context c, 164 | const int32_t *input, 165 | uint8_t *output); 166 | 167 | Performs the conversion of PCM samples stored in the input buffer to the 168 | DTS bitstream, stores one frame of the encoded bitstream in the output buffer. 169 | The input buffer should contain interleaved signed 32-bit samples. The channel 170 | order is as follows: 171 | 172 | DCAENC_CHANNELS_MONO: center 173 | DCAENC_CHANNELS_STEREO: left, right 174 | DCAENC_CHANNELS_3FRONT: center, left, right 175 | DCAENC_CHANNELS_2FRONT_1REAR: left, right, surround 176 | DCAENC_CHANNELS_3FRONT_1REAR: center, left, right, surround 177 | DCAENC_CHANNELS_2FRONT_2REAR: left, right, surround left, surround right 178 | DCAENC_CHANNELS_3FRONT_2REAR: center, left, right, surround left, surround right 179 | 180 | If the LFE channel is used, it should be added as the last one. 181 | 182 | The following layouts are also defined and do not return an error while 183 | encoding, but do not result in a high-quality bitstream due to incompatibility 184 | with the psychoacoustical model used by the library: 185 | 186 | DCAENC_CHANNELS_DUAL_MONO: A, B 187 | DCAENC_CHANNELS_STEREO_SUMDIFF: left+right, left-right 188 | DCAENC_CHANNELS_STEREO_TOTAL: left total, right total 189 | 190 | Unfortunately, there is currently no API to query the order of channels by the 191 | channel layout. This is because it is unclear what functionality related to 192 | channel mapping should be exposed. E.g., should speaker IDs compatible 193 | with ksmedia.h (as used in Windows and in WAVEFORMATEXTENSIBLE wav files) be 194 | used, even though a mapping between these speaker IDs and the positions used 195 | in the DTS specification is in some cases only approximate (e.g., there is no 196 | "Surround Left 2" speaker in ksmedia.h). Please mail your suggestions 197 | regarding this API to patrakov@gmail.com. 198 | 199 | dcaenc_convert_s32() returns the number of bytes written to the output buffer. 200 | Right now, it is always the same as returned by dcaenc_output_size(), but 201 | this will change if variable bitrate encoding is added to the library. 202 | 203 | int dcaenc_destroy(dcaenc_context c, uint8_t *output); 204 | 205 | Destroys the library context. If a non-NULL value is provided in the output 206 | parameter, the library encodes the final frame and puts it there. This may be 207 | useful because there is a 512-sample latency inherent in the DTS filterbank, 208 | so the output frame gets the last portion of the PCM input submitted earlier. 209 | The returned value indicates the number of bytes written to the output buffer. 210 | 211 | The command-line application 212 | ============================ 213 | 214 | The dcaenc command line utility converts multichannel wav files to DTS. The 215 | resulting DTS files can be written to an audio CD and played via a digital 216 | connection (SPDIF or HDMI) to a receiver, or, after changing the endianness, 217 | used as sound tracks for a DVD. Currently there are no options to select 218 | 28-bit encoding or change the endianness. This is a bug. 219 | 220 | Usage: 221 | 222 | dcaenc input.wav output.dts bitrate 223 | 224 | The input wav file should have the same channel order as defined by SMPTE, 225 | i.e.: left, right, center, lfe, surround left, surround right. 226 | 227 | Some destinations require a specific bitrate to be specified. To create a 228 | CD-compatible DTS file from a multichannel file (that needs to have the sample 229 | rate of 44100 Hz and either 16 or 32 bits per sample), run: 230 | 231 | dcaenc input.wav output.dts 1411200 232 | 233 | To create a DVD-compatible track from a multichannel wav file that has the 234 | 48 kHz sample rate: 235 | 236 | dcaenc input.wav output.dts 1509000 237 | 238 | or for a half-rate output: 239 | 240 | dcaenc input.wav output.dts 754500 241 | 242 | and then byte-swap the resulting output.dts file. Mux it with your MPEG2 video 243 | track using the "mplex" tool from the mjpeg-tools package. 244 | 245 | Known bug: wav files with floating-point samples are misinterpreted as 246 | containing 32-bit integer samples. 247 | 248 | ALSA Plugin 249 | =========== 250 | 251 | The ALSA plugin may be useful for playing multichannel sound from arbitrary 252 | ALSA applications through an SPDIF link. This is needed because the SPDIF 253 | link cannot carry enough bits per second to transport the raw uncompressed 254 | 5.1 audio. 255 | 256 | The "alsa-plugins" package contains a similar plugin for on-the-fly AC3 257 | encoding. 258 | 259 | The plugin should normally not be used with HDMI connections, because the 260 | HDMI standard defines enough bandwidth so that the uncompressed 5.1 PCM 261 | stream fits even at 192 kHz sample rate. So, attempting to encode that into 262 | DTS in the majority of cases is only a waste of CPU time and sound quality. 263 | There are, however, at least two valid use cases. 264 | 265 | 1. Radeon HD 6xxx video cards with open-source driver do not support more 266 | than two channels of PCM audio over HDMI. Encoding the output to DTS 267 | provides a useful workaround to the lack of multichannel capability in 268 | the driver. 269 | 270 | 2. Some soundbars are supposed to get the audio signal from the TV via the 271 | optical cable, while the TV itself is connected to the computer using 272 | HDMI. 273 | 274 | If you know another valid use case, please send an e-mail to 275 | patrakov@gmail.com. 276 | 277 | The ALSA plugin should work in real time on any modern CPU. Here on Intel 278 | Core i5 @ 1.20 GHz (i.e. in powersaving mode) it eats ~40% of a single core. 279 | 280 | To use the ALSA plugin, add the following line to your $HOME/.asoundrc 281 | file or to /etc/asound.conf: 282 | 283 | 284 | 285 | It will create an additional ALSA device for each of your sound cards that 286 | have an SPDIF output. The name of the device will be similar to 287 | "dca:CARD=Intel,DEV=0", or, for the default card, simply "dca". There are 288 | also devices that encode to HDMI outputs, they have names like 289 | "dcahdmi:CARD=Intel,DEV=0". 290 | 291 | If you want to encode DTS and send it to something that is not SPDIF or HDMI, 292 | add a snippet similar to the following: 293 | 294 | pcm.dcacustom { 295 | type dca 296 | slave.pcm "custompcm" 297 | # if your receiver requires it: 298 | # iec61937 1 299 | } 300 | 301 | Unlike the AC3 encoder, there is no bitrate configuration. This is because 302 | it does not make sense to have it. The hard-coded default (same bitrate as 303 | stereo PCM, all bits used) provides the best possible quality and should work 304 | for everyone. But it doesn't work with receivers that require IEC61937-5 305 | wrapping of the DTS frames, that's why the "iec61937" option exists, which 306 | can be set to 1 for such receivers. 307 | 308 | To direct mplayer output to the default card via the encoder: 309 | 310 | mplayer -channels 6 -ao alsa:device=dca file.flac 311 | 312 | It is not possible to use dmix on top of the encoder. This is a limitation 313 | of dmix: it only works on direct hardware devices providing mmap, and the 314 | dca plugin is not a hardware device and provides (non-working) mmap only due 315 | to what seems to be at least partially an ALSA bug. Please use PulseAudio 316 | instead. 317 | 318 | Known bug: the ALSA plugin doesn't report the supported sample rates correctly 319 | and pretends to support mmap. Fixing this requires rewriting the plugin from 320 | the extplug infrastructure to ioplug, or talking to ALSA developers. So you 321 | may need to add one of the following flags to mplayer command line: 322 | 323 | -af resample=44100 324 | -af resample=48000 325 | 326 | Use with PulseAudio 327 | =================== 328 | 329 | The ALSA plugin can be used with PulseAudio. To do so, add the following lines 330 | to the end of the /usr/share/pulseaudio/alsa-mixer/profile-sets/default.conf 331 | file: 332 | 333 | [Mapping iec958-dts-surround-51] 334 | device-strings = dca:%f 335 | channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe 336 | paths-output = iec958-stereo-output 337 | priority = 3 338 | direction = output 339 | 340 | [Mapping hdmi-dts-surround-51] 341 | device-strings = dcahdmi:%f 342 | channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe 343 | paths-output = hdmi-output-0 344 | priority = 1 345 | direction = output 346 | 347 | Newer and/or patched versions of PulseAudio use the 348 | /usr/share/pulseaudio/alsa-mixer/profile-sets/extra-hdmi.conf file instead 349 | for Intel and NVidia sound cards. If that file exists, add the above lines 350 | there, too, adjusting if needed for multiple HDMI outputs. 351 | 352 | Note that the iec958-dts-surround-51 part of the above is already provided 353 | by PulseAudio 3.0 or later. 354 | 355 | After restarting PulseAudio, it will see additional output profiles having 356 | "DTS" in their names and will allow you to select them in the volume control 357 | application such as pavucontrol or gnome-volume-control. 358 | 359 | Compatibility 360 | ============= 361 | 362 | The author has an LG 47LM640T TV that can decode DTS on HDMI inputs. It works. 363 | He also tests the encoder by decoding its output with ffmpeg, libdca or 364 | ArcSoft DTS decoder (the same engine as used in WinDVD). 365 | 366 | The ALSA plugin has been tested and found to work with the following receivers 367 | by other people: 368 | 369 | Logitech Z5500 370 | JVC TH-A25 371 | Samsung HT-Z310 372 | Sony STR-DB780 373 | 374 | Some receivers (including JVC TH-A25 and Sony STR-DB780) mute their outputs 375 | when receiving full 32-bit DTS stream (as generated by the ALSA plugin) over 376 | SPDIF with AES0=6 (the default for the "dca" and "dcahdmi" families of ALSA 377 | devices). To overcome this problem, add the following line to the end 378 | of .asoundrc: 379 | 380 | defaults.pcm.dca.aes0 0x04 381 | 382 | However, it can cause your receiver to unmute its output even if it does 383 | not support DTS streams or does not detect them reliably. This will result 384 | in very loud hiss that can damage the loudspeakers. So try this setting with 385 | the lowest possible volume, and this is why it is not the default. 386 | 387 | Similar settings exist for AES1, AES2 and AES3 SPDIF parameters. 388 | 389 | Some other receivers (including the LG 47LM640T TV) need not raw DTS frames, 390 | but DTS frames wrapped according to IEC61937-5, and either mute the output 391 | or produce loud hiss otherwise. For such receivers, add the following line to 392 | the end of .asoundrc: 393 | 394 | defaults.pcm.dca.iec61937 1 395 | 396 | This could not be made the default, because other receivers (such as Sony 397 | STR-DB780) reject DTS frames wrapped into IEC61937-5. 398 | 399 | Quality 400 | ======= 401 | 402 | There are debates on the Internet about the relative quality of AC3 vs DTS. 403 | AC3 uses more advanced compression algorithms, DTS allows for higher bit rates. 404 | There were no blind tests comparing the output of the encoder with anything 405 | else. However, this encoder uses only the most basic compression techniques 406 | defined in the DTS specification, and thus cannot win any comparison with 407 | commercial DTS encoders. Still, at 754 kbps, the internal psychoacoustical 408 | model considers the distortions to be just below the threshold of detection by 409 | human ears. 410 | 411 | How to report bugs 412 | ================== 413 | 414 | Bugs should be reported by email to patrakov@gmail.com, preferrably with a 415 | short (< 10 seconds) flac sample that demonstrates the problem, and a patch 416 | that fixes it. 417 | 418 | Thanks 419 | ====== 420 | 421 | The following people helped me to test the encoder (including the versions that 422 | did not work): 423 | 424 | Arun Raghavan 425 | Colin Guthrie 426 | Mikhail Elovskikh 427 | cryptonymous from the linux.org.ru forum 428 | rulet from the linux.org.ru forum 429 | Steven Newbury 430 | 431 | The following people contributed useful information: 432 | 433 | Adam Thomas-Murphy 434 | 435 | The following people reported bugs: 436 | 437 | LoRd_MuldeR from https://gitorious.org/~mulder 438 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | 505 | -------------------------------------------------------------------------------- /dcaenc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include "config.h" 24 | #include "dcaenc.h" 25 | #include "dcaenc_private.h" 26 | #include "int_data.h" 27 | #include "math_tables.h" 28 | 29 | #define max(a, b) (((a) > (b)) ? (a) : (b)) 30 | #define min(a, b) (((a) < (b)) ? (a) : (b)) 31 | #define div_round_up(a, b) (((a) + (b) - 1) / (b)) 32 | #define round_up(a, b) ((((a) + (b) - 1) / (b)) * (b)) 33 | 34 | int dcaenc_channel_config_to_count(int channel_config) 35 | { 36 | if (channel_config > DCAENC_CHANNELS_3FRONT_2REAR) 37 | return -1; 38 | 39 | if (channel_config < 0) 40 | return -1; 41 | 42 | return channels_table[channel_config]; 43 | } 44 | 45 | dcaenc_context dcaenc_create(int sample_rate, int channel_config, 46 | int approx_bitrate, int flags) 47 | { 48 | int i, frame_bits, bit_step, fir, useful_bitrate, min_frame_bits; 49 | dcaenc_context result; 50 | 51 | i = 0; 52 | while (i < 9 && sample_rate != sample_rates[i]) 53 | i++; 54 | if (i == 9) 55 | return NULL; 56 | 57 | if (approx_bitrate < 32000) 58 | return NULL; 59 | if (approx_bitrate > 6144000) 60 | return NULL; 61 | 62 | if (channel_config < 0) 63 | return NULL; 64 | if (channel_config > DCAENC_CHANNELS_3FRONT_2REAR) 65 | return NULL; 66 | 67 | 68 | if (flags & DCAENC_FLAG_28BIT) 69 | useful_bitrate = div_round_up(approx_bitrate * 7, 8); 70 | else 71 | useful_bitrate = approx_bitrate; 72 | 73 | frame_bits = div_round_up(useful_bitrate * 512, sample_rate); 74 | 75 | bit_step = (flags & DCAENC_FLAG_28BIT) ? (7 * 32) : 32; 76 | fir = (flags & DCAENC_FLAG_PERFECT_QMF) ? 0 : 1; 77 | /* Round frame_bits up to the next permitted value */ 78 | frame_bits = round_up(frame_bits, bit_step); 79 | 80 | min_frame_bits = 132 + (493 + 28 * 32) * channels_table[channel_config]; 81 | if (flags & DCAENC_FLAG_LFE) 82 | min_frame_bits += 72; 83 | 84 | if (frame_bits < min_frame_bits) 85 | return NULL; 86 | 87 | if (frame_bits > 131072) 88 | return NULL; 89 | 90 | if ((flags & DCAENC_FLAG_IEC_WRAP) && frame_bits > 16320) 91 | return NULL; 92 | 93 | result = (dcaenc_context)calloc(1, sizeof(struct dcaenc_context_s)); 94 | if (!result) 95 | return NULL; 96 | 97 | result->samplerate_index = i; 98 | result->frame_bits = frame_bits; 99 | result->channel_config = channel_config; 100 | result->flags = flags; 101 | result->channels = result->fullband_channels = channels_table[channel_config]; 102 | if (flags & DCAENC_FLAG_LFE) 103 | result->channels++; 104 | 105 | 106 | for (i = 0; target_bitrate_table[i] < approx_bitrate; i++) 107 | ; 108 | result->bitrate_index = i; 109 | result->band_interpolation = band_interpolation[fir]; 110 | result->band_spectrum = band_spectrum[fir]; 111 | result->worst_quantization_noise = -2047; 112 | result->worst_noise_ever = -2047; 113 | return result; 114 | } 115 | 116 | int dcaenc_input_size(dcaenc_context c) 117 | { 118 | return 512; 119 | } 120 | 121 | int dcaenc_output_size(dcaenc_context c) 122 | { 123 | if (c->flags & DCAENC_FLAG_IEC_WRAP) 124 | return 2048; 125 | return c->frame_bits / ((c->flags & DCAENC_FLAG_28BIT) ? 7 : 8); 126 | } 127 | 128 | static inline const int32_t *pcm_sample(dcaenc_context c, 129 | const int32_t *container, 130 | int sample, int channel) 131 | { 132 | return &container[sample * c->channels + channel]; 133 | } 134 | 135 | static inline int32_t half32(int32_t a) 136 | { 137 | return (a + 1) >> 1; 138 | } 139 | 140 | static inline int32_t mul32(int32_t a, int32_t b) 141 | { 142 | int64_t r = (int64_t)a * b + 0x80000000ULL; 143 | return r >> 32; 144 | } 145 | 146 | static void dcaenc_subband_transform(dcaenc_context c, const int32_t *input) 147 | { 148 | int ch, subs, i, k, j; 149 | 150 | for (ch = 0; ch < c->fullband_channels; ch++) { 151 | /* History is copied because it is also needed for PSY */ 152 | int32_t hist[512]; 153 | int hist_start = 0; 154 | 155 | for (i = 0; i < 512; i++) 156 | hist[i] = c->pcm_history[i][ch]; 157 | 158 | for (subs = 0; subs < DCAENC_SUBBAND_SAMPLES; subs++) { 159 | int32_t accum[64]; 160 | int32_t resp; 161 | int band; 162 | 163 | /* Calculate the convolutions at once */ 164 | for (i = 0; i < 64; i++) 165 | accum[i] = 0; 166 | 167 | for (k = 0, i = hist_start, j = 0; 168 | i < 512; k = (k + 1) & 63, i++, j++) 169 | accum[k] += mul32(hist[i], c->band_interpolation[j]); 170 | for (i = 0; i < hist_start; k = (k + 1) & 63, i++, j++) 171 | accum[k] += mul32(hist[i], c->band_interpolation[j]); 172 | 173 | for (k = 16; k < 32; k++) 174 | accum[k] = accum[k] - accum[31 - k]; 175 | for (k = 32; k < 48; k++) 176 | accum[k] = accum[k] + accum[95 - k]; 177 | 178 | for (band = 0; band < 32; band++) { 179 | resp = 0; 180 | for (i = 16; i < 48; i++) { 181 | int s = (2 * band + 1) * (2 * (i + 16) + 1); 182 | resp += mul32(accum[i], cos_t(s << 3)) >> 3; 183 | } 184 | 185 | c->subband_samples[subs][band][ch] = ((band + 1) & 2) ? 186 | (-resp) : resp; 187 | } 188 | 189 | /* Copy in 32 new samples from input */ 190 | for (i = 0; i < 32; i++) 191 | hist[i + hist_start] = *pcm_sample(c, input, subs * 32 + i, ch); 192 | 193 | hist_start = (hist_start + 32) & 511; 194 | } 195 | } 196 | } 197 | 198 | static void dcaenc_lfe_downsample(dcaenc_context c, const int32_t *input) 199 | { 200 | /* FIXME: make 128x LFE downsampling possible */ 201 | int i, j, lfes; 202 | 203 | int32_t hist[512]; 204 | int32_t accum; 205 | int hist_start = 0; 206 | 207 | for (i = 0; i < 512; i++) 208 | hist[i] = c->pcm_history[i][c->channels - 1]; 209 | 210 | for (lfes = 0; lfes < DCAENC_LFE_SAMPLES; lfes++) { 211 | /* Calculate the convolution */ 212 | accum = 0; 213 | 214 | for (i = hist_start, j = 0; i < 512; i++, j++) 215 | accum += mul32(hist[i], lfe_fir[j]); 216 | for (i = 0; i < hist_start; i++, j++) 217 | accum += mul32(hist[i], lfe_fir[j]); 218 | 219 | c->downsampled_lfe[lfes] = accum; 220 | 221 | /* Copy in 64 new samples from input */ 222 | for (i = 0; i < 64; i++) 223 | hist[i + hist_start] = *pcm_sample(c, input, 224 | lfes * 64 + i, c->channels - 1); 225 | 226 | hist_start = (hist_start + 64) & 511; 227 | } 228 | } 229 | 230 | typedef struct { 231 | int32_t re; 232 | int32_t im; 233 | } cplx32; 234 | 235 | static void fft(const int32_t in[2 * 256], cplx32 out[256]) 236 | { 237 | cplx32 buf[256], rin[256], rout[256]; 238 | int i, j, k, l; 239 | 240 | /* do two transforms in parallel */ 241 | for (i = 0; i < 256; i++) { 242 | /* Apply the Hann window */ 243 | rin[i].re = mul32(in[2 * i], 0x3fffffff - (cos_t(8 * i + 2) >> 1)); 244 | rin[i].im = mul32(in[2 * i + 1], 0x3fffffff - (cos_t(8 * i + 6) >> 1)); 245 | } 246 | /* pre-rotation */ 247 | for (i = 0; i < 256; i++) { 248 | buf[i].re = mul32(cos_t(4 * i + 2), rin[i].re) 249 | - mul32(sin_t(4 * i + 2), rin[i].im); 250 | buf[i].im = mul32(cos_t(4 * i + 2), rin[i].im) 251 | + mul32(sin_t(4 * i + 2), rin[i].re); 252 | } 253 | 254 | for (j = 256, l = 1; j != 1; j >>= 1, l <<= 1) 255 | for (k = 0; k < 256; k += j) 256 | for (i = k; i < k + j / 2; i++) { 257 | cplx32 sum, diff; 258 | 259 | int t = 8 * l * i; 260 | 261 | sum.re = buf[i].re + buf[i + j / 2].re; 262 | sum.im = buf[i].im + buf[i + j / 2].im; 263 | 264 | diff.re = buf[i].re - buf[i + j / 2].re; 265 | diff.im = buf[i].im - buf[i + j / 2].im; 266 | 267 | buf[i].re = half32(sum.re); 268 | buf[i].im = half32(sum.im); 269 | 270 | buf[i + j / 2].re = mul32(diff.re, cos_t(t)) 271 | - mul32(diff.im, sin_t(t)); 272 | buf[i + j / 2].im = mul32(diff.im, cos_t(t)) 273 | + mul32(diff.re, sin_t(t)); 274 | } 275 | /* post-rotation */ 276 | for (i = 0; i < 256; i++) { 277 | int b = bitrev[i]; 278 | rout[i].re = mul32(buf[b].re, cos_t(4 * i)) 279 | - mul32(buf[b].im, sin_t(4 * i)); 280 | rout[i].im = mul32(buf[b].im, cos_t(4 * i)) 281 | + mul32(buf[b].re, sin_t(4 * i)); 282 | } 283 | 284 | for (i = 0; i < 256; i++) { 285 | /* separate the results of the two transforms */ 286 | cplx32 o1, o2; 287 | 288 | o1.re = rout[i].re - rout[255 - i].re; 289 | o1.im = rout[i].im + rout[255 - i].im; 290 | 291 | o2.re = rout[i].im - rout[255 - i].im; 292 | o2.im = -rout[i].re - rout[255 - i].re; 293 | 294 | /* combine them into one long transform */ 295 | out[i].re = mul32(o1.re + o2.re, cos_t(2 * i + 1)) 296 | + mul32(o1.im - o2.im, sin_t(2 * i + 1)); 297 | out[i].im = mul32(o1.im + o2.im, cos_t(2 * i + 1)) 298 | + mul32(-o1.re + o2.re, sin_t(2 * i + 1)); 299 | } 300 | } 301 | 302 | /* in: anything, result: between -2047 and 0 */ 303 | static int32_t get_cb(int32_t in) 304 | { 305 | int i, res; 306 | res = 0; 307 | if (in < 0) 308 | in = -in; 309 | for (i = 1024; i > 0; i >>= 1) { 310 | if (cb_to_level[i + res] >= in) 311 | res += i; 312 | } 313 | return -res; 314 | } 315 | 316 | /* accepts any input, gives no guarantees about the range of the result, 317 | except that result >= a && result >= b */ 318 | static int32_t add_cb(int32_t a, int32_t b) 319 | { 320 | if (a < b) { 321 | int32_t tmp = a; 322 | a = b; 323 | b = tmp; 324 | } 325 | if (a - b >= 256) 326 | return a; 327 | 328 | return a + cb_to_add[a - b]; 329 | } 330 | 331 | /* accepts anything, out_cb[i] can only grow */ 332 | static void adjust_jnd(int samplerate_index, 333 | const int32_t in[512], int32_t out_cb[256]) 334 | { 335 | int i, j; 336 | int32_t power[256]; 337 | cplx32 out[256]; 338 | int32_t out_cb_unnorm[256]; 339 | int32_t denom; 340 | const int32_t ca_cb = -1114; 341 | const int32_t cs_cb = 928; 342 | 343 | fft(in, out); 344 | 345 | for (j = 0; j < 256; j++) { 346 | power[j] = add_cb(get_cb(out[j].re), get_cb(out[j].im)); 347 | out_cb_unnorm[j] = -2047; /* and can only grow */ 348 | } 349 | 350 | for (i = 0; i < AUBANDS; i++) { 351 | denom = ca_cb; /* and can only grow */ 352 | for (j = 0; j < 256; j++) 353 | denom = add_cb(denom, power[j] + auf[samplerate_index][i][j]); 354 | for (j = 0; j < 256; j++) 355 | out_cb_unnorm[j] = add_cb(out_cb_unnorm[j], 356 | -denom + auf[samplerate_index][i][j]); 357 | } 358 | 359 | for (j = 0; j < 256; j++) 360 | out_cb[j] = add_cb(out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb); 361 | } 362 | 363 | 364 | typedef void (*walk_band_t)(dcaenc_context c, int band1, int band2, int f, 365 | int32_t spectrum1, int32_t spectrum2, int channel, 366 | int32_t * arg); 367 | 368 | static void walk_band_low(dcaenc_context c, int band, int channel, 369 | walk_band_t walk, int32_t * arg) 370 | { 371 | int f; 372 | if (band == 0) { 373 | for (f = 0; f < 4; f++) 374 | walk(c, 0, 0, f, 0, -2047, channel, arg); 375 | } else { 376 | for (f = 0; f < 8; f++) 377 | walk(c, band, band - 1, 8 * band - 4 + f, 378 | c->band_spectrum[7 - f], c->band_spectrum[f], channel, arg); 379 | } 380 | } 381 | 382 | static void walk_band_high(dcaenc_context c, int band, int channel, 383 | walk_band_t walk, int32_t * arg) 384 | { 385 | int f; 386 | if (band == 31) { 387 | for (f = 0; f < 4; f++) 388 | walk(c, 31, 31, 256 - 4 + f, 0, -2047, channel, arg); 389 | } else { 390 | for (f = 0; f < 8; f++) 391 | walk(c, band, band + 1, 8 * band + 4 + f, 392 | c->band_spectrum[f], c->band_spectrum[7 - f], channel, arg); 393 | } 394 | } 395 | 396 | static void walk_whole_spectrum(dcaenc_context c, int channel, 397 | walk_band_t walk, int32_t * arg) 398 | { 399 | int band; 400 | for (band = 0; band < 32; band++) 401 | walk_band_low(c, band, channel, walk, arg); 402 | walk_band_high(c, 31, channel, walk, arg); 403 | } 404 | 405 | static void update_band_masking(dcaenc_context c, int band1, int band2, 406 | int f, int32_t spectrum1, int32_t spectrum2, 407 | int channel, int32_t * arg) 408 | { 409 | int32_t value = c->eff_masking_curve_cb[f] - spectrum1; 410 | if (value < c->band_masking_cb[band1]) 411 | c->band_masking_cb[band1] = value; 412 | } 413 | 414 | static void dcaenc_calc_masking(dcaenc_context c, const int32_t *input) 415 | { 416 | int i, k, band, ch, ssf; 417 | int32_t data[512]; 418 | 419 | for (i = 0; i < 256; i++) 420 | for (ssf = 0; ssf < DCAENC_SUBSUBFRAMES; ssf++) 421 | c->masking_curve_cb[ssf][i] = -2047; 422 | 423 | for (ssf = 0; ssf < DCAENC_SUBSUBFRAMES; ssf++) 424 | for (ch = 0; ch < c->fullband_channels; ch++) { 425 | for (i = 0, k = 128 + 256 * ssf; k < 512; i++, k++) 426 | data[i] = c->pcm_history[k][ch]; 427 | for (k -= 512; i < 512; i++, k++) 428 | data[i] = *pcm_sample(c, input, k, ch); 429 | adjust_jnd(c->samplerate_index, data, c->masking_curve_cb[ssf]); 430 | } 431 | for (i = 0; i < 256; i++) { 432 | int32_t m = 2048; 433 | for (ssf = 0; ssf < DCAENC_SUBSUBFRAMES; ssf++) 434 | if (c->masking_curve_cb[ssf][i] < m) 435 | m = c->masking_curve_cb[ssf][i]; 436 | c->eff_masking_curve_cb[i] = m; 437 | } 438 | 439 | for (band = 0; band < 32; band++) { 440 | c->band_masking_cb[band] = 2048; 441 | walk_band_low(c, band, 0, update_band_masking, NULL); 442 | walk_band_high(c, band, 0, update_band_masking, NULL); 443 | } 444 | } 445 | 446 | static void dcaenc_find_peaks(dcaenc_context c) 447 | { 448 | int band, ch; 449 | 450 | for (band = 0; band < 32; band++) 451 | for (ch = 0; ch < c->fullband_channels; ch++) { 452 | int sample; 453 | int32_t m = 0; 454 | for (sample = 0; sample < DCAENC_SUBBAND_SAMPLES; sample++) { 455 | int32_t s = abs(c->subband_samples[sample][band][ch]); 456 | if (m < s) 457 | m = s; 458 | } 459 | c->peak_cb[band][ch] = get_cb(m); 460 | } 461 | 462 | if (c->flags & DCAENC_FLAG_LFE) { 463 | int sample; 464 | int32_t m = 0; 465 | for (sample = 0; sample < DCAENC_LFE_SAMPLES; sample++) 466 | if (m < abs(c->downsampled_lfe[sample])) 467 | m = abs(c->downsampled_lfe[sample]); 468 | c->lfe_peak_cb = get_cb(m); 469 | } 470 | } 471 | 472 | static const int snr_fudge = 128; 473 | static const int USED_1ABITS = 1; 474 | static const int USED_NABITS = 2; 475 | static const int USED_26ABITS = 4; 476 | 477 | static int init_quantization_noise(dcaenc_context c, int noise) 478 | { 479 | int ch, band; 480 | int ret = 0; 481 | 482 | c->consumed_bits = 132 + 493 * c->fullband_channels; 483 | if (c->flags & DCAENC_FLAG_LFE) 484 | c->consumed_bits += 72; 485 | 486 | if (c->flags & DCAENC_FLAG_IEC_WRAP) 487 | c->consumed_bits += (c->flags & DCAENC_FLAG_28BIT) ? 56 : 64; 488 | 489 | /* attempt to guess the bit distribution based on the prevoius frame */ 490 | for (ch = 0; ch < c->fullband_channels; ch++) { 491 | for (band = 0; band < 32; band++) { 492 | int snr_cb = c->peak_cb[band][ch] 493 | - c->band_masking_cb[band] 494 | - noise; 495 | 496 | if (snr_cb >= 1312) { 497 | c->abits[band][ch] = 26; 498 | ret |= USED_26ABITS; 499 | } else if (snr_cb >= 222) { 500 | c->abits[band][ch] = 8 + mul32(snr_cb - 222, 69000000); 501 | ret |= USED_NABITS; 502 | } else if (snr_cb >= 0) { 503 | c->abits[band][ch] = 2 + mul32(snr_cb, 106000000); 504 | ret |= USED_NABITS; 505 | } else { 506 | c->abits[band][ch] = 1; 507 | ret |= USED_1ABITS; 508 | } 509 | } 510 | } 511 | 512 | for (band = 0; band < 32; band++) 513 | for (ch = 0; ch < c->fullband_channels; ch++) { 514 | c->consumed_bits += bit_consumption[c->abits[band][ch]]; 515 | } 516 | 517 | return ret; 518 | } 519 | 520 | static void dcaenc_assign_bits(dcaenc_context c) 521 | { 522 | /* Find the bounds where the binary search should work */ 523 | int low, high, down; 524 | int used_abits = 0; 525 | init_quantization_noise(c, c->worst_quantization_noise); 526 | low = high = c->worst_quantization_noise; 527 | if (c->consumed_bits > c->frame_bits) { 528 | while (c->consumed_bits > c->frame_bits) { 529 | assert(("Too low bitrate should have been rejected in dcaenc_create", used_abits != USED_1ABITS)); 530 | low = high; 531 | high += snr_fudge; 532 | used_abits = init_quantization_noise(c, high); 533 | } 534 | } else { 535 | while (c->consumed_bits <= c->frame_bits) { 536 | high = low; 537 | if (used_abits == USED_26ABITS) 538 | goto out; /* The requested bitrate is too high, pad with zeros */ 539 | low -= snr_fudge; 540 | used_abits = init_quantization_noise(c, low); 541 | } 542 | } 543 | 544 | /* Now do a binary search between low and high to see what fits */ 545 | for (down = snr_fudge >> 1; down; down >>= 1) { 546 | init_quantization_noise(c, high - down); 547 | if (c->consumed_bits <= c->frame_bits) 548 | high -= down; 549 | } 550 | init_quantization_noise(c, high); 551 | out: 552 | c->worst_quantization_noise = high; 553 | if (high > c->worst_noise_ever) 554 | c->worst_noise_ever = high; 555 | } 556 | 557 | static void dcaenc_shift_history(dcaenc_context c, const int32_t *input) 558 | { 559 | int k, ch; 560 | 561 | for (k = 0; k < 512; k++) 562 | for (ch = 0; ch < c->channels; ch++) 563 | c->pcm_history[k][ch] = *pcm_sample(c, input, k, ch); 564 | } 565 | 566 | static void bitstream_init(dcaenc_context c, uint8_t *output) 567 | { 568 | c->word = 0; 569 | c->wbits = 0; 570 | c->output = output; 571 | c->wrote = 0; 572 | } 573 | 574 | static void bitstream_put(dcaenc_context c, uint32_t bits, int nbits) 575 | { 576 | int max_bits = (c->flags & DCAENC_FLAG_28BIT) ? 28 : 32; 577 | assert(bits < (1 << nbits)); 578 | c->wrote += nbits; 579 | bits &= ~(0xffffffff << nbits); 580 | if (nbits + c->wbits >= max_bits) { 581 | uint8_t b1, b2, b3, b4; 582 | c->word |= bits >> (nbits + c->wbits - max_bits); 583 | if (c->flags & DCAENC_FLAG_28BIT) { 584 | b1 = (c->word >> 22) & 0x3f; 585 | if (b1 & 0x20) 586 | b1 |= 0xc0; 587 | b2 = (c->word >> 14) & 0xff; 588 | b3 = (c->word >> 8) & 0x3f; 589 | if (b3 & 0x20) 590 | b3 |= 0xc0; 591 | b4 = (c->word) & 0xff; 592 | } else { 593 | b1 = (c->word >> 24) & 0xff; 594 | b2 = (c->word >> 16) & 0xff; 595 | b3 = (c->word >> 8) & 0xff; 596 | b4 = (c->word) & 0xff; 597 | } 598 | if (c->flags & DCAENC_FLAG_BIGENDIAN) { 599 | *(c->output++) = b1; 600 | *(c->output++) = b2; 601 | *(c->output++) = b3; 602 | *(c->output++) = b4; 603 | } else { 604 | *(c->output++) = b2; 605 | *(c->output++) = b1; 606 | *(c->output++) = b4; 607 | *(c->output++) = b3; 608 | } 609 | c->wbits = nbits + c->wbits - max_bits; 610 | if (c->wbits) 611 | c->word = (bits << (32 - c->wbits)) >> (32 - max_bits); 612 | else 613 | c->word = 0; 614 | } else { 615 | c->word |= bits << (max_bits - nbits - c->wbits); 616 | c->wbits += nbits; 617 | } 618 | } 619 | 620 | static void bitstream_flush(dcaenc_context c) 621 | { 622 | int max_bits = (c->flags & DCAENC_FLAG_28BIT) ? 28 : 32; 623 | bitstream_put(c, 0, max_bits - 1); 624 | } 625 | 626 | static int32_t dcaenc_quantize_value(int32_t value, softfloat quant) 627 | { 628 | int32_t offset = 1 << (quant.e - 1); 629 | value = mul32(value, quant.m) + offset; 630 | value = value >> quant.e; 631 | return value; 632 | } 633 | 634 | static int32_t dcaenc_quantize(dcaenc_context c, int sample, int band, int ch) 635 | { 636 | int32_t result = dcaenc_quantize_value(c->subband_samples[sample][band][ch], 637 | c->quant[band][ch]); 638 | 639 | assert(result <= (quant_levels[c->abits[band][ch]] - 1) / 2); 640 | assert(result >= -(quant_levels[c->abits[band][ch]] / 2)); 641 | return result; 642 | } 643 | 644 | static int dcaenc_calc_one_scale(int32_t peak_cb, int abits, softfloat *quant) 645 | { 646 | int32_t peak; 647 | int our_nscale, try_remove; 648 | softfloat our_quant; 649 | 650 | assert(peak_cb <= 0); 651 | assert(peak_cb >= -2047); 652 | 653 | our_nscale = 127; 654 | peak = cb_to_level[-peak_cb]; 655 | 656 | for (try_remove = 64; try_remove > 0; try_remove >>= 1) { 657 | if (scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e <= 17) 658 | continue; 659 | our_quant.m = mul32(scalefactor_inv[our_nscale - try_remove].m, stepsize_inv[abits].m); 660 | our_quant.e = scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e - 17; 661 | if ((quant_levels[abits] - 1) / 2 < dcaenc_quantize_value(peak, our_quant)) 662 | continue; 663 | our_nscale -= try_remove; 664 | } 665 | if (our_nscale >= 125) 666 | our_nscale = 124; 667 | quant->m = mul32(scalefactor_inv[our_nscale].m, stepsize_inv[abits].m); 668 | quant->e = scalefactor_inv[our_nscale].e + stepsize_inv[abits].e - 17; 669 | assert((quant_levels[abits] - 1) / 2 >= dcaenc_quantize_value(peak, *quant)); 670 | return our_nscale; 671 | } 672 | 673 | static void dcaenc_calc_scales(dcaenc_context c) 674 | { 675 | int band, ch; 676 | 677 | for (band = 0; band < 32; band++) 678 | for (ch = 0; ch < c->fullband_channels; ch++) 679 | c->nscale[band][ch] = dcaenc_calc_one_scale(c->peak_cb[band][ch], c->abits[band][ch], &c->quant[band][ch]); 680 | 681 | if (c->flags & DCAENC_FLAG_LFE) 682 | c->lfe_nscale = dcaenc_calc_one_scale(c->lfe_peak_cb, 11, &c->lfe_quant); 683 | } 684 | 685 | static void dcaenc_quantize_all(dcaenc_context c) 686 | { 687 | int sample, band, ch; 688 | for (sample = 0; sample < DCAENC_SUBBAND_SAMPLES; sample++) 689 | for (band = 0; band < 32; band++) 690 | for (ch = 0; ch < c->fullband_channels; ch++) 691 | c->quantized_samples[sample][band][ch] = dcaenc_quantize(c, sample, band, ch); 692 | } 693 | 694 | static void put_frame_header(dcaenc_context c, int normal) 695 | { 696 | /* SYNC */ 697 | bitstream_put(c, 0x7ffe, 16); //16 698 | bitstream_put(c, 0x8001, 16); //32 699 | 700 | /* Frame type */ 701 | bitstream_put(c, normal, 1); //33 702 | 703 | /* Deficit sample count: none */ 704 | bitstream_put(c, 31, 5); //38 705 | 706 | /* CRC is not present */ 707 | bitstream_put(c, 0, 1); //39 708 | 709 | /* Number of PCM sample blocks: 16 */ 710 | bitstream_put(c, 15, 7); //46 711 | 712 | /* Primary frame byte size */ 713 | bitstream_put(c, c->frame_bits / 8 - 1, 14); //60 714 | 715 | /* Audio channel arrangement */ 716 | bitstream_put(c, c->channel_config, 6); //66 717 | 718 | /* Core audio sampling frequency */ 719 | bitstream_put(c, bitstream_sfreq[c->samplerate_index], 4); //70 720 | 721 | /* Transmission bit rate */ 722 | bitstream_put(c, c->bitrate_index, 5); //75 723 | 724 | /* Embedded down mix: disabled */ 725 | bitstream_put(c, 0, 1); //76 726 | 727 | /* Embedded dynamic range flag: not present */ 728 | bitstream_put(c, 0, 1); //77 729 | 730 | /* Embedded time stamp flag: not present */ 731 | bitstream_put(c, 0, 1); //78 732 | 733 | /* Auxiliary data flag: not present */ 734 | bitstream_put(c, 0, 1); //79 735 | 736 | /* HDCD source: no */ 737 | bitstream_put(c, 0, 1); //80 738 | 739 | /* Extension audio ID: N/A */ 740 | bitstream_put(c, 0, 3); //83 741 | 742 | /* Extended audio data: not present */ 743 | bitstream_put(c, 0, 1); //84 744 | 745 | /* Audio sync word insertion flag: after each sub-frame */ 746 | bitstream_put(c, 0, 1); //85 747 | 748 | /* Low frequency effects flag: not present or 64x subsampling */ 749 | bitstream_put(c, (c->flags & DCAENC_FLAG_LFE) ? 2 : 0, 2); //87 750 | 751 | /* Predictor history switch flag: on */ 752 | bitstream_put(c, 1, 1); //88 753 | 754 | /* No CRC */ 755 | /* Multirate interpolator switch */ 756 | bitstream_put(c, (c->flags & DCAENC_FLAG_PERFECT_QMF) ? 1 : 0, 1); //89 757 | 758 | /* Encoder software revision: 7 */ 759 | bitstream_put(c, 7, 4); //93 760 | 761 | /* Copy history: 0 */ 762 | bitstream_put(c, 0, 2); //95 763 | 764 | /* Source PCM resolution: 16 bits (even though the library accepts only 32-bit samples), not DTS ES */ 765 | bitstream_put(c, 0, 3); //98 766 | 767 | /* Front sum/difference coding: no */ 768 | bitstream_put(c, 0, 1); //99 769 | 770 | /* Surrounds sum/difference coding: no */ 771 | bitstream_put(c, 0, 1); //100 772 | 773 | /* Dialog normalization: 0 dB */ 774 | bitstream_put(c, 0, 4); //104 775 | } 776 | 777 | static void put_primary_audio_header(dcaenc_context c) 778 | { 779 | int ch; 780 | /* Number of subframes: 1 */ 781 | bitstream_put(c, 0, 4); //108 782 | 783 | /* Number of primary audio channels */ 784 | bitstream_put(c, c->fullband_channels - 1, 3); //111 785 | 786 | /* Subband activity count: 32 in each channel */ 787 | for (ch = 0; ch < c->fullband_channels; ch++) 788 | bitstream_put(c, 30, 5); //111 + 5 * c 789 | 790 | /* High frequency VQ start subband: 32 (i.e., no VQ) */ 791 | for (ch = 0; ch < c->fullband_channels; ch++) 792 | bitstream_put(c, 31, 5); // 111 + 10 * c 793 | 794 | /* Joint intensity coding index: 0 */ 795 | for (ch = 0; ch < c->fullband_channels; ch++) 796 | bitstream_put(c, 0, 3); // 111 + 13 * c 797 | 798 | /* Transient mode codebook: A4 (arbitrary) */ 799 | for (ch = 0; ch < c->fullband_channels; ch++) 800 | bitstream_put(c, 0, 2); // 111 + 15 * c 801 | 802 | /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */ 803 | for (ch = 0; ch < c->fullband_channels; ch++) 804 | bitstream_put(c, 6, 3); // 111 + 18 * c 805 | 806 | /* Bit allocation quantizer select: linear 5-bit */ 807 | for (ch = 0; ch < c->fullband_channels; ch++) 808 | bitstream_put(c, 6, 3); // 111 + 21 * c 809 | 810 | /* Quantization index codebook select: dummy data 811 | to avoid transmission of scale factor adjustment */ 812 | for (ch = 0; ch < c->fullband_channels; ch++) 813 | bitstream_put(c, 1, 1); // 111 + 22 * c 814 | for (ch = 0; ch < c->fullband_channels; ch++) 815 | bitstream_put(c, 3, 2); // 111 + 24 * c 816 | for (ch = 0; ch < c->fullband_channels; ch++) 817 | bitstream_put(c, 3, 2); // 111 + 26 * c 818 | for (ch = 0; ch < c->fullband_channels; ch++) 819 | bitstream_put(c, 3, 2); // 111 + 28 * c 820 | for (ch = 0; ch < c->fullband_channels; ch++) 821 | bitstream_put(c, 3, 2); // 111 + 30 * c 822 | for (ch = 0; ch < c->fullband_channels; ch++) 823 | bitstream_put(c, 7, 3); // 111 + 33 * c 824 | for (ch = 0; ch < c->fullband_channels; ch++) 825 | bitstream_put(c, 7, 3); // 111 + 36 * c 826 | for (ch = 0; ch < c->fullband_channels; ch++) 827 | bitstream_put(c, 7, 3); // 111 + 39 * c 828 | for (ch = 0; ch < c->fullband_channels; ch++) 829 | bitstream_put(c, 7, 3); // 111 + 42 * c 830 | for (ch = 0; ch < c->fullband_channels; ch++) 831 | bitstream_put(c, 7, 3); // 111 + 45 * c 832 | 833 | /* Scale factor adjustment index: not transmitted */ 834 | /* Audio header CRC check word: not transmitted */ 835 | } 836 | 837 | static void put_subframe_samples(dcaenc_context c, int ss, int band, int ch) 838 | { 839 | if (c->abits[band][ch] <= 7) { 840 | int sum, i, j; 841 | for (i = 0; i < 8; i += 4) { 842 | sum = 0; 843 | for (j = 3; j >= 0; j--) { 844 | sum *= quant_levels[c->abits[band][ch]]; 845 | sum += c->quantized_samples[ss * 8 + i + j][band][ch]; 846 | sum += (quant_levels[c->abits[band][ch]] - 1) / 2; 847 | } 848 | bitstream_put(c, sum, bit_consumption[c->abits[band][ch]] / 4); 849 | } 850 | } else { 851 | int i; 852 | for (i = 0; i < 8; i++) { 853 | int bits = bit_consumption[c->abits[band][ch]] / 16; 854 | int32_t mask = (1 << bits) - 1; 855 | bitstream_put(c, 856 | c->quantized_samples[ss * 8 + i][band][ch] & mask, 857 | bits); 858 | } 859 | } 860 | } 861 | 862 | static void put_subframe(dcaenc_context c) 863 | { 864 | int ch, band, ss; 865 | 866 | /* Subsubframe count: 2 */ 867 | bitstream_put(c, 1, 2); // 113 + 45 * c 868 | 869 | /* Partial subsubframe sample count: dummy */ 870 | bitstream_put(c, 0, 3); // 116 + 45 * c 871 | 872 | /* Prediction mode: no ADPCM, in each channel and subband */ 873 | for (ch = 0; ch < c->fullband_channels; ch++) 874 | for (band = 0; band < 32; band++) 875 | bitstream_put(c, 0, 1); // 116 + 77 * c 876 | 877 | /* Prediction VQ addres: not transmitted */ 878 | /* Bit allocation index for each channel and subband */ 879 | for (ch = 0; ch < c->fullband_channels; ch++) 880 | for (band = 0; band < 32; band++) 881 | bitstream_put(c, c->abits[band][ch], 5); // 116 + 237 * c 882 | 883 | /* Transition mode: none for each channel and subband */ 884 | for (ch = 0; ch < c->fullband_channels; ch++) 885 | for (band = 0; band < 32; band++) 886 | bitstream_put(c, 0, 1); /* according to Huffman codebook A4 */// 116 + 269 * c 887 | 888 | /* Scale factors */ 889 | for (ch = 0; ch < c->fullband_channels; ch++) 890 | for (band = 0; band < 32; band++) 891 | bitstream_put(c, c->nscale[band][ch], 7); // 116 + 493 * c 892 | 893 | /* Joint subband scale factor codebook select: not transmitted */ 894 | /* Scale factors for joint subband coding: not transmitted */ 895 | /* Stereo down-mix coefficients: not transmitted */ 896 | /* Dynamic range coefficient: not transmitted */ 897 | /* Side information CRC check word: not transmitted */ 898 | /* VQ encoded high frequency subbands: not transmitted */ 899 | /* LFE data: 8 samples and scalefactor */ 900 | if (c->flags & DCAENC_FLAG_LFE) { 901 | for (ss = 0; ss < DCAENC_LFE_SAMPLES; ss++) 902 | bitstream_put(c, dcaenc_quantize_value(c->downsampled_lfe[ss], c->lfe_quant) & 0xff, 8); 903 | bitstream_put(c, c->lfe_nscale, 8); 904 | } 905 | /* Audio data: 2 subsubframes */ 906 | for (ss = 0; ss < 2; ss++) 907 | for (ch = 0; ch < c->fullband_channels; ch++) 908 | for (band = 0; band < 32; band++) 909 | put_subframe_samples(c, ss, band, ch); 910 | /* DSYNC */ 911 | bitstream_put(c, 0xffff, 16); 912 | } 913 | 914 | static void dump_bits(dcaenc_context c) 915 | { 916 | int band, ch; 917 | printf("bits:"); 918 | for (band = 0; band < 32; band++) { 919 | printf("("); 920 | for (ch = 0; ch < c->fullband_channels; ch++) { 921 | printf("%02d", c->abits[band][ch]); 922 | if (ch < c->fullband_channels - 1) 923 | printf(" "); 924 | } 925 | printf(")"); 926 | } 927 | printf("\n"); 928 | } 929 | 930 | static void dump_masking_curve(dcaenc_context c) 931 | { 932 | int f; 933 | 934 | printf("\nWorst noise: %d (%d)\n", c->worst_quantization_noise, c->worst_noise_ever); 935 | printf("masking curve: "); 936 | for (f = 0; f < 256; f++) 937 | printf(" %d", c->eff_masking_curve_cb[f]); 938 | printf("\n"); 939 | } 940 | 941 | static int dcaenc_convert_frame(dcaenc_context c, const int32_t *input, uint8_t *output, int normal) 942 | { 943 | int i; 944 | 945 | int l = dcaenc_output_size(c); 946 | for (i = 0; i < l; i++) 947 | output[i] = 0; 948 | 949 | if (c->flags & DCAENC_FLAG_IEC_WRAP) { 950 | if (c->flags & DCAENC_FLAG_BIGENDIAN) { 951 | *(output++) = 0xf8; *(output++) = 0x72; 952 | *(output++) = 0x4e; *(output++) = 0x1f; 953 | *(output++) = 0x00; *(output++) = 0x0b; 954 | *(output++) = c->frame_bits >> 8; 955 | *(output++) = c->frame_bits & 0xff; 956 | } else { 957 | *(output++) = 0x72; *(output++) = 0xf8; 958 | *(output++) = 0x1f; *(output++) = 0x4e; 959 | *(output++) = 0x0b; *(output++) = 0x00; 960 | *(output++) = c->frame_bits & 0xff; 961 | *(output++) = c->frame_bits >> 8; 962 | } 963 | } 964 | 965 | bitstream_init(c, output); 966 | dcaenc_subband_transform(c, input); 967 | if (c->flags & DCAENC_FLAG_LFE) 968 | dcaenc_lfe_downsample(c, input); 969 | dcaenc_calc_masking(c, input); 970 | dcaenc_find_peaks(c); 971 | 972 | dcaenc_assign_bits(c); 973 | dcaenc_calc_scales(c); 974 | dcaenc_quantize_all(c); 975 | 976 | 977 | dcaenc_shift_history(c, input); 978 | put_frame_header(c, normal); 979 | put_primary_audio_header(c); 980 | put_subframe(c); 981 | bitstream_flush(c); 982 | 983 | /* FIXME: this will be invalid for VBR. We should return the actual 984 | * number of bytes that we wrote. 985 | */ 986 | // dump_bits(c); 987 | return dcaenc_output_size(c); 988 | } 989 | 990 | int dcaenc_convert_s32(dcaenc_context c, const int32_t *input, uint8_t *output) 991 | { 992 | return dcaenc_convert_frame(c, input, output, 1); 993 | } 994 | 995 | static int32_t zero[1024 * DCAENC_MAX_CHANNELS]; 996 | 997 | int dcaenc_destroy(dcaenc_context c, uint8_t *output) 998 | { 999 | int retval = output ? dcaenc_convert_frame(c, zero, output, 0) : 0; 1000 | free(c); 1001 | return retval; 1002 | } 1003 | -------------------------------------------------------------------------------- /float_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of dcaenc. 3 | * 4 | * Copyright (c) 2008-2012 Alexander E. Patrakov 5 | * 6 | * dcaenc is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * dcaenc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with dcaenc; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef FLOAT_DATA_H 22 | #define FLOAT_DATA_H 23 | 24 | /* 25 | * Official tables taken from: 26 | * ETSI TS 102 114 V1.2.1 27 | * 28 | * Copyright (C) European Telecommunications Standards Institute 2002. 29 | * Copyright (C) European Broadcasting Union 2002. 30 | * All rights reserved. 31 | */ 32 | 33 | /* D.9.1 64x interpolation 34 | * The 128x LFE interpolation FIR is the same, scaled up by a factor of 2. 35 | */ 36 | static const double lfe_fir_64[] = 37 | { 38 | 2.6584343868307770E-004, 39 | 8.1793652498163280E-005, 40 | 9.4393239123746760E-005, 41 | 1.0821702744578940E-004, 42 | 1.2333714403212070E-004, 43 | 1.3974857574794440E-004, 44 | 1.5759580128360540E-004, 45 | 1.7699223826639360E-004, 46 | 1.9817386055365200E-004, 47 | 2.2118473134469240E-004, 48 | 2.4602311896160240E-004, 49 | 2.7261159266345200E-004, 50 | 3.0138631700538100E-004, 51 | 3.3283955417573450E-004, 52 | 3.6589911906048660E-004, 53 | 4.0182814700528980E-004, 54 | 4.4018754852004350E-004, 55 | 4.8127761692740020E-004, 56 | 5.2524596685543660E-004, 57 | 5.7215924607589840E-004, 58 | 6.2221300322562460E-004, 59 | 6.7555153509601950E-004, 60 | 7.3241489008069040E-004, 61 | 7.9285167157649990E-004, 62 | 8.5701106581836940E-004, 63 | 9.2511920956894760E-004, 64 | 9.9747709464281800E-004, 65 | 1.0739302961155770E-003, 66 | 1.1550235794857140E-003, 67 | 1.2406768510118130E-003, 68 | 1.3312589144334200E-003, 69 | 1.4268938684836030E-003, 70 | 1.5278297942131760E-003, 71 | 1.6342115122824910E-003, 72 | 1.7463274998590350E-003, 73 | 1.8643775256350640E-003, 74 | 1.9886041991412640E-003, 75 | 2.1191518753767010E-003, 76 | 2.2563596721738580E-003, 77 | 2.4004334118217230E-003, 78 | 2.5515670422464610E-003, 79 | 2.7100932784378530E-003, 80 | 2.8761904686689380E-003, 81 | 3.0501529108732940E-003, 82 | 3.2322725746780640E-003, 83 | 3.4227769356220960E-003, 84 | 3.6219672765582800E-003, 85 | 3.8300913292914630E-003, 86 | 4.0474990382790560E-003, 87 | 4.2744171805679800E-003, 88 | 4.5111598446965220E-003, 89 | 4.7580120153725150E-003, 90 | 5.0153112970292570E-003, 91 | 5.2832840010523800E-003, 92 | 5.5623454973101620E-003, 93 | 5.8526843786239620E-003, 94 | 6.1547122895717620E-003, 95 | 6.4686913974583150E-003, 96 | 6.7949919030070300E-003, 97 | 7.1338820271193980E-003, 98 | 7.4857366271317010E-003, 99 | 7.8508658334612850E-003, 100 | 8.2296309992671010E-003, 101 | 8.6223213002085690E-003, 102 | 9.0293306857347480E-003, 103 | 9.4509534537792200E-003, 104 | 9.8875602707266800E-003, 105 | 1.0339494794607160E-002, 106 | 1.0807084850966930E-002, 107 | 1.1290682479739190E-002, 108 | 1.1790650896728040E-002, 109 | 1.2307321652770040E-002, 110 | 1.2841059826314450E-002, 111 | 1.3392185792326930E-002, 112 | 1.3961089774966240E-002, 113 | 1.4548087492585180E-002, 114 | 1.5153550542891020E-002, 115 | 1.5777811408042910E-002, 116 | 1.6421230509877200E-002, 117 | 1.7084129154682160E-002, 118 | 1.7766902223229410E-002, 119 | 1.8469827249646190E-002, 120 | 1.9193304702639580E-002, 121 | 1.9937623292207720E-002, 122 | 2.0703161135315900E-002, 123 | 2.1490212529897690E-002, 124 | 2.2299138829112050E-002, 125 | 2.3130238056182860E-002, 126 | 2.3983856663107870E-002, 127 | 2.4860285222530360E-002, 128 | 2.5759860873222350E-002, 129 | 2.6682861149311060E-002, 130 | 2.7629608288407320E-002, 131 | 2.8600392863154410E-002, 132 | 2.9595496132969860E-002, 133 | 3.0615204945206640E-002, 134 | 3.1659796833992000E-002, 135 | 3.2729536294937140E-002, 136 | 3.3824689686298370E-002, 137 | 3.4945506602525710E-002, 138 | 3.6092240363359450E-002, 139 | 3.7265110760927200E-002, 140 | 3.8464374840259550E-002, 141 | 3.9690230041742320E-002, 142 | 4.0942888706922530E-002, 143 | 4.2222552001476290E-002, 144 | 4.3529424816370010E-002, 145 | 4.4863656163215640E-002, 146 | 4.6225443482398990E-002, 147 | 4.7614917159080510E-002, 148 | 4.9032241106033330E-002, 149 | 5.0477534532547000E-002, 150 | 5.1950931549072270E-002, 151 | 5.3452525287866590E-002, 152 | 5.4982420057058330E-002, 153 | 5.6540694087743760E-002, 154 | 5.8127421885728840E-002, 155 | 5.9742655605077740E-002, 156 | 6.1386436223983760E-002, 157 | 6.3058786094188690E-002, 158 | 6.4759708940982820E-002, 159 | 6.6489234566688540E-002, 160 | 6.8247318267822270E-002, 161 | 7.0033922791481020E-002, 162 | 7.1849010884761810E-002, 163 | 7.3692522943019870E-002, 164 | 7.5564362108707430E-002, 165 | 7.7464438974857330E-002, 166 | 7.9392634332180020E-002, 167 | 8.1348828971385960E-002, 168 | 8.3332858979702000E-002, 169 | 8.5344567894935610E-002, 170 | 8.7383769452571870E-002, 171 | 8.9450262486934660E-002, 172 | 9.1543838381767280E-002, 173 | 9.3664251267910000E-002, 174 | 9.5811240375041960E-002, 175 | 9.7984537482261660E-002, 176 | 1.0018386691808700E-001, 177 | 1.0240890830755230E-001, 178 | 1.0465932637453080E-001, 179 | 1.0693479329347610E-001, 180 | 1.0923493653535840E-001, 181 | 1.1155936866998670E-001, 182 | 1.1390769481658940E-001, 183 | 1.1627949774265290E-001, 184 | 1.1867434531450270E-001, 185 | 1.2109176814556120E-001, 186 | 1.2353130429983140E-001, 187 | 1.2599244713783260E-001, 188 | 1.2847468256950380E-001, 189 | 1.3097748160362240E-001, 190 | 1.3350030779838560E-001, 191 | 1.3604259490966800E-001, 192 | 1.3860376179218290E-001, 193 | 1.4118319749832150E-001, 194 | 1.4378026127815250E-001, 195 | 1.4639437198638920E-001, 196 | 1.4902481436729430E-001, 197 | 1.5167096257209780E-001, 198 | 1.5433208644390100E-001, 199 | 1.5700751543045040E-001, 200 | 1.5969651937484740E-001, 201 | 1.6239835321903230E-001, 202 | 1.6511227190494540E-001, 203 | 1.6783750057220460E-001, 204 | 1.7057323455810550E-001, 205 | 1.7331869900226590E-001, 206 | 1.7607308924198150E-001, 207 | 1.7883554100990300E-001, 208 | 1.8160524964332580E-001, 209 | 1.8438133597373960E-001, 210 | 1.8716295063495640E-001, 211 | 1.8994916975498200E-001, 212 | 1.9273911416530610E-001, 213 | 1.9553191959857940E-001, 214 | 1.9832661747932440E-001, 215 | 2.0112232863903040E-001, 216 | 2.0391805469989780E-001, 217 | 2.0671287178993220E-001, 218 | 2.0950584113597870E-001, 219 | 2.1229594945907590E-001, 220 | 2.1508227288722990E-001, 221 | 2.1786379814147950E-001, 222 | 2.2063951194286350E-001, 223 | 2.2340846061706540E-001, 224 | 2.2616961598396300E-001, 225 | 2.2892196476459500E-001, 226 | 2.3166447877883910E-001, 227 | 2.3439615964889520E-001, 228 | 2.3711597919464110E-001, 229 | 2.3982289433479310E-001, 230 | 2.4251587688922880E-001, 231 | 2.4519388377666480E-001, 232 | 2.4785590171813960E-001, 233 | 2.5050088763237000E-001, 234 | 2.5312781333923340E-001, 235 | 2.5573557615280150E-001, 236 | 2.5832322239875800E-001, 237 | 2.6088967919349670E-001, 238 | 2.6343390345573420E-001, 239 | 2.6595494151115420E-001, 240 | 2.6845166087150580E-001, 241 | 2.7092313766479490E-001, 242 | 2.7336826920509340E-001, 243 | 2.7578607201576240E-001, 244 | 2.7817553281784060E-001, 245 | 2.8053569793701170E-001, 246 | 2.8286558389663700E-001, 247 | 2.8516408801078800E-001, 248 | 2.8743034601211550E-001, 249 | 2.8966337442398070E-001, 250 | 2.9186218976974480E-001, 251 | 2.9402589797973640E-001, 252 | 2.9615348577499390E-001, 253 | 2.9824411869049070E-001, 254 | 3.0029675364494320E-001, 255 | 3.0231067538261420E-001, 256 | 3.0428490042686460E-001, 257 | 3.0621853470802300E-001, 258 | 3.0811080336570740E-001, 259 | 3.0996081233024600E-001, 260 | 3.1176769733428960E-001, 261 | 3.1353080272674560E-001, 262 | 3.1524917483329780E-001, 263 | 3.1692212820053100E-001, 264 | 3.1854888796806340E-001, 265 | 3.2012873888015740E-001, 266 | 3.2166096568107600E-001, 267 | 3.2314485311508180E-001, 268 | 3.2457971572875980E-001, 269 | 3.2596495747566220E-001, 270 | 3.2729989290237420E-001, 271 | 3.2858389616012580E-001, 272 | 3.2981643080711360E-001, 273 | 3.3099696040153500E-001, 274 | 3.3212485909461980E-001, 275 | 3.3319962024688720E-001, 276 | 3.3422079682350160E-001, 277 | 3.3518791198730470E-001, 278 | 3.3610042929649360E-001, 279 | 3.3695802092552180E-001, 280 | 3.3776029944419860E-001, 281 | 3.3850681781768800E-001, 282 | 3.3919724822044380E-001, 283 | 3.3983129262924200E-001, 284 | 3.4040865302085880E-001, 285 | 3.4092903137207030E-001, 286 | 3.4139221906661980E-001, 287 | 3.4179797768592840E-001, 288 | 3.4214612841606140E-001, 289 | 3.4243649244308470E-001, 290 | 3.4266895055770880E-001, 291 | 3.4284341335296630E-001, 292 | 3.4295973181724550E-001, 293 | 3.4301793575286860E-001, 294 | 3.4301793575286860E-001, 295 | 3.4295973181724550E-001, 296 | 3.4284341335296630E-001, 297 | 3.4266895055770880E-001, 298 | 3.4243649244308470E-001, 299 | 3.4214612841606140E-001, 300 | 3.4179797768592840E-001, 301 | 3.4139221906661980E-001, 302 | 3.4092903137207030E-001, 303 | 3.4040865302085880E-001, 304 | 3.3983129262924200E-001, 305 | 3.3919724822044380E-001, 306 | 3.3850681781768800E-001, 307 | 3.3776029944419860E-001, 308 | 3.3695802092552180E-001, 309 | 3.3610042929649360E-001, 310 | 3.3518791198730470E-001, 311 | 3.3422079682350160E-001, 312 | 3.3319962024688720E-001, 313 | 3.3212485909461980E-001, 314 | 3.3099696040153500E-001, 315 | 3.2981643080711360E-001, 316 | 3.2858389616012580E-001, 317 | 3.2729989290237420E-001, 318 | 3.2596495747566220E-001, 319 | 3.2457971572875980E-001, 320 | 3.2314485311508180E-001, 321 | 3.2166096568107600E-001, 322 | 3.2012873888015740E-001, 323 | 3.1854888796806340E-001, 324 | 3.1692212820053100E-001, 325 | 3.1524917483329780E-001, 326 | 3.1353080272674560E-001, 327 | 3.1176769733428960E-001, 328 | 3.0996081233024600E-001, 329 | 3.0811080336570740E-001, 330 | 3.0621853470802300E-001, 331 | 3.0428490042686460E-001, 332 | 3.0231067538261420E-001, 333 | 3.0029675364494320E-001, 334 | 2.9824411869049070E-001, 335 | 2.9615348577499390E-001, 336 | 2.9402589797973640E-001, 337 | 2.9186218976974480E-001, 338 | 2.8966337442398070E-001, 339 | 2.8743034601211550E-001, 340 | 2.8516408801078800E-001, 341 | 2.8286558389663700E-001, 342 | 2.8053569793701170E-001, 343 | 2.7817553281784060E-001, 344 | 2.7578607201576240E-001, 345 | 2.7336826920509340E-001, 346 | 2.7092313766479490E-001, 347 | 2.6845166087150580E-001, 348 | 2.6595494151115420E-001, 349 | 2.6343390345573420E-001, 350 | 2.6088967919349670E-001, 351 | 2.5832322239875800E-001, 352 | 2.5573557615280150E-001, 353 | 2.5312781333923340E-001, 354 | 2.5050088763237000E-001, 355 | 2.4785590171813960E-001, 356 | 2.4519388377666480E-001, 357 | 2.4251587688922880E-001, 358 | 2.3982289433479310E-001, 359 | 2.3711597919464110E-001, 360 | 2.3439615964889520E-001, 361 | 2.3166447877883910E-001, 362 | 2.2892196476459500E-001, 363 | 2.2616961598396300E-001, 364 | 2.2340846061706540E-001, 365 | 2.2063951194286350E-001, 366 | 2.1786379814147950E-001, 367 | 2.1508227288722990E-001, 368 | 2.1229594945907590E-001, 369 | 2.0950584113597870E-001, 370 | 2.0671287178993220E-001, 371 | 2.0391805469989780E-001, 372 | 2.0112232863903040E-001, 373 | 1.9832661747932440E-001, 374 | 1.9553191959857940E-001, 375 | 1.9273911416530610E-001, 376 | 1.8994916975498200E-001, 377 | 1.8716295063495640E-001, 378 | 1.8438133597373960E-001, 379 | 1.8160524964332580E-001, 380 | 1.7883554100990300E-001, 381 | 1.7607308924198150E-001, 382 | 1.7331869900226590E-001, 383 | 1.7057323455810550E-001, 384 | 1.6783750057220460E-001, 385 | 1.6511227190494540E-001, 386 | 1.6239835321903230E-001, 387 | 1.5969651937484740E-001, 388 | 1.5700751543045040E-001, 389 | 1.5433208644390100E-001, 390 | 1.5167096257209780E-001, 391 | 1.4902481436729430E-001, 392 | 1.4639437198638920E-001, 393 | 1.4378026127815250E-001, 394 | 1.4118319749832150E-001, 395 | 1.3860376179218290E-001, 396 | 1.3604259490966800E-001, 397 | 1.3350030779838560E-001, 398 | 1.3097748160362240E-001, 399 | 1.2847468256950380E-001, 400 | 1.2599244713783260E-001, 401 | 1.2353130429983140E-001, 402 | 1.2109176814556120E-001, 403 | 1.1867434531450270E-001, 404 | 1.1627949774265290E-001, 405 | 1.1390769481658940E-001, 406 | 1.1155936866998670E-001, 407 | 1.0923493653535840E-001, 408 | 1.0693479329347610E-001, 409 | 1.0465932637453080E-001, 410 | 1.0240890830755230E-001, 411 | 1.0018386691808700E-001, 412 | 9.7984537482261660E-002, 413 | 9.5811240375041960E-002, 414 | 9.3664251267910000E-002, 415 | 9.1543838381767280E-002, 416 | 8.9450262486934660E-002, 417 | 8.7383769452571870E-002, 418 | 8.5344567894935610E-002, 419 | 8.3332858979702000E-002, 420 | 8.1348828971385960E-002, 421 | 7.9392634332180020E-002, 422 | 7.7464438974857330E-002, 423 | 7.5564362108707430E-002, 424 | 7.3692522943019870E-002, 425 | 7.1849010884761810E-002, 426 | 7.0033922791481020E-002, 427 | 6.8247318267822270E-002, 428 | 6.6489234566688540E-002, 429 | 6.4759708940982820E-002, 430 | 6.3058786094188690E-002, 431 | 6.1386436223983760E-002, 432 | 5.9742655605077740E-002, 433 | 5.8127421885728840E-002, 434 | 5.6540694087743760E-002, 435 | 5.4982420057058330E-002, 436 | 5.3452525287866590E-002, 437 | 5.1950931549072270E-002, 438 | 5.0477534532547000E-002, 439 | 4.9032241106033330E-002, 440 | 4.7614917159080510E-002, 441 | 4.6225443482398990E-002, 442 | 4.4863656163215640E-002, 443 | 4.3529424816370010E-002, 444 | 4.2222552001476290E-002, 445 | 4.0942888706922530E-002, 446 | 3.9690230041742320E-002, 447 | 3.8464374840259550E-002, 448 | 3.7265110760927200E-002, 449 | 3.6092240363359450E-002, 450 | 3.4945506602525710E-002, 451 | 3.3824689686298370E-002, 452 | 3.2729536294937140E-002, 453 | 3.1659796833992000E-002, 454 | 3.0615204945206640E-002, 455 | 2.9595496132969860E-002, 456 | 2.8600392863154410E-002, 457 | 2.7629608288407320E-002, 458 | 2.6682861149311060E-002, 459 | 2.5759860873222350E-002, 460 | 2.4860285222530360E-002, 461 | 2.3983856663107870E-002, 462 | 2.3130238056182860E-002, 463 | 2.2299138829112050E-002, 464 | 2.1490212529897690E-002, 465 | 2.0703161135315900E-002, 466 | 1.9937623292207720E-002, 467 | 1.9193304702639580E-002, 468 | 1.8469827249646190E-002, 469 | 1.7766902223229410E-002, 470 | 1.7084129154682160E-002, 471 | 1.6421230509877200E-002, 472 | 1.5777811408042910E-002, 473 | 1.5153550542891020E-002, 474 | 1.4548087492585180E-002, 475 | 1.3961089774966240E-002, 476 | 1.3392185792326930E-002, 477 | 1.2841059826314450E-002, 478 | 1.2307321652770040E-002, 479 | 1.1790650896728040E-002, 480 | 1.1290682479739190E-002, 481 | 1.0807084850966930E-002, 482 | 1.0339494794607160E-002, 483 | 9.8875602707266800E-003, 484 | 9.4509534537792200E-003, 485 | 9.0293306857347480E-003, 486 | 8.6223213002085690E-003, 487 | 8.2296309992671010E-003, 488 | 7.8508658334612850E-003, 489 | 7.4857366271317010E-003, 490 | 7.1338820271193980E-003, 491 | 6.7949919030070300E-003, 492 | 6.4686913974583150E-003, 493 | 6.1547122895717620E-003, 494 | 5.8526843786239620E-003, 495 | 5.5623454973101620E-003, 496 | 5.2832840010523800E-003, 497 | 5.0153112970292570E-003, 498 | 4.7580120153725150E-003, 499 | 4.5111598446965220E-003, 500 | 4.2744171805679800E-003, 501 | 4.0474990382790560E-003, 502 | 3.8300913292914630E-003, 503 | 3.6219672765582800E-003, 504 | 3.4227769356220960E-003, 505 | 3.2322725746780640E-003, 506 | 3.0501529108732940E-003, 507 | 2.8761904686689380E-003, 508 | 2.7100932784378530E-003, 509 | 2.5515670422464610E-003, 510 | 2.4004334118217230E-003, 511 | 2.2563596721738580E-003, 512 | 2.1191518753767010E-003, 513 | 1.9886041991412640E-003, 514 | 1.8643775256350640E-003, 515 | 1.7463274998590350E-003, 516 | 1.6342115122824910E-003, 517 | 1.5278297942131760E-003, 518 | 1.4268938684836030E-003, 519 | 1.3312589144334200E-003, 520 | 1.2406768510118130E-003, 521 | 1.1550235794857140E-003, 522 | 1.0739302961155770E-003, 523 | 9.9747709464281800E-004, 524 | 9.2511920956894760E-004, 525 | 8.5701106581836940E-004, 526 | 7.9285167157649990E-004, 527 | 7.3241489008069040E-004, 528 | 6.7555153509601950E-004, 529 | 6.2221300322562460E-004, 530 | 5.7215924607589840E-004, 531 | 5.2524596685543660E-004, 532 | 4.8127761692740020E-004, 533 | 4.4018754852004350E-004, 534 | 4.0182814700528980E-004, 535 | 3.6589911906048660E-004, 536 | 3.3283955417573450E-004, 537 | 3.0138631700538100E-004, 538 | 2.7261159266345200E-004, 539 | 2.4602311896160240E-004, 540 | 2.2118473134469240E-004, 541 | 1.9817386055365200E-004, 542 | 1.7699223826639360E-004, 543 | 1.5759580128360540E-004, 544 | 1.3974857574794440E-004, 545 | 1.2333714403212070E-004, 546 | 1.0821702744578940E-004, 547 | 9.4393239123746760E-005, 548 | 8.1793652498163280E-005, 549 | 2.6584343868307770E-004 550 | }; 551 | 552 | /* 553 | * D.8 32-Band Interpolation FIR 554 | * 555 | * To be used with the "official" interpolation procedure, 556 | * which is deliberately obfuscated in the specification. 557 | * 558 | * reconstruction_fir[0][] = D.8.1 Perfect Reconstruction 559 | * reconstruction_fir[1][] = D.8.2 Non-Perfect Reconstruction 560 | */ 561 | 562 | static const double reconstruction_fir[2][512] = { 563 | { 564 | +1.135985195E-010, 565 | +7.018770981E-011, 566 | -1.608403011E-008, 567 | -5.083275667E-008, 568 | -1.543309907E-007, 569 | -3.961981463E-007, 570 | -7.342250683E-007, 571 | -3.970030775E-007, 572 | -4.741137047E-007, 573 | -6.022448247E-007, 574 | -6.628192182E-007, 575 | -6.982898526E-007, 576 | -7.020648809E-007, 577 | -6.767839409E-007, 578 | -6.262345096E-007, 579 | -5.564140224E-007, 580 | +7.003467317E-007, 581 | +8.419976893E-007, 582 | +9.742954035E-007, 583 | +1.085227950E-006, 584 | +1.162929266E-006, 585 | +1.194632091E-006, 586 | +1.179182050E-006, 587 | +1.033426656E-006, 588 | +9.451737242E-007, 589 | +1.975324267E-006, 590 | +1.190443072E-006, 591 | +5.234479659E-007, 592 | +2.014677420E-007, 593 | +7.834767501E-008, 594 | -6.702406963E-010, 595 | -1.613285505E-009, 596 | -2.682709610E-009, 597 | -3.399493131E-009, 598 | +1.314406006E-008, 599 | +7.506701927E-009, 600 | +2.788728892E-008, 601 | +1.444918922E-007, 602 | +3.132386439E-007, 603 | +1.399798180E-006, 604 | +2.032118118E-006, 605 | +2.715013807E-006, 606 | +3.453840463E-006, 607 | +4.195037945E-006, 608 | +4.896494374E-006, 609 | +5.516381407E-006, 610 | +6.015239251E-006, 611 | +6.361419310E-006, 612 | +8.006985809E-006, 613 | +8.087732567E-006, 614 | +7.941360309E-006, 615 | +7.568834008E-006, 616 | +6.986399967E-006, 617 | +6.225028756E-006, 618 | +5.315936960E-006, 619 | +4.429412002E-006, 620 | +3.332600045E-006, 621 | +8.427224429E-007, 622 | +4.341498823E-007, 623 | +9.458596395E-008, 624 | +2.975164826E-008, 625 | +6.402664354E-008, 626 | -3.246264413E-008, 627 | -3.809887872E-008, 628 | +8.434094667E-008, 629 | +6.437721822E-008, 630 | +1.189317118E-006, 631 | +2.497214155E-006, 632 | +3.617151151E-006, 633 | +3.157242645E-006, 634 | +2.319611212E-006, 635 | +7.869333785E-006, 636 | +9.826449968E-006, 637 | +1.177108606E-005, 638 | +1.379448349E-005, 639 | +1.571428584E-005, 640 | +1.743183020E-005, 641 | +1.884208177E-005, 642 | +1.987093310E-005, 643 | +2.042970118E-005, 644 | -3.144468428E-005, 645 | -3.334947178E-005, 646 | -3.460439257E-005, 647 | -3.515914432E-005, 648 | -3.495384954E-005, 649 | -3.397853652E-005, 650 | -3.225446198E-005, 651 | -2.978993689E-005, 652 | -2.677291741E-005, 653 | -1.806914770E-005, 654 | -1.776598037E-005, 655 | -1.661818715E-005, 656 | -1.207003334E-005, 657 | -6.993315310E-006, 658 | -5.633860383E-007, 659 | -9.984935332E-007, 660 | -1.470520488E-006, 661 | -1.853591357E-006, 662 | +7.198007665E-007, 663 | +3.086857760E-006, 664 | +6.084746474E-006, 665 | +9.561075785E-006, 666 | +1.309637537E-005, 667 | +2.263354872E-005, 668 | +2.847247197E-005, 669 | +3.415624451E-005, 670 | +3.946387005E-005, 671 | +4.425736552E-005, 672 | +4.839275425E-005, 673 | +5.176846025E-005, 674 | +5.429694284E-005, 675 | +5.595519906E-005, 676 | +4.916387297E-006, 677 | +9.299508747E-006, 678 | +1.356193479E-005, 679 | +1.751866148E-005, 680 | +2.093936746E-005, 681 | +2.362549276E-005, 682 | +2.537086584E-005, 683 | +2.618136386E-005, 684 | +2.554462844E-005, 685 | +3.018750249E-005, 686 | +2.570833203E-005, 687 | +1.985177369E-005, 688 | +1.191342653E-005, 689 | +2.525620175E-006, 690 | -1.521241393E-005, 691 | -1.617751332E-005, 692 | +1.992636317E-005, 693 | +1.774702469E-005, 694 | +4.624524081E-005, 695 | +5.610509834E-005, 696 | +6.568001118E-005, 697 | +7.513730816E-005, 698 | +8.413690375E-005, 699 | +8.757545584E-005, 700 | +9.517164290E-005, 701 | +1.020687996E-004, 702 | +1.084438481E-004, 703 | +1.140582463E-004, 704 | +1.187910311E-004, 705 | +1.224978914E-004, 706 | +1.250260248E-004, 707 | +1.262027217E-004, 708 | +1.226499153E-004, 709 | +1.213575742E-004, 710 | +1.180980107E-004, 711 | +1.126275165E-004, 712 | +1.047207043E-004, 713 | +9.417100227E-005, 714 | +8.078388782E-005, 715 | +6.447290798E-005, 716 | +4.491530854E-005, 717 | +2.470704203E-005, 718 | -1.714242217E-006, 719 | -3.193307566E-005, 720 | -6.541742187E-005, 721 | -1.024175072E-004, 722 | -1.312203676E-004, 723 | -1.774113771E-004, 724 | -2.233728592E-004, 725 | -2.682086197E-004, 726 | -3.347633174E-004, 727 | -3.906481725E-004, 728 | -4.490280990E-004, 729 | -5.099929986E-004, 730 | -5.729619297E-004, 731 | -6.358824321E-004, 732 | -7.021900383E-004, 733 | -7.698345580E-004, 734 | -8.385353722E-004, 735 | -9.078957955E-004, 736 | -9.775133803E-004, 737 | -1.046945457E-003, 738 | -1.115717343E-003, 739 | -1.183370827E-003, 740 | -1.252829796E-003, 741 | -1.316190348E-003, 742 | -1.376571832E-003, 743 | -1.433344092E-003, 744 | -1.485876855E-003, 745 | -1.533520175E-003, 746 | -1.575609902E-003, 747 | -1.611457788E-003, 748 | -1.640390139E-003, 749 | -1.661288203E-003, 750 | -1.674512983E-003, 751 | -1.678415807E-003, 752 | -1.672798418E-003, 753 | -1.656501088E-003, 754 | -1.633993932E-003, 755 | -1.593449386E-003, 756 | +1.542080659E-003, 757 | +1.479332102E-003, 758 | +1.395521569E-003, 759 | +1.303116791E-003, 760 | +1.196175464E-003, 761 | +1.073757303E-003, 762 | +9.358961834E-004, 763 | +7.817269652E-004, 764 | +6.114174030E-004, 765 | +4.244441516E-004, 766 | +2.206075296E-004, 767 | -2.719412748E-007, 768 | -2.382978710E-004, 769 | -4.935106263E-004, 770 | -7.658848190E-004, 771 | -1.055365428E-003, 772 | -1.361547387E-003, 773 | -1.684492454E-003, 774 | -2.023874084E-003, 775 | -2.379294252E-003, 776 | -2.750317100E-003, 777 | -3.136433195E-003, 778 | -3.537061159E-003, 779 | -3.951539751E-003, 780 | -4.379155114E-003, 781 | -4.819062538E-003, 782 | -5.270531867E-003, 783 | -5.732392892E-003, 784 | -6.203945260E-003, 785 | -6.683901884E-003, 786 | -7.170005701E-003, 787 | -7.664063945E-003, 788 | -8.162760176E-003, 789 | -8.665001951E-003, 790 | -9.170533158E-003, 791 | -9.676489048E-003, 792 | -1.018219907E-002, 793 | -1.068630442E-002, 794 | -1.118756086E-002, 795 | -1.168460958E-002, 796 | -1.217562053E-002, 797 | -1.265939046E-002, 798 | -1.313448418E-002, 799 | -1.359948888E-002, 800 | -1.405300573E-002, 801 | -1.449365262E-002, 802 | -1.492007636E-002, 803 | -1.533095632E-002, 804 | -1.572482102E-002, 805 | -1.610082202E-002, 806 | -1.645756140E-002, 807 | -1.679391414E-002, 808 | -1.710879989E-002, 809 | -1.740120351E-002, 810 | -1.767017506E-002, 811 | -1.791484281E-002, 812 | -1.813439466E-002, 813 | -1.832821220E-002, 814 | -1.849545911E-002, 815 | -1.863567345E-002, 816 | -1.874836907E-002, 817 | -1.883326657E-002, 818 | -1.889026538E-002, 819 | -1.891860925E-002, 820 | +1.891860925E-002, 821 | +1.889026538E-002, 822 | +1.883326657E-002, 823 | +1.874836907E-002, 824 | +1.863567345E-002, 825 | +1.849545911E-002, 826 | +1.832821220E-002, 827 | +1.813439466E-002, 828 | +1.791484281E-002, 829 | +1.767017506E-002, 830 | +1.740120351E-002, 831 | +1.710879989E-002, 832 | +1.679391414E-002, 833 | +1.645756140E-002, 834 | +1.610082202E-002, 835 | +1.572482102E-002, 836 | +1.533095632E-002, 837 | +1.492007636E-002, 838 | +1.449365262E-002, 839 | +1.405300573E-002, 840 | +1.359948888E-002, 841 | +1.313448418E-002, 842 | +1.265939046E-002, 843 | +1.217562053E-002, 844 | +1.168460958E-002, 845 | +1.118756086E-002, 846 | +1.068630442E-002, 847 | +1.018219907E-002, 848 | +9.676489048E-003, 849 | +9.170533158E-003, 850 | +8.665001951E-003, 851 | +8.162760176E-003, 852 | +7.664063945E-003, 853 | +7.170005701E-003, 854 | +6.683901884E-003, 855 | +6.203945260E-003, 856 | +5.732392892E-003, 857 | +5.270531867E-003, 858 | +4.819062538E-003, 859 | +4.379155114E-003, 860 | +3.951539751E-003, 861 | +3.537061159E-003, 862 | +3.136433195E-003, 863 | +2.750317100E-003, 864 | +2.379294252E-003, 865 | +2.023874084E-003, 866 | +1.684492454E-003, 867 | +1.361547387E-003, 868 | +1.055365428E-003, 869 | +7.658848190E-004, 870 | +4.935106263E-004, 871 | +2.382978710E-004, 872 | +2.719412748E-007, 873 | -2.206075296E-004, 874 | -4.244441516E-004, 875 | -6.114174030E-004, 876 | -7.817269652E-004, 877 | -9.358961834E-004, 878 | -1.073757303E-003, 879 | -1.196175464E-003, 880 | -1.303116791E-003, 881 | -1.395521569E-003, 882 | -1.479332102E-003, 883 | -1.542080659E-003, 884 | +1.593449386E-003, 885 | +1.633993932E-003, 886 | +1.656501088E-003, 887 | +1.672798418E-003, 888 | +1.678415807E-003, 889 | +1.674512983E-003, 890 | +1.661288203E-003, 891 | +1.640390139E-003, 892 | +1.611457788E-003, 893 | +1.575609902E-003, 894 | +1.533520175E-003, 895 | +1.485876855E-003, 896 | +1.433344092E-003, 897 | +1.376571832E-003, 898 | +1.316190348E-003, 899 | +1.252829796E-003, 900 | +1.183370827E-003, 901 | +1.115717343E-003, 902 | +1.046945457E-003, 903 | +9.775133803E-004, 904 | +9.078957955E-004, 905 | +8.385353722E-004, 906 | +7.698345580E-004, 907 | +7.021900383E-004, 908 | +6.358824321E-004, 909 | +5.729619297E-004, 910 | +5.099929986E-004, 911 | +4.490280990E-004, 912 | +3.906481725E-004, 913 | +3.347633174E-004, 914 | +2.682086197E-004, 915 | +2.233728592E-004, 916 | +1.774113771E-004, 917 | +1.312203676E-004, 918 | +1.024175072E-004, 919 | +6.541742187E-005, 920 | +3.193307566E-005, 921 | +1.714242217E-006, 922 | -2.470704203E-005, 923 | -4.491530854E-005, 924 | -6.447290798E-005, 925 | -8.078388782E-005, 926 | -9.417100227E-005, 927 | -1.047207043E-004, 928 | -1.126275165E-004, 929 | -1.180980107E-004, 930 | -1.213575742E-004, 931 | -1.226499153E-004, 932 | -1.262027217E-004, 933 | -1.250260248E-004, 934 | -1.224978914E-004, 935 | -1.187910311E-004, 936 | -1.140582463E-004, 937 | -1.084438481E-004, 938 | -1.020687996E-004, 939 | -9.517164290E-005, 940 | -8.757545584E-005, 941 | -8.413690375E-005, 942 | -7.513730816E-005, 943 | -6.568001118E-005, 944 | -5.610509834E-005, 945 | -4.624524081E-005, 946 | -1.774702469E-005, 947 | -1.992636317E-005, 948 | +1.617751332E-005, 949 | +1.521241393E-005, 950 | -2.525620175E-006, 951 | -1.191342653E-005, 952 | -1.985177369E-005, 953 | -2.570833203E-005, 954 | -3.018750249E-005, 955 | -2.554462844E-005, 956 | -2.618136386E-005, 957 | -2.537086584E-005, 958 | -2.362549276E-005, 959 | -2.093936746E-005, 960 | -1.751866148E-005, 961 | -1.356193479E-005, 962 | -9.299508747E-006, 963 | -4.916387297E-006, 964 | -5.595519906E-005, 965 | -5.429694284E-005, 966 | -5.176846025E-005, 967 | -4.839275425E-005, 968 | -4.425736552E-005, 969 | -3.946387005E-005, 970 | -3.415624451E-005, 971 | -2.847247197E-005, 972 | -2.263354872E-005, 973 | -1.309637537E-005, 974 | -9.561075785E-006, 975 | -6.084746474E-006, 976 | -3.086857760E-006, 977 | -7.198007665E-007, 978 | +1.853591357E-006, 979 | +1.470520488E-006, 980 | +9.984935332E-007, 981 | +5.633860383E-007, 982 | +6.993315310E-006, 983 | +1.207003334E-005, 984 | +1.661818715E-005, 985 | +1.776598037E-005, 986 | +1.806914770E-005, 987 | +2.677291741E-005, 988 | +2.978993689E-005, 989 | +3.225446198E-005, 990 | +3.397853652E-005, 991 | +3.495384954E-005, 992 | +3.515914432E-005, 993 | +3.460439257E-005, 994 | +3.334947178E-005, 995 | +3.144468428E-005, 996 | -2.042970118E-005, 997 | -1.987093310E-005, 998 | -1.884208177E-005, 999 | -1.743183020E-005, 1000 | -1.571428584E-005, 1001 | -1.379448349E-005, 1002 | -1.177108606E-005, 1003 | -9.826449968E-006, 1004 | -7.869333785E-006, 1005 | -2.319611212E-006, 1006 | -3.157242645E-006, 1007 | -3.617151151E-006, 1008 | -2.497214155E-006, 1009 | -1.189317118E-006, 1010 | -6.437721822E-008, 1011 | -8.434094667E-008, 1012 | +3.809887872E-008, 1013 | +3.246264413E-008, 1014 | -6.402664354E-008, 1015 | -2.975164826E-008, 1016 | -9.458596395E-008, 1017 | -4.341498823E-007, 1018 | -8.427224429E-007, 1019 | -3.332600045E-006, 1020 | -4.429412002E-006, 1021 | -5.315936960E-006, 1022 | -6.225028756E-006, 1023 | -6.986399967E-006, 1024 | -7.568834008E-006, 1025 | -7.941360309E-006, 1026 | -8.087732567E-006, 1027 | -8.006985809E-006, 1028 | -6.361419310E-006, 1029 | -6.015239251E-006, 1030 | -5.516381407E-006, 1031 | -4.896494374E-006, 1032 | -4.195037945E-006, 1033 | -3.453840463E-006, 1034 | -2.715013807E-006, 1035 | -2.032118118E-006, 1036 | -1.399798180E-006, 1037 | -3.132386439E-007, 1038 | -1.444918922E-007, 1039 | -2.788728892E-008, 1040 | -7.506701927E-009, 1041 | -1.314406006E-008, 1042 | +3.399493131E-009, 1043 | +2.682709610E-009, 1044 | +1.613285505E-009, 1045 | +6.702406963E-010, 1046 | -7.834767501E-008, 1047 | -2.014677420E-007, 1048 | -5.234479659E-007, 1049 | -1.190443072E-006, 1050 | -1.975324267E-006, 1051 | -9.451737242E-007, 1052 | -1.033426656E-006, 1053 | -1.179182050E-006, 1054 | -1.194632091E-006, 1055 | -1.162929266E-006, 1056 | -1.085227950E-006, 1057 | -9.742954035E-007, 1058 | -8.419976893E-007, 1059 | -7.003467317E-007, 1060 | +5.564140224E-007, 1061 | +6.262345096E-007, 1062 | +6.767839409E-007, 1063 | +7.020648809E-007, 1064 | +6.982898526E-007, 1065 | +6.628192182E-007, 1066 | +6.022448247E-007, 1067 | +4.741137047E-007, 1068 | +3.970030775E-007, 1069 | +7.342250683E-007, 1070 | +3.961981463E-007, 1071 | +1.543309907E-007, 1072 | +5.083275667E-008, 1073 | +1.608403011E-008, 1074 | -7.018770981E-011, 1075 | -1.135985195E-010, 1076 | }, 1077 | { 1078 | -1.390191784E-007, 1079 | -1.693738625E-007, 1080 | -2.030677564E-007, 1081 | -2.404238444E-007, 1082 | -2.818143514E-007, 1083 | -3.276689142E-007, 1084 | -3.784752209E-007, 1085 | -4.347855338E-007, 1086 | -4.972276315E-007, 1087 | -5.665120852E-007, 1088 | -6.434325428E-007, 1089 | -7.288739425E-007, 1090 | -8.238164355E-007, 1091 | -9.293416952E-007, 1092 | -1.046637067E-006, 1093 | -1.176999604E-006, 1094 | -1.321840614E-006, 1095 | -1.482681114E-006, 1096 | -1.661159786E-006, 1097 | -1.859034001E-006, 1098 | -2.078171747E-006, 1099 | -2.320550948E-006, 1100 | -2.588257530E-006, 1101 | -2.883470643E-006, 1102 | -3.208459020E-006, 1103 | -3.565570978E-006, 1104 | -3.957220997E-006, 1105 | -4.385879038E-006, 1106 | -4.854050530E-006, 1107 | -5.364252502E-006, 1108 | -5.918994248E-006, 1109 | -6.520755960E-006, 1110 | -7.171964626E-006, 1111 | -7.874960829E-006, 1112 | -8.631964192E-006, 1113 | -9.445050637E-006, 1114 | -1.031611009E-005, 1115 | -1.124680875E-005, 1116 | -1.223855270E-005, 1117 | -1.329243969E-005, 1118 | -1.440921824E-005, 1119 | -1.558924305E-005, 1120 | -1.683242772E-005, 1121 | -1.813820381E-005, 1122 | -1.950545993E-005, 1123 | -2.093250441E-005, 1124 | -2.241701623E-005, 1125 | -2.395598858E-005, 1126 | -2.554569073E-005, 1127 | -2.718161704E-005, 1128 | -2.885844333E-005, 1129 | -3.056998685E-005, 1130 | -3.230916263E-005, 1131 | -3.406793985E-005, 1132 | -3.583733633E-005, 1133 | -3.760734762E-005, 1134 | -3.936696885E-005, 1135 | -4.110412556E-005, 1136 | -4.280570283E-005, 1137 | -4.445751256E-005, 1138 | -4.604430433E-005, 1139 | -4.754976908E-005, 1140 | -4.895655002E-005, 1141 | -5.024627535E-005, 1142 | +5.139957648E-005, 1143 | +5.239612074E-005, 1144 | +5.321469871E-005, 1145 | +5.383323878E-005, 1146 | +5.422891263E-005, 1147 | +5.437819709E-005, 1148 | +5.425697600E-005, 1149 | +5.384063843E-005, 1150 | +5.310418419E-005, 1151 | +5.202236207E-005, 1152 | +5.056979353E-005, 1153 | +4.872112549E-005, 1154 | +4.645117951E-005, 1155 | +4.373511547E-005, 1156 | +4.054862075E-005, 1157 | +3.686808850E-005, 1158 | +3.267079956E-005, 1159 | +2.793515523E-005, 1160 | +2.264085742E-005, 1161 | +1.676913780E-005, 1162 | +1.030297699E-005, 1163 | +3.227306706E-006, 1164 | -4.470633485E-006, 1165 | -1.280130618E-005, 1166 | -2.177240640E-005, 1167 | -3.138873581E-005, 1168 | -4.165195787E-005, 1169 | -5.256036457E-005, 1170 | -6.410864444E-005, 1171 | -7.628766616E-005, 1172 | -8.908427117E-005, 1173 | -1.024810626E-004, 1174 | -1.164562127E-004, 1175 | -1.309833024E-004, 1176 | -1.460311323E-004, 1177 | -1.615635992E-004, 1178 | -1.775395358E-004, 1179 | -1.939126523E-004, 1180 | -2.106313768E-004, 1181 | -2.276388550E-004, 1182 | -2.448728774E-004, 1183 | -2.622658503E-004, 1184 | -2.797449124E-004, 1185 | -2.972317743E-004, 1186 | -3.146430245E-004, 1187 | -3.318900708E-004, 1188 | -3.488793736E-004, 1189 | -3.655125911E-004, 1190 | -3.816867538E-004, 1191 | -3.972945851E-004, 1192 | -4.122247046E-004, 1193 | -4.263620067E-004, 1194 | -4.395879805E-004, 1195 | -4.517810594E-004, 1196 | -4.628172028E-004, 1197 | -4.725702747E-004, 1198 | -4.809123348E-004, 1199 | -4.877146275E-004, 1200 | -4.928477574E-004, 1201 | -4.961824161E-004, 1202 | -4.975944757E-004, 1203 | -4.969481961E-004, 1204 | -4.941228544E-004, 1205 | -4.889960401E-004, 1206 | +4.814492422E-004, 1207 | +4.713678791E-004, 1208 | +4.586426076E-004, 1209 | +4.431701091E-004, 1210 | +4.248536134E-004, 1211 | +4.036037717E-004, 1212 | +3.793396754E-004, 1213 | +3.519894381E-004, 1214 | +3.214911267E-004, 1215 | +2.877934603E-004, 1216 | +2.508567995E-004, 1217 | +2.106537577E-004, 1218 | +1.671699720E-004, 1219 | +1.204049113E-004, 1220 | +7.037253090E-005, 1221 | +1.710198012E-005, 1222 | -3.936182839E-005, 1223 | -9.895755647E-005, 1224 | -1.616069785E-004, 1225 | -2.272142592E-004, 1226 | -2.956659591E-004, 1227 | -3.668301215E-004, 1228 | -4.405563814E-004, 1229 | -5.166754709E-004, 1230 | -5.949990009E-004, 1231 | -6.753197522E-004, 1232 | -7.574109477E-004, 1233 | -8.410271257E-004, 1234 | -9.259034996E-004, 1235 | -1.011756598E-003, 1236 | -1.098284614E-003, 1237 | -1.185167348E-003, 1238 | -1.272067428E-003, 1239 | -1.358630019E-003, 1240 | -1.444484224E-003, 1241 | -1.529243193E-003, 1242 | -1.612505526E-003, 1243 | -1.693855622E-003, 1244 | -1.772865304E-003, 1245 | -1.849094522E-003, 1246 | -1.922092517E-003, 1247 | -1.991399564E-003, 1248 | -2.056547208E-003, 1249 | -2.117061289E-003, 1250 | -2.172462177E-003, 1251 | -2.222266514E-003, 1252 | -2.265989315E-003, 1253 | -2.303145360E-003, 1254 | -2.333251061E-003, 1255 | -2.355825622E-003, 1256 | -2.370394068E-003, 1257 | -2.376487479E-003, 1258 | -2.373647178E-003, 1259 | -2.361423569E-003, 1260 | -2.339380793E-003, 1261 | -2.307097195E-003, 1262 | -2.264167881E-003, 1263 | -2.210205887E-003, 1264 | -2.144844970E-003, 1265 | -2.067740774E-003, 1266 | -1.978572691E-003, 1267 | -1.877046190E-003, 1268 | -1.762894331E-003, 1269 | -1.635878929E-003, 1270 | +1.495792647E-003, 1271 | +1.342460280E-003, 1272 | +1.175740734E-003, 1273 | +9.955273708E-004, 1274 | +8.017504588E-004, 1275 | +5.943773431E-004, 1276 | +3.734139318E-004, 1277 | +1.389056415E-004, 1278 | -1.090620208E-004, 1279 | -3.703625989E-004, 1280 | -6.448282511E-004, 1281 | -9.322494152E-004, 1282 | -1.232374110E-003, 1283 | -1.544908970E-003, 1284 | -1.869517611E-003, 1285 | -2.205822384E-003, 1286 | -2.553403843E-003, 1287 | -2.911801683E-003, 1288 | -3.280514618E-003, 1289 | -3.659002949E-003, 1290 | -4.046686925E-003, 1291 | -4.442950245E-003, 1292 | -4.847140983E-003, 1293 | -5.258570891E-003, 1294 | -5.676518660E-003, 1295 | -6.100233644E-003, 1296 | -6.528933067E-003, 1297 | -6.961807609E-003, 1298 | -7.398022339E-003, 1299 | -7.836719044E-003, 1300 | -8.277016692E-003, 1301 | -8.718019351E-003, 1302 | -9.158811532E-003, 1303 | -9.598465636E-003, 1304 | -1.003604382E-002, 1305 | -1.047059800E-002, 1306 | -1.090117730E-002, 1307 | -1.132682897E-002, 1308 | -1.174659748E-002, 1309 | -1.215953380E-002, 1310 | -1.256469358E-002, 1311 | -1.296114177E-002, 1312 | -1.334795821E-002, 1313 | -1.372423489E-002, 1314 | -1.408908330E-002, 1315 | -1.444163360E-002, 1316 | -1.478104480E-002, 1317 | -1.510649733E-002, 1318 | -1.541720331E-002, 1319 | -1.571240649E-002, 1320 | -1.599138230E-002, 1321 | -1.625344716E-002, 1322 | -1.649795473E-002, 1323 | -1.672429405E-002, 1324 | -1.693190821E-002, 1325 | -1.712027565E-002, 1326 | -1.728892699E-002, 1327 | -1.743743755E-002, 1328 | -1.756543480E-002, 1329 | -1.767260395E-002, 1330 | -1.775865816E-002, 1331 | -1.782339066E-002, 1332 | -1.786663756E-002, 1333 | -1.788828894E-002, 1334 | +1.788828894E-002, 1335 | +1.786663756E-002, 1336 | +1.782339066E-002, 1337 | +1.775865816E-002, 1338 | +1.767260395E-002, 1339 | +1.756543480E-002, 1340 | +1.743743755E-002, 1341 | +1.728892699E-002, 1342 | +1.712027565E-002, 1343 | +1.693190821E-002, 1344 | +1.672429405E-002, 1345 | +1.649795473E-002, 1346 | +1.625344716E-002, 1347 | +1.599138230E-002, 1348 | +1.571240649E-002, 1349 | +1.541720331E-002, 1350 | +1.510649733E-002, 1351 | +1.478104480E-002, 1352 | +1.444163360E-002, 1353 | +1.408908330E-002, 1354 | +1.372423489E-002, 1355 | +1.334795821E-002, 1356 | +1.296114177E-002, 1357 | +1.256469358E-002, 1358 | +1.215953380E-002, 1359 | +1.174659748E-002, 1360 | +1.132682897E-002, 1361 | +1.090117730E-002, 1362 | +1.047059800E-002, 1363 | +1.003604382E-002, 1364 | +9.598465636E-003, 1365 | +9.158811532E-003, 1366 | +8.718019351E-003, 1367 | +8.277016692E-003, 1368 | +7.836719044E-003, 1369 | +7.398022339E-003, 1370 | +6.961807609E-003, 1371 | +6.528933067E-003, 1372 | +6.100233644E-003, 1373 | +5.676518660E-003, 1374 | +5.258570891E-003, 1375 | +4.847140983E-003, 1376 | +4.442950245E-003, 1377 | +4.046686925E-003, 1378 | +3.659002949E-003, 1379 | +3.280514618E-003, 1380 | +2.911801683E-003, 1381 | +2.553403843E-003, 1382 | +2.205822384E-003, 1383 | +1.869517611E-003, 1384 | +1.544908970E-003, 1385 | +1.232374110E-003, 1386 | +9.322494152E-004, 1387 | +6.448282511E-004, 1388 | +3.703625989E-004, 1389 | +1.090620208E-004, 1390 | -1.389056415E-004, 1391 | -3.734139318E-004, 1392 | -5.943773431E-004, 1393 | -8.017504588E-004, 1394 | -9.955273708E-004, 1395 | -1.175740734E-003, 1396 | -1.342460280E-003, 1397 | -1.495792647E-003, 1398 | +1.635878929E-003, 1399 | +1.762894331E-003, 1400 | +1.877046190E-003, 1401 | +1.978572691E-003, 1402 | +2.067740774E-003, 1403 | +2.144844970E-003, 1404 | +2.210205887E-003, 1405 | +2.264167881E-003, 1406 | +2.307097195E-003, 1407 | +2.339380793E-003, 1408 | +2.361423569E-003, 1409 | +2.373647178E-003, 1410 | +2.376487479E-003, 1411 | +2.370394068E-003, 1412 | +2.355825622E-003, 1413 | +2.333251061E-003, 1414 | +2.303145360E-003, 1415 | +2.265989315E-003, 1416 | +2.222266514E-003, 1417 | +2.172462177E-003, 1418 | +2.117061289E-003, 1419 | +2.056547208E-003, 1420 | +1.991399564E-003, 1421 | +1.922092517E-003, 1422 | +1.849094522E-003, 1423 | +1.772865304E-003, 1424 | +1.693855622E-003, 1425 | +1.612505526E-003, 1426 | +1.529243193E-003, 1427 | +1.444484224E-003, 1428 | +1.358630019E-003, 1429 | +1.272067428E-003, 1430 | +1.185167348E-003, 1431 | +1.098284614E-003, 1432 | +1.011756598E-003, 1433 | +9.259034996E-004, 1434 | +8.410271257E-004, 1435 | +7.574109477E-004, 1436 | +6.753197522E-004, 1437 | +5.949990009E-004, 1438 | +5.166754709E-004, 1439 | +4.405563814E-004, 1440 | +3.668301215E-004, 1441 | +2.956659591E-004, 1442 | +2.272142592E-004, 1443 | +1.616069785E-004, 1444 | +9.895755647E-005, 1445 | +3.936182839E-005, 1446 | -1.710198012E-005, 1447 | -7.037253090E-005, 1448 | -1.204049113E-004, 1449 | -1.671699720E-004, 1450 | -2.106537577E-004, 1451 | -2.508567995E-004, 1452 | -2.877934603E-004, 1453 | -3.214911267E-004, 1454 | -3.519894381E-004, 1455 | -3.793396754E-004, 1456 | -4.036037717E-004, 1457 | -4.248536134E-004, 1458 | -4.431701091E-004, 1459 | -4.586426076E-004, 1460 | -4.713678791E-004, 1461 | -4.814492422E-004, 1462 | +4.889960401E-004, 1463 | +4.941228544E-004, 1464 | +4.969481961E-004, 1465 | +4.975944757E-004, 1466 | +4.961824161E-004, 1467 | +4.928477574E-004, 1468 | +4.877146275E-004, 1469 | +4.809123348E-004, 1470 | +4.725702747E-004, 1471 | +4.628172028E-004, 1472 | +4.517810594E-004, 1473 | +4.395879805E-004, 1474 | +4.263620067E-004, 1475 | +4.122247046E-004, 1476 | +3.972945851E-004, 1477 | +3.816867538E-004, 1478 | +3.655125911E-004, 1479 | +3.488793736E-004, 1480 | +3.318900708E-004, 1481 | +3.146430245E-004, 1482 | +2.972317743E-004, 1483 | +2.797449124E-004, 1484 | +2.622658503E-004, 1485 | +2.448728774E-004, 1486 | +2.276388550E-004, 1487 | +2.106313768E-004, 1488 | +1.939126523E-004, 1489 | +1.775395358E-004, 1490 | +1.615635992E-004, 1491 | +1.460311323E-004, 1492 | +1.309833024E-004, 1493 | +1.164562127E-004, 1494 | +1.024810626E-004, 1495 | +8.908427117E-005, 1496 | +7.628766616E-005, 1497 | +6.410864444E-005, 1498 | +5.256036457E-005, 1499 | +4.165195787E-005, 1500 | +3.138873581E-005, 1501 | +2.177240640E-005, 1502 | +1.280130618E-005, 1503 | +4.470633485E-006, 1504 | -3.227306706E-006, 1505 | -1.030297699E-005, 1506 | -1.676913780E-005, 1507 | -2.264085742E-005, 1508 | -2.793515523E-005, 1509 | -3.267079956E-005, 1510 | -3.686808850E-005, 1511 | -4.054862075E-005, 1512 | -4.373511547E-005, 1513 | -4.645117951E-005, 1514 | -4.872112549E-005, 1515 | -5.056979353E-005, 1516 | -5.202236207E-005, 1517 | -5.310418419E-005, 1518 | -5.384063843E-005, 1519 | -5.425697600E-005, 1520 | -5.437819709E-005, 1521 | -5.422891263E-005, 1522 | -5.383323878E-005, 1523 | -5.321469871E-005, 1524 | -5.239612074E-005, 1525 | -5.139957648E-005, 1526 | +5.024627535E-005, 1527 | +4.895655002E-005, 1528 | +4.754976908E-005, 1529 | +4.604430433E-005, 1530 | +4.445751256E-005, 1531 | +4.280570283E-005, 1532 | +4.110412556E-005, 1533 | +3.936696885E-005, 1534 | +3.760734762E-005, 1535 | +3.583733633E-005, 1536 | +3.406793985E-005, 1537 | +3.230916263E-005, 1538 | +3.056998685E-005, 1539 | +2.885844333E-005, 1540 | +2.718161704E-005, 1541 | +2.554569073E-005, 1542 | +2.395598858E-005, 1543 | +2.241701623E-005, 1544 | +2.093250441E-005, 1545 | +1.950545993E-005, 1546 | +1.813820381E-005, 1547 | +1.683242772E-005, 1548 | +1.558924305E-005, 1549 | +1.440921824E-005, 1550 | +1.329243969E-005, 1551 | +1.223855270E-005, 1552 | +1.124680875E-005, 1553 | +1.031611009E-005, 1554 | +9.445050637E-006, 1555 | +8.631964192E-006, 1556 | +7.874960829E-006, 1557 | +7.171964626E-006, 1558 | +6.520755960E-006, 1559 | +5.918994248E-006, 1560 | +5.364252502E-006, 1561 | +4.854050530E-006, 1562 | +4.385879038E-006, 1563 | +3.957220997E-006, 1564 | +3.565570978E-006, 1565 | +3.208459020E-006, 1566 | +2.883470643E-006, 1567 | +2.588257530E-006, 1568 | +2.320550948E-006, 1569 | +2.078171747E-006, 1570 | +1.859034001E-006, 1571 | +1.661159786E-006, 1572 | +1.482681114E-006, 1573 | +1.321840614E-006, 1574 | +1.176999604E-006, 1575 | +1.046637067E-006, 1576 | +9.293416952E-007, 1577 | +8.238164355E-007, 1578 | +7.288739425E-007, 1579 | +6.434325428E-007, 1580 | +5.665120852E-007, 1581 | +4.972276315E-007, 1582 | +4.347855338E-007, 1583 | +3.784752209E-007, 1584 | +3.276689142E-007, 1585 | +2.818143514E-007, 1586 | +2.404238444E-007, 1587 | +2.030677564E-007, 1588 | +1.693738625E-007, 1589 | +1.390191784E-007, 1590 | } 1591 | }; 1592 | 1593 | #endif 1594 | --------------------------------------------------------------------------------