Projects
Essentials
dcadec
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 6
View file
dcadec.changes
Changed
@@ -1,4 +1,21 @@ ------------------------------------------------------------------- +Fri Jan 15 11:37:22 UTC 2016 - aloisio@gmx.com + +- Update to version 0.2.0 + * Fixed installation of shared library symlink. + * Switched LFE channel interpolation to FIR filter by default. + * Added command line option and context flag to select IIR + filter for LFE channel interpolation. + * Fixed two bugs that could cause decoder to crash when + processing invalid input. + * Fixed handling of sync loss when decoding MA streams with + multiple frequency bands. + * Fixed decoding of MA streams with multiple frequency bands + when sampling frequency of the first band is not 96 kHz. + * Fixed decoding to standard output on Windows causing junk + to be appended after normal PCM data. + +------------------------------------------------------------------- Mon Dec 7 06:15:40 UTC 2015 - virtuousfox@gmail.com - Added missing baselibs.conf needed for 32bit ffmpeg
View file
dcadec.spec
Changed
@@ -1,7 +1,7 @@ # # spec file for package dcadec # -# Copyright (c) 2015 Packman Team <packman@links2linux.de> +# Copyright (c) 2016 Packman Team <packman@links2linux.de> # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ %define libmaj 0 Name: dcadec -Version: 0.1.0 +Version: 0.2.0 Release: 0 Summary: DTS Coherent Acoustics decoder with support for HD extensions License: LGPL-2.1 @@ -81,7 +81,8 @@ %files -n lib%{name}%{libmaj} %defattr(-,root,root) %doc COPYING.LGPLv2.1 README.md -%{_libdir}/lib%{name}.so.0.0.0 +%{_libdir}/lib%{name}.so.0 +%{_libdir}/lib%{name}.so.0.1.0 %files -n lib%{name}-devel %defattr(-,root,root)
View file
dcadec-0.2.0.tar.gz/CHANGELOG.md
Added
@@ -0,0 +1,19 @@ +v0.2.0 - Jan 04, 2016 +===================== +- Fixed installation of shared library symlink. +- Switched LFE channel interpolation to FIR filter by default. +- Added command line option and context flag to select IIR filter for LFE + channel interpolation. +- Fixed two bugs that could cause decoder to crash when processing invalid + input. +- Fixed handling of sync loss when decoding MA streams with multiple frequency + bands. +- Fixed decoding of MA streams with multiple frequency bands when sampling + frequency of the first band is not 96 kHz. +- Fixed decoding to standard output on Windows causing junk to be appended + after normal PCM data. + + +v0.1.0 - Nov 27, 2015 +===================== +- Initial public release.
View file
dcadec-0.1.0.tar.gz/Makefile -> dcadec-0.2.0.tar.gz/Makefile
Changed
@@ -1,7 +1,7 @@ -VERSION = 0.1.0 +VERSION = 0.2.0 API_MAJOR = 0 -API_MINOR = 0 +API_MINOR = 1 API_PATCH = 0 CFLAGS := -std=gnu99 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -O3 -ffast-math -g -MMD $(CFLAGS) @@ -179,6 +179,7 @@ install -m 644 dcadec.pc $(DESTDIR)$(LIBDIR)/pkgconfig ifdef SONAME ln -sf libdcadec$(DLLSUF)$(SONAMESUF) $(DESTDIR)$(LIBDIR)/libdcadec$(DLLSUF) + ln -sf libdcadec$(DLLSUF)$(SONAMESUF) $(DESTDIR)$(LIBDIR)/libdcadec$(DLLSUF)$(SONAMESUF_MAJOR) endif install-dec: $(OUT_DEC)
View file
dcadec-0.1.0.tar.gz/README.md -> dcadec-0.2.0.tar.gz/README.md
Changed
@@ -38,6 +38,8 @@ -h Show this help message. +-i Use IIR filter for floating point DTS core LFE channel interpolation. + -l Enable lenient decoding mode. Attempt to recover from errors by skipping non-decodable parts of the stream.
View file
dcadec-0.1.0.tar.gz/dcadec.c -> dcadec-0.2.0.tar.gz/dcadec.c
Changed
@@ -40,10 +40,10 @@ #include "libdcadec/dca_context.h" #include "libdcadec/dca_waveout.h" -static void print_help(char *name) +static void print_help(const char *name) { fprintf(stderr, -"Usage: %s [-26bcfhlmnPqSx] <input.dts> [output.wav]\n" +"Usage: %s [-26bcfhilmnPqSx] <input.dts> [output.wav]\n" "dcadec is a free DTS Coherent Acoustics decoder. Supported options:\n" "\n" "-2 Extract embedded 2.0 downmix if present, otherwise extract 5.1 downmix.\n" @@ -59,6 +59,8 @@ "\n" "-h Show this help message.\n" "\n" +"-i Use IIR filter for floating point DTS core LFE channel interpolation.\n" +"\n" "-l Enable lenient decoding mode. Attempt to recover from errors by skipping\n" " non-decodable parts of the stream.\n" "\n" @@ -103,7 +105,7 @@ return "???"; buf[0] = 0; - for (int i = 0; i < 16; i++) { + for (size_t i = 0; i < sizeof(spkr_pair_names) / sizeof(spkr_pair_names[0]); i++) { if (mask & (1 << i)) { if (buf[0]) strcat(buf, " "); @@ -209,7 +211,7 @@ bool no_strip = false; int opt; - while ((opt = getopt(argc, argv, "26bcfhlmnPqSsx")) != -1) { + while ((opt = getopt(argc, argv, "26bcfhilmnPqSsx")) != -1) { switch (opt) { case '2': flags |= DCADEC_FLAG_KEEP_DMIX_2CH; @@ -224,11 +226,16 @@ flags |= DCADEC_FLAG_CORE_ONLY; break; case 'f': + flags &= ~DCADEC_FLAG_CORE_LFE_IIR; flags |= DCADEC_FLAG_CORE_LFE_FIR; break; case 'h': print_help(argv[0]); return 0; + case 'i': + flags &= ~DCADEC_FLAG_CORE_LFE_FIR; + flags |= DCADEC_FLAG_CORE_LFE_IIR; + break; case 'l': flags &= ~DCADEC_FLAG_STRICT; break; @@ -354,17 +361,10 @@ } if (!quiet) { - if (waveout) { - if (flags & DCADEC_FLAG_CORE_ONLY) - fprintf(stderr, "Decoding (core only)...\n"); - else - fprintf(stderr, "Decoding...\n"); - } else { - if (flags & DCADEC_FLAG_CORE_ONLY) - fprintf(stderr, "Parsing (core only)...\n"); - else - fprintf(stderr, "Parsing...\n"); - } + const bool core_only = (flags & DCADEC_FLAG_CORE_ONLY); + fprintf(stderr, "%s%s...\n", + waveout ? "Decoding" : "Parsing", + core_only ? " (core only)" : ""); } while (!interrupted) {
View file
dcadec-0.1.0.tar.gz/libdcadec/bitstream.c -> dcadec-0.2.0.tar.gz/libdcadec/bitstream.c
Changed
@@ -19,21 +19,13 @@ #include "common.h" #include "bitstream.h" -void bits_init(struct bitstream *bits, uint8_t *data, size_t size) -{ - assert(!((uintptr_t)data & 3)); - bits->data = (uint32_t *)data; - bits->total = size << 3; - bits->index = 0; -} - static inline uint32_t bits_peek(struct bitstream *bits) { if (bits->index >= bits->total) return 0; - size_t pos = bits->index >> 5; - size_t shift = bits->index & 31; + int pos = bits->index >> 5; + int shift = bits->index & 31; uint32_t v = DCA_32BE(bits->data[pos]); if (shift) { @@ -59,8 +51,6 @@ int bits_get(struct bitstream *bits, int n) { - assert(n > 0 && n <= 32); - uint32_t v = bits_peek(bits); v >>= 32 - n; @@ -70,8 +60,6 @@ int bits_get_signed(struct bitstream *bits, int n) { - assert(n > 0 && n <= 32); - int32_t v = bits_peek(bits); v >>= 32 - n; @@ -84,18 +72,18 @@ if (n == 0) return 0; - int v = bits_get(bits, n); + unsigned int v = bits_get(bits, n); return (v >> 1) ^ -(v & 1); } -int bits_get_unsigned_rice(struct bitstream *bits, int k) +static int bits_get_unsigned_rice(struct bitstream *bits, int k) { - int unary = 0; + unsigned int unary = 0; while (bits->index < bits->total) { uint32_t v = bits_peek(bits); if (v) { - int z = dca_clz32(v); + int z = dca_clz(v); bits->index += z + 1; unary += z; break; @@ -109,7 +97,7 @@ int bits_get_signed_rice(struct bitstream *bits, int k) { - int v = bits_get_unsigned_rice(bits, k); + unsigned int v = bits_get_unsigned_rice(bits, k); return (v >> 1) ^ -(v & 1); } @@ -129,61 +117,31 @@ int bits_get_signed_vlc(struct bitstream *bits, const struct huffman *h) { - int v = bits_get_unsigned_vlc(bits, h); + unsigned int v = bits_get_unsigned_vlc(bits, h); return ((v >> 1) ^ ((v & 1) - 1)) + 1; } -void bits_skip(struct bitstream *bits, int n) -{ - assert(n >= 0); - bits->index += n; -} - -void bits_skip1(struct bitstream *bits) -{ - bits->index++; -} - -int bits_seek(struct bitstream *bits, size_t n) -{ - if (n < bits->index || n > bits->total) - return -DCADEC_EBADREAD; - bits->index = n; - return 0; -} - -size_t bits_align1(struct bitstream *bits) -{ - bits->index = DCA_ALIGN(bits->index, 8); - return bits->index; -} - -size_t bits_align4(struct bitstream *bits) -{ - bits->index = DCA_ALIGN(bits->index, 32); - return bits->index; -} - -static uint16_t crc16(const uint8_t *data, size_t size) +static uint16_t crc16(const uint8_t *data, int size) { static const uint16_t crctab[16] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef }; + uint16_t res = 0xffff; - while (size--) { - uint8_t c = *data++; - res = (res << 4) ^ crctab[(c >> 4) ^ (res >> 12)]; - res = (res << 4) ^ crctab[(c & 15) ^ (res >> 12)]; + for (int i = 0; i < size; i++) { + res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)]; + res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)]; } + return res; } -int bits_check_crc(struct bitstream *bits, size_t p1, size_t p2) +int bits_check_crc(struct bitstream *bits, int p1, int p2) { - if (((p1 | p2) & 7) || p1 > p2 || p2 - p1 < 16 || p2 > bits->total) + if (((p1 | p2) & 7) || p1 < 0 || p2 > bits->total || p2 - p1 < 16) return -DCADEC_EBADREAD; - if (crc16((uint8_t *)bits->data + (p1 >> 3), (p2 - p1) >> 3)) + if (crc16((uint8_t *)bits->data + p1 / 8, (p2 - p1) / 8)) return -DCADEC_EBADCRC; return 0; } @@ -202,12 +160,10 @@ void bits_get_signed_linear_array(struct bitstream *bits, int *array, int size, int n) { - if (n == 0) { + if (n == 0) memset(array, 0, sizeof(*array) * size); - } else for (int i = 0; i < size; i++) { - int v = bits_get(bits, n); - array[i] = (v >> 1) ^ -(v & 1); - } + else for (int i = 0; i < size; i++) + array[i] = bits_get_signed_linear(bits, n); } void bits_get_signed_rice_array(struct bitstream *bits, int *array, int size, int k)
View file
dcadec-0.1.0.tar.gz/libdcadec/bitstream.h -> dcadec-0.2.0.tar.gz/libdcadec/bitstream.h
Changed
@@ -26,26 +26,59 @@ struct bitstream { uint32_t *data; - size_t total; - size_t index; + int total; + int index; }; -void bits_init(struct bitstream *bits, uint8_t *data, size_t size); +static inline void bits_init(struct bitstream *bits, uint8_t *data, int size) +{ + assert(data && !((uintptr_t)data & 3)); + assert(size > 0 && size < INT_MAX / 8); + bits->data = (uint32_t *)data; + bits->total = size * 8; + bits->index = 0; +} + bool bits_get1(struct bitstream *bits); int bits_get(struct bitstream *bits, int n); int bits_get_signed(struct bitstream *bits, int n); int bits_get_signed_linear(struct bitstream *bits, int n); -int bits_get_unsigned_rice(struct bitstream *bits, int k); int bits_get_signed_rice(struct bitstream *bits, int k); int bits_get_unsigned_vlc(struct bitstream *bits, const struct huffman *h); int bits_get_signed_vlc(struct bitstream *bits, const struct huffman *h); -void bits_skip(struct bitstream *bits, int n); -void bits_skip1(struct bitstream *bits); -int bits_seek(struct bitstream *bits, size_t n); -void bits_seek1(struct bitstream *bits); -size_t bits_align1(struct bitstream *bits); -size_t bits_align4(struct bitstream *bits); -int bits_check_crc(struct bitstream *bits, size_t p1, size_t p2); + +static inline void bits_skip(struct bitstream *bits, int n) +{ + assert(n >= 0); + bits->index += n; +} + +static inline void bits_skip1(struct bitstream *bits) +{ + bits->index++; +} + +static inline int bits_seek(struct bitstream *bits, int n) +{ + if (n < bits->index || n > bits->total) + return -DCADEC_EBADREAD; + bits->index = n; + return 0; +} + +static inline int bits_align1(struct bitstream *bits) +{ + bits->index = DCA_ALIGN(bits->index, 8); + return bits->index; +} + +static inline int bits_align4(struct bitstream *bits) +{ + bits->index = DCA_ALIGN(bits->index, 32); + return bits->index; +} + +int bits_check_crc(struct bitstream *bits, int p1, int p2); void bits_get_array(struct bitstream *bits, int *array, int size, int n); void bits_get_signed_array(struct bitstream *bits, int *array, int size, int n); void bits_get_signed_linear_array(struct bitstream *bits, int *array, int size, int n);
View file
dcadec-0.1.0.tar.gz/libdcadec/common.h -> dcadec-0.2.0.tar.gz/libdcadec/common.h
Changed
@@ -23,20 +23,21 @@ #include <stdio.h> #include <stdint.h> #include <stdbool.h> +#include <stdarg.h> #include <string.h> #include <math.h> #include <errno.h> #include <assert.h> +#include <limits.h> #include "compiler.h" #include "dca_context.h" #include "ta.h" #if AT_LEAST_GCC(3, 4) -#define dca_clz32(x) __builtin_clz(x) -#define dca_clz64(x) __builtin_clzll(x) +#define dca_clz(x) __builtin_clz(x) #else -static inline int dca_clz32(uint32_t x) +static inline int dca_clz(uint32_t x) { int r = 0; @@ -49,21 +50,6 @@ return 31 - r; } - -static inline int dca_clz64(uint64_t x) -{ - int r = 0; - - assert(x); - if (x & 0xffffffff00000000) { x >>= 32; r |= 32; } - if (x & 0x00000000ffff0000) { x >>= 16; r |= 16; } - if (x & 0x000000000000ff00) { x >>= 8; r |= 8; } - if (x & 0x00000000000000f0) { x >>= 4; r |= 4; } - if (x & 0x000000000000000c) { x >>= 2; r |= 2; } - if (x & 0x0000000000000002) { x >>= 1; r |= 1; } - - return 63 - r; -} #endif #if (defined __GNUC__) && (defined __POPCNT__) @@ -165,32 +151,32 @@ return res; } -void dca_format_log(dcadec_log_cb cb, void *cbarg, int level, +void dca_format_log(struct dcadec_context *dca, int level, const char *file, int line, const char *fmt, ...) -#ifdef __GNUC__ - __attribute__((format(printf, 6, 7))) -#endif -; - -#define dca_log(lvl, obj, ...) \ - do { \ - if (obj->log_cb) \ - dca_format_log(obj->log_cb, obj->log_cbarg, DCADEC_LOG_##lvl, \ - __FILE__, __LINE__, __VA_ARGS__); \ - } while (0) - -#define dca_log_once(lvl, obj, flag, ...) \ - do { \ - if (obj->log_cb && !obj->flag) { \ - dca_format_log(obj->log_cb, obj->log_cbarg, DCADEC_LOG_##lvl, \ - __FILE__, __LINE__, __VA_ARGS__); \ - obj->flag = true; \ - } \ - } while (0) + __attribute__((format(printf, 5, 6))); + +#define DCADEC_LOG_ONCE 0x80000000 + +#define dca_log(obj, lvl, ...) \ + dca_format_log((obj)->ctx, DCADEC_LOG_##lvl, __FILE__, __LINE__, __VA_ARGS__) + +#define dca_log_once(obj, lvl, ...) \ + dca_format_log((obj)->ctx, DCADEC_LOG_##lvl | DCADEC_LOG_ONCE, __FILE__, __LINE__, __VA_ARGS__) #define DCADEC_FLAG_KEEP_DMIX_MASK \ (DCADEC_FLAG_KEEP_DMIX_2CH | DCADEC_FLAG_KEEP_DMIX_6CH) +#define SPEAKER_LAYOUT_MONO (SPEAKER_MASK_C) +#define SPEAKER_LAYOUT_STEREO (SPEAKER_MASK_L | SPEAKER_MASK_R) +#define SPEAKER_LAYOUT_2POINT1 (SPEAKER_LAYOUT_STEREO | SPEAKER_MASK_LFE1) +#define SPEAKER_LAYOUT_3_0 (SPEAKER_LAYOUT_STEREO | SPEAKER_MASK_C) +#define SPEAKER_LAYOUT_2_1 (SPEAKER_LAYOUT_STEREO | SPEAKER_MASK_Cs) +#define SPEAKER_LAYOUT_3_1 (SPEAKER_LAYOUT_3_0 | SPEAKER_MASK_Cs) +#define SPEAKER_LAYOUT_2_2 (SPEAKER_LAYOUT_STEREO | SPEAKER_MASK_Ls | SPEAKER_MASK_Rs) +#define SPEAKER_LAYOUT_5POINT0 (SPEAKER_LAYOUT_3_0 | SPEAKER_MASK_Ls | SPEAKER_MASK_Rs) +#define SPEAKER_LAYOUT_7POINT0_WIDE (SPEAKER_LAYOUT_5POINT0 | SPEAKER_MASK_Lw | SPEAKER_MASK_Rw) +#define SPEAKER_LAYOUT_7POINT1_WIDE (SPEAKER_LAYOUT_7POINT0_WIDE | SPEAKER_MASK_LFE1) + enum WaveTag { TAG_RIFF = 0x46464952, TAG_WAVE = 0x45564157,
View file
dcadec-0.1.0.tar.gz/libdcadec/compiler.h -> dcadec-0.2.0.tar.gz/libdcadec/compiler.h
Changed
@@ -31,6 +31,10 @@ typedef __int64 off_t; #endif +#ifndef __GNUC__ +#define __attribute__(x) +#endif + #define AT_LEAST_GCC(major, minor) \ (defined __GNUC__) && ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
View file
dcadec-0.1.0.tar.gz/libdcadec/core_decoder.c -> dcadec-0.2.0.tar.gz/libdcadec/core_decoder.c
Changed
@@ -29,13 +29,6 @@ #include "core_huffman.h" #include "core_vectors.h" -enum SampleType { - NO_BITS_ALLOCATED, - HUFFMAN_CODE, - BLOCK_CODE, - NO_FURTHER_ENCODING -}; - enum HeaderType { HEADER_CORE, HEADER_XCH, @@ -63,6 +56,13 @@ EXT_AUDIO_XXCH = 6 }; +enum LFEFlag { + LFE_FLAG_NONE, + LFE_FLAG_128, + LFE_FLAG_64, + LFE_FLAG_INVALID +}; + static const int8_t prm_ch_to_spkr_map[AMODE_COUNT][5] = { { SPEAKER_C, -1, -1, -1, -1 }, { SPEAKER_L, SPEAKER_R, -1, -1, -1 }, @@ -77,16 +77,16 @@ }; static const uint8_t audio_mode_ch_mask[AMODE_COUNT] = { - SPEAKER_MASK_C, - SPEAKER_MASK_L | SPEAKER_MASK_R, - SPEAKER_MASK_L | SPEAKER_MASK_R, - SPEAKER_MASK_L | SPEAKER_MASK_R, - SPEAKER_MASK_L | SPEAKER_MASK_R, - SPEAKER_MASK_C | SPEAKER_MASK_L | SPEAKER_MASK_R, - SPEAKER_MASK_L | SPEAKER_MASK_R | SPEAKER_MASK_Cs, - SPEAKER_MASK_C | SPEAKER_MASK_L | SPEAKER_MASK_R | SPEAKER_MASK_Cs, - SPEAKER_MASK_L | SPEAKER_MASK_R | SPEAKER_MASK_Ls | SPEAKER_MASK_Rs, - SPEAKER_MASK_C | SPEAKER_MASK_L | SPEAKER_MASK_R | SPEAKER_MASK_Ls | SPEAKER_MASK_Rs + SPEAKER_LAYOUT_MONO, + SPEAKER_LAYOUT_STEREO, + SPEAKER_LAYOUT_STEREO, + SPEAKER_LAYOUT_STEREO, + SPEAKER_LAYOUT_STEREO, + SPEAKER_LAYOUT_3_0, + SPEAKER_LAYOUT_2_1, + SPEAKER_LAYOUT_3_1, + SPEAKER_LAYOUT_2_2, + SPEAKER_LAYOUT_5POINT0 }; // 5.3.1 - Bit stream header @@ -96,10 +96,9 @@ bool normal_frame = bits_get1(&core->bits); // Deficit sample count - int deficit_samples = bits_get(&core->bits, 5) + 1; - if (deficit_samples < NUM_PCMBLOCK_SAMPLES && normal_frame) { + if (bits_get(&core->bits, 5) != NUM_PCMBLOCK_SAMPLES - 1) { core_err("Invalid deficit sample count"); - return -DCADEC_EBADDATA; + return normal_frame ? -DCADEC_EBADDATA : -DCADEC_ENOSUP; } // CRC present flag @@ -115,7 +114,7 @@ // Primary frame byte size core->frame_size = bits_get(&core->bits, 14) + 1; if (core->frame_size < 96) { - core_err("Invalid frame size"); + core_err("Invalid core frame size"); return -DCADEC_EBADDATA; } @@ -166,7 +165,7 @@ // Low frequency effects flag core->lfe_present = bits_get(&core->bits, 2); - if (core->lfe_present == 3) { + if (core->lfe_present == LFE_FLAG_INVALID) { core_err("Invalid low frequency effects flag"); return -DCADEC_EBADDATA; } @@ -211,10 +210,7 @@ // 5.3.2 - Primary audio coding header static int parse_coding_header(struct core_decoder *core, enum HeaderType header, int xch_base) { - int ch, n, ret; - - size_t header_pos = core->bits.index; - size_t header_size = 0; + int ch, n, ret, header_size = 0, header_pos = core->bits.index; switch (header) { case HEADER_CORE: @@ -235,8 +231,6 @@ // Add LFE channel if present if (core->lfe_present) core->ch_mask |= SPEAKER_MASK_LFE1; - - core->dmix_coeffs_present = core->dmix_embedded = false; break; case HEADER_XCH: @@ -256,19 +250,19 @@ } // Number of channels in a channel set - n = bits_get(&core->bits, 3) + 1; - if (n > 2) { - core_err_once("Unsupported number of XXCH channels (%d)", n); + int nchannels = bits_get(&core->bits, 3) + 1; + if (nchannels > MAX_CHANNELS_XXCH) { + core_err_once("Unsupported number of XXCH channels (%d)", nchannels); return -DCADEC_ENOSUP; } - core->nchannels = audio_mode_nch[core->audio_mode] + n; + core->nchannels = audio_mode_nch[core->audio_mode] + nchannels; assert(core->nchannels <= MAX_CHANNELS); // Loudspeaker layout mask unsigned int mask = bits_get(&core->bits, core->xxch_mask_nbits - SPEAKER_Cs); core->xxch_spkr_mask = mask << SPEAKER_Cs; - if (dca_popcount(core->xxch_spkr_mask) != n) { + if (dca_popcount(core->xxch_spkr_mask) != nchannels) { core_err("Invalid XXCH speaker layout mask (%#x)", core->xxch_spkr_mask); return -DCADEC_EBADDATA; } @@ -283,40 +277,39 @@ core->ch_mask = core->xxch_core_mask | core->xxch_spkr_mask; // Downmix coefficients present in stream - core->dmix_coeffs_present = bits_get1(&core->bits); - - if (core->dmix_coeffs_present) { + if (bits_get1(&core->bits)) { // Downmix already performed by encoder - core->dmix_embedded = bits_get1(&core->bits); + core->xxch_dmix_embedded = bits_get1(&core->bits); // Downmix scale factor - int code = bits_get(&core->bits, 6); - if (code) { - unsigned int index = code * 4 - 44; - if (index >= dca_countof(dmix_table_inv)) { - core_err("Invalid downmix scale index"); - return -DCADEC_EBADDATA; - } - core->dmix_scale_inv = dmix_table_inv[index]; - } else { - core->dmix_scale_inv = 0; + unsigned int index = bits_get(&core->bits, 6) * 4 - 44; + if (index >= dca_countof(dmix_table_inv)) { + core_err("Invalid XXCH downmix scale index"); + return -DCADEC_EBADDATA; } + core->xxch_dmix_scale_inv = dmix_table_inv[index]; // Downmix channel mapping mask - for (ch = xch_base; ch < core->nchannels; ch++) - core->dmix_mask[ch] = bits_get(&core->bits, core->xxch_mask_nbits); + for (ch = 0; ch < nchannels; ch++) { + mask = bits_get(&core->bits, core->xxch_mask_nbits); + if ((mask & core->xxch_core_mask) != mask) { + core_err("Invalid XXCH downmix channel mapping mask (%#x)", mask); + return -DCADEC_EBADDATA; + } + core->xxch_dmix_mask[ch] = mask; + } // Downmix coefficients - int *coeff_ptr = core->dmix_coeff; - for (ch = xch_base; ch < core->nchannels; ch++) { + int *coeff_ptr = core->xxch_dmix_coeff; + for (ch = 0; ch < nchannels; ch++) { for (n = 0; n < core->xxch_mask_nbits; n++) { - if (core->dmix_mask[ch] & (1U << n)) { + if (core->xxch_dmix_mask[ch] & (1U << n)) { int code = bits_get(&core->bits, 7); - int sign = (code >> 6) - 1; code &= 63; - if (code) { + int sign = (code >> 6) - 1; + if (code &= 63) { unsigned int index = code * 4 - 4; if (index >= dca_countof(dmix_table)) { - core_err("Invalid downmix coefficient index"); + core_err("Invalid XXCH downmix coefficient index"); return -DCADEC_EBADDATA; } *coeff_ptr++ = (dmix_table[index] ^ sign) - sign; @@ -327,7 +320,7 @@ } } } else { - core->dmix_embedded = false; + core->xxch_dmix_embedded = false;
View file
dcadec-0.1.0.tar.gz/libdcadec/core_decoder.h -> dcadec-0.2.0.tar.gz/libdcadec/core_decoder.h
Changed
@@ -32,141 +32,131 @@ #define MAX_SUBBANDS_X96 64 -#define core_err(...) dca_log(ERROR, core, __VA_ARGS__) -#define core_warn(...) dca_log(WARNING, core, __VA_ARGS__) +#define MAX_CHANNELS_CORE 6 +#define MAX_CHANNELS_DMIX 4 +#define MAX_CHANNELS_XXCH 2 +#define MAX_CHANNELS_CHSET 8 -#define core_err_once(...) dca_log_once(ERROR, core, err_shown, __VA_ARGS__) -#define core_warn_once(...) dca_log_once(WARNING, core, warn_shown, __VA_ARGS__) +#define MAX_EXSS_CHSETS 4 + +#define core_err(...) dca_log(core, ERROR, __VA_ARGS__) +#define core_warn(...) dca_log(core, WARNING, __VA_ARGS__) + +#define core_err_once(...) dca_log_once(core, ERROR, __VA_ARGS__) +#define core_warn_once(...) dca_log_once(core, WARNING, __VA_ARGS__) -struct core_decoder; struct exss_asset; -struct dcadec_core_info; - -struct x96_decoder { - struct core_decoder *core; - - int rev_no; - bool crc_present; - int nchannels; - bool high_res; - int subband_start; - int nsubbands[MAX_CHANNELS]; - int joint_intensity_index[MAX_CHANNELS]; - int scale_factor_sel[MAX_CHANNELS]; - int bit_allocation_sel[MAX_CHANNELS]; - int quant_index_sel[MAX_CHANNELS][NUM_CODE_BOOKS]; - - bool prediction_mode[MAX_CHANNELS][MAX_SUBBANDS_X96]; - int prediction_vq_index[MAX_CHANNELS][MAX_SUBBANDS_X96]; - int bit_allocation[MAX_CHANNELS][MAX_SUBBANDS_X96]; - int scale_factors[MAX_CHANNELS][MAX_SUBBANDS_X96]; - int joint_scale_sel[MAX_CHANNELS]; - int joint_scale_factors[MAX_CHANNELS][MAX_SUBBANDS_X96]; - - int rand; - - int *subband_buffer; - int *subband_samples[MAX_CHANNELS][MAX_SUBBANDS_X96]; -}; struct core_decoder { - struct bitstream bits; - - dcadec_log_cb log_cb; - void *log_cbarg; - bool err_shown; - bool warn_shown; - - bool crc_present; - int npcmblocks; - size_t frame_size; - int audio_mode; - int sample_rate; - int bit_rate; - bool drc_present; - bool ts_present; - bool aux_present; - int ext_audio_type; - bool ext_audio_present; - bool sync_ssf; - int lfe_present; - bool predictor_history; - bool filter_perfect; - int source_pcm_res; - bool es_format; - bool sumdiff_front; - bool sumdiff_surround; - - int nsubframes; - int nsubsubframes[MAX_SUBFRAMES]; - - int nchannels; - int ch_mask; - - bool dmix_coeffs_present; - bool dmix_embedded; - int dmix_scale_inv; - int dmix_mask[MAX_CHANNELS]; - int dmix_coeff[64]; - - int nsubbands[MAX_CHANNELS]; - int subband_vq_start[MAX_CHANNELS]; - int joint_intensity_index[MAX_CHANNELS]; - int transition_mode_sel[MAX_CHANNELS]; - int scale_factor_sel[MAX_CHANNELS]; - int bit_allocation_sel[MAX_CHANNELS]; - int quant_index_sel[MAX_CHANNELS][NUM_CODE_BOOKS]; - int scale_factor_adj[MAX_CHANNELS][NUM_CODE_BOOKS]; - - bool prediction_mode[MAX_CHANNELS][MAX_SUBBANDS]; - int prediction_vq_index[MAX_CHANNELS][MAX_SUBBANDS]; - int bit_allocation[MAX_CHANNELS][MAX_SUBBANDS]; - int transition_mode[MAX_SUBFRAMES][MAX_CHANNELS][MAX_SUBBANDS]; - int scale_factors[MAX_CHANNELS][MAX_SUBBANDS][2]; - int joint_scale_sel[MAX_CHANNELS]; - int joint_scale_factors[MAX_CHANNELS][MAX_SUBBANDS]; - - int *subband_buffer; - int *subband_samples[MAX_CHANNELS][MAX_SUBBANDS]; - struct interpolator *subband_dsp[MAX_CHANNELS]; - struct idct_context *subband_dsp_idct; - - int *lfe_samples; - - bool prim_dmix_embedded; - int prim_dmix_type; - int prim_dmix_coeff[4 * 6]; - - int ext_audio_mask; - - size_t xch_pos; - - bool xxch_crc_present; - int xxch_mask_nbits; - int xxch_core_mask; - int xxch_spkr_mask; - size_t xxch_pos; - - struct x96_decoder *x96_decoder; - size_t x96_pos; - - int *output_buffer; - int *output_samples[SPEAKER_COUNT]; - int output_history_lfe; - - int npcmsamples; - int output_rate; - - int filter_flags; + struct dcadec_context *ctx; ///< Parent context + struct bitstream bits; ///< Bitstream reader + + // Bit stream header + bool crc_present; ///< CRC present flag + int npcmblocks; ///< Number of PCM sample blocks + int frame_size; ///< Primary frame byte size + int audio_mode; ///< Audio channel arrangement + int sample_rate; ///< Core audio sampling frequency + int bit_rate; ///< Transmission bit rate + bool drc_present; ///< Embedded dynamic range flag + bool ts_present; ///< Embedded time stamp flag + bool aux_present; ///< Auxiliary data flag + int ext_audio_type; ///< Extension audio descriptor flag + bool ext_audio_present; ///< Extended coding flag + bool sync_ssf; ///< Audio sync word insertion flag + int lfe_present; ///< Low frequency effects flag + bool predictor_history; ///< Predictor history flag switch + bool filter_perfect; ///< Multirate interpolator switch + int source_pcm_res; ///< Source PCM resolution + bool es_format; ///< Extended surround (ES) mastering flag + bool sumdiff_front; ///< Front sum/difference flag + bool sumdiff_surround; ///< Surround sum/difference flag + + // Primary audio coding header + int nsubframes; ///< Number of subframes + int nchannels; ///< Number of primary audio channels (incl. extension channels) + int ch_mask; ///< Speaker layout mask (incl. LFE and extension channels) + int8_t nsubbands[MAX_CHANNELS]; ///< Subband activity count + int8_t subband_vq_start[MAX_CHANNELS]; ///< High frequency VQ start subband + int8_t joint_intensity_index[MAX_CHANNELS]; ///< Joint intensity coding index + int8_t transition_mode_sel[MAX_CHANNELS]; ///< Transient mode code book + int8_t scale_factor_sel[MAX_CHANNELS]; ///< Scale factor code book + int8_t bit_allocation_sel[MAX_CHANNELS]; ///< Bit allocation quantizer select + int8_t quant_index_sel[MAX_CHANNELS][NUM_CODE_BOOKS]; ///< Quantization index codebook select + int32_t scale_factor_adj[MAX_CHANNELS][NUM_CODE_BOOKS]; ///< Scale factor adjustment + + // Primary audio coding side information + int8_t nsubsubframes[MAX_SUBFRAMES]; ///< Subsubframe count for each subframe + int8_t prediction_mode[MAX_CHANNELS][MAX_SUBBANDS_X96]; ///< Prediction mode + int16_t prediction_vq_index[MAX_CHANNELS][MAX_SUBBANDS_X96]; ///< Prediction coefficients VQ address + int8_t bit_allocation[MAX_CHANNELS][MAX_SUBBANDS_X96]; ///< Bit allocation index + int8_t transition_mode[MAX_SUBFRAMES][MAX_CHANNELS][MAX_SUBBANDS]; ///< Transition mode + union { + int32_t scale_factors[MAX_CHANNELS][MAX_SUBBANDS][2]; ///< Scale factors (2x for transients) + int32_t x96_scale_factors[MAX_CHANNELS][MAX_SUBBANDS_X96]; ///< X96 scale factors + }; + int8_t joint_scale_sel[MAX_CHANNELS]; ///< Joint subband codebook select + int32_t joint_scale_factors[MAX_CHANNELS][MAX_SUBBANDS_X96]; ///< Scale factors for joint subband coding + + // Auxiliary data + bool prim_dmix_embedded; ///< Auxiliary dynamic downmix flag + int prim_dmix_type; ///< Auxiliary primary channel downmix type + int prim_dmix_coeff[MAX_CHANNELS_DMIX * MAX_CHANNELS_CORE]; ///< Dynamic downmix code coefficients + + // Core extensions + int ext_audio_mask; ///< Bit mask of fully decoded core extensions + + // XCH extension data
View file
dcadec-0.1.0.tar.gz/libdcadec/dca_context.c -> dcadec-0.2.0.tar.gz/libdcadec/dca_context.c
Changed
@@ -22,36 +22,42 @@ #include "xll_decoder.h" #include "fixed_math.h" -#define DCADEC_PACKET_CORE 0x01 -#define DCADEC_PACKET_EXSS 0x02 -#define DCADEC_PACKET_XLL 0x04 +#define MAX_PACKET_SIZE 0x104000 -#define DCADEC_PACKET_FILTERED 0x100 -#define DCADEC_PACKET_RECOVERY 0x200 +#define PACKET_CORE 0x01 +#define PACKET_EXSS 0x02 +#define PACKET_XLL 0x04 + +#define PACKET_FILTERED 0x100 +#define PACKET_RECOVERY 0x200 + +#define dca_warn_once(...) \ + dca_format_log(dca, DCADEC_LOG_WARNING | DCADEC_LOG_ONCE, __FILE__, __LINE__, __VA_ARGS__) struct dcadec_context { - dcadec_log_cb log_cb; - void *log_cbarg; + dcadec_log_cb log_cb; ///< Logging callback function + void *log_cbarg; ///< Logging callback argument + int log_shown; ///< Bitmask of logging levels shown once - int flags; - int packet; - int status; + int flags; ///< Context flags passed to dcadec_context_create() + int packet; ///< Packet flags set by dcadec_context_parse() - struct core_decoder *core; - struct exss_parser *exss; - struct xll_decoder *xll; + struct core_decoder *core; ///< Core decoder context + struct exss_parser *exss; ///< EXSS parser context + struct xll_decoder *xll; ///< XLL decoder context - bool has_residual_encoded; - bool core_residual_valid; + bool has_residual_encoded; ///< XLL residual encoded channels present + bool core_residual_valid; ///< Core valid for residual decoding - int *dmix_sample_buffer; + int *dmix_sample_buffer; ///< Primary channel set downmixing buffer - int nframesamples; - int sample_rate; - int bits_per_sample; - int profile; - int channel_mask; - int *samples[SPEAKER_COUNT]; + int status; ///< Filtering status + int nframesamples; ///< Number of PCM samples per channel + int sample_rate; ///< Sample rate in Hz + int bits_per_sample; ///< PCM resolution in bits + int profile; ///< Type of DTS profile decoded + int channel_mask; ///< Channel or speaker mask + int *samples[SPEAKER_COUNT]; ///< Sample buffer pointers }; static const uint8_t dca2wav_norm[] = { @@ -74,25 +80,27 @@ WAVESPKR_TBR, WAVESPKR_BC, WAVESPKR_BL, WAVESPKR_BR }; -#define DCADEC_LAYOUT_7POINT0_WIDE \ - (SPEAKER_MASK_C | SPEAKER_MASK_L | SPEAKER_MASK_R | \ - SPEAKER_MASK_Ls | SPEAKER_MASK_Rs | \ - SPEAKER_MASK_Lw | SPEAKER_MASK_Rw) - -#define DCADEC_LAYOUT_7POINT1_WIDE \ - (DCADEC_LAYOUT_7POINT0_WIDE | SPEAKER_MASK_LFE1) - -void dca_format_log(dcadec_log_cb cb, void *cbarg, int level, +void dca_format_log(struct dcadec_context *dca, int level, const char *file, int line, const char *fmt, ...) { char buffer[1024]; va_list ap; + if (!dca || !dca->log_cb) + return; + + if (level & DCADEC_LOG_ONCE) { + level &= ~DCADEC_LOG_ONCE; + if (dca->log_shown & (1 << level)) + return; + dca->log_shown |= 1 << level; + } + va_start(ap, fmt); vsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); - cb(level, file, line, buffer, cbarg); + dca->log_cb(level, file, line, buffer, dca->log_cbarg); } static int reorder_samples(struct dcadec_context *dca, int **dca_samples, int dca_mask) @@ -112,8 +120,8 @@ int wav_mask = 0; int *wav_samples[WAVESPKR_COUNT] = { NULL }; const uint8_t *dca2wav; - if (dca_mask == DCADEC_LAYOUT_7POINT0_WIDE || - dca_mask == DCADEC_LAYOUT_7POINT1_WIDE) + if (dca_mask == SPEAKER_LAYOUT_7POINT0_WIDE || + dca_mask == SPEAKER_LAYOUT_7POINT1_WIDE) dca2wav = dca2wav_wide; else dca2wav = dca2wav_norm; @@ -139,62 +147,106 @@ return nchannels; } -static int clip_vector(int *samples, int nsamples, int bits_per_sample) +static bool shift_and_clip__(int *samples, int nsamples, int shift, int bits) { - int limit = 1 << (bits_per_sample - 1); - int mask = ~((1 << bits_per_sample) - 1); - int nclipped = 0; - - while (nsamples-- > 0) { - if ((*samples + limit) & mask) { - *samples = (*samples >> 31) ^ (limit - 1); - nclipped++; + bool clipped = false; + + for (int n = 0; n < nsamples; n++) { + int s = samples[n] * (1 << shift); +#ifdef __ARM_FEATURE_SAT + s = clip__(s, bits); +#else + if ((s + (1 << bits)) & ~((1 << (bits + 1)) - 1)) { + s = (s >> 31) ^ ((1 << bits) - 1); + clipped = true; } - samples++; +#endif + samples[n] = s; } - return nclipped; + return clipped; } -static int clip_samples(struct dcadec_context *dca, int nchannels) +static bool shift_and_clip(struct dcadec_context *dca, int nchannels, + int storage_bit_res, int pcm_bit_res) { + int shift = storage_bit_res - pcm_bit_res; int nsamples = dca->nframesamples; - int nclipped = 0; - if (dca->flags & DCADEC_FLAG_DONT_CLIP) - return 0; + if (dca->flags & DCADEC_FLAG_DONT_CLIP) { + if (shift) + for (int ch = 0; ch < nchannels; ch++) + for (int n = 0; n < nsamples; n++) + dca->samples[ch][n] *= 1 << shift; + return false; + } - switch (dca->bits_per_sample) { + bool clipped = false; + switch (storage_bit_res) { case 24: for (int ch = 0; ch < nchannels; ch++) - nclipped += clip_vector(dca->samples[ch], nsamples, 24); + clipped |= shift_and_clip__(dca->samples[ch], nsamples, shift, 23); break; case 16: for (int ch = 0; ch < nchannels; ch++) - nclipped += clip_vector(dca->samples[ch], nsamples, 16); + clipped |= shift_and_clip__(dca->samples[ch], nsamples, shift, 15); break; default: assert(0); break; } - return nclipped; + return clipped; } -static int down_mix_prim_chset(struct dcadec_context *dca, int **samples, - int nsamples, int *ch_mask, int *dmix_coeff) +static int get_dmix_coeff(int nchannels, int spkr, int ch) { - // No action if already 2.0. Remove LFE channel if 2.1. - if ((*ch_mask & ~SPEAKER_MASK_LFE1) == (SPEAKER_MASK_L | SPEAKER_MASK_R)) { - *ch_mask = SPEAKER_MASK_L | SPEAKER_MASK_R; + switch (spkr) { + case SPEAKER_C: + case SPEAKER_Cs: + return (nchannels == 1) ? 23170 : 16423;
View file
dcadec-0.1.0.tar.gz/libdcadec/dca_context.h -> dcadec-0.2.0.tar.gz/libdcadec/dca_context.h
Changed
@@ -34,7 +34,7 @@ * that remains compatible. Patch is reserved for non-API related changes. */ #define DCADEC_API_VERSION_MAJOR 0 -#define DCADEC_API_VERSION_MINOR 0 +#define DCADEC_API_VERSION_MINOR 1 #define DCADEC_API_VERSION_PATCH 0 #define DCADEC_API_VERSION \ @@ -106,8 +106,8 @@ */ #define DCADEC_FLAG_CORE_SYNTH_X96 0x04 -/** Reserved flag, don't use */ -#define DCADEC_FLAG_CORE_RESERVED 0x08 +/** Use IIR filter for floating point DTS core LFE channel interpolation */ +#define DCADEC_FLAG_CORE_LFE_IIR 0x08 /** Use FIR filter for floating point DTS core LFE channel interpolation */ #define DCADEC_FLAG_CORE_LFE_FIR 0x10 @@ -263,8 +263,8 @@ * @param dca Pointer to decoder context. * * @param samples Filled with address of array of pointers to planes - * containing PCM data for active channels. This data is only - * valid until the next call to any libdcadec function. + * containing PCM data for active channels. This data is valid + * until the next call to dcadec_context_parse() or _destroy(). * Returned array is tightly packed, there are no gaps for * missing channels. Use channel_mask to determine total number * of channels and size of returned array. By default channels
View file
dcadec-0.1.0.tar.gz/libdcadec/dca_frame.c -> dcadec-0.2.0.tar.gz/libdcadec/dca_frame.c
Changed
@@ -46,7 +46,7 @@ uint16_t *_dst = (uint16_t *)dst; size_t count; - if ((uintptr_t)_dst & 3) + if (!dst || !dst_size || !src || src_size < 4 || ((uintptr_t)_dst & 3)) return -DCADEC_EINVAL; if ((uintptr_t)_src & 1) @@ -104,6 +104,9 @@ uint8_t header[DCADEC_FRAME_HEADER_SIZE]; size_t header_size, frame_size; + if (!data || !size) + return -DCADEC_EINVAL; + int ret; if ((ret = dcadec_frame_convert_bitstream(header, &header_size, data, DCADEC_FRAME_HEADER_SIZE)) < 0) @@ -119,7 +122,7 @@ return -DCADEC_ENOSYNC; bits_skip1(&bits); int npcmblocks = bits_get(&bits, 7) + 1; - if (npcmblocks < 6) + if ((npcmblocks & 7) && (npcmblocks < 6 || normal_frame)) return -DCADEC_ENOSYNC; frame_size = bits_get(&bits, 14) + 1; if (frame_size < 96) @@ -134,11 +137,11 @@ case SYNC_WORD_EXSS: { bits_skip(&bits, 10); bool wide_hdr = bits_get1(&bits); - bits_skip(&bits, 8 + 4 * wide_hdr); - frame_size = bits_get(&bits, 16 + 4 * wide_hdr) + 1; - if (frame_size < DCADEC_FRAME_HEADER_SIZE) + header_size = bits_get(&bits, 8 + 4 * wide_hdr) + 1; + if ((header_size & 3) || header_size < DCADEC_FRAME_HEADER_SIZE) return -DCADEC_ENOSYNC; - if (frame_size & 3) + frame_size = bits_get(&bits, 16 + 4 * wide_hdr) + 1; + if ((frame_size & 3) || frame_size < header_size) return -DCADEC_ENOSYNC; *size = frame_size; return DCADEC_FRAME_TYPE_EXSS;
View file
dcadec-0.1.0.tar.gz/libdcadec/dca_stream.c -> dcadec-0.2.0.tar.gz/libdcadec/dca_stream.c
Changed
@@ -22,6 +22,7 @@ #include "dca_stream.h" #ifdef _WIN32 +#include <windows.h> #include <fcntl.h> #include <io.h> #else @@ -43,25 +44,25 @@ #endif struct dcadec_stream { - FILE *fp; + FILE *fp; ///< Input file - off_t stream_size; - off_t stream_start; - off_t stream_end; + off_t stream_size; ///< Size of stream data + off_t stream_start; ///< Starting position of stream data in file + off_t stream_end; ///< Ending position of stream data in file - bool aupr_present; - uint32_t aupr_sample_rate; - uint32_t aupr_nframes; - uint32_t aupr_nframesamples; - uint64_t aupr_npcmsamples; - uint32_t aupr_ch_mask; - uint32_t aupr_ndelaysamples; + bool aupr_present; ///< Audio presentation header flag + uint32_t aupr_sample_rate; ///< Audio sample rate in Hz + uint32_t aupr_nframes; ///< Number of encoded frames + uint32_t aupr_nframesamples; ///< Number of PCM samples in each encoded frame + uint64_t aupr_npcmsamples; ///< Number of PCM samples in original audio + uint32_t aupr_ch_mask; ///< Channel mask in EXSS format + uint32_t aupr_ndelaysamples; ///< Codec delay in PCM samples - uint8_t *buffer; - size_t packet_size; - uint32_t backup_sync; + uint8_t *buffer; ///< Packet buffer + size_t packet_size; ///< Size of packet + uint32_t backup_sync; ///< Backed-up sync word - bool core_plus_exss; + bool core_plus_exss; ///< Whether previous packet was core plus extension substream }; // Check for DTS-HD container format. Such files have an extra `blackout' @@ -216,7 +217,12 @@ #endif } - if (!fseeko(stream->fp, 0, SEEK_END)) { + bool can_seek = true; +#ifdef _WIN32 + can_seek = GetFileType((HANDLE)_get_osfhandle(_fileno(stream->fp))) == FILE_TYPE_DISK; +#endif + + if (can_seek && !fseeko(stream->fp, 0, SEEK_END)) { off_t pos = ftello(stream->fp); if (pos > 0) stream->stream_size = pos; @@ -349,6 +355,9 @@ uint32_t sync; int ret; + if (!stream || !data || !size) + return -DCADEC_EINVAL; + // Loop until valid DTS core or standalone EXSS frame is read or EOF is // reached while (true) { @@ -385,7 +394,7 @@ DCADEC_API int dcadec_stream_progress(struct dcadec_stream *stream) { - if (stream->stream_size > 0) { + if (stream && stream->stream_size > 0) { off_t pos = ftello(stream->fp); if (pos < stream->stream_start) return 0;
View file
dcadec-0.1.0.tar.gz/libdcadec/dca_stream.h -> dcadec-0.2.0.tar.gz/libdcadec/dca_stream.h
Changed
@@ -79,7 +79,7 @@ DCADEC_API int dcadec_stream_progress(struct dcadec_stream *stream); /** - * Get audio properties information from DTS-HD container. For raw DTS streams + * Get audio presentation information from DTS-HD container. For raw DTS streams * this function always fails. * * @param stream Stream handle. @@ -91,7 +91,7 @@ DCADEC_API struct dcadec_stream_info *dcadec_stream_get_info(struct dcadec_stream *stream); /** - * Free audio properties information structure. + * Free audio presentation information structure. * * @param info Pointer to information structure. */
View file
dcadec-0.1.0.tar.gz/libdcadec/dca_waveout.c -> dcadec-0.2.0.tar.gz/libdcadec/dca_waveout.c
Changed
@@ -20,6 +20,7 @@ #include "dca_waveout.h" #ifdef _WIN32 +#include <windows.h> #include <fcntl.h> #include <io.h> #else @@ -27,18 +28,18 @@ #endif struct dcadec_waveout { - FILE *fp[SPEAKER_COUNT]; - uint64_t size; - uint8_t *buffer; - char *pattern; - int flags; - - int channel_mask; - int nchannels; - int sample_rate; - int bits_per_sample; - int bytes_per_sample; - int block_align; + FILE *fp[SPEAKER_COUNT]; ///< Output file(s) + uint64_t size; ///< Size of PCM data written + uint8_t *buffer; ///< PCM data conversion buffer + char *pattern; ///< Filename pattern for writing multiple mono files + int flags; ///< Option flags passed to dcadec_waveout_open() + + int channel_mask; ///< WAVEFORMATEXTENSIBLE channel mask + int nchannels; ///< Number of channels + int sample_rate; ///< Audio sample rate + int bits_per_sample; ///< Audio PCM resolution + int bytes_per_sample; ///< Number of bytes per sample + int block_align; ///< Alignment of PCM data block }; static const char * const dca_speaker_names[] = { @@ -334,7 +335,11 @@ for (int i = 0; i < SPEAKER_COUNT; i++) { if (wave->fp[i]) { - if (wave->size && !fseeko(wave->fp[i], 0, SEEK_SET)) + bool can_seek = true; +#ifdef _WIN32 + can_seek = GetFileType((HANDLE)_get_osfhandle(_fileno(wave->fp[i]))) == FILE_TYPE_DISK; +#endif + if (wave->size && can_seek && !fseeko(wave->fp[i], 0, SEEK_SET)) write_header(wave, wave->fp[i]); fclose(wave->fp[i]); }
View file
dcadec-0.1.0.tar.gz/libdcadec/exss_parser.c -> dcadec-0.2.0.tar.gz/libdcadec/exss_parser.c
Changed
@@ -70,12 +70,10 @@ static int parse_descriptor(struct exss_asset *asset) { struct exss_parser *exss = asset->parser; - int i, j, ret; - - size_t descr_pos = exss->bits.index; + int i, j, ret, descr_pos = exss->bits.index; // Size of audio asset descriptor in bytes - size_t descr_size = bits_get(&exss->bits, 9) + 1; + int descr_size = bits_get(&exss->bits, 9) + 1; // Audio asset identifier asset->asset_index = bits_get(&exss->bits, 3); @@ -307,8 +305,8 @@ static int set_exss_offsets(struct exss_asset *asset) { - size_t offs = asset->asset_offset; - size_t size = asset->asset_size; + int offs = asset->asset_offset; + int size = asset->asset_size; if (asset->extension_mask & EXSS_CORE) { asset->core_offset = offs; @@ -361,7 +359,7 @@ return 0; } -int exss_parse(struct exss_parser *exss, uint8_t *data, size_t size) +int exss_parse(struct exss_parser *exss, uint8_t *data, int size) { int i, j, ret; @@ -380,11 +378,11 @@ bool wide_hdr = bits_get1(&exss->bits); // Extension substream header length - size_t header_size = bits_get(&exss->bits, 8 + 4 * wide_hdr) + 1; + int header_size = bits_get(&exss->bits, 8 + 4 * wide_hdr) + 1; // Check CRC if ((ret = bits_check_crc(&exss->bits, 32 + 8, header_size * 8)) < 0) { - exss_err("Invalid header checksum"); + exss_err("Invalid EXSS header checksum"); return ret; } @@ -393,7 +391,7 @@ // Number of bytes of extension substream exss->exss_size = bits_get(&exss->bits, exss->exss_size_nbits) + 1; if (exss->exss_size > size) { - exss_err("Packet too short"); + exss_err("Packet too short for EXSS frame"); return -DCADEC_EBADDATA; } @@ -463,7 +461,7 @@ return -DCADEC_ENOMEM; // Size of encoded asset data in bytes - size_t offset = header_size; + int offset = header_size; for (i = 0; i < exss->nassets; i++) { exss->assets[i].asset_offset = offset; exss->assets[i].asset_size = bits_get(&exss->bits, exss->exss_size_nbits) + 1; @@ -492,7 +490,7 @@ // Byte align // CRC16 of extension substream header if ((ret = bits_seek(&exss->bits, header_size * 8)) < 0) - exss_err("Read past end of header"); + exss_err("Read past end of EXSS header"); return ret; }
View file
dcadec-0.1.0.tar.gz/libdcadec/exss_parser.h -> dcadec-0.2.0.tar.gz/libdcadec/exss_parser.h
Changed
@@ -21,81 +21,78 @@ #include "bitstream.h" -#define exss_err(...) dca_log(ERROR, exss, __VA_ARGS__) +#define exss_err(...) dca_log(exss, ERROR, __VA_ARGS__) -#define exss_err_once(...) dca_log_once(ERROR, exss, err_shown, __VA_ARGS__) +#define exss_err_once(...) dca_log_once(exss, ERROR, __VA_ARGS__) struct exss_parser; struct exss_asset { - struct exss_parser *parser; + struct exss_parser *parser; ///< Parent context - size_t asset_offset; - size_t asset_size; - int asset_index; + int asset_offset; ///< Offset to asset data from start of substream + int asset_size; ///< Size of encoded asset data + int asset_index; ///< Audio asset identifier - int pcm_bit_res; - int max_sample_rate; - int nchannels_total; - bool one_to_one_map_ch_to_spkr; - bool embedded_stereo; - bool embedded_6ch; - bool spkr_mask_enabled; - int spkr_mask; - int representation_type; + int pcm_bit_res; ///< PCM bit resolution + int max_sample_rate; ///< Maximum sample rate + int nchannels_total; ///< Total number of channels + bool one_to_one_map_ch_to_spkr; ///< One to one channel to speaker mapping flag + bool embedded_stereo; ///< Embedded stereo flag + bool embedded_6ch; ///< Embedded 6 channels flag + bool spkr_mask_enabled; ///< Speaker mask enabled flag + int spkr_mask; ///< Loudspeaker activity mask + int representation_type; ///< Representation type - int coding_mode; - int extension_mask; + int coding_mode; ///< Coding mode for the asset + int extension_mask; ///< Coding components used in asset - size_t core_offset; - size_t core_size; + int core_offset; ///< Offset to core component from start of substream + int core_size; ///< Size of core component in extension substream - size_t xbr_offset; - size_t xbr_size; + int xbr_offset; ///< Offset to XBR extension from start of substream + int xbr_size; ///< Size of XBR extension in extension substream - size_t xxch_offset; - size_t xxch_size; + int xxch_offset; ///< Offset to XXCH extension from start of substream + int xxch_size; ///< Size of XXCH extension in extension substream - size_t x96_offset; - size_t x96_size; + int x96_offset; ///< Offset to X96 extension from start of substream + int x96_size; ///< Size of X96 extension in extension substream - size_t lbr_offset; - size_t lbr_size; + int lbr_offset; ///< Offset to LBR component from start of substream + int lbr_size; ///< Size of LBR component in extension substream - size_t xll_offset; - size_t xll_size; - bool xll_sync_present; - int xll_delay_nframes; - size_t xll_sync_offset; + int xll_offset; ///< Offset to XLL data from start of substream + int xll_size; ///< Size of XLL data in extension substream + bool xll_sync_present; ///< XLL sync word present flag + int xll_delay_nframes; ///< Initial XLL decoding delay in frames + int xll_sync_offset; ///< Number of bytes offset to XLL sync - int hd_stream_id; + int hd_stream_id; ///< DTS-HD stream ID }; struct exss_parser { - struct bitstream bits; + struct dcadec_context *ctx; ///< Parent context + struct bitstream bits; ///< Bitstream reader - dcadec_log_cb log_cb; - void *log_cbarg; - bool err_shown; + int exss_index; ///< Extension substream index + int exss_size_nbits; ///< Number of bits for extension substream size + int exss_size; ///< Number of bytes of extension substream - int exss_index; - int exss_size_nbits; - size_t exss_size; + bool static_fields_present; ///< Per stream static fields presence flag + int npresents; ///< Number of defined audio presentations + int nassets; ///< Number of audio assets in extension substream - bool static_fields_present; - int npresents; - int nassets; + bool mix_metadata_enabled; ///< Mixing metadata enable flag + int nmixoutconfigs; ///< Number of mixing configurations + int nmixoutchs[4]; ///< Speaker layout mask for mixer output channels - bool mix_metadata_enabled; - int nmixoutconfigs; - int nmixoutchs[4]; - - struct exss_asset *assets; + struct exss_asset *assets; ///< Audio asset descriptors }; extern const uint32_t exss_sample_rates[16]; -int exss_parse(struct exss_parser *exss, uint8_t *data, size_t size); -struct dcadec_exss_info *exss_get_info(struct exss_parser *exss); +int exss_parse(struct exss_parser *exss, uint8_t *data, int size); +struct dcadec_exss_info *exss_get_info(struct exss_parser *exss) __attribute__((cold)); #endif
View file
dcadec-0.1.0.tar.gz/libdcadec/fir_fixed.h -> dcadec-0.2.0.tar.gz/libdcadec/fir_fixed.h
Changed
@@ -282,71 +282,39 @@ -91, -77, -64, -53 }; -static const int32_t lfe_fir_64[512] = { - 6103, 1930, 2228, 2552, 2904, 3287, 3704, 4152, - 4631, 5139, 5682, 6264, 6886, 7531, 8230, 8959, - 9727, 10535, 11381, 12267, 13190, 14152, 15153, 16192, - 17267, 18377, 19525, 20704, 21915, 23157, 24426, 25721, - 27038, 28376, 29732, 31101, 32480, 33866, 35256, 36642, - 38022, 39391, 40743, 42072, 43373, 44640, 45866, 47044, - 48168, 49231, 50224, 51140, 51972, 52711, 53348, 53876, - 54285, 54566, 54710, 54708, 54550, 54228, 53729, 53047, - 52170, 51089, 49794, 48275, 46523, 44529, 42282, 39774, - 36995, 33937, 30591, 26948, 23001, 18741, 14162, 9257, - 4018, -1558, -7480, -13750, -20372, -27352, -34691, -42390, - -50453, -58879, -67667, -76817, -86327, -96193, -106412, -116977, - -127884, -139125, -150692, -162575, -174764, -187246, -200010, -213041, - -226323, -239840, -253574, -267505, -281613, -295877, -310273, -324777, - -339362, -354003, -368671, -383335, -397966, -412531, -426998, -441330, - -455494, -469451, -483164, -496595, -509702, -522445, -534782, -546669, - -558064, -568920, -579194, -588839, -597808, -606054, -613529, -620186, - -625976, -630850, -634759, -637655, -639488, -640210, -639772, -638125, - -635222, -631014, -625455, -618499, -610098, -600209, -588788, -575791, - -561178, -544906, -526937, -507233, -485757, -462476, -437356, -410365, - -381475, -350658, -317890, -283146, -246406, -207653, -166869, -124041, - -79159, -32214, 16800, 67886, 121042, 176267, 233555, 292897, - 354281, 417692, 483113, 550521, 619894, 691203, 764419, 839507, - 916430, 995149, 1075621, 1157798, 1241632, 1327070, 1414057, 1502534, - 1592440, 1683709, 1776276, 1870070, 1965017, 2061044, 2158071, 2256019, - 2354805, 2454343, 2554547, 2655326, 2756591, 2858248, 2960201, 3062355, - 3164612, 3266872, 3369035, 3471000, 3572664, 3673924, 3774676, 3874816, - 3974239, 4072841, 4170517, 4267162, 4362672, 4456942, 4549871, 4641355, - 4731293, 4819584, 4906129, 4990831, 5073593, 5154321, 5232922, 5309305, - 5383383, 5455069, 5524280, 5590933, 5654952, 5716260, 5774785, 5830457, - 5883210, 5932981, 5979711, 6023343, 6063824, 6101107, 6135146, 6165900, - 6193332, 6217408, 6238099, 6255380, 6269231, 6279634, 6286575, 6290049, - 6290049, 6286575, 6279634, 6269231, 6255380, 6238099, 6217408, 6193332, - 6165900, 6135146, 6101107, 6063824, 6023343, 5979711, 5932981, 5883210, - 5830457, 5774785, 5716260, 5654952, 5590933, 5524280, 5455069, 5383383, - 5309305, 5232922, 5154321, 5073593, 4990831, 4906129, 4819584, 4731293, - 4641355, 4549871, 4456942, 4362672, 4267162, 4170517, 4072841, 3974239, - 3874816, 3774676, 3673924, 3572664, 3471000, 3369035, 3266872, 3164612, - 3062355, 2960201, 2858248, 2756591, 2655326, 2554547, 2454343, 2354805, - 2256019, 2158071, 2061044, 1965017, 1870070, 1776276, 1683709, 1592440, - 1502534, 1414057, 1327070, 1241632, 1157798, 1075621, 995149, 916430, - 839507, 764419, 691203, 619894, 550521, 483113, 417692, 354281, - 292897, 233555, 176267, 121042, 67886, 16800, -32214, -79159, - -124041, -166869, -207653, -246406, -283146, -317890, -350658, -381475, - -410365, -437356, -462476, -485757, -507233, -526937, -544906, -561178, - -575791, -588788, -600209, -610098, -618499, -625455, -631014, -635222, - -638125, -639772, -640210, -639488, -637655, -634759, -630850, -625976, - -620186, -613529, -606054, -597808, -588839, -579194, -568920, -558064, - -546669, -534782, -522445, -509702, -496595, -483164, -469451, -455494, - -441330, -426998, -412531, -397966, -383335, -368671, -354003, -339362, - -324777, -310273, -295877, -281613, -267505, -253574, -239840, -226323, - -213041, -200010, -187246, -174764, -162575, -150692, -139125, -127884, - -116977, -106412, -96193, -86327, -76817, -67667, -58879, -50453, - -42390, -34691, -27352, -20372, -13750, -7480, -1558, 4018, - 9257, 14162, 18741, 23001, 26948, 30591, 33937, 36995, - 39774, 42282, 44529, 46523, 48275, 49794, 51089, 52170, - 53047, 53729, 54228, 54550, 54708, 54710, 54566, 54285, - 53876, 53348, 52711, 51972, 51140, 50224, 49231, 48168, - 47044, 45866, 44640, 43373, 42072, 40743, 39391, 38022, - 36642, 35256, 33866, 32480, 31101, 29732, 28376, 27038, - 25721, 24426, 23157, 21915, 20704, 19525, 18377, 17267, - 16192, 15153, 14152, 13190, 12267, 11381, 10535, 9727, - 8959, 8230, 7531, 6886, 6264, 5682, 5139, 4631, - 4152, 3704, 3287, 2904, 2552, 2228, 1930, 6103 +static const int32_t lfe_fir_64[256] = { + 6103, 52170, -558064, 1592440, 6290049, 1502534, -546669, 53047, + 1930, 51089, -568920, 1683709, 6286575, 1414057, -534782, 53729, + 2228, 49794, -579194, 1776276, 6279634, 1327070, -522445, 54228, + 2552, 48275, -588839, 1870070, 6269231, 1241632, -509702, 54550, + 2904, 46523, -597808, 1965017, 6255380, 1157798, -496595, 54708, + 3287, 44529, -606054, 2061044, 6238099, 1075621, -483164, 54710, + 3704, 42282, -613529, 2158071, 6217408, 995149, -469451, 54566, + 4152, 39774, -620186, 2256019, 6193332, 916430, -455494, 54285, + 4631, 36995, -625976, 2354805, 6165900, 839507, -441330, 53876, + 5139, 33937, -630850, 2454343, 6135146, 764419, -426998, 53348, + 5682, 30591, -634759, 2554547, 6101107, 691203, -412531, 52711, + 6264, 26948, -637655, 2655326, 6063824, 619894, -397966, 51972, + 6886, 23001, -639488, 2756591, 6023343, 550521, -383335, 51140, + 7531, 18741, -640210, 2858248, 5979711, 483113, -368671, 50224, + 8230, 14162, -639772, 2960201, 5932981, 417692, -354003, 49231, + 8959, 9257, -638125, 3062355, 5883210, 354281, -339362, 48168, + 9727, 4018, -635222, 3164612, 5830457, 292897, -324777, 47044, + 10535, -1558, -631014, 3266872, 5774785, 233555, -310273, 45866, + 11381, -7480, -625455, 3369035, 5716260, 176267, -295877, 44640, + 12267, -13750, -618499, 3471000, 5654952, 121042, -281613, 43373, + 13190, -20372, -610098, 3572664, 5590933, 67886, -267505, 42072, + 14152, -27352, -600209, 3673924, 5524280, 16800, -253574, 40743, + 15153, -34691, -588788, 3774676, 5455069, -32214, -239840, 39391, + 16192, -42390, -575791, 3874816, 5383383, -79159, -226323, 38022, + 17267, -50453, -561178, 3974239, 5309305, -124041, -213041, 36642, + 18377, -58879, -544906, 4072841, 5232922, -166869, -200010, 35256, + 19525, -67667, -526937, 4170517, 5154321, -207653, -187246, 33866, + 20704, -76817, -507233, 4267162, 5073593, -246406, -174764, 32480, + 21915, -86327, -485757, 4362672, 4990831, -283146, -162575, 31101, + 23157, -96193, -462476, 4456942, 4906129, -317890, -150692, 29732, + 24426, -106412, -437356, 4549871, 4819584, -350658, -139125, 28376, + 25721, -116977, -410365, 4641355, 4731293, -381475, -127884, 27038 }; // floor(fir_float.band_fir_x96[i] * (1 << 29) + 0.5), (i & 127) < 32
View file
dcadec-0.1.0.tar.gz/libdcadec/fir_float.h -> dcadec-0.2.0.tar.gz/libdcadec/fir_float.h
Changed
@@ -541,267 +541,139 @@ #undef SCALE // Annex D.8 - LFE interpolation FIR, 64x interpolation -static const double lfe_fir_64[512] = { - 2.658434387E-04, 8.179365250E-05, 9.439323912E-05, 1.082170274E-04, - 1.233371440E-04, 1.397485757E-04, 1.575958013E-04, 1.769922383E-04, - 1.981738606E-04, 2.211847313E-04, 2.460231190E-04, 2.726115927E-04, - 3.013863170E-04, 3.328395542E-04, 3.658991191E-04, 4.018281470E-04, - 4.401875485E-04, 4.812776169E-04, 5.252459669E-04, 5.721592461E-04, - 6.222130032E-04, 6.755515351E-04, 7.324148901E-04, 7.928516716E-04, - 8.570110658E-04, 9.251192096E-04, 9.974770946E-04, 1.073930296E-03, - 1.155023579E-03, 1.240676851E-03, 1.331258914E-03, 1.426893868E-03, - 1.527829794E-03, 1.634211512E-03, 1.746327500E-03, 1.864377526E-03, - 1.988604199E-03, 2.119151875E-03, 2.256359672E-03, 2.400433412E-03, - 2.551567042E-03, 2.710093278E-03, 2.876190469E-03, 3.050152911E-03, - 3.232272575E-03, 3.422776936E-03, 3.621967277E-03, 3.830091329E-03, - 4.047499038E-03, 4.274417181E-03, 4.511159845E-03, 4.758012015E-03, - 5.015311297E-03, 5.283284001E-03, 5.562345497E-03, 5.852684379E-03, - 6.154712290E-03, 6.468691397E-03, 6.794991903E-03, 7.133882027E-03, - 7.485736627E-03, 7.850865833E-03, 8.229630999E-03, 8.622321300E-03, - 9.029330686E-03, 9.450953454E-03, 9.887560271E-03, 1.033949479E-02, - 1.080708485E-02, 1.129068248E-02, 1.179065090E-02, 1.230732165E-02, - 1.284105983E-02, 1.339218579E-02, 1.396108977E-02, 1.454808749E-02, - 1.515355054E-02, 1.577781141E-02, 1.642123051E-02, 1.708412915E-02, - 1.776690222E-02, 1.846982725E-02, 1.919330470E-02, 1.993762329E-02, - 2.070316114E-02, 2.149021253E-02, 2.229913883E-02, 2.313023806E-02, - 2.398385666E-02, 2.486028522E-02, 2.575986087E-02, 2.668286115E-02, - 2.762960829E-02, 2.860039286E-02, 2.959549613E-02, 3.061520495E-02, - 3.165979683E-02, 3.272953629E-02, 3.382468969E-02, 3.494550660E-02, - 3.609224036E-02, 3.726511076E-02, 3.846437484E-02, 3.969023004E-02, - 4.094288871E-02, 4.222255200E-02, 4.352942482E-02, 4.486365616E-02, - 4.622544348E-02, 4.761491716E-02, 4.903224111E-02, 5.047753453E-02, - 5.195093155E-02, 5.345252529E-02, 5.498242006E-02, 5.654069409E-02, - 5.812742189E-02, 5.974265561E-02, 6.138643622E-02, 6.305878609E-02, - 6.475970894E-02, 6.648923457E-02, 6.824731827E-02, 7.003392279E-02, - 7.184901088E-02, 7.369252294E-02, 7.556436211E-02, 7.746443897E-02, - 7.939263433E-02, 8.134882897E-02, 8.333285898E-02, 8.534456789E-02, - 8.738376945E-02, 8.945026249E-02, 9.154383838E-02, 9.366425127E-02, - 9.581124038E-02, 9.798453748E-02, 1.001838669E-01, 1.024089083E-01, - 1.046593264E-01, 1.069347933E-01, 1.092349365E-01, 1.115593687E-01, - 1.139076948E-01, 1.162794977E-01, 1.186743453E-01, 1.210917681E-01, - 1.235313043E-01, 1.259924471E-01, 1.284746826E-01, 1.309774816E-01, - 1.335003078E-01, 1.360425949E-01, 1.386037618E-01, 1.411831975E-01, - 1.437802613E-01, 1.463943720E-01, 1.490248144E-01, 1.516709626E-01, - 1.543320864E-01, 1.570075154E-01, 1.596965194E-01, 1.623983532E-01, - 1.651122719E-01, 1.678375006E-01, 1.705732346E-01, 1.733186990E-01, - 1.760730892E-01, 1.788355410E-01, 1.816052496E-01, 1.843813360E-01, - 1.871629506E-01, 1.899491698E-01, 1.927391142E-01, 1.955319196E-01, - 1.983266175E-01, 2.011223286E-01, 2.039180547E-01, 2.067128718E-01, - 2.095058411E-01, 2.122959495E-01, 2.150822729E-01, 2.178637981E-01, - 2.206395119E-01, 2.234084606E-01, 2.261696160E-01, 2.289219648E-01, - 2.316644788E-01, 2.343961596E-01, 2.371159792E-01, 2.398228943E-01, - 2.425158769E-01, 2.451938838E-01, 2.478559017E-01, 2.505008876E-01, - 2.531278133E-01, 2.557355762E-01, 2.583232224E-01, 2.608896792E-01, - 2.634339035E-01, 2.659549415E-01, 2.684516609E-01, 2.709231377E-01, - 2.733682692E-01, 2.757860720E-01, 2.781755328E-01, 2.805356979E-01, - 2.828655839E-01, 2.851640880E-01, 2.874303460E-01, 2.896633744E-01, - 2.918621898E-01, 2.940258980E-01, 2.961534858E-01, 2.982441187E-01, - 3.002967536E-01, 3.023106754E-01, 3.042849004E-01, 3.062185347E-01, - 3.081108034E-01, 3.099608123E-01, 3.117676973E-01, 3.135308027E-01, - 3.152491748E-01, 3.169221282E-01, 3.185488880E-01, 3.201287389E-01, - 3.216609657E-01, 3.231448531E-01, 3.245797157E-01, 3.259649575E-01, - 3.272998929E-01, 3.285838962E-01, 3.298164308E-01, 3.309969604E-01, - 3.321248591E-01, 3.331996202E-01, 3.342207968E-01, 3.351879120E-01, - 3.361004293E-01, 3.369580209E-01, 3.377602994E-01, 3.385068178E-01, - 3.391972482E-01, 3.398312926E-01, 3.404086530E-01, 3.409290314E-01, - 3.413922191E-01, 3.417979777E-01, 3.421461284E-01, 3.424364924E-01, - 3.426689506E-01, 3.428434134E-01, 3.429597318E-01, 3.430179358E-01, - 3.430179358E-01, 3.429597318E-01, 3.428434134E-01, 3.426689506E-01, - 3.424364924E-01, 3.421461284E-01, 3.417979777E-01, 3.413922191E-01, - 3.409290314E-01, 3.404086530E-01, 3.398312926E-01, 3.391972482E-01, - 3.385068178E-01, 3.377602994E-01, 3.369580209E-01, 3.361004293E-01, - 3.351879120E-01, 3.342207968E-01, 3.331996202E-01, 3.321248591E-01, - 3.309969604E-01, 3.298164308E-01, 3.285838962E-01, 3.272998929E-01, - 3.259649575E-01, 3.245797157E-01, 3.231448531E-01, 3.216609657E-01, - 3.201287389E-01, 3.185488880E-01, 3.169221282E-01, 3.152491748E-01, - 3.135308027E-01, 3.117676973E-01, 3.099608123E-01, 3.081108034E-01, - 3.062185347E-01, 3.042849004E-01, 3.023106754E-01, 3.002967536E-01, - 2.982441187E-01, 2.961534858E-01, 2.940258980E-01, 2.918621898E-01, - 2.896633744E-01, 2.874303460E-01, 2.851640880E-01, 2.828655839E-01, - 2.805356979E-01, 2.781755328E-01, 2.757860720E-01, 2.733682692E-01, - 2.709231377E-01, 2.684516609E-01, 2.659549415E-01, 2.634339035E-01, - 2.608896792E-01, 2.583232224E-01, 2.557355762E-01, 2.531278133E-01, - 2.505008876E-01, 2.478559017E-01, 2.451938838E-01, 2.425158769E-01, - 2.398228943E-01, 2.371159792E-01, 2.343961596E-01, 2.316644788E-01, - 2.289219648E-01, 2.261696160E-01, 2.234084606E-01, 2.206395119E-01, - 2.178637981E-01, 2.150822729E-01, 2.122959495E-01, 2.095058411E-01, - 2.067128718E-01, 2.039180547E-01, 2.011223286E-01, 1.983266175E-01, - 1.955319196E-01, 1.927391142E-01, 1.899491698E-01, 1.871629506E-01, - 1.843813360E-01, 1.816052496E-01, 1.788355410E-01, 1.760730892E-01, - 1.733186990E-01, 1.705732346E-01, 1.678375006E-01, 1.651122719E-01, - 1.623983532E-01, 1.596965194E-01, 1.570075154E-01, 1.543320864E-01, - 1.516709626E-01, 1.490248144E-01, 1.463943720E-01, 1.437802613E-01, - 1.411831975E-01, 1.386037618E-01, 1.360425949E-01, 1.335003078E-01, - 1.309774816E-01, 1.284746826E-01, 1.259924471E-01, 1.235313043E-01, - 1.210917681E-01, 1.186743453E-01, 1.162794977E-01, 1.139076948E-01, - 1.115593687E-01, 1.092349365E-01, 1.069347933E-01, 1.046593264E-01, - 1.024089083E-01, 1.001838669E-01, 9.798453748E-02, 9.581124038E-02, - 9.366425127E-02, 9.154383838E-02, 8.945026249E-02, 8.738376945E-02, - 8.534456789E-02, 8.333285898E-02, 8.134882897E-02, 7.939263433E-02, - 7.746443897E-02, 7.556436211E-02, 7.369252294E-02, 7.184901088E-02, - 7.003392279E-02, 6.824731827E-02, 6.648923457E-02, 6.475970894E-02, - 6.305878609E-02, 6.138643622E-02, 5.974265561E-02, 5.812742189E-02, - 5.654069409E-02, 5.498242006E-02, 5.345252529E-02, 5.195093155E-02, - 5.047753453E-02, 4.903224111E-02, 4.761491716E-02, 4.622544348E-02, - 4.486365616E-02, 4.352942482E-02, 4.222255200E-02, 4.094288871E-02, - 3.969023004E-02, 3.846437484E-02, 3.726511076E-02, 3.609224036E-02, - 3.494550660E-02, 3.382468969E-02, 3.272953629E-02, 3.165979683E-02, - 3.061520495E-02, 2.959549613E-02, 2.860039286E-02, 2.762960829E-02, - 2.668286115E-02, 2.575986087E-02, 2.486028522E-02, 2.398385666E-02, - 2.313023806E-02, 2.229913883E-02, 2.149021253E-02, 2.070316114E-02, - 1.993762329E-02, 1.919330470E-02, 1.846982725E-02, 1.776690222E-02, - 1.708412915E-02, 1.642123051E-02, 1.577781141E-02, 1.515355054E-02, - 1.454808749E-02, 1.396108977E-02, 1.339218579E-02, 1.284105983E-02, - 1.230732165E-02, 1.179065090E-02, 1.129068248E-02, 1.080708485E-02, - 1.033949479E-02, 9.887560271E-03, 9.450953454E-03, 9.029330686E-03, - 8.622321300E-03, 8.229630999E-03, 7.850865833E-03, 7.485736627E-03, - 7.133882027E-03, 6.794991903E-03, 6.468691397E-03, 6.154712290E-03, - 5.852684379E-03, 5.562345497E-03, 5.283284001E-03, 5.015311297E-03, - 4.758012015E-03, 4.511159845E-03, 4.274417181E-03, 4.047499038E-03, - 3.830091329E-03, 3.621967277E-03, 3.422776936E-03, 3.232272575E-03, - 3.050152911E-03, 2.876190469E-03, 2.710093278E-03, 2.551567042E-03, - 2.400433412E-03, 2.256359672E-03, 2.119151875E-03, 1.988604199E-03, - 1.864377526E-03, 1.746327500E-03, 1.634211512E-03, 1.527829794E-03, - 1.426893868E-03, 1.331258914E-03, 1.240676851E-03, 1.155023579E-03, - 1.073930296E-03, 9.974770946E-04, 9.251192096E-04, 8.570110658E-04, - 7.928516716E-04, 7.324148901E-04, 6.755515351E-04, 6.222130032E-04, - 5.721592461E-04, 5.252459669E-04, 4.812776169E-04, 4.401875485E-04, - 4.018281470E-04, 3.658991191E-04, 3.328395542E-04, 3.013863170E-04, - 2.726115927E-04, 2.460231190E-04, 2.211847313E-04, 1.981738606E-04, - 1.769922383E-04, 1.575958013E-04, 1.397485757E-04, 1.233371440E-04, - 1.082170274E-04, 9.439323912E-05, 8.179365250E-05, 2.658434387E-04 +static const double lfe_fir_64[256] = { + 2.658434387E-04, 9.029330686E-03, 7.939263433E-02, 2.425158769E-01, + 3.430179358E-01, 2.398228943E-01, 7.746443897E-02, 8.622321300E-03, + 8.179365250E-05, 9.450953454E-03, 8.134882897E-02, 2.451938838E-01, + 3.429597318E-01, 2.371159792E-01, 7.556436211E-02, 8.229630999E-03, + 9.439323912E-05, 9.887560271E-03, 8.333285898E-02, 2.478559017E-01, + 3.428434134E-01, 2.343961596E-01, 7.369252294E-02, 7.850865833E-03, + 1.082170274E-04, 1.033949479E-02, 8.534456789E-02, 2.505008876E-01, + 3.426689506E-01, 2.316644788E-01, 7.184901088E-02, 7.485736627E-03, + 1.233371440E-04, 1.080708485E-02, 8.738376945E-02, 2.531278133E-01, + 3.424364924E-01, 2.289219648E-01, 7.003392279E-02, 7.133882027E-03, + 1.397485757E-04, 1.129068248E-02, 8.945026249E-02, 2.557355762E-01, + 3.421461284E-01, 2.261696160E-01, 6.824731827E-02, 6.794991903E-03, + 1.575958013E-04, 1.179065090E-02, 9.154383838E-02, 2.583232224E-01, + 3.417979777E-01, 2.234084606E-01, 6.648923457E-02, 6.468691397E-03, + 1.769922383E-04, 1.230732165E-02, 9.366425127E-02, 2.608896792E-01, + 3.413922191E-01, 2.206395119E-01, 6.475970894E-02, 6.154712290E-03, + 1.981738606E-04, 1.284105983E-02, 9.581124038E-02, 2.634339035E-01, + 3.409290314E-01, 2.178637981E-01, 6.305878609E-02, 5.852684379E-03, + 2.211847313E-04, 1.339218579E-02, 9.798453748E-02, 2.659549415E-01, + 3.404086530E-01, 2.150822729E-01, 6.138643622E-02, 5.562345497E-03, + 2.460231190E-04, 1.396108977E-02, 1.001838669E-01, 2.684516609E-01, + 3.398312926E-01, 2.122959495E-01, 5.974265561E-02, 5.283284001E-03, + 2.726115927E-04, 1.454808749E-02, 1.024089083E-01, 2.709231377E-01, + 3.391972482E-01, 2.095058411E-01, 5.812742189E-02, 5.015311297E-03, + 3.013863170E-04, 1.515355054E-02, 1.046593264E-01, 2.733682692E-01, + 3.385068178E-01, 2.067128718E-01, 5.654069409E-02, 4.758012015E-03, + 3.328395542E-04, 1.577781141E-02, 1.069347933E-01, 2.757860720E-01, + 3.377602994E-01, 2.039180547E-01, 5.498242006E-02, 4.511159845E-03, + 3.658991191E-04, 1.642123051E-02, 1.092349365E-01, 2.781755328E-01, + 3.369580209E-01, 2.011223286E-01, 5.345252529E-02, 4.274417181E-03, + 4.018281470E-04, 1.708412915E-02, 1.115593687E-01, 2.805356979E-01, + 3.361004293E-01, 1.983266175E-01, 5.195093155E-02, 4.047499038E-03, + 4.401875485E-04, 1.776690222E-02, 1.139076948E-01, 2.828655839E-01, + 3.351879120E-01, 1.955319196E-01, 5.047753453E-02, 3.830091329E-03, + 4.812776169E-04, 1.846982725E-02, 1.162794977E-01, 2.851640880E-01, + 3.342207968E-01, 1.927391142E-01, 4.903224111E-02, 3.621967277E-03, + 5.252459669E-04, 1.919330470E-02, 1.186743453E-01, 2.874303460E-01, + 3.331996202E-01, 1.899491698E-01, 4.761491716E-02, 3.422776936E-03, + 5.721592461E-04, 1.993762329E-02, 1.210917681E-01, 2.896633744E-01, + 3.321248591E-01, 1.871629506E-01, 4.622544348E-02, 3.232272575E-03, + 6.222130032E-04, 2.070316114E-02, 1.235313043E-01, 2.918621898E-01, + 3.309969604E-01, 1.843813360E-01, 4.486365616E-02, 3.050152911E-03, + 6.755515351E-04, 2.149021253E-02, 1.259924471E-01, 2.940258980E-01, + 3.298164308E-01, 1.816052496E-01, 4.352942482E-02, 2.876190469E-03, + 7.324148901E-04, 2.229913883E-02, 1.284746826E-01, 2.961534858E-01, + 3.285838962E-01, 1.788355410E-01, 4.222255200E-02, 2.710093278E-03, + 7.928516716E-04, 2.313023806E-02, 1.309774816E-01, 2.982441187E-01, + 3.272998929E-01, 1.760730892E-01, 4.094288871E-02, 2.551567042E-03, + 8.570110658E-04, 2.398385666E-02, 1.335003078E-01, 3.002967536E-01, + 3.259649575E-01, 1.733186990E-01, 3.969023004E-02, 2.400433412E-03, + 9.251192096E-04, 2.486028522E-02, 1.360425949E-01, 3.023106754E-01, + 3.245797157E-01, 1.705732346E-01, 3.846437484E-02, 2.256359672E-03, + 9.974770946E-04, 2.575986087E-02, 1.386037618E-01, 3.042849004E-01, + 3.231448531E-01, 1.678375006E-01, 3.726511076E-02, 2.119151875E-03, + 1.073930296E-03, 2.668286115E-02, 1.411831975E-01, 3.062185347E-01, + 3.216609657E-01, 1.651122719E-01, 3.609224036E-02, 1.988604199E-03, + 1.155023579E-03, 2.762960829E-02, 1.437802613E-01, 3.081108034E-01, + 3.201287389E-01, 1.623983532E-01, 3.494550660E-02, 1.864377526E-03, + 1.240676851E-03, 2.860039286E-02, 1.463943720E-01, 3.099608123E-01, + 3.185488880E-01, 1.596965194E-01, 3.382468969E-02, 1.746327500E-03, + 1.331258914E-03, 2.959549613E-02, 1.490248144E-01, 3.117676973E-01, + 3.169221282E-01, 1.570075154E-01, 3.272953629E-02, 1.634211512E-03, + 1.426893868E-03, 3.061520495E-02, 1.516709626E-01, 3.135308027E-01, + 3.152491748E-01, 1.543320864E-01, 3.165979683E-02, 1.527829794E-03 };
View file
dcadec-0.1.0.tar.gz/libdcadec/fixed_math.h -> dcadec-0.2.0.tar.gz/libdcadec/fixed_math.h
Changed
@@ -42,10 +42,16 @@ static inline int32_t clip__(int32_t a, int bits) { +#ifdef __ARM_FEATURE_SAT + int x; + __asm__("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(bits + 1)); + return x; +#else if ((a + (1 << bits)) & ~((1 << (bits + 1)) - 1)) return (a >> 31) ^ ((1 << bits) - 1); else return a; +#endif } static inline int64_t round20(int64_t a) { return round__(a, 20); } @@ -67,11 +73,6 @@ return (a * b + (1 << 3)) >> 4; } -static inline int32_t mul22nrd(int32_t a, int32_t b) -{ - return (int32_t)(((int64_t)a * b) >> 22); -} - static inline int32_t mul15(int32_t a, int32_t b) { return mul__(a, b, 15); } static inline int32_t mul16(int32_t a, int32_t b) { return mul__(a, b, 16); } static inline int32_t mul17(int32_t a, int32_t b) { return mul__(a, b, 17); } @@ -79,8 +80,6 @@ static inline int32_t mul23(int32_t a, int32_t b) { return mul__(a, b, 23); } static inline int32_t mul31(int32_t a, int32_t b) { return mul__(a, b, 31); } -static inline int32_t clip15(int32_t a) { return clip__(a, 15); } -static inline int32_t clip19(int32_t a) { return clip__(a, 19); } static inline int32_t clip23(int32_t a) { return clip__(a, 23); } #endif
View file
dcadec-0.1.0.tar.gz/libdcadec/idct.h -> dcadec-0.2.0.tar.gz/libdcadec/idct.h
Changed
@@ -19,22 +19,50 @@ #ifndef IDCT_H #define IDCT_H +#define DCT_A_ROWS 8 +#define DCT_A_COLS 8 +#define DCT_B_ROWS 8 +#define DCT_B_COLS 7 + +#define IDCT_SIZE 32 +#define IDCT_SIZE_2 (IDCT_SIZE / 2) +#define IDCT_SIZE_4 (IDCT_SIZE / 4) + +#define MOD_A_SIZE IDCT_SIZE_2 +#define MOD_B_SIZE IDCT_SIZE_4 +#define MOD_C_SIZE IDCT_SIZE +#define MOD_A_HALF (MOD_A_SIZE / 2) +#define MOD_B_HALF (MOD_B_SIZE / 2) +#define MOD_C_HALF (MOD_C_SIZE / 2) + +#define IDCT64_SIZE 64 +#define IDCT64_SIZE_2 (IDCT64_SIZE / 2) +#define IDCT64_SIZE_4 (IDCT64_SIZE / 4) +#define IDCT64_SIZE_8 (IDCT64_SIZE / 8) + +#define MOD64_A_SIZE IDCT64_SIZE_2 +#define MOD64_B_SIZE IDCT64_SIZE_4 +#define MOD64_C_SIZE IDCT64_SIZE +#define MOD64_A_HALF (MOD64_A_SIZE / 2) +#define MOD64_B_HALF (MOD64_B_SIZE / 2) +#define MOD64_C_HALF (MOD64_C_SIZE / 2) + struct core_decoder; struct idct_context { - double dct_a[8][8]; - double dct_b[8][7]; + double dct_a[DCT_A_ROWS][DCT_A_COLS]; + double dct_b[DCT_B_ROWS][DCT_B_COLS]; - double mod_a[16]; - double mod_b[ 8]; - double mod_c[32]; + double mod_a[MOD_A_SIZE]; + double mod_b[MOD_B_SIZE]; + double mod_c[MOD_C_SIZE]; - double mod64_a[32]; - double mod64_b[16]; - double mod64_c[64]; + double mod64_a[MOD64_A_SIZE]; + double mod64_b[MOD64_B_SIZE]; + double mod64_c[MOD64_C_SIZE]; }; -struct idct_context *idct_init(struct core_decoder *parent); +struct idct_context *idct_init(struct core_decoder *parent) __attribute__((cold)); void idct_perform32_float(const struct idct_context * restrict idct, double * restrict input, double * restrict output);
View file
dcadec-0.1.0.tar.gz/libdcadec/idct_fixed.c -> dcadec-0.2.0.tar.gz/libdcadec/idct_fixed.c
Changed
@@ -50,7 +50,7 @@ { // floor(sin((2 * i + 1) * (2 * (7 - j) + 1) * PI / 32) * (1 << 23) + 0.5), i = 2 * k // -floor(sin((2 * i + 1) * (2 * (7 - j) + 1) * PI / 32) * (1 << 23) + 0.5), i = 2 * k + 1 - static const int cos_mod[8][8] = { + static const int cos_mod[DCT_A_ROWS][DCT_A_COLS] = { { 8348215, 8027397, 7398092, 6484482, 5321677, 3954362, 2435084, 822227 }, { 8027397, 5321677, 822227, -3954362, -7398092, -8348215, -6484482, -2435084 }, { 7398092, 822227, -6484482, -8027397, -2435084, 5321677, 8348215, 3954362 }, @@ -61,9 +61,9 @@ { 822227, -2435084, 3954362, -5321677, 6484482, -7398092, 8027397, -8348215 } }; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < DCT_A_ROWS; i++) { int64_t res = INT64_C(0); - for (int j = 0; j < 8; j++) + for (int j = 0; j < DCT_A_COLS; j++) res += (int64_t)cos_mod[i][j] * input[j]; output[i] = norm23(res); } @@ -72,7 +72,7 @@ static void dct_b(const int * restrict input, int * restrict output) { // floor(cos((2 * i + 1) * (j + 1) * PI / 16) * (1 << 23) + 0.5) - static const int cos_mod[8][7] = { + static const int cos_mod[DCT_B_ROWS][DCT_B_COLS] = { { 8227423, 7750063, 6974873, 5931642, 4660461, 3210181, 1636536 }, { 6974873, 3210181, -1636536, -5931642, -8227423, -7750063, -4660461 }, { 4660461, -3210181, -8227423, -5931642, 1636536, 7750063, 6974873 }, @@ -83,9 +83,9 @@ { -8227423, 7750063, -6974873, 5931642, -4660461, 3210181, -1636536 } }; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < DCT_B_ROWS; i++) { int64_t res = (int64_t)input[0] * (1 << 23); - for (int j = 0; j < 7; j++) + for (int j = 0; j < DCT_B_COLS; j++) res += (int64_t)cos_mod[i][j] * input[1 + j]; output[i] = norm23(res); } @@ -95,44 +95,43 @@ { // floor(0.5 / cos((2 * ( i) + 1) * PI / 64) * (1 << 23) + 0.5), i = 0 .. 8 // -floor(0.5 / sin((2 * (15 - i) + 1) * PI / 64) * (1 << 23) + 0.5), i = 8 .. 16 - static const int cos_mod[16] = { + static const int cos_mod[MOD_A_SIZE] = { 4199362, 4240198, 4323885, 4454708, 4639772, 4890013, 5221943, 5660703, -6245623, -7040975, -8158494, -9809974, -12450076, -17261920, -28585092, -85479984 }; - for (int i = 0; i < 8; i++) - output[i] = mul23(cos_mod[i], input[i] + input[8 + i]); + for (int i = 0; i < MOD_A_HALF; i++) + output[i] = mul23(cos_mod[i], input[i] + input[MOD_A_HALF + i]); - for (int i = 8, k = 7; i < 16; i++, k--) - output[i] = mul23(cos_mod[i], input[k] - input[8 + k]); + for (int i = MOD_A_HALF, k = MOD_A_HALF - 1; i < MOD_A_SIZE; i++, k--) + output[i] = mul23(cos_mod[i], input[k] - input[MOD_A_HALF + k]); } static void mod_b(int * restrict input, int * restrict output) { // floor(0.5 / cos((2 * ( i) + 1) * PI / 32) * (1 << 23) + 0.5), i = 0 .. 4 // floor(0.5 / sin((2 * (7 - i) + 1) * PI / 32) * (1 << 23) + 0.5), i = 4 .. 8 - static const int cos_mod[8] = { + static const int cos_mod[MOD_B_SIZE] = { 4214598, 4383036, 4755871, 5425934, 6611520, 8897610, 14448934, 42791536 }; - for (int i = 0; i < 8; i++) - input[8 + i] = mul23(cos_mod[i], input[8 + i]); - - for (int i = 0; i < 8; i++) - output[i] = input[i] + input[8 + i]; + for (int i = 0; i < MOD_B_SIZE; i++) { + input[MOD_B_SIZE + i] = mul23(cos_mod[i], input[MOD_B_SIZE + i]); + output[i] = input[i] + input[MOD_B_SIZE + i]; + } - for (int i = 8, k = 7; i < 16; i++, k--) - output[i] = input[k] - input[8 + k]; + for (int i = 0, k = MOD_B_SIZE - 1; i < MOD_B_SIZE; i++, k--) + output[MOD_B_SIZE + i] = input[k] - input[MOD_B_SIZE + k]; } static void mod_c(const int * restrict input, int * restrict output) { // floor(0.125 / cos((2 * ( i) + 1) * PI / 128) * (1 << 23) + 0.5), i = 0 .. 16 // -floor(0.125 / sin((2 * (31 - i) + 1) * PI / 128) * (1 << 23) + 0.5), i = 16 .. 32 - static const int cos_mod[32] = { + static const int cos_mod[MOD_C_SIZE] = { 1048892, 1051425, 1056522, 1064244, 1074689, 1087987, 1104313, 1123884, 1146975, 1173922, 1205139, 1241133, @@ -143,11 +142,11 @@ -6133390, -8566050, -14253820, -42727120 }; - for (int i = 0; i < 16; i++) - output[i] = mul23(cos_mod[i], input[i] + input[16 + i]); + for (int i = 0; i < MOD_C_HALF; i++) + output[i] = mul23(cos_mod[i], input[i] + input[MOD_C_HALF + i]); - for (int i = 16, k = 15; i < 32; i++, k--) - output[i] = mul23(cos_mod[i], input[k] - input[16 + k]); + for (int i = MOD_C_HALF, k = MOD_C_HALF - 1; i < MOD_C_SIZE; i++, k--) + output[i] = mul23(cos_mod[i], input[k] - input[MOD_C_HALF + k]); } static void clp_v(int *input, int len) @@ -159,38 +158,38 @@ void idct_perform32_fixed(int * restrict input, int * restrict output) { int mag = 0; - for (int i = 0; i < 32; i++) + for (int i = 0; i < IDCT_SIZE; i++) mag += abs(input[i]); int shift = mag > 0x400000 ? 2 : 0; int round = shift > 0 ? 1 << (shift - 1) : 0; - for (int i = 0; i < 32; i++) + for (int i = 0; i < IDCT_SIZE; i++) input[i] = (input[i] + round) >> shift; - sum_a(input, output + 0, 16); - sum_b(input, output + 16, 16); - clp_v(output, 32); + sum_a(input, output + 0 * IDCT_SIZE_2, IDCT_SIZE_2); + sum_b(input, output + 1 * IDCT_SIZE_2, IDCT_SIZE_2); + clp_v(output, IDCT_SIZE); - sum_a(output + 0, input + 0, 8); - sum_b(output + 0, input + 8, 8); - sum_c(output + 16, input + 16, 8); - sum_d(output + 16, input + 24, 8); - clp_v(input, 32); + sum_a(output + 0 * IDCT_SIZE_2, input + 0 * IDCT_SIZE_4, IDCT_SIZE_4); + sum_b(output + 0 * IDCT_SIZE_2, input + 1 * IDCT_SIZE_4, IDCT_SIZE_4); + sum_c(output + 1 * IDCT_SIZE_2, input + 2 * IDCT_SIZE_4, IDCT_SIZE_4); + sum_d(output + 1 * IDCT_SIZE_2, input + 3 * IDCT_SIZE_4, IDCT_SIZE_4); + clp_v(input, IDCT_SIZE); - dct_a(input + 0, output + 0); - dct_b(input + 8, output + 8); - dct_b(input + 16, output + 16); - dct_b(input + 24, output + 24); - clp_v(output, 32); + dct_a(input + 0 * IDCT_SIZE_4, output + 0 * IDCT_SIZE_4); + dct_b(input + 1 * IDCT_SIZE_4, output + 1 * IDCT_SIZE_4); + dct_b(input + 2 * IDCT_SIZE_4, output + 2 * IDCT_SIZE_4); + dct_b(input + 3 * IDCT_SIZE_4, output + 3 * IDCT_SIZE_4); + clp_v(output, IDCT_SIZE); - mod_a(output + 0, input + 0); - mod_b(output + 16, input + 16); - clp_v(input, 32); + mod_a(output + 0 * IDCT_SIZE_2, input + 0 * IDCT_SIZE_2); + mod_b(output + 1 * IDCT_SIZE_2, input + 1 * IDCT_SIZE_2); + clp_v(input, IDCT_SIZE); mod_c(input, output); - for (int i = 0; i < 32; i++) + for (int i = 0; i < IDCT_SIZE; i++) output[i] = clip23(output[i] * (1 << shift)); } @@ -198,7 +197,7 @@ { // floor(0.5 / cos((2 * ( i) + 1) * PI / 128) * (1 << 23) + 0.5), i = 0 .. 16 // -floor(0.5 / sin((2 * (31 - i) + 1) * PI / 128) * (1 << 23) + 0.5), i = 16 .. 32 - static const int cos_mod[32] = { + static const int cos_mod[MOD64_A_SIZE] = { 4195568, 4205700, 4226086, 4256977, 4298755, 4351949, 4417251, 4495537, 4587901, 4695690, 4820557, 4964534, @@ -209,39 +208,38 @@ -24533560, -34264200, -57015280, -170908480 }; - for (int i = 0; i < 16; i++) - output[i] = mul23(cos_mod[i], input[i] + input[16 + i]); + for (int i = 0; i < MOD64_A_HALF; i++) + output[i] = mul23(cos_mod[i], input[i] + input[MOD64_A_HALF + i]); - for (int i = 16, k = 15; i < 32; i++, k--) - output[i] = mul23(cos_mod[i], input[k] - input[16 + k]); + for (int i = MOD64_A_HALF, k = MOD64_A_HALF - 1; i < MOD64_A_SIZE; i++, k--) + output[i] = mul23(cos_mod[i], input[k] - input[MOD64_A_HALF + k]); } static void mod64_b(int * restrict input, int * restrict output) {
View file
dcadec-0.1.0.tar.gz/libdcadec/idct_float.c -> dcadec-0.2.0.tar.gz/libdcadec/idct_float.c
Changed
@@ -27,8 +27,8 @@ if (!idct) return NULL; - for (i = 0; i < 8; i++) { - for (j = 0, k = 7; j < 8; j++, k--) { + for (i = 0; i < DCT_A_ROWS; i++) { + for (j = 0, k = DCT_A_COLS - 1; j < DCT_A_COLS; j++, k--) { if (i & 1) idct->dct_a[i][j] = -sin((2 * i + 1) * (2 * k + 1) * M_PI / 32); else @@ -36,44 +36,44 @@ } } - for (i = 0; i < 8; i++) - for (j = 0; j < 7; j++) + for (i = 0; i < DCT_B_ROWS; i++) + for (j = 0; j < DCT_B_COLS; j++) idct->dct_b[i][j] = cos((2 * i + 1) * (1 + j) * M_PI / 16); - for (i = 0; i < 8; i++) + for (i = 0; i < MOD_A_HALF; i++) idct->mod_a[i] = 0.5 / cos((2 * i + 1) * M_PI / 64); - for (i = 8, k = 7; i < 16; i++, k--) + for (i = MOD_A_HALF, k = MOD_A_HALF - 1; i < MOD_A_SIZE; i++, k--) idct->mod_a[i] = -0.5 / sin((2 * k + 1) * M_PI / 64); - for (i = 0; i < 4; i++) + for (i = 0; i < MOD_B_HALF; i++) idct->mod_b[i] = 0.5 / cos((2 * i + 1) * M_PI / 32); - for (i = 4, k = 3; i < 8; i++, k--) + for (i = MOD_B_HALF, k = MOD_B_HALF - 1; i < MOD_B_SIZE; i++, k--) idct->mod_b[i] = 0.5 / sin((2 * k + 1) * M_PI / 32); - for (i = 0; i < 16; i++) + for (i = 0; i < MOD_C_HALF; i++) idct->mod_c[i] = 0.125 / cos((2 * i + 1) * M_PI / 128); - for (i = 16, k = 15; i < 32; i++, k--) + for (i = MOD_C_HALF, k = MOD_C_HALF - 1; i < MOD_C_SIZE; i++, k--) idct->mod_c[i] = -0.125 / sin((2 * k + 1) * M_PI / 128); - for (i = 0; i < 16; i++) + for (i = 0; i < MOD64_A_HALF; i++) idct->mod64_a[i] = 0.5 / cos((2 * i + 1) * M_PI / 128); - for (i = 16, k = 15; i < 32; i++, k--) + for (i = MOD64_A_HALF, k = MOD64_A_HALF - 1; i < MOD64_A_SIZE; i++, k--) idct->mod64_a[i] = -0.5 / sin((2 * k + 1) * M_PI / 128); - for (i = 0; i < 8; i++) + for (i = 0; i < MOD64_B_HALF; i++) idct->mod64_b[i] = 0.5 / cos((2 * i + 1) * M_PI / 64); - for (i = 8, k = 7; i < 16; i++, k--) + for (i = MOD64_B_HALF, k = MOD64_B_HALF - 1; i < MOD64_B_SIZE; i++, k--) idct->mod64_b[i] = 0.5 / sin((2 * k + 1) * M_PI / 64); - for (i = 0; i < 32; i++) + for (i = 0; i < MOD64_C_HALF; i++) idct->mod64_c[i] = 0.125 / cos((2 * i + 1) * M_PI / 256); - for (i = 32, k = 31; i < 64; i++, k--) + for (i = MOD64_C_HALF, k = MOD64_C_HALF - 1; i < MOD64_C_SIZE; i++, k--) idct->mod64_c[i] = -0.125 / sin((2 * k + 1) * M_PI / 256); return idct; @@ -108,9 +108,9 @@ static void dct_a(const struct idct_context * restrict idct, const double * restrict input, double * restrict output) { - for (int i = 0; i < 8; i++) { + for (int i = 0; i < DCT_A_ROWS; i++) { double res = 0.0; - for (int j = 0; j < 8; j++) + for (int j = 0; j < DCT_A_COLS; j++) res += idct->dct_a[i][j] * input[j]; output[i] = res; } @@ -119,9 +119,9 @@ static void dct_b(const struct idct_context * restrict idct, const double * restrict input, double * restrict output) { - for (int i = 0; i < 8; i++) { + for (int i = 0; i < DCT_B_ROWS; i++) { double res = input[0]; - for (int j = 0; j < 7; j++) + for (int j = 0; j < DCT_B_COLS; j++) res += idct->dct_b[i][j] * input[1 + j]; output[i] = res; } @@ -130,54 +130,53 @@ static void mod_a(const struct idct_context * restrict idct, const double * restrict input, double * restrict output) { - for (int i = 0; i < 8; i++) - output[i] = idct->mod_a[i] * (input[i] + input[8 + i]); + for (int i = 0; i < MOD_A_HALF; i++) + output[i] = idct->mod_a[i] * (input[i] + input[MOD_A_HALF + i]); - for (int i = 8, k = 7; i < 16; i++, k--) - output[i] = idct->mod_a[i] * (input[k] - input[8 + k]); + for (int i = MOD_A_HALF, k = MOD_A_HALF - 1; i < MOD_A_SIZE; i++, k--) + output[i] = idct->mod_a[i] * (input[k] - input[MOD_A_HALF + k]); } static void mod_b(const struct idct_context * restrict idct, double * restrict input, double * restrict output) { - for (int i = 0; i < 8; i++) - input[8 + i] = idct->mod_b[i] * input[8 + i]; - - for (int i = 0; i < 8; i++) - output[i] = input[i] + input[8 + i]; + for (int i = 0; i < MOD_B_SIZE; i++) { + input[MOD_B_SIZE + i] = idct->mod_b[i] * input[MOD_B_SIZE + i]; + output[i] = input[i] + input[MOD_B_SIZE + i]; + } - for (int i = 8, k = 7; i < 16; i++, k--) - output[i] = input[k] - input[8 + k]; + for (int i = 0, k = MOD_B_SIZE - 1; i < MOD_B_SIZE; i++, k--) + output[MOD_B_SIZE + i] = input[k] - input[MOD_B_SIZE + k]; } static void mod_c(const struct idct_context * restrict idct, const double * restrict input, double * restrict output) { - for (int i = 0; i < 16; i++) - output[i] = idct->mod_c[i] * (input[i] + input[16 + i]); + for (int i = 0; i < MOD_C_HALF; i++) + output[i] = idct->mod_c[i] * (input[i] + input[MOD_C_HALF + i]); - for (int i = 16, k = 15; i < 32; i++, k--) - output[i] = idct->mod_c[i] * (input[k] - input[16 + k]); + for (int i = MOD_C_HALF, k = MOD_C_HALF - 1; i < MOD_C_SIZE; i++, k--) + output[i] = idct->mod_c[i] * (input[k] - input[MOD_C_HALF + k]); } void idct_perform32_float(const struct idct_context * restrict idct, double * restrict input, double * restrict output) { - sum_a(input, output + 0, 16); - sum_b(input, output + 16, 16); + sum_a(input, output + 0 * IDCT_SIZE_2, IDCT_SIZE_2); + sum_b(input, output + 1 * IDCT_SIZE_2, IDCT_SIZE_2); - sum_a(output + 0, input + 0, 8); - sum_b(output + 0, input + 8, 8); - sum_c(output + 16, input + 16, 8); - sum_d(output + 16, input + 24, 8); + sum_a(output + 0 * IDCT_SIZE_2, input + 0 * IDCT_SIZE_4, IDCT_SIZE_4); + sum_b(output + 0 * IDCT_SIZE_2, input + 1 * IDCT_SIZE_4, IDCT_SIZE_4); + sum_c(output + 1 * IDCT_SIZE_2, input + 2 * IDCT_SIZE_4, IDCT_SIZE_4); + sum_d(output + 1 * IDCT_SIZE_2, input + 3 * IDCT_SIZE_4, IDCT_SIZE_4); - dct_a(idct, input + 0, output + 0); - dct_b(idct, input + 8, output + 8); - dct_b(idct, input + 16, output + 16); - dct_b(idct, input + 24, output + 24); + dct_a(idct, input + 0 * IDCT_SIZE_4, output + 0 * IDCT_SIZE_4); + dct_b(idct, input + 1 * IDCT_SIZE_4, output + 1 * IDCT_SIZE_4); + dct_b(idct, input + 2 * IDCT_SIZE_4, output + 2 * IDCT_SIZE_4); + dct_b(idct, input + 3 * IDCT_SIZE_4, output + 3 * IDCT_SIZE_4); - mod_a(idct, output + 0, input + 0); - mod_b(idct, output + 16, input + 16); + mod_a(idct, output + 0 * IDCT_SIZE_2, input + 0 * IDCT_SIZE_2); + mod_b(idct, output + 1 * IDCT_SIZE_2, input + 1 * IDCT_SIZE_2); mod_c(idct, input, output); } @@ -185,72 +184,71 @@ static void mod64_a(const struct idct_context * restrict idct, const double * restrict input, double * restrict output) { - for (int i = 0; i < 16; i++) - output[i] = idct->mod64_a[i] * (input[i] + input[16 + i]); + for (int i = 0; i < MOD64_A_HALF; i++) + output[i] = idct->mod64_a[i] * (input[i] + input[MOD64_A_HALF + i]); - for (int i = 16, k = 15; i < 32; i++, k--) - output[i] = idct->mod64_a[i] * (input[k] - input[16 + k]); + for (int i = MOD64_A_HALF, k = MOD64_A_HALF - 1; i < MOD64_A_SIZE; i++, k--) + output[i] = idct->mod64_a[i] * (input[k] - input[MOD64_A_HALF + k]); } static void mod64_b(const struct idct_context * restrict idct, double * restrict input, double * restrict output) { - for (int i = 0; i < 16; i++) - input[16 + i] = idct->mod64_b[i] * input[16 + i]; - - for (int i = 0; i < 16; i++) - output[i] = input[i] + input[16 + i]; + for (int i = 0; i < MOD64_B_SIZE; i++) { + input[MOD64_B_SIZE + i] = idct->mod64_b[i] * input[MOD64_B_SIZE + i];
View file
dcadec-0.1.0.tar.gz/libdcadec/interpolator.h -> dcadec-0.2.0.tar.gz/libdcadec/interpolator.h
Changed
@@ -25,8 +25,7 @@ struct idct_context; typedef void (*interpolate_lfe_cb)(int *pcm_samples, int *lfe_samples, - int nsamples, bool dec_select, - bool synth_x96); + int npcmblocks, bool dec_select); typedef void (*interpolate_sub_cb)(struct interpolator *dsp, int *pcm_samples, int **subband_samples_lo, @@ -39,13 +38,13 @@ interpolate_sub_cb interpolate; }; -struct interpolator *interpolator_create(struct idct_context *parent, int flags); -void interpolator_clear(struct interpolator *dsp); +struct interpolator *interpolator_create(struct idct_context *parent, int flags) + __attribute__((cold)); +void interpolator_clear(struct interpolator *dsp) __attribute__((cold)); #define INTERPOLATE_LFE(x) \ void interpolate_##x(int *pcm_samples, int *lfe_samples, \ - int nsamples, bool dec_select, \ - bool synth_x96) + int npcmblocks, bool dec_select) #define INTERPOLATE_SUB(x) \ void interpolate_##x(struct interpolator *dsp, int *pcm_samples, \ @@ -54,6 +53,7 @@ int nsamples, bool perfect) INTERPOLATE_LFE(lfe_float_fir); +INTERPOLATE_LFE(lfe_float_fir_2x); INTERPOLATE_LFE(lfe_float_iir); INTERPOLATE_SUB(sub32_float); INTERPOLATE_SUB(sub64_float);
View file
dcadec-0.1.0.tar.gz/libdcadec/interpolator_fixed.c -> dcadec-0.2.0.tar.gz/libdcadec/interpolator_fixed.c
Changed
@@ -24,42 +24,52 @@ INTERPOLATE_LFE(lfe_fixed_fir) { + (void)dec_select; + assert(!dec_select); + // Select decimation factor - int dec_factor = 64 << dec_select; + int nlfesamples = npcmblocks >> 1; // Interpolation - for (int i = 0; i < nsamples; i++) { - // One decimated sample generates 64 or 128 interpolated ones - for (int j = 0; j < dec_factor; j++) { + for (int i = 0; i < nlfesamples; i++) { + int *src = lfe_samples + MAX_LFE_HISTORY + i; + + // One decimated sample generates 64 interpolated ones + for (int j = 0; j < 32; j++) { // Clear accumulation - int64_t res = INT64_C(0); + int64_t res1 = INT64_C(0); + int64_t res2 = INT64_C(0); // Accumulate - for (int k = 0; k < 512 / dec_factor; k++) - res += (int64_t)lfe_fir_64[k * dec_factor + j] * - lfe_samples[MAX_LFE_HISTORY + i - k]; + for (int k = 0; k < 8; k++) { + res1 += (int64_t)lfe_fir_64[ j * 8 + k] * src[-k]; + res2 += (int64_t)lfe_fir_64[255 - j * 8 - k] * src[-k]; + } // Save interpolated samples - pcm_samples[(i * dec_factor + j) << synth_x96] = clip23(norm23(res)); + pcm_samples[ j] = clip23(norm23(res1)); + pcm_samples[32 + j] = clip23(norm23(res2)); } + + // Advance output pointer + pcm_samples += 64; } // Update history - for (int n = MAX_LFE_HISTORY - 1; n >= 0; n--) - lfe_samples[n] = lfe_samples[nsamples + n]; + for (int n = MAX_LFE_HISTORY - 1; n >= MAX_LFE_HISTORY - 8; n--) + lfe_samples[n] = lfe_samples[nlfesamples + n]; } INTERPOLATE_SUB(sub32_fixed) { (void)subband_samples_hi; - assert(subband_samples_hi == NULL); + assert(!subband_samples_hi); // Get history pointer int *history = dsp->history; // Select filter - const int32_t *filter_coeff = perfect ? - band_fir_perfect : band_fir_nonperfect; + const int32_t *filter_coeff = perfect ? band_fir_perfect : band_fir_nonperfect; // Interpolation begins for (int sample = 0; sample < nsamples; sample++) { @@ -81,36 +91,33 @@ } // One subband sample generates 32 interpolated ones - for (i = 0; i < 16; i++) { + for (i = 0, k = 15; i < 16; i++, k--) { // Clear accumulation - int64_t res = INT64_C(0); + int64_t res1 = INT64_C(0); + int64_t res2 = INT64_C(0); // Accumulate - for (j = 32; j < 512; j += 64) - res += (int64_t)history[16 + i + j] * filter_coeff[i + j]; - res = round21(res); - for (j = 0; j < 512; j += 64) - res += (int64_t)history[ i + j] * filter_coeff[i + j]; - - // Save interpolated samples - pcm_samples[sample * 32 + i] = clip23(norm21(res)); - } + for (j = 32; j < 512; j += 64) { + res1 += (int64_t)history[16 + i + j] * filter_coeff[ i + j]; + res2 += (int64_t)history[16 + k + j] * filter_coeff[16 + i + j]; + } - for (i = 16, k = 15; i < 32; i++, k--) { - // Clear accumulation - int64_t res = INT64_C(0); + res1 = round21(res1); + res2 = round21(res2); - // Accumulate - for (j = 32; j < 512; j += 64) - res += (int64_t)history[16 + k + j] * filter_coeff[i + j]; - res = round21(res); - for (j = 0; j < 512; j += 64) - res += (int64_t)history[ k + j] * filter_coeff[i + j]; + for (j = 0; j < 512; j += 64) { + res1 += (int64_t)history[i + j] * filter_coeff[ i + j]; + res2 += (int64_t)history[k + j] * filter_coeff[16 + i + j]; + } // Save interpolated samples - pcm_samples[sample * 32 + i] = clip23(norm21(res)); + pcm_samples[ i] = clip23(norm21(res1)); + pcm_samples[16 + i] = clip23(norm21(res2)); } + // Advance output pointer + pcm_samples += 32; + // Shift history for (i = 511; i >= 32; i--) history[i] = history[i - 32]; @@ -155,36 +162,33 @@ } // One subband sample generates 64 interpolated ones - for (i = 0; i < 32; i++) { + for (i = 0, k = 31; i < 32; i++, k--) { // Clear accumulation - int64_t res = INT64_C(0); + int64_t res1 = INT64_C(0); + int64_t res2 = INT64_C(0); // Accumulate - for (j = 64; j < 1024; j += 128) - res += (int64_t)history[32 + i + j] * band_fir_x96[i + j]; - res = round20(res); - for (j = 0; j < 1024; j += 128) - res += (int64_t)history[ i + j] * band_fir_x96[i + j]; + for (j = 64; j < 1024; j += 128) { + res1 += (int64_t)history[32 + i + j] * band_fir_x96[ i + j]; + res2 += (int64_t)history[32 + k + j] * band_fir_x96[32 + i + j]; + } - // Save interpolated samples - pcm_samples[sample * 64 + i] = clip23(norm20(res)); - } + res1 = round20(res1); + res2 = round20(res2); - for (i = 32, k = 31; i < 64; i++, k--) { - // Clear accumulation - int64_t res = INT64_C(0); - - // Accumulate - for (j = 64; j < 1024; j += 128) - res += (int64_t)history[32 + k + j] * band_fir_x96[i + j]; - res = round20(res); - for (j = 0; j < 1024; j += 128) - res += (int64_t)history[ k + j] * band_fir_x96[i + j]; + for (j = 0; j < 1024; j += 128) { + res1 += (int64_t)history[i + j] * band_fir_x96[ i + j]; + res2 += (int64_t)history[k + j] * band_fir_x96[32 + i + j]; + } // Save interpolated samples - pcm_samples[sample * 64 + i] = clip23(norm20(res)); + pcm_samples[ i] = clip23(norm20(res1)); + pcm_samples[32 + i] = clip23(norm20(res2)); } + // Advance output pointer + pcm_samples += 64; + // Shift history for (i = 1023; i >= 64; i--) history[i] = history[i - 64];
View file
dcadec-0.1.0.tar.gz/libdcadec/interpolator_float.c -> dcadec-0.2.0.tar.gz/libdcadec/interpolator_float.c
Changed
@@ -36,38 +36,65 @@ return clip23(lrint(a)); } -INTERPOLATE_LFE(lfe_float_fir) +static void interpolate_lfe(int *pcm_samples, int *lfe_samples, int npcmblocks, + const double *filter_coeff, bool dec_select) { - // Select decimation filter - int dec_factor = dec_select ? 128 : 64; - const double *filter_coeff = dec_select ? lfe_fir_128 : lfe_fir_64; + // Select decimation factor + int factor = 64 << dec_select; + int ncoeffs = 8 >> dec_select; + int nlfesamples = npcmblocks >> (dec_select + 1); // Interpolation - for (int i = 0; i < nsamples; i++) { + for (int i = 0; i < nlfesamples; i++) { + int *src = lfe_samples + MAX_LFE_HISTORY + i; + // One decimated sample generates 64 or 128 interpolated ones - for (int j = 0; j < dec_factor; j++) { + for (int j = 0; j < factor / 2; j++) { // Clear accumulation - double res = 0.0; + double res1 = 0.0; + double res2 = 0.0; // Accumulate - for (int k = 0; k < 512 / dec_factor; k++) - res += lfe_samples[MAX_LFE_HISTORY + i - k] * - filter_coeff[k * dec_factor + j]; + for (int k = 0; k < ncoeffs; k++) { + res1 += filter_coeff[ j * ncoeffs + k] * src[-k]; + res2 += filter_coeff[255 - j * ncoeffs - k] * src[-k]; + } // Save interpolated samples - pcm_samples[(i * dec_factor + j) << synth_x96] = convert(res); + pcm_samples[ j] = convert(res1); + pcm_samples[factor / 2 + j] = convert(res2); } + + // Advance output pointer + pcm_samples += factor; } // Update history - for (int n = MAX_LFE_HISTORY - 1; n >= 0; n--) - lfe_samples[n] = lfe_samples[nsamples + n]; + for (int n = MAX_LFE_HISTORY - 1; n >= MAX_LFE_HISTORY - 8; n--) + lfe_samples[n] = lfe_samples[nlfesamples + n]; +} + +INTERPOLATE_LFE(lfe_float_fir) +{ + (void)dec_select; + assert(!dec_select); + + interpolate_lfe(pcm_samples, lfe_samples, npcmblocks, lfe_fir_64, false); +} + +INTERPOLATE_LFE(lfe_float_fir_2x) +{ + (void)dec_select; + assert(dec_select); + + interpolate_lfe(pcm_samples, lfe_samples, npcmblocks, lfe_fir_128, true); } INTERPOLATE_LFE(lfe_float_iir) { // Select decimation factor - int dec_factor = 64 << dec_select; + int factor = 64 << dec_select; + int nlfesamples = npcmblocks >> (dec_select + 1); // Load history double lfe_history[6]; @@ -75,12 +102,12 @@ lfe_history[i] = ((double *)lfe_samples)[i]; // Interpolation - for (int i = 0; i < nsamples; i++) { + for (int i = 0; i < nlfesamples; i++) { double res1 = lfe_samples[MAX_LFE_HISTORY + i] * lfe_iir_scale; double res2; // One decimated sample generates 64 or 128 interpolated ones - for (int j = 0; j < dec_factor; j++) { + for (int j = 0; j < factor; j++) { // Filter for (int k = 0; k < 3; k++) { double tmp1 = lfe_history[k * 2 + 0]; @@ -94,7 +121,7 @@ } // Save interpolated samples - pcm_samples[(i * dec_factor + j) << synth_x96] = convert(res1); + *pcm_samples++ = convert(res1); res1 = 0.0; } } @@ -107,7 +134,7 @@ INTERPOLATE_SUB(sub32_float) { (void)subband_samples_hi; - assert(subband_samples_hi == NULL); + assert(!subband_samples_hi); // Get history pointer double *history = dsp->history; @@ -135,34 +162,30 @@ } // One subband sample generates 32 interpolated ones - for (i = 0; i < 16; i++) { + for (i = 0, k = 15; i < 16; i++, k--) { // Clear accumulation - double res = 0.0; + double res1 = 0.0; + double res2 = 0.0; // Accumulate - for (j = 0; j < 512; j += 64) - res += history[ i + j] * filter_coeff[i + j]; - for (j = 32; j < 512; j += 64) - res += history[16 + i + j] * filter_coeff[i + j]; - - // Save interpolated samples - pcm_samples[sample * 32 + i] = convert(res); - } - - for (i = 16, k = 15; i < 32; i++, k--) { - // Clear accumulation - double res = 0.0; + for (j = 0; j < 512; j += 64) { + res1 += history[i + j] * filter_coeff[ i + j]; + res2 += history[k + j] * filter_coeff[16 + i + j]; + } - // Accumulate - for (j = 0; j < 512; j += 64) - res += history[ k + j] * filter_coeff[i + j]; - for (j = 32; j < 512; j += 64) - res += history[16 + k + j] * filter_coeff[i + j]; + for (j = 32; j < 512; j += 64) { + res1 += history[16 + i + j] * filter_coeff[ i + j]; + res2 += history[16 + k + j] * filter_coeff[16 + i + j]; + } // Save interpolated samples - pcm_samples[sample * 32 + i] = convert(res); + pcm_samples[ i] = convert(res1); + pcm_samples[16 + i] = convert(res2); } + // Advance output pointer + pcm_samples += 32; + // Shift history for (i = 511; i >= 32; i--) history[i] = history[i - 32]; @@ -207,34 +230,30 @@ } // One subband sample generates 64 interpolated ones - for (i = 0; i < 32; i++) { + for (i = 0, k = 31; i < 32; i++, k--) { // Clear accumulation - double res = 0.0; + double res1 = 0.0; + double res2 = 0.0; // Accumulate - for (j = 0; j < 1024; j += 128) - res += history[ i + j] * band_fir_x96[i + j]; - for (j = 64; j < 1024; j += 128) - res += history[32 + i + j] * band_fir_x96[i + j]; - - // Save interpolated samples - pcm_samples[sample * 64 + i] = convert(res); - } - - for (i = 32, k = 31; i < 64; i++, k--) { - // Clear accumulation - double res = 0.0; + for (j = 0; j < 1024; j += 128) { + res1 += history[i + j] * band_fir_x96[ i + j]; + res2 += history[k + j] * band_fir_x96[32 + i + j]; + } - // Accumulate - for (j = 0; j < 1024; j += 128) - res += history[ k + j] * band_fir_x96[i + j]; - for (j = 64; j < 1024; j += 128) - res += history[32 + k + j] * band_fir_x96[i + j]; + for (j = 64; j < 1024; j += 128) { + res1 += history[32 + i + j] * band_fir_x96[ i + j];
View file
dcadec-0.1.0.tar.gz/libdcadec/xll_decoder.c -> dcadec-0.2.0.tar.gz/libdcadec/xll_decoder.c
Changed
@@ -36,7 +36,7 @@ m = dmix_primary_nch[chs->dmix_type]; n = chs->nchannels; } else { - m = chs->dmix_m; + m = chs->hier_m; n = chs->nchannels + 2; // Two extra columns for scales } @@ -67,31 +67,26 @@ // Only for non-primary channel sets if (!chs->primary_chset) { int code = bits_get(&xll->bits, 9); - int sign = (code >> 8) - 1; code &= 0xff; - if (code > 0) { - unsigned int index = code - 1; - if (index < 40 || index >= dca_countof(dmix_table)) { - xll_err("Invalid downmix scale index"); - return -DCADEC_EBADDATA; - } - int scale = dmix_table[index]; - scale_inv = dmix_table_inv[index - 40]; - chs->dmix_scale_cur[i] = (scale ^ sign) - sign; - chs->dmix_scale_inv_cur[i] = (scale_inv ^ sign) - sign; - } else { - chs->dmix_scale_cur[i] = 0; - chs->dmix_scale_inv_cur[i] = 0; + int sign = (code >> 8) - 1; + unsigned int index = (code & 0xff) - 1; + if (index < 40 || index >= dca_countof(dmix_table)) { + xll_err("Invalid XLL downmix scale index"); + return -DCADEC_EBADDATA; } + int scale = dmix_table[index]; + scale_inv = dmix_table_inv[index - 40]; + chs->dmix_scale_cur[i] = (scale ^ sign) - sign; + chs->dmix_scale_inv_cur[i] = (scale_inv ^ sign) - sign; } // Downmix coefficients for (int j = 0; j < chs->nchannels; j++) { int code = bits_get(&xll->bits, 9); - int sign = (code >> 8) - 1; code &= 0xff; - if (code > 0) { + int sign = (code >> 8) - 1; + if (code &= 0xff) { unsigned int index = code - 1; if (index >= dca_countof(dmix_table)) { - xll_err("Invalid downmix coefficient index"); + xll_err("Invalid XLL downmix coefficient index"); return -DCADEC_EBADDATA; } int coeff = dmix_table[index]; @@ -112,22 +107,21 @@ static int chs_parse_header(struct xll_chset *chs, struct exss_asset *asset) { struct xll_decoder *xll = chs->decoder; - int i, j, k, ret; - size_t header_pos = xll->bits.index; + int i, j, k, ret, header_pos = xll->bits.index; // Size of channel set sub-header - size_t header_size = bits_get(&xll->bits, 10) + 1; + int header_size = bits_get(&xll->bits, 10) + 1; // Check CRC if ((ret = bits_check_crc(&xll->bits, header_pos, header_pos + header_size * 8)) < 0) { - xll_err("Invalid sub-header checksum"); + xll_err("Invalid XLL sub-header checksum"); return ret; } // Number of channels in the channel set chs->nchannels = bits_get(&xll->bits, 4) + 1; if (chs->nchannels > XLL_MAX_CHANNELS) { - xll_err_once("Unsupported number of channels (%d)", chs->nchannels); + xll_err_once("Unsupported number of XLL channels (%d)", chs->nchannels); return -DCADEC_ENOSUP; } @@ -143,7 +137,7 @@ // Original sampling frequency chs->freq = exss_sample_rates[bits_get(&xll->bits, 4)]; if (chs->freq > 192000) { - xll_err_once("Unsupported sampling frequency"); + xll_err_once("Unsupported XLL sampling frequency"); return -DCADEC_ENOSUP; } @@ -175,7 +169,7 @@ if (chs->dmix_coeffs_present && chs->primary_chset) { chs->dmix_type = bits_get(&xll->bits, 3); if (chs->dmix_type >= DMIX_TYPE_COUNT) { - xll_err("Invalid primary channel set downmix type"); + xll_err("Invalid XLL primary channel set downmix type"); return -DCADEC_EBADDATA; } } @@ -193,7 +187,7 @@ // Channel mask for set chs->ch_mask = bits_get(&xll->bits, xll->ch_mask_nbits); if (dca_popcount(chs->ch_mask) != chs->nchannels) { - xll_err("Invalid channel mask"); + xll_err("Invalid XLL channel mask"); return -DCADEC_EBADDATA; } } else { @@ -266,28 +260,32 @@ return -DCADEC_ENOSUP; } - // Clamp the sampling frequency to 96 kHz. The rest of the code will use - // the number of bands to determine maximum frequency. - if (chs->freq > 96000) - chs->freq = 96000; + // Set the sampling frequency to that of the first frequency band. + // Frequency will be doubled again after bands assembly. + chs->freq >>= chs->nfreqbands - 1; + // Determine number of bits to read bit allocation coding parameter if (chs->storage_bit_res > 16) chs->nabits = 5; else if (chs->storage_bit_res > 8) chs->nabits = 4; else chs->nabits = 3; + + // Account for embedded downmix and decimator saturation if ((xll->nchsets > 1 || chs->nfreqbands > 1) && chs->nabits < 5) chs->nabits++; - for (int band = 0; band < chs->nfreqbands; band++) { + for (int band_i = 0; band_i < chs->nfreqbands; band_i++) { + struct xll_band *band = &chs->bands[band_i]; + // Pairwise channel decorrelation - chs->decor_enabled[band] = bits_get1(&xll->bits); - if (chs->decor_enabled[band] && chs->nchannels > 1) { + band->decor_enabled = bits_get1(&xll->bits); + if (band->decor_enabled && chs->nchannels > 1) { // Original channel order for (i = 0; i < chs->nchannels; i++) { - chs->orig_order[band][i] = bits_get(&xll->bits, ch_nbits[chs->nchannels - 1]); - if (chs->orig_order[band][i] >= chs->nchannels) { + band->orig_order[i] = bits_get(&xll->bits, ch_nbits[chs->nchannels - 1]); + if (band->orig_order[i] >= chs->nchannels) { xll_err("Invalid original channel order"); return -DCADEC_EBADDATA; } @@ -295,87 +293,91 @@ // Pairwise channel coefficients for (i = 0; i < chs->nchannels / 2; i++) { if (bits_get1(&xll->bits)) - chs->decor_coeff[band][i] = bits_get_signed_linear(&xll->bits, 7); + band->decor_coeff[i] = bits_get_signed_linear(&xll->bits, 7); else - chs->decor_coeff[band][i] = 0; + band->decor_coeff[i] = 0; } } else { for (i = 0; i < chs->nchannels; i++) - chs->orig_order[band][i] = i; + band->orig_order[i] = i; for (i = 0; i < chs->nchannels / 2; i++) - chs->decor_coeff[band][i] = 0; + band->decor_coeff[i] = 0; } // Adaptive predictor order - chs->highest_pred_order[band] = 0; + band->highest_pred_order = 0; for (i = 0; i < chs->nchannels; i++) { - chs->adapt_pred_order[band][i] = bits_get(&xll->bits, 4); - if (chs->adapt_pred_order[band][i] > chs->highest_pred_order[band]) - chs->highest_pred_order[band] = chs->adapt_pred_order[band][i]; + band->adapt_pred_order[i] = bits_get(&xll->bits, 4); + if (band->adapt_pred_order[i] > band->highest_pred_order) + band->highest_pred_order = band->adapt_pred_order[i]; } - if (chs->highest_pred_order[band] > xll->nsegsamples) { + if (band->highest_pred_order > xll->nsegsamples) { xll_err("Invalid adaptive predicition order"); return -DCADEC_EBADDATA; } // Fixed predictor order for (i = 0; i < chs->nchannels; i++) { - if (chs->adapt_pred_order[band][i] == 0) - chs->fixed_pred_order[band][i] = bits_get(&xll->bits, 2); + if (band->adapt_pred_order[i] == 0) + band->fixed_pred_order[i] = bits_get(&xll->bits, 2); else - chs->fixed_pred_order[band][i] = 0; + band->fixed_pred_order[i] = 0; } // Adaptive predictor quantized reflection coefficients for (i = 0; i < chs->nchannels; i++) { - for (j = 0; j < chs->adapt_pred_order[band][i]; j++) { + for (j = 0; j < band->adapt_pred_order[i]; j++) {
View file
dcadec-0.1.0.tar.gz/libdcadec/xll_decoder.h -> dcadec-0.2.0.tar.gz/libdcadec/xll_decoder.h
Changed
@@ -21,9 +21,9 @@ #include "bitstream.h" -#define XLL_MAX_CHSETS 16 #define XLL_MAX_CHANNELS 8 #define XLL_MAX_BANDS 2 +#define XLL_MAX_ADAPT_PRED_ORDER 16 #define XLL_DECI_HISTORY 8 @@ -31,142 +31,136 @@ #define XLL_BAND_1 1 #define XLL_DMIX_SIGNATURE(chs) \ - ((chs)->nchannels | ((chs)->dmix_m << 4) | ((chs)->primary_chset << 12) \ + ((chs)->nchannels | ((chs)->hier_m << 4) | ((chs)->primary_chset << 12) \ | ((chs)->dmix_embedded << 13) | ((chs)->hier_chset << 14) | ((chs)->dmix_type << 15)) -#define for_each_chset(xll, chs) \ - for (struct xll_chset *(chs) = (xll)->chset; \ - (chs) != &(xll)->chset[(xll)->nchsets]; (chs)++) +#define xll_err(...) dca_log(xll, ERROR, __VA_ARGS__) +#define xll_warn(...) dca_log(xll, WARNING, __VA_ARGS__) +#define xll_verbose(...) dca_log(xll, VERBOSE, __VA_ARGS__) -#define for_each_chset_reverse(xll, chs) \ - for (struct xll_chset *(chs) = &(xll)->chset[(xll)->nchsets - 1]; \ - (chs) >= (xll)->chset; (chs)--) +#define xll_err_once(...) dca_log_once(xll, ERROR, __VA_ARGS__) +#define xll_warn_once(...) dca_log_once(xll, WARNING, __VA_ARGS__) -#define for_each_active_chset(xll, chs) \ - for (struct xll_chset *(chs) = (xll)->chset; \ - (chs) != &(xll)->chset[(xll)->nactivechsets]; (chs)++) +struct xll_decoder; +struct exss_asset; -#define xll_err(...) dca_log(ERROR, xll, __VA_ARGS__) -#define xll_verbose(...) dca_log(VERBOSE, xll, __VA_ARGS__) +struct xll_band { + bool decor_enabled; ///< Pairwise channel decorrelation flag + int orig_order[XLL_MAX_CHANNELS]; ///< Original channel order + int decor_coeff[XLL_MAX_CHANNELS / 2]; ///< Pairwise channel coefficients -#define xll_err_once(...) dca_log_once(ERROR, xll, err_shown, __VA_ARGS__) -#define xll_warn_once(...) dca_log_once(WARNING, xll, warn_shown, __VA_ARGS__) + int adapt_pred_order[XLL_MAX_CHANNELS]; ///< Adaptive predictor order + int highest_pred_order; ///< Highest adaptive predictor order + int fixed_pred_order[XLL_MAX_CHANNELS]; ///< Fixed predictor order + int adapt_refl_coeff[XLL_MAX_CHANNELS][XLL_MAX_ADAPT_PRED_ORDER]; ///< Adaptive predictor reflection coefficients -struct xll_decoder; -struct exss_asset; + bool dmix_embedded; ///< Downmix performed by encoder in frequency band + + int lsb_section_size; ///< Size of LSB section in any segment + int nscalablelsbs[XLL_MAX_CHANNELS]; ///< Number of bits to represent the samples in LSB part + int bit_width_adjust[XLL_MAX_CHANNELS]; ///< Number of bits discarded by authoring + + int *msb_sample_buffer[XLL_MAX_CHANNELS]; ///< MSB sample buffer pointers + int *lsb_sample_buffer[XLL_MAX_CHANNELS]; ///< LSB sample buffer pointers or NULL +}; struct xll_chset { - struct xll_decoder *decoder; - - int nchannels; - int residual_encode; - int pcm_bit_res; - int storage_bit_res; - int freq; - int interpolate; - int replace_set_index; - - bool primary_chset; - bool dmix_coeffs_present; - bool dmix_embedded; - int dmix_type; - bool hier_chset; - int dmix_m; - int *dmix_coeff; - int *dmix_coeff_cur; - int *dmix_coeff_pre; - int *dmix_scale_cur; - int *dmix_scale_pre; - int *dmix_scale_inv_cur; - int *dmix_scale_inv_pre; - int dmix_coeffs_signature; - bool dmix_coeffs_parity; - bool ch_mask_enabled; - int ch_mask; - - int nfreqbands; - int nabits; - - bool decor_enabled[XLL_MAX_BANDS]; - int orig_order[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - int decor_coeff[XLL_MAX_BANDS][XLL_MAX_CHANNELS / 2]; - - int adapt_pred_order[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - int highest_pred_order[XLL_MAX_BANDS]; - int fixed_pred_order[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - int adapt_refl_coeff[XLL_MAX_BANDS][XLL_MAX_CHANNELS][16]; - - bool band_dmix_embedded[XLL_MAX_BANDS]; - - size_t lsb_section_size[XLL_MAX_BANDS]; - int nscalablelsbs[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - int bit_width_adjust[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - - bool seg_type; - bool rice_code_flag[XLL_MAX_CHANNELS]; - int bitalloc_hybrid_linear[XLL_MAX_CHANNELS]; - int bitalloc_part_a[XLL_MAX_CHANNELS]; - int bitalloc_part_b[XLL_MAX_CHANNELS]; - int nsamples_part_a[XLL_MAX_CHANNELS]; - - int deci_history[XLL_MAX_CHANNELS][XLL_DECI_HISTORY]; - - int *msb_sample_buffer[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - int *lsb_sample_buffer[XLL_MAX_BANDS][XLL_MAX_CHANNELS]; - int *out_sample_buffer[XLL_MAX_CHANNELS]; - - int *sample_buffer1; - int *sample_buffer2; - int *sample_buffer3; + struct xll_decoder *decoder; ///< Parent context + + // Channel set header + int nchannels; ///< Number of channels in the channel set (N) + int residual_encode; ///< Residual encoding mask (0 - residual, 1 - full channel) + int pcm_bit_res; ///< PCM bit resolution (variable) + int storage_bit_res; ///< Storage bit resolution (16 or 24) + int freq; ///< Original sampling frequency (max. 96000 Hz) + int interpolate; ///< Sampling frequency modifier + int replace_set_index; ///< Which replacement set this channel set is member of + + bool primary_chset; ///< Primary channel set flag + bool dmix_coeffs_present; ///< Downmix coefficients present in stream + bool dmix_embedded; ///< Downmix already performed by encoder + int dmix_type; ///< Primary channel set downmix type + bool hier_chset; ///< Whether the channel set is part of a hierarchy + int hier_m; ///< Number of preceding channels in a hierarchy (M) + int *dmix_coeff; ///< Downmixing coefficients buffer base + int *dmix_coeff_cur; ///< M*N downmixing coefficients for current frame + int *dmix_coeff_pre; ///< M*N downmixing coefficients for previous frame + int *dmix_scale_cur; ///< M downmixing scales for current frame + int *dmix_scale_pre; ///< M downmixing scales for previous frame + int *dmix_scale_inv_cur; ///< M inverse downmixing scales for current frame + int *dmix_scale_inv_pre; ///< M inverse downmixing scales for previous frame + int dmix_coeffs_signature; ///< Signature of downmixing parameters from previous frame + bool dmix_coeffs_parity; ///< Index of current downmixing coefficients buffer, flipped each frame + bool ch_mask_enabled; ///< Channel mask enabled + int ch_mask; ///< Channel mask for set + + int nfreqbands; ///< Number of frequency bands (1 or 2) + int nabits; ///< Number of bits to read bit allocation coding parameter + + struct xll_band bands[XLL_MAX_BANDS]; ///< Frequency bands + + // Frequency band coding parameters + bool seg_common; ///< Segment type + bool rice_code_flag[XLL_MAX_CHANNELS]; ///< Rice coding flag + int bitalloc_hybrid_linear[XLL_MAX_CHANNELS]; ///< Binary code length for isolated samples + int bitalloc_part_a[XLL_MAX_CHANNELS]; ///< Coding parameter for part A of segment + int bitalloc_part_b[XLL_MAX_CHANNELS]; ///< Coding parameter for part B of segment + int nsamples_part_a[XLL_MAX_CHANNELS]; ///< Number of samples in part A of segment + + // Decimator history + int deci_history[XLL_MAX_CHANNELS][XLL_DECI_HISTORY]; ///< Decimator history for frequency band 1 + + // Sample buffers + int *out_sample_buffer[XLL_MAX_CHANNELS]; ///< Output sample buffer pointers + + int *sample_buffer1; ///< MSB sample buffer base + int *sample_buffer2; ///< LSB sample buffer base + int *sample_buffer3; ///< Frequency band assembly buffer base }; struct xll_decoder { - struct bitstream bits; - - dcadec_log_cb log_cb; - void *log_cbarg; - bool err_shown; - bool warn_shown; + struct dcadec_context *ctx; ///< Parent context + struct bitstream bits; ///< Bitstream reader - int flags; + int flags; ///< Context flags - size_t frame_size; - int nchsets; - int nframesegs; - int nsegsamples_log2; - int nsegsamples; - int nframesamples_log2; - int nframesamples;
View file
dcadec-0.1.0.tar.gz/test/test.sh -> dcadec-0.2.0.tar.gz/test/test.sh
Changed
@@ -23,7 +23,7 @@ ../dcadec -b -q $i decoded/dmix_0/$(basename $i .dtshd).wav ../dcadec -b -q -2 $i decoded/dmix_2/$(basename $i .dtshd).wav ../dcadec -b -q -6 $i decoded/dmix_6/$(basename $i .dtshd).wav - ../dcadec -m -q $i decoded/mono/$(basename $i .dtshd)_%s.wav + ../dcadec -i -m -q $i decoded/mono/$(basename $i .dtshd)_%s.wav done LOSSY="\
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.