diff --git a/modules/juce_audio_formats/codecs/flac_134/Flac Licence.txt b/modules/juce_audio_formats/codecs/flac_134/Flac Licence.txt new file mode 100644 index 0000000000..1bb5807e94 --- /dev/null +++ b/modules/juce_audio_formats/codecs/flac_134/Flac Licence.txt @@ -0,0 +1,51 @@ + +===================================================================== + +I've incorporated FLAC directly into the JUCE codebase because it makes +things much easier than having to make all your builds link correctly to +the appropriate libraries on every different platform. + +I've made minimal changes to the FLAC code - just tweaked a few include paths +to make it build smoothly, added some headers to allow you to turn off FLAC +compilation, and commented-out a couple of unused bits of code. + +===================================================================== + + +The following license is the BSD-style license that comes with the +Flac distribution, and which applies just to the files I've +included in this directory. For more info, and to get the rest of the +distribution, visit the Flac homepage: https://xiph.org/flac/ + +===================================================================== + +libFLAC - Free Lossless Audio Codec library +Copyright (C) 2001-2009 Josh Coalson +Copyright (C) 2011-2016 Xiph.Org Foundation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of the Xiph.org Foundation nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/modules/juce_audio_formats/codecs/flac_134/all.h b/modules/juce_audio_formats/codecs/flac_134/all.h index 72fd0f1b39..161b9a85bd 100644 --- a/modules/juce_audio_formats/codecs/flac_134/all.h +++ b/modules/juce_audio_formats/codecs/flac_134/all.h @@ -33,6 +33,10 @@ #ifndef FLAC__ALL_H #define FLAC__ALL_H +#ifndef FLAC__HAS_OGG + #define FLAC__HAS_OGG 0 +#endif + #include "export.h" #include "assert.h" diff --git a/modules/juce_audio_formats/codecs/flac_134/alloc.h b/modules/juce_audio_formats/codecs/flac_134/alloc.h index 30a16b209f..81c1fbcd2d 100644 --- a/modules/juce_audio_formats/codecs/flac_134/alloc.h +++ b/modules/juce_audio_formats/codecs/flac_134/alloc.h @@ -41,11 +41,14 @@ * before #including this file, otherwise SIZE_MAX might not be defined */ -#include /* for SIZE_MAX */ -#if HAVE_STDINT_H -#include /* for SIZE_MAX in case limits.h didn't get it */ -#endif -#include /* for size_t, malloc(), etc */ +// JUCE: removed as JUCE already includes standard headers and including +// these in FlacNamespace will cause problems + +//#include /* for SIZE_MAX */ +//#if HAVE_STDINT_H +//#include /* for SIZE_MAX in case limits.h didn't get it */ +//#endif +//#include /* for size_t, malloc(), etc */ #include "compat.h" #ifndef SIZE_MAX diff --git a/modules/juce_audio_formats/codecs/flac_134/assert.h b/modules/juce_audio_formats/codecs/flac_134/assert.h index b0b1e05e40..7b2a21aeeb 100644 --- a/modules/juce_audio_formats/codecs/flac_134/assert.h +++ b/modules/juce_audio_formats/codecs/flac_134/assert.h @@ -35,7 +35,10 @@ /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */ #ifndef NDEBUG -#include +// JUCE: removed as JUCE already includes standard headers and including +// these in FlacNamespace will cause problems + +//#include #define FLAC__ASSERT(x) assert(x) #define FLAC__ASSERT_DECLARATION(x) x #else diff --git a/modules/juce_audio_formats/codecs/flac_134/callback.h b/modules/juce_audio_formats/codecs/flac_134/callback.h index b8d151d3ab..6c9bbbea31 100644 --- a/modules/juce_audio_formats/codecs/flac_134/callback.h +++ b/modules/juce_audio_formats/codecs/flac_134/callback.h @@ -34,7 +34,10 @@ #define FLAC__CALLBACK_H #include "ordinals.h" -#include /* for size_t */ + +// JUCE: removed as JUCE already includes this and including stdlib +// in FlacNamespace will cause problems +//#include /* for size_t */ /** \file include/FLAC/callback.h * diff --git a/modules/juce_audio_formats/codecs/flac_134/compat.h b/modules/juce_audio_formats/codecs/flac_134/compat.h index 1f8559b464..30887dbb8e 100644 --- a/modules/juce_audio_formats/codecs/flac_134/compat.h +++ b/modules/juce_audio_formats/codecs/flac_134/compat.h @@ -39,15 +39,7 @@ #ifndef FLAC__SHARE__COMPAT_H #define FLAC__SHARE__COMPAT_H -#if defined _WIN32 && !defined __CYGWIN__ -/* where MSVC puts unlink() */ -# include -#else -# include -#endif - #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ -#include /* for off_t */ #define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */ #if !defined __MINGW32__ #define fseeko _fseeki64 @@ -62,11 +54,6 @@ #define FLAC__off_t off_t #endif -#if HAVE_INTTYPES_H -#define __STDC_FORMAT_MACROS -#include -#endif - #if defined(_MSC_VER) #define strtoll _strtoi64 #define strtoull _strtoui64 @@ -98,39 +85,15 @@ #define FLAC__STRNCASECMP strncasecmp #endif -#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__ -#include /* for _setmode(), chmod() */ -#include /* for _O_BINARY */ -#else -#include /* for chown(), unlink() */ -#endif - -#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ -#if defined __BORLANDC__ -#include /* for utime() */ -#else -#include /* for utime() */ -#endif -#else -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) -#include -#else -#include /* some flavors of BSD (like OS X) require this to get time_t */ -#include /* for utime() */ -#endif -#endif - #if defined _MSC_VER # if _MSC_VER >= 1800 # include # elif _MSC_VER >= 1600 /* Visual Studio 2010 has decent C99 support */ -# include # define PRIu64 "llu" # define PRId64 "lld" # define PRIx64 "llx" # else -# include # ifndef UINT32_MAX # define UINT32_MAX _UI32_MAX # endif @@ -143,6 +106,7 @@ #ifdef _WIN32 /* All char* strings are in UTF-8 format. Added to support Unicode files on Windows */ +#if 0 #include "win_utf8_io.h" #define flac_printf printf_utf8 #define flac_fprintf fprintf_utf8 @@ -155,6 +119,7 @@ #define flac_unlink flac_internal_unlink_utf8 #define flac_rename flac_internal_rename_utf8 #define flac_stat flac_internal_stat64_utf8 +#endif #else @@ -200,14 +165,13 @@ * * This function wraps the MS version to behave more like the ISO version. */ -#include #ifdef __cplusplus extern "C" { #endif int flac_snprintf(char *str, size_t size, const char *fmt, ...); int flac_vsnprintf(char *str, size_t size, const char *fmt, va_list va); #ifdef __cplusplus -}; +} #endif #endif /* FLAC__SHARE__COMPAT_H */ diff --git a/modules/juce_audio_formats/codecs/flac_134/endswap.h b/modules/juce_audio_formats/codecs/flac_134/endswap.h index 52914dc29a..790d1e4edf 100644 --- a/modules/juce_audio_formats/codecs/flac_134/endswap.h +++ b/modules/juce_audio_formats/codecs/flac_134/endswap.h @@ -55,7 +55,9 @@ static inline unsigned short __builtin_bswap16(unsigned short a) #elif defined HAVE_BYTESWAP_H /* Linux */ -#include +// JUCE: removed as JUCE already includes standard headers and including +// these in FlacNamespace will cause problems +//#include #define ENDSWAP_16(x) (bswap_16 (x)) #define ENDSWAP_32(x) (bswap_32 (x)) diff --git a/modules/juce_audio_formats/codecs/flac_134/getopt.h b/modules/juce_audio_formats/codecs/flac_134/getopt.h deleted file mode 100644 index cf03497a78..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/getopt.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - NOTE: - I cannot get the vanilla getopt code to work (i.e. compile only what - is needed and not duplicate symbols found in the standard library) - on all the platforms that FLAC supports. In particular the gating - of code with the ELIDE_CODE #define is not accurate enough on systems - that are POSIX but not glibc. If someone has a patch that works on - GNU/Linux, Darwin, AND Solaris please submit it on the project page: - https://sourceforge.net/p/flac/patches/ - - In the meantime I have munged the global symbols and removed gates - around code, while at the same time trying to touch the original as - little as possible. -*/ -/* Declarations for getopt. - Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -#ifndef SHARE__GETOPT_H -#define SHARE__GETOPT_H - -/*[JEC] was:#ifndef __need_getopt*/ -/*[JEC] was:# define _GETOPT_H 1*/ -/*[JEC] was:#endif*/ - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `share__getopt' to the caller. - When `share__getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *share__optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `share__getopt'. - - On entry to `share__getopt', zero means this is the first call; initialize. - - When `share__getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `share__optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int share__optind; - -/* Callers store zero here to inhibit the error message `share__getopt' prints - for unrecognized options. */ - -extern int share__opterr; - -/* Set to an option character which was unrecognized. */ - -extern int share__optopt; - -/*[JEC] was:#ifndef __need_getopt */ -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to share__getopt_long or share__getopt_long_only is a vector - of `struct share__option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - share__no_argument (or 0) if the option does not take an argument, - share__required_argument (or 1) if the option requires an argument, - share__optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `share__optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `share__getopt' - returns the contents of the `val' field. */ - -struct share__option -{ -# if defined __STDC__ && __STDC__ - const char *name; -# else - char *name; -# endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct share__option'. */ - -# define share__no_argument 0 -# define share__required_argument 1 -# define share__optional_argument 2 -/*[JEC] was:#endif*/ /* need getopt */ - - -/* Get definitions and prototypes for functions to process the - arguments in ARGV (ARGC of them, minus the program name) for - options given in OPTS. - - Return the option character from OPTS just read. Return -1 when - there are no more options. For unrecognized options, or options - missing arguments, `share__optopt' is set to the option letter, and '?' is - returned. - - The OPTS string is a list of characters which are recognized option - letters, optionally followed by colons, specifying that that letter - takes an argument, to be placed in `share__optarg'. - - If a letter in OPTS is followed by two colons, its argument is - optional. This behavior is specific to the GNU `share__getopt'. - - The argument `--' causes premature termination of argument - scanning, explicitly telling `share__getopt' that there are no more - options. - - If OPTS begins with `--', then non-option arguments are treated as - arguments to the option '\0'. This behavior is specific to the GNU - `share__getopt'. */ - -/*[JEC] was:#if defined __STDC__ && __STDC__*/ -/*[JEC] was:# ifdef __GNU_LIBRARY__*/ -/* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int share__getopt (int argc, char *const *argv, const char *shortopts); -/*[JEC] was:# else*/ /* not __GNU_LIBRARY__ */ -/*[JEC] was:extern int getopt ();*/ -/*[JEC] was:# endif*/ /* __GNU_LIBRARY__ */ - -/*[JEC] was:# ifndef __need_getopt*/ -extern int share__getopt_long (int argc, char *const *argv, const char *shortopts, - const struct share__option *longopts, int *longind); -extern int share__getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct share__option *longopts, int *longind); - -/* Internal only. Users should not call this directly. */ -extern int share___getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct share__option *longopts, int *longind, - int long_only); -/*[JEC] was:# endif*/ -/*[JEC] was:#else*/ /* not __STDC__ */ -/*[JEC] was:extern int getopt ();*/ -/*[JEC] was:# ifndef __need_getopt*/ -/*[JEC] was:extern int getopt_long ();*/ -/*[JEC] was:extern int getopt_long_only ();*/ - -/*[JEC] was:extern int _getopt_internal ();*/ -/*[JEC] was:# endif*/ -/*[JEC] was:#endif*/ /* __STDC__ */ - -#ifdef __cplusplus -} -#endif - -/* Make sure we later can get all the definitions and declarations. */ -/*[JEC] was:#undef __need_getopt*/ - -#endif /* getopt.h */ diff --git a/modules/juce_audio_formats/codecs/flac_134/grabbag.h b/modules/juce_audio_formats/codecs/flac_134/grabbag.h deleted file mode 100644 index c70c8cfd58..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/grabbag.h +++ /dev/null @@ -1,30 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef SHARE__GRABBAG_H -#define SHARE__GRABBAG_H - -/* These can't be included by themselves, only from within grabbag.h */ -#include "grabbag/cuesheet.h" -#include "grabbag/file.h" -#include "grabbag/picture.h" -#include "grabbag/replaygain.h" -#include "grabbag/seektable.h" - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitreader.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitreader.c index 58f72e43fd..eb401c728d 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitreader.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitreader.c @@ -39,7 +39,6 @@ #include "include/private/bitmath.h" #include "include/private/bitreader.h" #include "include/private/crc.h" -#include "include/private/macros.h" #include "../assert.h" #include "../compat.h" #include "../endswap.h" @@ -117,7 +116,7 @@ struct FLAC__BitReader { static inline void crc16_update_word_(FLAC__BitReader *br, brword word) { - register uint32_t crc = br->read_crc16; + uint32_t crc = br->read_crc16; for ( ; br->crc16_align < FLAC__BITS_PER_WORD ; br->crc16_align += 8) { uint32_t shift = FLAC__BITS_PER_WORD - 8 - br->crc16_align ; @@ -235,7 +234,7 @@ static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br) FLAC__BitReader *FLAC__bitreader_new(void) { - FLAC__BitReader *br = calloc(1, sizeof(FLAC__BitReader)); + FLAC__BitReader *br = (FLAC__BitReader*) calloc(1, sizeof(FLAC__BitReader)); /* calloc() implies: memset(br, 0, sizeof(FLAC__BitReader)); @@ -270,7 +269,7 @@ FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__BitReaderReadCallback br->words = br->bytes = 0; br->consumed_words = br->consumed_bits = 0; br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY; - br->buffer = malloc(sizeof(brword) * br->capacity); + br->buffer = (brword*) malloc(sizeof(brword) * br->capacity); if(br->buffer == 0) return false; br->read_callback = rcb; diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitwriter.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitwriter.c index 84de600d3e..f280dc3587 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitwriter.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/bitwriter.c @@ -38,7 +38,6 @@ #include #include "include/private/bitwriter.h" #include "include/private/crc.h" -#include "include/private/macros.h" #include "../assert.h" #include "../alloc.h" #include "../compat.h" @@ -124,7 +123,7 @@ FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add) FLAC__ASSERT(new_capacity > bw->capacity); FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD)); - new_buffer = safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity); + new_buffer = (bwword*) safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity); if(new_buffer == 0) return false; bw->buffer = new_buffer; @@ -141,7 +140,7 @@ FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add) FLAC__BitWriter *FLAC__bitwriter_new(void) { - FLAC__BitWriter *bw = calloc(1, sizeof(FLAC__BitWriter)); + FLAC__BitWriter *bw = (FLAC__BitWriter*) calloc(1, sizeof(FLAC__BitWriter)); /* note that calloc() sets all members to 0 for us */ return bw; } @@ -166,7 +165,7 @@ FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw) bw->words = bw->bits = 0; bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY; - bw->buffer = malloc(sizeof(bwword) * bw->capacity); + bw->buffer = (bwword*) malloc(sizeof(bwword) * bw->capacity); if(bw->buffer == 0) return false; @@ -321,7 +320,7 @@ inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bit static inline FLAC__bool FLAC__bitwriter_write_raw_uint32_nocheck(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits) { - register uint32_t left; + uint32_t left; /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */ FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32); diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/cpu.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/cpu.c index f2e9234cab..95ff976597 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/cpu.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/cpu.c @@ -36,17 +36,17 @@ #include "include/private/cpu.h" #include "../compat.h" -#include -#include +//#include +//#include #if defined _MSC_VER -#include /* for __cpuid() and _xgetbv() */ +//#include /* for __cpuid() and _xgetbv() */ #elif defined __GNUC__ && defined HAVE_CPUID_H #include /* for __get_cpuid() and __get_cpuid_max() */ #endif #ifndef NDEBUG -#include +//#include #define dfprintf fprintf #else /* This is bad practice, it should be a static void empty function */ @@ -79,6 +79,7 @@ static const uint32_t FLAC__CPUINFO_X86_CPUID_FMA = 0x00001000; /* these are flags in EBX of CPUID AX=00000007 */ static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX2 = 0x00000020; +#if FLAC__AVX_SUPPORTED static uint32_t cpu_xgetbv_x86(void) { @@ -92,6 +93,7 @@ cpu_xgetbv_x86(void) return 0; #endif } +#endif static uint32_t cpu_have_cpuid(void) @@ -157,6 +159,7 @@ cpuinfo_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint FLAC__cpu_info_asm_ia32(level, eax, ebx, ecx, edx); return; #endif + ignoreUnused (level); *eax = *ebx = *ecx = *edx = 0; } @@ -166,7 +169,9 @@ static void x86_cpu_info (FLAC__CPUInfo *info) { #if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && (defined FLAC__HAS_NASM || FLAC__HAS_X86INTRIN) && !defined FLAC__NO_ASM +#if FLAC__AVX_SUPPORTED FLAC__bool x86_osxsave = false; +#endif FLAC__bool os_avx = false; FLAC__uint32 flags_eax, flags_ebx, flags_ecx, flags_edx; @@ -187,18 +192,18 @@ x86_cpu_info (FLAC__CPUInfo *info) info->x86.sse41 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSE41) ? true : false; info->x86.sse42 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSE42) ? true : false; - if (FLAC__AVX_SUPPORTED) { - x86_osxsave = (flags_ecx & FLAC__CPUINFO_X86_CPUID_OSXSAVE) ? true : false; - info->x86.avx = (flags_ecx & FLAC__CPUINFO_X86_CPUID_AVX ) ? true : false; - info->x86.fma = (flags_ecx & FLAC__CPUINFO_X86_CPUID_FMA ) ? true : false; - cpuinfo_x86(7, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx); - info->x86.avx2 = (flags_ebx & FLAC__CPUINFO_X86_CPUID_AVX2 ) ? true : false; - } +#if FLAC__AVX_SUPPORTED + x86_osxsave = (flags_ecx & FLAC__CPUINFO_X86_CPUID_OSXSAVE) ? true : false; + info->x86.avx = (flags_ecx & FLAC__CPUINFO_X86_CPUID_AVX ) ? true : false; + info->x86.fma = (flags_ecx & FLAC__CPUINFO_X86_CPUID_FMA ) ? true : false; + cpuinfo_x86(7, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx); + info->x86.avx2 = (flags_ebx & FLAC__CPUINFO_X86_CPUID_AVX2 ) ? true : false; +#endif #if defined FLAC__CPU_IA32 - dfprintf(stderr, "CPU info (IA-32):\n"); + dfprintf(stderr, "CPU info (IA-32):\n", ""); #else - dfprintf(stderr, "CPU info (x86-64):\n"); + dfprintf(stderr, "CPU info (x86-64):\n", ""); #endif dfprintf(stderr, " CMOV ....... %c\n", info->x86.cmov ? 'Y' : 'n'); dfprintf(stderr, " MMX ........ %c\n", info->x86.mmx ? 'Y' : 'n'); @@ -218,9 +223,12 @@ x86_cpu_info (FLAC__CPUInfo *info) /* * now have to check for OS support of AVX instructions */ - if (FLAC__AVX_SUPPORTED && info->x86.avx && x86_osxsave && (cpu_xgetbv_x86() & 0x6) == 0x6) { + #if FLAC__AVX_SUPPORTED + if (info->x86.avx && x86_osxsave && (cpu_xgetbv_x86() & 0x6) == 0x6) { os_avx = true; } + #endif + if (os_avx) { dfprintf(stderr, " AVX OS sup . %c\n", info->x86.avx ? 'Y' : 'n'); } diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed.c index da3c0be531..a31c8fffaa 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed.c @@ -39,7 +39,6 @@ #include "../compat.h" #include "include/private/bitmath.h" #include "include/private/fixed.h" -#include "include/private/macros.h" #include "../assert.h" #ifdef local_abs diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed_intrin_sse2.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed_intrin_sse2.c deleted file mode 100644 index c615dc3a76..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed_intrin_sse2.c +++ /dev/null @@ -1,255 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN -#include "include/private/fixed.h" -#ifdef FLAC__SSE2_SUPPORTED - -#include /* SSE2 */ -#include -#include "include/private/macros.h" -#include "../compat.h" -#include "../assert.h" - -#ifdef FLAC__CPU_IA32 -#define m128i_to_i64(dest, src) _mm_storel_epi64((__m128i*)&dest, src) -#else -#define m128i_to_i64(dest, src) dest = _mm_cvtsi128_si64(src) -#endif - -FLAC__SSE_TARGET("sse2") -uint32_t FLAC__fixed_compute_best_predictor_intrin_sse2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint32 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - uint32_t i, order; - - __m128i total_err0, total_err1, total_err2; - - { - FLAC__int32 itmp; - __m128i last_error; - - last_error = _mm_cvtsi32_si128(data[-1]); // 0 0 0 le0 - itmp = data[-2]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 0 le0 le1 - itmp -= data[-3]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 le0 le1 le2 - itmp -= data[-3] - data[-4]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // le0 le1 le2 le3 - - total_err0 = total_err1 = _mm_setzero_si128(); - for(i = 0; i < data_len; i++) { - __m128i err0, err1, tmp; - err0 = _mm_cvtsi32_si128(data[i]); // 0 0 0 e0 - err1 = _mm_shuffle_epi32(err0, _MM_SHUFFLE(0,0,0,0)); // e0 e0 e0 e0 -#if 1 /* OPT_SSE */ - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 le0 le1 le2 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 le0 le1 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 0 le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#else - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 8)); // le0 le1 le2+le0 le3+le1 - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 4)); // le0 le1+le0 le2+le0+le1 le3+le1+le2+le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#endif - tmp = _mm_slli_si128(err0, 12); // e0 0 0 0 - last_error = _mm_srli_si128(err1, 4); // 0 e1 e2 e3 - last_error = _mm_or_si128(last_error, tmp); // e0 e1 e2 e3 - - tmp = _mm_srai_epi32(err0, 31); - err0 = _mm_xor_si128(err0, tmp); - err0 = _mm_sub_epi32(err0, tmp); - tmp = _mm_srai_epi32(err1, 31); - err1 = _mm_xor_si128(err1, tmp); - err1 = _mm_sub_epi32(err1, tmp); - - total_err0 = _mm_add_epi32(total_err0, err0); // 0 0 0 te0 - total_err1 = _mm_add_epi32(total_err1, err1); // te1 te2 te3 te4 - } - } - - total_error_0 = _mm_cvtsi128_si32(total_err0); - total_err2 = total_err1; // te1 te2 te3 te4 - total_err1 = _mm_srli_si128(total_err1, 8); // 0 0 te1 te2 - total_error_4 = _mm_cvtsi128_si32(total_err2); - total_error_2 = _mm_cvtsi128_si32(total_err1); - total_err2 = _mm_srli_si128(total_err2, 4); // 0 te1 te2 te3 - total_err1 = _mm_srli_si128(total_err1, 4); // 0 0 0 te1 - total_error_3 = _mm_cvtsi128_si32(total_err2); - total_error_1 = _mm_cvtsi128_si32(total_err1); - - /* prefer higher order */ - if(total_error_0 < flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 < flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 < flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 < total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -FLAC__SSE_TARGET("sse2") -uint32_t FLAC__fixed_compute_best_predictor_wide_intrin_sse2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint64 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - uint32_t i, order; - - __m128i total_err0, total_err1, total_err3; - - { - FLAC__int32 itmp; - __m128i last_error, zero = _mm_setzero_si128(); - - last_error = _mm_cvtsi32_si128(data[-1]); // 0 0 0 le0 - itmp = data[-2]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 0 le0 le1 - itmp -= data[-3]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 le0 le1 le2 - itmp -= data[-3] - data[-4]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // le0 le1 le2 le3 - - total_err0 = total_err1 = total_err3 = _mm_setzero_si128(); - for(i = 0; i < data_len; i++) { - __m128i err0, err1, tmp; - err0 = _mm_cvtsi32_si128(data[i]); // 0 0 0 e0 - err1 = _mm_shuffle_epi32(err0, _MM_SHUFFLE(0,0,0,0)); // e0 e0 e0 e0 -#if 1 /* OPT_SSE */ - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 le0 le1 le2 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 le0 le1 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 0 le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#else - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 8)); // le0 le1 le2+le0 le3+le1 - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 4)); // le0 le1+le0 le2+le0+le1 le3+le1+le2+le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#endif - tmp = _mm_slli_si128(err0, 12); // e0 0 0 0 - last_error = _mm_srli_si128(err1, 4); // 0 e1 e2 e3 - last_error = _mm_or_si128(last_error, tmp); // e0 e1 e2 e3 - - tmp = _mm_srai_epi32(err0, 31); - err0 = _mm_xor_si128(err0, tmp); - err0 = _mm_sub_epi32(err0, tmp); - tmp = _mm_srai_epi32(err1, 31); - err1 = _mm_xor_si128(err1, tmp); - err1 = _mm_sub_epi32(err1, tmp); - - total_err0 = _mm_add_epi64(total_err0, err0); // 0 te0 - err0 = _mm_unpacklo_epi32(err1, zero); // 0 |e3| 0 |e4| - err1 = _mm_unpackhi_epi32(err1, zero); // 0 |e1| 0 |e2| - total_err3 = _mm_add_epi64(total_err3, err0); // te3 te4 - total_err1 = _mm_add_epi64(total_err1, err1); // te1 te2 - } - } - - m128i_to_i64(total_error_0, total_err0); - m128i_to_i64(total_error_4, total_err3); - m128i_to_i64(total_error_2, total_err1); - total_err3 = _mm_srli_si128(total_err3, 8); // 0 te3 - total_err1 = _mm_srli_si128(total_err1, 8); // 0 te1 - m128i_to_i64(total_error_3, total_err3); - m128i_to_i64(total_error_1, total_err1); - - /* prefer higher order */ - if(total_error_0 < flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 < flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 < flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 < total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -#endif /* FLAC__SSE2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed_intrin_ssse3.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed_intrin_ssse3.c deleted file mode 100644 index de948a901e..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/fixed_intrin_ssse3.c +++ /dev/null @@ -1,243 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/fixed.h" -#ifdef FLAC__SSSE3_SUPPORTED - -#include /* SSSE3 */ -#include -#include "include/private/macros.h" -#include "../compat.h" -#include "../assert.h" - -#ifdef FLAC__CPU_IA32 -#define m128i_to_i64(dest, src) _mm_storel_epi64((__m128i*)&dest, src) -#else -#define m128i_to_i64(dest, src) dest = _mm_cvtsi128_si64(src) -#endif - -FLAC__SSE_TARGET("ssse3") -uint32_t FLAC__fixed_compute_best_predictor_intrin_ssse3(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint32 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - uint32_t i, order; - - __m128i total_err0, total_err1, total_err2; - - { - FLAC__int32 itmp; - __m128i last_error; - - last_error = _mm_cvtsi32_si128(data[-1]); // 0 0 0 le0 - itmp = data[-2]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 0 le0 le1 - itmp -= data[-3]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 le0 le1 le2 - itmp -= data[-3] - data[-4]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // le0 le1 le2 le3 - - total_err0 = total_err1 = _mm_setzero_si128(); - for(i = 0; i < data_len; i++) { - __m128i err0, err1; - err0 = _mm_cvtsi32_si128(data[i]); // 0 0 0 e0 - err1 = _mm_shuffle_epi32(err0, _MM_SHUFFLE(0,0,0,0)); // e0 e0 e0 e0 -#if 1 /* OPT_SSE */ - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 le0 le1 le2 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 le0 le1 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 0 le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#else - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 8)); // le0 le1 le2+le0 le3+le1 - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 4)); // le0 le1+le0 le2+le0+le1 le3+le1+le2+le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#endif - last_error = _mm_alignr_epi8(err0, err1, 4); // e0 e1 e2 e3 - - err0 = _mm_abs_epi32(err0); - err1 = _mm_abs_epi32(err1); - - total_err0 = _mm_add_epi32(total_err0, err0); // 0 0 0 te0 - total_err1 = _mm_add_epi32(total_err1, err1); // te1 te2 te3 te4 - } - } - - total_error_0 = _mm_cvtsi128_si32(total_err0); - total_err2 = total_err1; // te1 te2 te3 te4 - total_err1 = _mm_srli_si128(total_err1, 8); // 0 0 te1 te2 - total_error_4 = _mm_cvtsi128_si32(total_err2); - total_error_2 = _mm_cvtsi128_si32(total_err1); - total_err2 = _mm_srli_si128(total_err2, 4); // 0 te1 te2 te3 - total_err1 = _mm_srli_si128(total_err1, 4); // 0 0 0 te1 - total_error_3 = _mm_cvtsi128_si32(total_err2); - total_error_1 = _mm_cvtsi128_si32(total_err1); - - /* prefer higher order */ - if(total_error_0 < flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 < flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 < flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 < total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -FLAC__SSE_TARGET("ssse3") -uint32_t FLAC__fixed_compute_best_predictor_wide_intrin_ssse3(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint64 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - uint32_t i, order; - - __m128i total_err0, total_err1, total_err3; - - { - FLAC__int32 itmp; - __m128i last_error, zero = _mm_setzero_si128(); - - last_error = _mm_cvtsi32_si128(data[-1]); // 0 0 0 le0 - itmp = data[-2]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 0 le0 le1 - itmp -= data[-3]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // 0 le0 le1 le2 - itmp -= data[-3] - data[-4]; - last_error = _mm_shuffle_epi32(last_error, _MM_SHUFFLE(2,1,0,0)); - last_error = _mm_sub_epi32(last_error, _mm_cvtsi32_si128(itmp)); // le0 le1 le2 le3 - - total_err0 = total_err1 = total_err3 = _mm_setzero_si128(); - for(i = 0; i < data_len; i++) { - __m128i err0, err1; - err0 = _mm_cvtsi32_si128(data[i]); // 0 0 0 e0 - err1 = _mm_shuffle_epi32(err0, _MM_SHUFFLE(0,0,0,0)); // e0 e0 e0 e0 -#if 1 /* OPT_SSE */ - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 le0 le1 le2 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 le0 le1 - err1 = _mm_sub_epi32(err1, last_error); - last_error = _mm_srli_si128(last_error, 4); // 0 0 0 le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#else - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 8)); // le0 le1 le2+le0 le3+le1 - last_error = _mm_add_epi32(last_error, _mm_srli_si128(last_error, 4)); // le0 le1+le0 le2+le0+le1 le3+le1+le2+le0 - err1 = _mm_sub_epi32(err1, last_error); // e1 e2 e3 e4 -#endif - last_error = _mm_alignr_epi8(err0, err1, 4); // e0 e1 e2 e3 - - err0 = _mm_abs_epi32(err0); - err1 = _mm_abs_epi32(err1); // |e1| |e2| |e3| |e4| - - total_err0 = _mm_add_epi64(total_err0, err0); // 0 te0 - err0 = _mm_unpacklo_epi32(err1, zero); // 0 |e3| 0 |e4| - err1 = _mm_unpackhi_epi32(err1, zero); // 0 |e1| 0 |e2| - total_err3 = _mm_add_epi64(total_err3, err0); // te3 te4 - total_err1 = _mm_add_epi64(total_err1, err1); // te1 te2 - } - } - - m128i_to_i64(total_error_0, total_err0); - m128i_to_i64(total_error_4, total_err3); - m128i_to_i64(total_error_2, total_err1); - total_err3 = _mm_srli_si128(total_err3, 8); // 0 te3 - total_err1 = _mm_srli_si128(total_err1, 8); // 0 te1 - m128i_to_i64(total_error_3, total_err3); - m128i_to_i64(total_error_1, total_err1); - - /* prefer higher order */ - if(total_error_0 < flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 < flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 < flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 < total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -#endif /* FLAC__SSSE3_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/format.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/format.c index b43903ffb6..cec9b4993c 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/format.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/format.c @@ -42,7 +42,6 @@ #include "../alloc.h" #include "../compat.h" #include "include/private/format.h" -#include "include/private/macros.h" /* PACKAGE_VERSION should come from configure */ FLAC_API const char *FLAC__VERSION_STRING = PACKAGE_VERSION; @@ -577,9 +576,9 @@ FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_s FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits)); if(object->capacity_by_order < max_partition_order) { - if(0 == (object->parameters = safe_realloc_(object->parameters, sizeof(uint32_t)*(1 << max_partition_order)))) + if(0 == (object->parameters = (uint32_t*) safe_realloc_(object->parameters, sizeof(uint32_t)*(1 << max_partition_order)))) return false; - if(0 == (object->raw_bits = safe_realloc_(object->raw_bits, sizeof(uint32_t)*(1 << max_partition_order)))) + if(0 == (object->raw_bits = (uint32_t*) safe_realloc_(object->raw_bits, sizeof(uint32_t)*(1 << max_partition_order)))) return false; memset(object->raw_bits, 0, sizeof(uint32_t)*(1 << max_partition_order)); object->capacity_by_order = max_partition_order; diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/bitmath.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/bitmath.h index d01e15e88c..d4cf69a2e6 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/bitmath.h +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/bitmath.h @@ -83,7 +83,7 @@ static inline uint32_t FLAC__clz_uint32(FLAC__uint32 v) #elif defined(_MSC_VER) { uint32_t idx; - _BitScanReverse(&idx, v); + _BitScanReverse((unsigned long*) &idx, v); return idx ^ 31U; } #else @@ -107,7 +107,7 @@ static inline uint32_t FLAC__clz_uint64(FLAC__uint64 v) #elif (defined(__INTEL_COMPILER) || defined(_MSC_VER)) && (defined(_M_IA64) || defined(_M_X64)) { uint32_t idx; - _BitScanReverse64(&idx, v); + _BitScanReverse64((unsigned long*) &idx, v); return idx ^ 63U; } #else @@ -161,7 +161,7 @@ static inline uint32_t FLAC__bitmath_ilog2(FLAC__uint32 v) #elif defined(_MSC_VER) { uint32_t idx; - _BitScanReverse(&idx, v); + _BitScanReverse((unsigned long*) &idx, v); return idx; } #else @@ -178,7 +178,7 @@ static inline uint32_t FLAC__bitmath_ilog2_wide(FLAC__uint64 v) #elif (defined(__INTEL_COMPILER) || defined(_MSC_VER)) && (defined(_M_IA64) || defined(_M_X64)) { uint32_t idx; - _BitScanReverse64(&idx, v); + _BitScanReverse64((unsigned long*) &idx, v); return idx; } #else diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/cpu.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/cpu.h index 3c90270d7d..439f6aad97 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/cpu.h +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/cpu.h @@ -59,99 +59,6 @@ #define __has_attribute(x) 0 #endif -#if FLAC__HAS_X86INTRIN -/* SSE intrinsics support by ICC/MSVC/GCC */ -#if defined __INTEL_COMPILER - #define FLAC__SSE_TARGET(x) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #if (__INTEL_COMPILER >= 1000) /* Intel C++ Compiler 10.0 */ - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #endif - #if (__INTEL_COMPILER >= 1110) /* Intel C++ Compiler 11.1 */ - #define FLAC__AVX_SUPPORTED 1 - #endif - #if (__INTEL_COMPILER >= 1300) /* Intel C++ Compiler 13.0 */ - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #endif -#elif defined __clang__ && __has_attribute(__target__) /* clang */ - #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x))) - #if __has_builtin(__builtin_ia32_maxps) - #define FLAC__SSE_SUPPORTED 1 - #endif - #if __has_builtin(__builtin_ia32_pmuludq128) - #define FLAC__SSE2_SUPPORTED 1 - #endif - #if __has_builtin(__builtin_ia32_pabsd128) - #define FLAC__SSSE3_SUPPORTED 1 - #endif - #if __has_builtin(__builtin_ia32_pmuldq128) - #define FLAC__SSE4_1_SUPPORTED 1 - #endif - #if __has_builtin(__builtin_ia32_maxps256) - #define FLAC__AVX_SUPPORTED 1 - #endif - #if __has_builtin(__builtin_ia32_pabsd256) - #define FLAC__AVX2_SUPPORTED 1 - #endif - #if __has_builtin(__builtin_ia32_vfmaddps) - #define FLAC__FMA_SUPPORTED 1 - #endif -#elif defined __GNUC__ && !defined __clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* GCC 4.9+ */ - #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x))) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #ifdef FLAC__USE_AVX - #define FLAC__AVX_SUPPORTED 1 - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #endif -#elif defined _MSC_VER - #define FLAC__SSE_TARGET(x) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #if (_MSC_VER >= 1500) /* MS Visual Studio 2008 */ - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #endif - #if (_MSC_FULL_VER >= 160040219) /* MS Visual Studio 2010 SP1 */ - #define FLAC__AVX_SUPPORTED 1 - #endif - #if (_MSC_VER >= 1700) /* MS Visual Studio 2012 */ - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #endif -#else - #define FLAC__SSE_TARGET(x) - #ifdef __SSE__ - #define FLAC__SSE_SUPPORTED 1 - #endif - #ifdef __SSE2__ - #define FLAC__SSE2_SUPPORTED 1 - #endif - #ifdef __SSSE3__ - #define FLAC__SSSE3_SUPPORTED 1 - #endif - #ifdef __SSE4_1__ - #define FLAC__SSE4_1_SUPPORTED 1 - #endif - #ifdef __AVX__ - #define FLAC__AVX_SUPPORTED 1 - #endif - #ifdef __AVX2__ - #define FLAC__AVX2_SUPPORTED 1 - #endif - #ifdef __FMA__ - #define FLAC__FMA_SUPPORTED 1 - #endif -#endif /* compiler version */ -#endif /* intrinsics support */ - - #ifndef FLAC__AVX_SUPPORTED #define FLAC__AVX_SUPPORTED 0 #endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/macros.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/macros.h deleted file mode 100644 index b8f6783a67..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/macros.h +++ /dev/null @@ -1,74 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2012-2016 Xiph.org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef FLAC__PRIVATE__MACROS_H -#define FLAC__PRIVATE__MACROS_H - -#if defined(__GNUC__) && (__GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 3)) - -#define flac_max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) - -#define MIN_PASTE(A,B) A##B -#define MIN_IMPL(A,B,L) ({ \ - __typeof__(A) MIN_PASTE(__a,L) = (A); \ - __typeof__(B) MIN_PASTE(__b,L) = (B); \ - MIN_PASTE(__a,L) < MIN_PASTE(__b,L) ? MIN_PASTE(__a,L) : MIN_PASTE(__b,L); \ - }) - -#define flac_min(A,B) MIN_IMPL(A,B,__COUNTER__) - -/* Whatever other unix that has sys/param.h */ -#elif defined(HAVE_SYS_PARAM_H) -#include -#if defined(MIN) && defined(MAX) -#define flac_max(a,b) MAX(a,b) -#define flac_min(a,b) MIN(a,b) -#endif - -/* Windows VS has them in stdlib.h.. XXX:Untested */ -#elif defined(_MSC_VER) -#include -#define flac_max(a,b) __max(a,b) -#define flac_min(a,b) __min(a,b) -#endif - -#ifndef flac_min -#define flac_min(x,y) ((x) <= (y) ? (x) : (y)) -#endif - -#ifndef flac_max -#define flac_max(x,y) ((x) >= (y) ? (x) : (y)) -#endif - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_decoder_aspect.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_decoder_aspect.h deleted file mode 100644 index 08ac869d73..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_decoder_aspect.h +++ /dev/null @@ -1,80 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef FLAC__PRIVATE__OGG_DECODER_ASPECT_H -#define FLAC__PRIVATE__OGG_DECODER_ASPECT_H - -#include - -#include "../../../ordinals.h" -#include "../../../stream_decoder.h" /* for FLAC__StreamDecoderReadStatus */ - -typedef struct FLAC__OggDecoderAspect { - /* these are storage for values that can be set through the API */ - FLAC__bool use_first_serial_number; - long serial_number; - - /* these are for internal state related to Ogg decoding */ - ogg_stream_state stream_state; - ogg_sync_state sync_state; - uint32_t version_major, version_minor; - FLAC__bool need_serial_number; - FLAC__bool end_of_stream; - FLAC__bool have_working_page; /* only if true will the following vars be valid */ - ogg_page working_page; - FLAC__bool have_working_packet; /* only if true will the following vars be valid */ - ogg_packet working_packet; /* as we work through the packet we will move working_packet.packet forward and working_packet.bytes down */ -} FLAC__OggDecoderAspect; - -void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value); -void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect); -FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect); -void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect); -void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect); -void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect); - -typedef enum { - FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK = 0, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR -} FLAC__OggDecoderAspectReadStatus; - -typedef FLAC__OggDecoderAspectReadStatus (*FLAC__OggDecoderAspectReadCallbackProxy)(const void *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); - -FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], size_t *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data); - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_encoder_aspect.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_encoder_aspect.h deleted file mode 100644 index 48224bccbe..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_encoder_aspect.h +++ /dev/null @@ -1,63 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef FLAC__PRIVATE__OGG_ENCODER_ASPECT_H -#define FLAC__PRIVATE__OGG_ENCODER_ASPECT_H - -#include - -#include "../../../ordinals.h" -#include "../../../stream_encoder.h" /* for FLAC__StreamEncoderWriteStatus */ - -typedef struct FLAC__OggEncoderAspect { - /* these are storage for values that can be set through the API */ - long serial_number; - uint32_t num_metadata; - - /* these are for internal state related to Ogg encoding */ - ogg_stream_state stream_state; - ogg_page page; - FLAC__bool seen_magic; /* true if we've seen the fLaC magic in the write callback yet */ - FLAC__bool is_first_packet; - FLAC__uint64 samples_written; -} FLAC__OggEncoderAspect; - -void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value); -FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, uint32_t value); -void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect); -FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect); -void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect); - -typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); - -FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data); -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_helper.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_helper.h deleted file mode 100644 index b763552795..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_helper.h +++ /dev/null @@ -1,44 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef FLAC__PRIVATE__OGG_HELPER_H -#define FLAC__PRIVATE__OGG_HELPER_H - -#include -#include "../../../stream_encoder.h" /* for FLAC__StreamEncoder */ - -void simple_ogg_page__init(ogg_page *page); -void simple_ogg_page__clear(ogg_page *page); -FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data); -FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data); - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_mapping.h b/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_mapping.h deleted file mode 100644 index 3f31d09814..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/include/private/ogg_mapping.h +++ /dev/null @@ -1,64 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef FLAC__PRIVATE__OGG_MAPPING_H -#define FLAC__PRIVATE__OGG_MAPPING_H - -#include "../../../ordinals.h" - -/** The length of the packet type field in bytes. */ -#define FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH (1u) - -extern const uint32_t FLAC__OGG_MAPPING_PACKET_TYPE_LEN; /* = 8 bits */ - -extern const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */ - -/** The length of the 'FLAC' magic in bytes. */ -#define FLAC__OGG_MAPPING_MAGIC_LENGTH (4u) - -extern const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC; /* = "FLAC" */ - -extern const uint32_t FLAC__OGG_MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */ -extern const uint32_t FLAC__OGG_MAPPING_VERSION_MINOR_LEN; /* = 8 bits */ - -/** The length of the Ogg FLAC mapping major version number in bytes. */ -#define FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH (1u) - -/** The length of the Ogg FLAC mapping minor version number in bytes. */ -#define FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH (1u) - -extern const uint32_t FLAC__OGG_MAPPING_NUM_HEADERS_LEN; /* = 16 bits */ - -/** The length of the #-of-header-packets number bytes. */ -#define FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH (2u) - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_flac.c similarity index 97% rename from modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc.c rename to modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_flac.c index d53b8d819d..9835b12bc2 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_flac.c @@ -41,7 +41,6 @@ #include "../compat.h" #include "include/private/bitmath.h" #include "include/private/lpc.h" -#include "include/private/macros.h" #if !defined(NDEBUG) || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE #include #endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_avx2.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_avx2.c deleted file mode 100644 index 1eb2ae3c74..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_avx2.c +++ /dev/null @@ -1,1122 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/lpc.h" -#ifdef FLAC__AVX2_SUPPORTED - -#include "../assert.h" -#include "../format.h" - -#include /* AVX2 */ - -FLAC__SSE_TARGET("avx2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(0xffff & qlp_coeff[10]); - q11 = _mm256_set1_epi32(0xffff & qlp_coeff[11]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q11, _mm256_loadu_si256((const __m256i*)(data+i-12))); - mull = _mm256_madd_epi16(q10, _mm256_loadu_si256((const __m256i*)(data+i-11))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(0xffff & qlp_coeff[10]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q10, _mm256_loadu_si256((const __m256i*)(data+i-11))); - mull = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); - mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m256i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m256i q0, q1, q2, q3, q4, q5; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m256i q0, q1, q2, q3, q4; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m256i q0, q1, q2, q3; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m256i q0, q1, q2; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m256i q0, q1; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m256i q0; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ; - summ = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - _mm256_zeroupper(); -} - -FLAC__SSE_TARGET("avx2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(qlp_coeff[10]); - q11 = _mm256_set1_epi32(qlp_coeff[11]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q11, _mm256_loadu_si256((const __m256i*)(data+i-12))); - mull = _mm256_mullo_epi32(q10, _mm256_loadu_si256((const __m256i*)(data+i-11))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(qlp_coeff[10]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q10, _mm256_loadu_si256((const __m256i*)(data+i-11))); - mull = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(qlp_coeff[9 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); - mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m256i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m256i q0, q1, q2, q3, q4, q5; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m256i q0, q1, q2, q3, q4; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m256i q0, q1, q2, q3; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m256i q0, q1, q2; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m256i q0, q1; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m256i q0; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ; - summ = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - _mm256_zeroupper(); -} - -static FLAC__int32 pack_arr[8] = { 0, 2, 4, 6, 1, 3, 5, 7 }; - -FLAC__SSE_TARGET("avx2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int64 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - const __m256i pack = _mm256_loadu_si256((const __m256i *)pack_arr); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - FLAC__ASSERT(lp_quantization <= 32); /* there's no _mm256_sra_epi64() so we have to use _mm256_srl_epi64() */ - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ])); - q10 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[10])); - q11 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[11])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q11, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-12)))); - mull = _mm256_mul_epi32(q10, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-11)))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-10)))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 11 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ])); - q10 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[10])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q10, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-11)))); - mull = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-10)))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - else { - if(order == 10) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-10)))); - mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 9 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 7 */ - __m256i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - else { - if(order == 6) { - __m256i q0, q1, q2, q3, q4, q5; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 5 */ - __m256i q0, q1, q2, q3, q4; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m256i q0, q1, q2, q3; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 3 */ - __m256i q0, q1, q2; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - else { - if(order == 2) { - __m256i q0, q1; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 1 */ - __m256i q0; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ; - summ = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; - sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; - sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; - sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; - sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; - sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; - sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; - sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; - sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization); - } - } - _mm256_zeroupper(); -} - -#endif /* FLAC__AVX2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse.c deleted file mode 100644 index 4c2e14c772..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse.c +++ /dev/null @@ -1,454 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/lpc.h" -#ifdef FLAC__SSE_SUPPORTED -#include "../assert.h" -#include "../format.h" - -#include /* SSE */ - -/* new routines: more unaligned loads, less shuffle - * old routines: less unaligned loads, more shuffle - * these *_old routines are equivalent to the ASM routines in ia32/lpc_asm.nasm - */ - -/* new routines: faster on current Intel (starting from Core i aka Nehalem) and all AMD CPUs */ - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - int i; - int limit = data_len - 4; - __m128 sum0; - - (void) lag; - FLAC__ASSERT(lag <= 4); - FLAC__ASSERT(lag <= data_len); - - sum0 = _mm_setzero_ps(); - - for(i = 0; i <= limit; i++) { - __m128 d, d0; - d0 = _mm_loadu_ps(data+i); - d = _mm_shuffle_ps(d0, d0, 0); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d0, d)); - } - - { - __m128 d0 = _mm_setzero_ps(); - limit++; if(limit < 0) limit = 0; - - for(i = data_len-1; i >= limit; i--) { - __m128 d; - d = _mm_load_ss(data+i); d = _mm_shuffle_ps(d, d, 0); - d0 = _mm_shuffle_ps(d0, d0, _MM_SHUFFLE(2,1,0,3)); - d0 = _mm_move_ss(d0, d); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d, d0)); - } - } - - _mm_storeu_ps(autoc, sum0); -} - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - int i; - int limit = data_len - 8; - __m128 sum0, sum1; - - (void) lag; - FLAC__ASSERT(lag <= 8); - FLAC__ASSERT(lag <= data_len); - - sum0 = _mm_setzero_ps(); - sum1 = _mm_setzero_ps(); - - for(i = 0; i <= limit; i++) { - __m128 d, d0, d1; - d0 = _mm_loadu_ps(data+i); - d1 = _mm_loadu_ps(data+i+4); - d = _mm_shuffle_ps(d0, d0, 0); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d0, d)); - sum1 = _mm_add_ps(sum1, _mm_mul_ps(d1, d)); - } - - { - __m128 d0 = _mm_setzero_ps(); - __m128 d1 = _mm_setzero_ps(); - limit++; if(limit < 0) limit = 0; - - for(i = data_len-1; i >= limit; i--) { - __m128 d; - d = _mm_load_ss(data+i); d = _mm_shuffle_ps(d, d, 0); - d1 = _mm_shuffle_ps(d1, d1, _MM_SHUFFLE(2,1,0,3)); - d0 = _mm_shuffle_ps(d0, d0, _MM_SHUFFLE(2,1,0,3)); - d1 = _mm_move_ss(d1, d0); - d0 = _mm_move_ss(d0, d); - sum1 = _mm_add_ps(sum1, _mm_mul_ps(d, d1)); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d, d0)); - } - } - - _mm_storeu_ps(autoc, sum0); - _mm_storeu_ps(autoc+4, sum1); -} - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - int i; - int limit = data_len - 12; - __m128 sum0, sum1, sum2; - - (void) lag; - FLAC__ASSERT(lag <= 12); - FLAC__ASSERT(lag <= data_len); - - sum0 = _mm_setzero_ps(); - sum1 = _mm_setzero_ps(); - sum2 = _mm_setzero_ps(); - - for(i = 0; i <= limit; i++) { - __m128 d, d0, d1, d2; - d0 = _mm_loadu_ps(data+i); - d1 = _mm_loadu_ps(data+i+4); - d2 = _mm_loadu_ps(data+i+8); - d = _mm_shuffle_ps(d0, d0, 0); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d0, d)); - sum1 = _mm_add_ps(sum1, _mm_mul_ps(d1, d)); - sum2 = _mm_add_ps(sum2, _mm_mul_ps(d2, d)); - } - - { - __m128 d0 = _mm_setzero_ps(); - __m128 d1 = _mm_setzero_ps(); - __m128 d2 = _mm_setzero_ps(); - limit++; if(limit < 0) limit = 0; - - for(i = data_len-1; i >= limit; i--) { - __m128 d; - d = _mm_load_ss(data+i); d = _mm_shuffle_ps(d, d, 0); - d2 = _mm_shuffle_ps(d2, d2, _MM_SHUFFLE(2,1,0,3)); - d1 = _mm_shuffle_ps(d1, d1, _MM_SHUFFLE(2,1,0,3)); - d0 = _mm_shuffle_ps(d0, d0, _MM_SHUFFLE(2,1,0,3)); - d2 = _mm_move_ss(d2, d1); - d1 = _mm_move_ss(d1, d0); - d0 = _mm_move_ss(d0, d); - sum2 = _mm_add_ps(sum2, _mm_mul_ps(d, d2)); - sum1 = _mm_add_ps(sum1, _mm_mul_ps(d, d1)); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d, d0)); - } - } - - _mm_storeu_ps(autoc, sum0); - _mm_storeu_ps(autoc+4, sum1); - _mm_storeu_ps(autoc+8, sum2); -} - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - int i; - int limit = data_len - 16; - __m128 sum0, sum1, sum2, sum3; - - (void) lag; - FLAC__ASSERT(lag <= 16); - FLAC__ASSERT(lag <= data_len); - - sum0 = _mm_setzero_ps(); - sum1 = _mm_setzero_ps(); - sum2 = _mm_setzero_ps(); - sum3 = _mm_setzero_ps(); - - for(i = 0; i <= limit; i++) { - __m128 d, d0, d1, d2, d3; - d0 = _mm_loadu_ps(data+i); - d1 = _mm_loadu_ps(data+i+4); - d2 = _mm_loadu_ps(data+i+8); - d3 = _mm_loadu_ps(data+i+12); - d = _mm_shuffle_ps(d0, d0, 0); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d0, d)); - sum1 = _mm_add_ps(sum1, _mm_mul_ps(d1, d)); - sum2 = _mm_add_ps(sum2, _mm_mul_ps(d2, d)); - sum3 = _mm_add_ps(sum3, _mm_mul_ps(d3, d)); - } - - { - __m128 d0 = _mm_setzero_ps(); - __m128 d1 = _mm_setzero_ps(); - __m128 d2 = _mm_setzero_ps(); - __m128 d3 = _mm_setzero_ps(); - limit++; if(limit < 0) limit = 0; - - for(i = data_len-1; i >= limit; i--) { - __m128 d; - d = _mm_load_ss(data+i); d = _mm_shuffle_ps(d, d, 0); - d3 = _mm_shuffle_ps(d3, d3, _MM_SHUFFLE(2,1,0,3)); - d2 = _mm_shuffle_ps(d2, d2, _MM_SHUFFLE(2,1,0,3)); - d1 = _mm_shuffle_ps(d1, d1, _MM_SHUFFLE(2,1,0,3)); - d0 = _mm_shuffle_ps(d0, d0, _MM_SHUFFLE(2,1,0,3)); - d3 = _mm_move_ss(d3, d2); - d2 = _mm_move_ss(d2, d1); - d1 = _mm_move_ss(d1, d0); - d0 = _mm_move_ss(d0, d); - sum3 = _mm_add_ps(sum3, _mm_mul_ps(d, d3)); - sum2 = _mm_add_ps(sum2, _mm_mul_ps(d, d2)); - sum1 = _mm_add_ps(sum1, _mm_mul_ps(d, d1)); - sum0 = _mm_add_ps(sum0, _mm_mul_ps(d, d0)); - } - } - - _mm_storeu_ps(autoc, sum0); - _mm_storeu_ps(autoc+4, sum1); - _mm_storeu_ps(autoc+8, sum2); - _mm_storeu_ps(autoc+12,sum3); -} - -/* old routines: faster on older Intel CPUs (up to Core 2) */ - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - __m128 xmm0, xmm2, xmm5; - - (void) lag; - FLAC__ASSERT(lag > 0); - FLAC__ASSERT(lag <= 4); - FLAC__ASSERT(lag <= data_len); - FLAC__ASSERT(data_len > 0); - - xmm5 = _mm_setzero_ps(); - - xmm0 = _mm_load_ss(data++); - xmm2 = xmm0; - xmm0 = _mm_shuffle_ps(xmm0, xmm0, 0); - - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm5 = _mm_add_ps(xmm5, xmm0); - - data_len--; - - while(data_len) - { - xmm0 = _mm_load1_ps(data++); - - xmm2 = _mm_shuffle_ps(xmm2, xmm2, _MM_SHUFFLE(2,1,0,3)); - xmm2 = _mm_move_ss(xmm2, xmm0); - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm5 = _mm_add_ps(xmm5, xmm0); - - data_len--; - } - - _mm_storeu_ps(autoc, xmm5); -} - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - __m128 xmm0, xmm1, xmm2, xmm3, xmm5, xmm6; - - (void) lag; - FLAC__ASSERT(lag > 0); - FLAC__ASSERT(lag <= 8); - FLAC__ASSERT(lag <= data_len); - FLAC__ASSERT(data_len > 0); - - xmm5 = _mm_setzero_ps(); - xmm6 = _mm_setzero_ps(); - - xmm0 = _mm_load_ss(data++); - xmm2 = xmm0; - xmm0 = _mm_shuffle_ps(xmm0, xmm0, 0); - xmm3 = _mm_setzero_ps(); - - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm5 = _mm_add_ps(xmm5, xmm0); - - data_len--; - - while(data_len) - { - xmm0 = _mm_load1_ps(data++); - - xmm2 = _mm_shuffle_ps(xmm2, xmm2, _MM_SHUFFLE(2,1,0,3)); - xmm3 = _mm_shuffle_ps(xmm3, xmm3, _MM_SHUFFLE(2,1,0,3)); - xmm3 = _mm_move_ss(xmm3, xmm2); - xmm2 = _mm_move_ss(xmm2, xmm0); - - xmm1 = xmm0; - xmm1 = _mm_mul_ps(xmm1, xmm3); - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm6 = _mm_add_ps(xmm6, xmm1); - xmm5 = _mm_add_ps(xmm5, xmm0); - - data_len--; - } - - _mm_storeu_ps(autoc, xmm5); - _mm_storeu_ps(autoc+4, xmm6); -} - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - __m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - - (void) lag; - FLAC__ASSERT(lag > 0); - FLAC__ASSERT(lag <= 12); - FLAC__ASSERT(lag <= data_len); - FLAC__ASSERT(data_len > 0); - - xmm5 = _mm_setzero_ps(); - xmm6 = _mm_setzero_ps(); - xmm7 = _mm_setzero_ps(); - - xmm0 = _mm_load_ss(data++); - xmm2 = xmm0; - xmm0 = _mm_shuffle_ps(xmm0, xmm0, 0); - xmm3 = _mm_setzero_ps(); - xmm4 = _mm_setzero_ps(); - - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm5 = _mm_add_ps(xmm5, xmm0); - - data_len--; - - while(data_len) - { - xmm0 = _mm_load1_ps(data++); - - xmm2 = _mm_shuffle_ps(xmm2, xmm2, _MM_SHUFFLE(2,1,0,3)); - xmm3 = _mm_shuffle_ps(xmm3, xmm3, _MM_SHUFFLE(2,1,0,3)); - xmm4 = _mm_shuffle_ps(xmm4, xmm4, _MM_SHUFFLE(2,1,0,3)); - xmm4 = _mm_move_ss(xmm4, xmm3); - xmm3 = _mm_move_ss(xmm3, xmm2); - xmm2 = _mm_move_ss(xmm2, xmm0); - - xmm1 = xmm0; - xmm1 = _mm_mul_ps(xmm1, xmm2); - xmm5 = _mm_add_ps(xmm5, xmm1); - xmm1 = xmm0; - xmm1 = _mm_mul_ps(xmm1, xmm3); - xmm6 = _mm_add_ps(xmm6, xmm1); - xmm0 = _mm_mul_ps(xmm0, xmm4); - xmm7 = _mm_add_ps(xmm7, xmm0); - - data_len--; - } - - _mm_storeu_ps(autoc, xmm5); - _mm_storeu_ps(autoc+4, xmm6); - _mm_storeu_ps(autoc+8, xmm7); -} - -FLAC__SSE_TARGET("sse") -void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - __m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9; - - (void) lag; - FLAC__ASSERT(lag > 0); - FLAC__ASSERT(lag <= 16); - FLAC__ASSERT(lag <= data_len); - FLAC__ASSERT(data_len > 0); - - xmm6 = _mm_setzero_ps(); - xmm7 = _mm_setzero_ps(); - xmm8 = _mm_setzero_ps(); - xmm9 = _mm_setzero_ps(); - - xmm0 = _mm_load_ss(data++); - xmm2 = xmm0; - xmm0 = _mm_shuffle_ps(xmm0, xmm0, 0); - xmm3 = _mm_setzero_ps(); - xmm4 = _mm_setzero_ps(); - xmm5 = _mm_setzero_ps(); - - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm6 = _mm_add_ps(xmm6, xmm0); - - data_len--; - - while(data_len) - { - xmm0 = _mm_load1_ps(data++); - - /* shift xmm5:xmm4:xmm3:xmm2 left by one float */ - xmm5 = _mm_shuffle_ps(xmm5, xmm5, _MM_SHUFFLE(2,1,0,3)); - xmm4 = _mm_shuffle_ps(xmm4, xmm4, _MM_SHUFFLE(2,1,0,3)); - xmm3 = _mm_shuffle_ps(xmm3, xmm3, _MM_SHUFFLE(2,1,0,3)); - xmm2 = _mm_shuffle_ps(xmm2, xmm2, _MM_SHUFFLE(2,1,0,3)); - xmm5 = _mm_move_ss(xmm5, xmm4); - xmm4 = _mm_move_ss(xmm4, xmm3); - xmm3 = _mm_move_ss(xmm3, xmm2); - xmm2 = _mm_move_ss(xmm2, xmm0); - - /* xmm9|xmm8|xmm7|xmm6 += xmm0|xmm0|xmm0|xmm0 * xmm5|xmm4|xmm3|xmm2 */ - xmm1 = xmm0; - xmm1 = _mm_mul_ps(xmm1, xmm5); - xmm9 = _mm_add_ps(xmm9, xmm1); - xmm1 = xmm0; - xmm1 = _mm_mul_ps(xmm1, xmm4); - xmm8 = _mm_add_ps(xmm8, xmm1); - xmm1 = xmm0; - xmm1 = _mm_mul_ps(xmm1, xmm3); - xmm7 = _mm_add_ps(xmm7, xmm1); - xmm0 = _mm_mul_ps(xmm0, xmm2); - xmm6 = _mm_add_ps(xmm6, xmm0); - - data_len--; - } - - _mm_storeu_ps(autoc, xmm6); - _mm_storeu_ps(autoc+4, xmm7); - _mm_storeu_ps(autoc+8, xmm8); - _mm_storeu_ps(autoc+12,xmm9); -} - -#endif /* FLAC__SSE_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse2.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse2.c deleted file mode 100644 index 37067aa9a1..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse2.c +++ /dev/null @@ -1,937 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/lpc.h" -#ifdef FLAC__SSE2_SUPPORTED - -#include "../assert.h" -#include "../format.h" - -#include /* SSE2 */ - -#define RESIDUAL32_RESULT(xmmN) residual[i] = data[i] - (_mm_cvtsi128_si32(xmmN) >> lp_quantization); -#define DATA32_RESULT(xmmN) data[i] = residual[i] + (_mm_cvtsi128_si32(xmmN) >> lp_quantization); - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(0xffff & qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(0xffff & qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - q11 = _mm_cvtsi32_si128(0xffff & qlp_coeff[11]); q11 = _mm_shuffle_epi32(q11, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q11, _mm_loadu_si128((const __m128i*)(data+i-12))); - mull = _mm_madd_epi16(q10, _mm_loadu_si128((const __m128i*)(data+i-11))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q9, _mm_loadu_si128((const __m128i*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(0xffff & qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(0xffff & qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q10, _mm_loadu_si128((const __m128i*)(data+i-11))); - mull = _mm_madd_epi16(q9, _mm_loadu_si128((const __m128i*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(0xffff & qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q9, _mm_loadu_si128((const __m128i*)(data+i-10))); - mull = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m128i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m128i q0, q1, q2, q3, q4, q5; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m128i q0, q1, q2, q3, q4; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m128i q0, q1, q2, q3; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m128i q0, q1, q2; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m128i q0, q1; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m128i q0; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ; - summ = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { /* order == 9, 10, 11, 12 */ - if(order > 10) { /* order == 11, 12 */ - if(order == 12) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); // 0 0 q[1] q[0] - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); // 0 0 q[3] q[2] - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); // 0 0 q[5] q[4] - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); // 0 0 q[7] q[6] - xmm4 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+8)); // 0 0 q[9] q[8] - xmm5 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+10)); // 0 0 q[11] q[10] - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); // 0 q[1] 0 q[0] - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); // 0 q[3] 0 q[2] - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); // 0 q[5] 0 q[4] - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); // 0 q[7] 0 q[6] - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); // 0 q[9] 0 q[8] - xmm5 = _mm_shuffle_epi32(xmm5, _MM_SHUFFLE(3,1,2,0)); // 0 q[11] 0 q[10] - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[11] * data[i-12]; - //sum += qlp_coeff[10] * data[i-11]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-12)); // 0 0 d[i-11] d[i-12] - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); // 0 d[i-12] 0 d[i-11] - xmm7 = _mm_mul_epu32(xmm7, xmm5); /* we use _unsigned_ multiplication and discard high dword of the result values */ - - //sum += qlp_coeff[9] * data[i-10]; - //sum += qlp_coeff[8] * data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm4); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 11 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+8)); - xmm5 = _mm_cvtsi32_si128(qlp_coeff[10]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[10] * data[i-11]; - xmm7 = _mm_cvtsi32_si128(data[i-11]); - xmm7 = _mm_mul_epu32(xmm7, xmm5); - - //sum += qlp_coeff[9] * data[i-10]; - //sum += qlp_coeff[8] * data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm4); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - else { /* order == 9, 10 */ - if(order == 10) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+8)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[9] * data[i-10]; - //sum += qlp_coeff[8] * data[i-9]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-10)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm4); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 9 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - xmm4 = _mm_cvtsi32_si128(qlp_coeff[8]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[8] * data[i-9]; - xmm7 = _mm_cvtsi32_si128(data[i-9]); - xmm7 = _mm_mul_epu32(xmm7, xmm4); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - } - else if(order > 4) { /* order == 5, 6, 7, 8 */ - if(order > 6) { /* order == 7, 8 */ - if(order == 8) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm3); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 7 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_cvtsi32_si128(qlp_coeff[6]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[6] * data[i-7]; - xmm7 = _mm_cvtsi32_si128(data[i-7]); - xmm7 = _mm_mul_epu32(xmm7, xmm3); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - else { /* order == 5, 6 */ - if(order == 6) { - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm2); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 5 */ - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_cvtsi32_si128(qlp_coeff[4]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[4] * data[i-5]; - xmm7 = _mm_cvtsi32_si128(data[i-5]); - xmm7 = _mm_mul_epu32(xmm7, xmm2); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - } - else { /* order == 1, 2, 3, 4 */ - if(order > 2) { /* order == 3, 4 */ - if(order == 4) { - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm1); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 3 */ - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_cvtsi32_si128(qlp_coeff[2]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[2] * data[i-3]; - xmm7 = _mm_cvtsi32_si128(data[i-3]); - xmm7 = _mm_mul_epu32(xmm7, xmm1); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - else { /* order == 1, 2 */ - if(order == 2) { - __m128i xmm0, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm0); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 1 */ - for(i = 0; i < (int)data_len; i++) - residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization); - } - } - } - } - else { /* order > 12 */ - FLAC__int32 sum; - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - -#endif /* FLAC__SSE2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse41.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse41.c deleted file mode 100644 index 4174bf2059..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_sse41.c +++ /dev/null @@ -1,1494 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/lpc.h" -#ifdef FLAC__SSE4_1_SUPPORTED - -#include "../assert.h" -#include "../format.h" - -#include /* SSE4.1 */ - -#if defined FLAC__CPU_IA32 /* unused for x64 */ - -#define RESIDUAL64_RESULT(xmmN) residual[i] = data[i] - _mm_cvtsi128_si32(_mm_srl_epi64(xmmN, cnt)) -#define RESIDUAL64_RESULT1(xmmN) residual[i] = data[i] - _mm_cvtsi128_si32(_mm_srli_epi64(xmmN, lp_quantization)) - -FLAC__SSE_TARGET("sse4.1") -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - FLAC__ASSERT(lp_quantization <= 32); /* there's no _mm_sra_epi64() so we have to use _mm_srl_epi64() */ - - if(order <= 12) { - if(order > 8) { /* order == 9, 10, 11, 12 */ - if(order > 10) { /* order == 11, 12 */ - if(order == 12) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); // 0 0 q[1] q[0] - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); // 0 0 q[3] q[2] - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); // 0 0 q[5] q[4] - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); // 0 0 q[7] q[6] - xmm4 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+8)); // 0 0 q[9] q[8] - xmm5 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+10)); // 0 0 q[11] q[10] - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); // 0 q[1] 0 q[0] - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); // 0 q[3] 0 q[2] - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); // 0 q[5] 0 q[4] - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); // 0 q[7] 0 q[6] - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); // 0 q[9] 0 q[8] - xmm5 = _mm_shuffle_epi32(xmm5, _MM_SHUFFLE(3,1,2,0)); // 0 q[11] 0 q[10] - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - //sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-12)); // 0 0 d[i-11] d[i-12] - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); // 0 d[i-12] 0 d[i-11] - xmm7 = _mm_mul_epi32(xmm7, xmm5); - - //sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - //sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm4); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT1(xmm7); - } - } - else { /* order == 11 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+8)); - xmm5 = _mm_cvtsi32_si128(qlp_coeff[10]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[10] * (FLAC__int64)data[i-11]; - xmm7 = _mm_cvtsi32_si128(data[i-11]); - xmm7 = _mm_mul_epi32(xmm7, xmm5); - - //sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - //sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm4); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT1(xmm7); - } - } - } - else { /* order == 9, 10 */ - if(order == 10) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+8)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - //sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-10)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm4); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 9 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - xmm4 = _mm_cvtsi32_si128(qlp_coeff[8]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm7 = _mm_cvtsi32_si128(data[i-9]); - xmm7 = _mm_mul_epi32(xmm7, xmm4); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - } - else if(order > 4) { /* order == 5, 6, 7, 8 */ - if(order > 6) { /* order == 7, 8 */ - if(order == 8) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+6)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-8)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm3); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 7 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - xmm3 = _mm_cvtsi32_si128(qlp_coeff[6]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm7 = _mm_cvtsi32_si128(data[i-7]); - xmm7 = _mm_mul_epi32(xmm7, xmm3); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - else { /* order == 5, 6 */ - if(order == 6) { - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+4)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-6)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm2); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 5 */ - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - xmm2 = _mm_cvtsi32_si128(qlp_coeff[4]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm7 = _mm_cvtsi32_si128(data[i-5]); - xmm7 = _mm_mul_epi32(xmm7, xmm2); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - } - else { /* order == 1, 2, 3, 4 */ - if(order > 2) { /* order == 3, 4 */ - if(order == 4) { - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+2)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-4)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm1); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 3 */ - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm1 = _mm_cvtsi32_si128(qlp_coeff[2]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm7 = _mm_cvtsi32_si128(data[i-3]); - xmm7 = _mm_mul_epi32(xmm7, xmm1); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - else { /* order == 1, 2 */ - if(order == 2) { - __m128i xmm0, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(qlp_coeff+0)); - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm7 = _mm_loadl_epi64((const __m128i*)(data+i-2)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm0); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 1 */ - __m128i xmm0, xmm7; - xmm0 = _mm_cvtsi32_si128(qlp_coeff[0]); - - for(i = 0; i < (int)data_len; i++) { - //sum = qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm7 = _mm_cvtsi32_si128(data[i-1]); - xmm7 = _mm_mul_epi32(xmm7, xmm0); - RESIDUAL64_RESULT(xmm7); - } - } - } - } - } - else { /* order > 12 */ - FLAC__int64 sum; - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; - sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; - sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; - sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; - sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; - sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; - sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; - sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; - sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization); - } - } -} - -FLAC__SSE_TARGET("sse4.1") -void FLAC__lpc_restore_signal_wide_intrin_sse41(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]) -{ - int i; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - if (!data_len) - return; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - FLAC__ASSERT(lp_quantization <= 32); /* there's no _mm_sra_epi64() so we have to use _mm_srl_epi64() */ - - if(order <= 12) { - if(order > 8) { /* order == 9, 10, 11, 12 */ - if(order > 10) { /* order == 11, 12 */ - __m128i qlp[6], dat[6]; - __m128i summ, temp; - qlp[0] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+0))); // 0 q[1] 0 q[0] - qlp[1] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+2))); // 0 q[3] 0 q[2] - qlp[2] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+4))); // 0 q[5] 0 q[4] - qlp[3] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+6))); // 0 q[7] 0 q[6] - qlp[4] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+8))); // 0 q[9] 0 q[8] - if (order == 12) - qlp[5] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+10))); // 0 q[11] 0 q[10] - else - qlp[5] = _mm_cvtepu32_epi64(_mm_cvtsi32_si128(qlp_coeff[10])); // 0 0 0 q[10] - - dat[5] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-12)), _MM_SHUFFLE(2,0,3,1)); // 0 d[i-12] 0 d[i-11] - dat[4] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-10)), _MM_SHUFFLE(2,0,3,1)); // 0 d[i-10] 0 d[i-9] - dat[3] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-8 )), _MM_SHUFFLE(2,0,3,1)); // 0 d[i-8] 0 d[i-7] - dat[2] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-6 )), _MM_SHUFFLE(2,0,3,1)); // 0 d[i-6] 0 d[i-5] - dat[1] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-4 )), _MM_SHUFFLE(2,0,3,1)); // 0 d[i-4] 0 d[i-3] - dat[0] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-2 )), _MM_SHUFFLE(2,0,3,1)); // 0 d[i-2] 0 d[i-1] - - summ = _mm_mul_epi32(dat[5], qlp[5]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[4], qlp[4])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[3], qlp[3])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[2], qlp[2])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); // ?_64 sum_64 - summ = _mm_srl_epi64(summ, cnt); // ?_64 (sum >> lp_quantization)_64 == ?_32 ?_32 ?_32 (sum >> lp_quantization)_32 - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); // ? ? ? d[i] - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - temp = _mm_slli_si128(temp, 8); - dat[5] = _mm_alignr_epi8(dat[5], dat[4], 8); // ? d[i-11] ? d[i-10] - dat[4] = _mm_alignr_epi8(dat[4], dat[3], 8); // ? d[i-9] ? d[i-8] - dat[3] = _mm_alignr_epi8(dat[3], dat[2], 8); // ? d[i-7] ? d[i-6] - dat[2] = _mm_alignr_epi8(dat[2], dat[1], 8); // ? d[i-5] ? d[i-4] - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 8); // ? d[i-3] ? d[i-2] - dat[0] = _mm_alignr_epi8(dat[0], temp, 8); // ? d[i-1] ? d[i ] - - summ = _mm_mul_epi32(dat[5], qlp[5]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[4], qlp[4])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[3], qlp[3])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[2], qlp[2])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); // ?_64 sum_64 - summ = _mm_srl_epi64(summ, cnt); // ?_64 (sum >> lp_quantization)_64 == ?_32 ?_32 ?_32 (sum >> lp_quantization)_32 - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); // ? ? ? d[i] - data[i] = _mm_cvtsi128_si32(temp); - } - } - else { /* order == 9, 10 */ - __m128i qlp[5], dat[5]; - __m128i summ, temp; - qlp[0] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+0))); - qlp[1] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+2))); - qlp[2] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+4))); - qlp[3] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+6))); - if (order == 10) - qlp[4] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+8))); - else - qlp[4] = _mm_cvtepu32_epi64(_mm_cvtsi32_si128(qlp_coeff[8])); - - dat[4] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-10)), _MM_SHUFFLE(2,0,3,1)); - dat[3] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-8 )), _MM_SHUFFLE(2,0,3,1)); - dat[2] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-6 )), _MM_SHUFFLE(2,0,3,1)); - dat[1] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-4 )), _MM_SHUFFLE(2,0,3,1)); - dat[0] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-2 )), _MM_SHUFFLE(2,0,3,1)); - - summ = _mm_mul_epi32(dat[4], qlp[4]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[3], qlp[3])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[2], qlp[2])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - temp = _mm_slli_si128(temp, 8); - dat[4] = _mm_alignr_epi8(dat[4], dat[3], 8); - dat[3] = _mm_alignr_epi8(dat[3], dat[2], 8); - dat[2] = _mm_alignr_epi8(dat[2], dat[1], 8); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 8); - dat[0] = _mm_alignr_epi8(dat[0], temp, 8); - - summ = _mm_mul_epi32(dat[4], qlp[4]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[3], qlp[3])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[2], qlp[2])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - } - } - } - else if(order > 4) { /* order == 5, 6, 7, 8 */ - if(order > 6) { /* order == 7, 8 */ - __m128i qlp[4], dat[4]; - __m128i summ, temp; - qlp[0] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+0))); - qlp[1] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+2))); - qlp[2] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+4))); - if (order == 8) - qlp[3] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+6))); - else - qlp[3] = _mm_cvtepu32_epi64(_mm_cvtsi32_si128(qlp_coeff[6])); - - dat[3] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-8 )), _MM_SHUFFLE(2,0,3,1)); - dat[2] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-6 )), _MM_SHUFFLE(2,0,3,1)); - dat[1] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-4 )), _MM_SHUFFLE(2,0,3,1)); - dat[0] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-2 )), _MM_SHUFFLE(2,0,3,1)); - - summ = _mm_mul_epi32(dat[3], qlp[3]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[2], qlp[2])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - temp = _mm_slli_si128(temp, 8); - dat[3] = _mm_alignr_epi8(dat[3], dat[2], 8); - dat[2] = _mm_alignr_epi8(dat[2], dat[1], 8); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 8); - dat[0] = _mm_alignr_epi8(dat[0], temp, 8); - - summ = _mm_mul_epi32(dat[3], qlp[3]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[2], qlp[2])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - } - } - else { /* order == 5, 6 */ - __m128i qlp[3], dat[3]; - __m128i summ, temp; - qlp[0] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+0))); - qlp[1] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+2))); - if (order == 6) - qlp[2] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+4))); - else - qlp[2] = _mm_cvtepu32_epi64(_mm_cvtsi32_si128(qlp_coeff[4])); - - dat[2] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-6 )), _MM_SHUFFLE(2,0,3,1)); - dat[1] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-4 )), _MM_SHUFFLE(2,0,3,1)); - dat[0] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-2 )), _MM_SHUFFLE(2,0,3,1)); - - summ = _mm_mul_epi32(dat[2], qlp[2]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - temp = _mm_slli_si128(temp, 8); - dat[2] = _mm_alignr_epi8(dat[2], dat[1], 8); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 8); - dat[0] = _mm_alignr_epi8(dat[0], temp, 8); - - summ = _mm_mul_epi32(dat[2], qlp[2]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[1], qlp[1])); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - } - } - } - else { /* order == 1, 2, 3, 4 */ - if(order > 2) { /* order == 3, 4 */ - __m128i qlp[2], dat[2]; - __m128i summ, temp; - qlp[0] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+0))); - if (order == 4) - qlp[1] = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff+2))); - else - qlp[1] = _mm_cvtepu32_epi64(_mm_cvtsi32_si128(qlp_coeff[2])); - - dat[1] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-4 )), _MM_SHUFFLE(2,0,3,1)); - dat[0] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-2 )), _MM_SHUFFLE(2,0,3,1)); - - summ = _mm_mul_epi32(dat[1], qlp[1]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - temp = _mm_slli_si128(temp, 8); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 8); - dat[0] = _mm_alignr_epi8(dat[0], temp, 8); - - summ = _mm_mul_epi32(dat[1], qlp[1]) ; - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - } - } - else { /* order == 1, 2 */ - if(order == 2) { - __m128i qlp0, dat0; - __m128i summ, temp; - qlp0 = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(qlp_coeff))); - - dat0 = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(data-2 )), _MM_SHUFFLE(2,0,3,1)); - - summ = _mm_mul_epi32(dat0, qlp0); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - dat0 = _mm_alignr_epi8(dat0, _mm_slli_si128(temp, 8), 8); - - summ = _mm_mul_epi32(dat0, qlp0); - - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - } - } - else { /* order == 1 */ - __m128i qlp0; - __m128i summ, temp; - qlp0 = _mm_cvtsi32_si128(qlp_coeff[0]); - temp = _mm_cvtsi32_si128(data[-1]); - - summ = _mm_mul_epi32(temp, qlp0); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[0]), summ); - data[0] = _mm_cvtsi128_si32(temp); - - for(i = 1; i < (int)data_len; i++) { - summ = _mm_mul_epi32(temp, qlp0); - summ = _mm_srl_epi64(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - } - } - } - } - } - else { /* order > 12 */ - __m128i qlp[16]; - - for(i = 0; i < (int)order/2; i++) - qlp[i] = _mm_shuffle_epi32(_mm_loadl_epi64((const __m128i*)(qlp_coeff+i*2)), _MM_SHUFFLE(2,0,3,1)); // 0 q[2*i] 0 q[2*i+1] - if(order & 1) - qlp[i] = _mm_shuffle_epi32(_mm_cvtsi32_si128(qlp_coeff[i*2]), _MM_SHUFFLE(2,0,3,1)); - - for(i = 0; i < (int)data_len; i++) { - __m128i summ = _mm_setzero_si128(), dat; - FLAC__int32 * const datai = &data[i]; - - switch((order+1) / 2) { - case 16: /* order == 31, 32 */ - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-32))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[15])); /* Falls through. */ - case 15: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-30))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[14])); /* Falls through. */ - case 14: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-28))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[13])); /* Falls through. */ - case 13: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-26))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[12])); /* Falls through. */ - case 12: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-24))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[11])); /* Falls through. */ - case 11: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-22))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[10])); /* Falls through. */ - case 10: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-20))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[9])); /* Falls through. */ - case 9: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-18))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[8])); /* Falls through. */ - case 8: - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-16))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[7])); /* Falls through. */ - case 7: /* order == 13, 14 */ - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-14))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[6])); - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-12))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[5])); - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-10))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[4])); - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-8))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[3])); - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-6))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[2])); - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-4))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[1])); - dat = _mm_cvtepu32_epi64(_mm_loadl_epi64((const __m128i*)(datai-2))); - summ = _mm_add_epi64(summ, _mm_mul_epi32(dat, qlp[0])); - } - summ = _mm_add_epi64(summ, _mm_srli_si128(summ, 8)); - summ = _mm_srl_epi64(summ, cnt); - summ = _mm_add_epi32(summ, _mm_cvtsi32_si128(residual[i])); - data[i] = _mm_cvtsi128_si32(summ); - } - } -} - -FLAC__SSE_TARGET("sse4.1") -void FLAC__lpc_restore_signal_intrin_sse41(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]) -{ - if(order < 8) { - FLAC__lpc_restore_signal(residual, data_len, qlp_coeff, order, lp_quantization, data); - return; - } - - FLAC__ASSERT(order >= 8); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - int i; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - if(order > 8) /* order == 9, 10, 11, 12 */ - { - __m128i qlp[3], dat[3]; - __m128i summ, temp; - - qlp[0] = _mm_loadu_si128((const __m128i*)(qlp_coeff + 0)); // q[3] q[2] q[1] q[0] - qlp[1] = _mm_loadu_si128((const __m128i*)(qlp_coeff + 4)); // q[7] q[6] q[5] q[4] - qlp[2] = _mm_loadu_si128((const __m128i*)(qlp_coeff + 8)); // q[11] q[10] q[9] q[8] - switch (order) - { - case 9: - qlp[2] = _mm_slli_si128(qlp[2], 12); qlp[2] = _mm_srli_si128(qlp[2], 12); break; // 0 0 0 q[8] - case 10: - qlp[2] = _mm_slli_si128(qlp[2], 8); qlp[2] = _mm_srli_si128(qlp[2], 8); break; // 0 0 q[9] q[8] - case 11: - qlp[2] = _mm_slli_si128(qlp[2], 4); qlp[2] = _mm_srli_si128(qlp[2], 4); break; // 0 q[10] q[9] q[8] - } - - dat[2] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data - 12)), _MM_SHUFFLE(0, 1, 2, 3)); // d[i-12] d[i-11] d[i-10] d[i-9] - dat[1] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data - 8)), _MM_SHUFFLE(0, 1, 2, 3)); // d[i-8] d[i-7] d[i-6] d[i-5] - dat[0] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data - 4)), _MM_SHUFFLE(0, 1, 2, 3)); // d[i-4] d[i-3] d[i-2] d[i-1] - - for (i = 0;;) { - summ = _mm_mullo_epi32(dat[2], qlp[2]); - summ = _mm_add_epi32(summ, _mm_mullo_epi32(dat[1], qlp[1])); - summ = _mm_add_epi32(summ, _mm_mullo_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi32(summ, _mm_shuffle_epi32(summ, _MM_SHUFFLE(1,0,3,2))); - summ = _mm_add_epi32(summ, _mm_shufflelo_epi16(summ, _MM_SHUFFLE(1,0,3,2))); - - summ = _mm_sra_epi32(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - - if(++i >= (int)data_len) break; - - temp = _mm_slli_si128(temp, 12); - dat[2] = _mm_alignr_epi8(dat[2], dat[1], 12); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 12); - dat[0] = _mm_alignr_epi8(dat[0], temp, 12); - } - } - else /* order == 8 */ - { - __m128i qlp[2], dat[2]; - __m128i summ, temp; - - qlp[0] = _mm_loadu_si128((const __m128i*)(qlp_coeff + 0)); - qlp[1] = _mm_loadu_si128((const __m128i*)(qlp_coeff + 4)); - - dat[1] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data - 8)), _MM_SHUFFLE(0, 1, 2, 3)); - dat[0] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data - 4)), _MM_SHUFFLE(0, 1, 2, 3)); - - for (i = 0;;) { - summ = _mm_add_epi32(_mm_mullo_epi32(dat[1], qlp[1]), _mm_mullo_epi32(dat[0], qlp[0])); - - summ = _mm_add_epi32(summ, _mm_shuffle_epi32(summ, _MM_SHUFFLE(1,0,3,2))); - summ = _mm_add_epi32(summ, _mm_shufflelo_epi16(summ, _MM_SHUFFLE(1,0,3,2))); - - summ = _mm_sra_epi32(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - - if(++i >= (int)data_len) break; - - temp = _mm_slli_si128(temp, 12); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 12); - dat[0] = _mm_alignr_epi8(dat[0], temp, 12); - } - } - } - else { /* order > 12 */ -#ifdef FLAC__HAS_NASM - FLAC__lpc_restore_signal_asm_ia32(residual, data_len, qlp_coeff, order, lp_quantization, data); -#else - FLAC__lpc_restore_signal(residual, data_len, qlp_coeff, order, lp_quantization, data); -#endif - } -} - -FLAC__SSE_TARGET("ssse3") -void FLAC__lpc_restore_signal_16_intrin_sse41(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]) -{ - if(order < 8) { - FLAC__lpc_restore_signal(residual, data_len, qlp_coeff, order, lp_quantization, data); - return; - } - - FLAC__ASSERT(order >= 8); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - int i; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - if(order > 8) /* order == 9, 10, 11, 12 */ - { - __m128i qlp[2], dat[2]; - __m128i summ, temp; - - qlp[0] = _mm_loadu_si128((const __m128i*)(qlp_coeff+0)); // q[3] q[2] q[1] q[0] - temp = _mm_loadu_si128((const __m128i*)(qlp_coeff+4)); // q[7] q[6] q[5] q[4] - qlp[1] = _mm_loadu_si128((const __m128i*)(qlp_coeff+8)); // q[11] q[10] q[9] q[8] - switch(order) - { - case 9: - qlp[1] = _mm_slli_si128(qlp[1], 12); qlp[1] = _mm_srli_si128(qlp[1], 12); break; // 0 0 0 q[8] - case 10: - qlp[1] = _mm_slli_si128(qlp[1], 8); qlp[1] = _mm_srli_si128(qlp[1], 8); break; // 0 0 q[9] q[8] - case 11: - qlp[1] = _mm_slli_si128(qlp[1], 4); qlp[1] = _mm_srli_si128(qlp[1], 4); break; // 0 q[10] q[9] q[8] - } - qlp[0] = _mm_packs_epi32(qlp[0], temp); // q[7] q[6] q[5] q[4] q[3] q[2] q[1] q[0] - qlp[1] = _mm_packs_epi32(qlp[1], _mm_setzero_si128()); // 0 0 0 0 q[11] q[10] q[9] q[8] - - dat[1] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data-12)), _MM_SHUFFLE(0,1,2,3)); // d[i-12] d[i-11] d[i-10] d[i-9] - temp = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data-8)), _MM_SHUFFLE(0,1,2,3)); // d[i-8] d[i-7] d[i-6] d[i-5] - dat[0] = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data-4)), _MM_SHUFFLE(0,1,2,3)); // d[i-4] d[i-3] d[i-2] d[i-1] - - dat[1] = _mm_packs_epi32(dat[1], _mm_setzero_si128()); // 0 0 0 0 d[i-12] d[i-11] d[i-10] d[i-9] - dat[0] = _mm_packs_epi32(dat[0], temp); // d[i-8] d[i-7] d[i-6] d[i-5] d[i-4] d[i-3] d[i-2] d[i-1] - - for(i = 0;;) { - summ = _mm_madd_epi16(dat[1], qlp[1]); - summ = _mm_add_epi32(summ, _mm_madd_epi16(dat[0], qlp[0])); - - summ = _mm_add_epi32(summ, _mm_shuffle_epi32(summ, _MM_SHUFFLE(1,0,3,2))); - summ = _mm_add_epi32(summ, _mm_shufflelo_epi16(summ, _MM_SHUFFLE(1,0,3,2))); - - summ = _mm_sra_epi32(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - - if(++i >= (int)data_len) break; - - temp = _mm_slli_si128(temp, 14); - dat[1] = _mm_alignr_epi8(dat[1], dat[0], 14); // 0 0 0 d[i-12] d[i-11] d[i-10] d[i-9] d[i-8] - dat[0] = _mm_alignr_epi8(dat[0], temp, 14); // d[i-7] d[i-6] d[i-5] d[i-4] d[i-3] d[i-2] d[i-1] d[i] - } - } - else /* order == 8 */ - { - __m128i qlp0, dat0; - __m128i summ, temp; - - qlp0 = _mm_loadu_si128((const __m128i*)(qlp_coeff+0)); // q[3] q[2] q[1] q[0] - temp = _mm_loadu_si128((const __m128i*)(qlp_coeff+4)); // q[7] q[6] q[5] q[4] - qlp0 = _mm_packs_epi32(qlp0, temp); // q[7] q[6] q[5] q[4] q[3] q[2] q[1] q[0] - - temp = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data-8)), _MM_SHUFFLE(0,1,2,3)); - dat0 = _mm_shuffle_epi32(_mm_loadu_si128((const __m128i*)(data-4)), _MM_SHUFFLE(0,1,2,3)); - dat0 = _mm_packs_epi32(dat0, temp); // d[i-8] d[i-7] d[i-6] d[i-5] d[i-4] d[i-3] d[i-2] d[i-1] - - for(i = 0;;) { - summ = _mm_madd_epi16(dat0, qlp0); - - summ = _mm_add_epi32(summ, _mm_shuffle_epi32(summ, _MM_SHUFFLE(1,0,3,2))); - summ = _mm_add_epi32(summ, _mm_shufflelo_epi16(summ, _MM_SHUFFLE(1,0,3,2))); - - summ = _mm_sra_epi32(summ, cnt); - temp = _mm_add_epi32(_mm_cvtsi32_si128(residual[i]), summ); - data[i] = _mm_cvtsi128_si32(temp); - - if(++i >= (int)data_len) break; - - temp = _mm_slli_si128(temp, 14); - dat0 = _mm_alignr_epi8(dat0, temp, 14); // d[i-7] d[i-6] d[i-5] d[i-4] d[i-3] d[i-2] d[i-1] d[i] - } - } - } - else { /* order > 12 */ -#ifdef FLAC__HAS_NASM - FLAC__lpc_restore_signal_asm_ia32_mmx(residual, data_len, qlp_coeff, order, lp_quantization, data); -#else - FLAC__lpc_restore_signal(residual, data_len, qlp_coeff, order, lp_quantization, data); -#endif - } -} - -#endif /* defined FLAC__CPU_IA32 */ - -FLAC__SSE_TARGET("sse4.1") -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - q11 = _mm_cvtsi32_si128(qlp_coeff[11]); q11 = _mm_shuffle_epi32(q11, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q11, _mm_loadu_si128((const __m128i*)(data+i-12))); - mull = _mm_mullo_epi32(q10, _mm_loadu_si128((const __m128i*)(data+i-11))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q9, _mm_loadu_si128((const __m128i*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q10, _mm_loadu_si128((const __m128i*)(data+i-11))); - mull = _mm_mullo_epi32(q9, _mm_loadu_si128((const __m128i*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q9, _mm_loadu_si128((const __m128i*)(data+i-10))); - mull = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(data+i-9))); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(data+i-8))); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m128i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(data+i-7))); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m128i q0, q1, q2, q3, q4, q5; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(data+i-6))); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m128i q0, q1, q2, q3, q4; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(data+i-5))); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m128i q0, q1, q2, q3; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(data+i-4))); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m128i q0, q1, q2; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(data+i-3))); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m128i q0, q1; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(data+i-2))); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m128i q0; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ; - summ = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(data+i-1))); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - -#endif /* FLAC__SSE4_1_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_vsx.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_vsx.c deleted file mode 100644 index 91bdd6c965..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/lpc_intrin_vsx.c +++ /dev/null @@ -1,942 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if defined(FLAC__CPU_PPC64) && defined(FLAC__USE_VSX) - -#include "include/private/cpu.h" -#include "include/private/lpc.h" -#include "../assert.h" -#include "../format.h" - -#include - -#ifdef FLAC__HAS_TARGET_POWER8 -__attribute__((target("cpu=power8"))) -void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 16; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum1 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum2 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum3 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum11 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum12 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum13 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum21 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum22 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum23 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum31 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum32 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum33 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1, d2, d3, d4; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 16); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - d1 = vec_vsx_ld(16, base); - d2 = vec_vsx_ld(32, base); - d3 = vec_vsx_ld(48, base); - - base += 16; - - for (i = 0; i <= (limit-4); i += 4) { - vector float d, d0_orig = d0; - - d4 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - sum3 += d3 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d4, vsel1); - sum10 += d0 * d; - sum11 += d1 * d; - sum12 += d2 * d; - sum13 += d3 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d4, vsel2); - sum20 += d0 * d; - sum21 += d1 * d; - sum22 += d2 * d; - sum23 += d3 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d4, vsel3); - sum30 += d0 * d; - sum31 += d1 * d; - sum32 += d2 * d; - sum33 += d3 * d; - - d0 = d1; - d1 = d2; - d2 = d3; - d3 = d4; - } - - sum0 += vec_perm(sum10, sum11, (vector unsigned char)vperm1); - sum1 += vec_perm(sum11, sum12, (vector unsigned char)vperm1); - sum2 += vec_perm(sum12, sum13, (vector unsigned char)vperm1); - sum3 += vec_perm(sum13, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum21, (vector unsigned char)vperm2); - sum1 += vec_perm(sum21, sum22, (vector unsigned char)vperm2); - sum2 += vec_perm(sum22, sum23, (vector unsigned char)vperm2); - sum3 += vec_perm(sum23, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum31, (vector unsigned char)vperm3); - sum1 += vec_perm(sum31, sum32, (vector unsigned char)vperm3); - sum2 += vec_perm(sum32, sum33, (vector unsigned char)vperm3); - sum3 += vec_perm(sum33, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - d1 = vec_vsx_ld(16, data+i); - d2 = vec_vsx_ld(32, data+i); - d3 = vec_vsx_ld(48, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - sum3 += d3 * d; - } - - vec_vsx_st(sum0, 0, autoc); - vec_vsx_st(sum1, 16, autoc); - vec_vsx_st(sum2, 32, autoc); - vec_vsx_st(sum3, 48, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} - -__attribute__((target("cpu=power8"))) -void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 12; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum1 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum2 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum11 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum12 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum21 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum22 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum31 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum32 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1, d2, d3; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 12); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - d1 = vec_vsx_ld(16, base); - d2 = vec_vsx_ld(32, base); - - base += 12; - - for (i = 0; i <= (limit-3); i += 4) { - vector float d, d0_orig = d0; - - d3 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d3, vsel1); - sum10 += d0 * d; - sum11 += d1 * d; - sum12 += d2 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d3, vsel2); - sum20 += d0 * d; - sum21 += d1 * d; - sum22 += d2 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d3, vsel3); - sum30 += d0 * d; - sum31 += d1 * d; - sum32 += d2 * d; - - d0 = d1; - d1 = d2; - d2 = d3; - } - - sum0 += vec_perm(sum10, sum11, (vector unsigned char)vperm1); - sum1 += vec_perm(sum11, sum12, (vector unsigned char)vperm1); - sum2 += vec_perm(sum12, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum21, (vector unsigned char)vperm2); - sum1 += vec_perm(sum21, sum22, (vector unsigned char)vperm2); - sum2 += vec_perm(sum22, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum31, (vector unsigned char)vperm3); - sum1 += vec_perm(sum31, sum32, (vector unsigned char)vperm3); - sum2 += vec_perm(sum32, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - d1 = vec_vsx_ld(16, data+i); - d2 = vec_vsx_ld(32, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - } - - vec_vsx_st(sum0, 0, autoc); - vec_vsx_st(sum1, 16, autoc); - vec_vsx_st(sum2, 32, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} - -__attribute__((target("cpu=power8"))) -void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 8; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum1 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum11 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum21 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum31 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1, d2; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 8); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - d1 = vec_vsx_ld(16, base); - - base += 8; - - for (i = 0; i <= (limit-2); i += 4) { - vector float d, d0_orig = d0; - - d2 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - sum1 += d1 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d2, vsel1); - sum10 += d0 * d; - sum11 += d1 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d2, vsel2); - sum20 += d0 * d; - sum21 += d1 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d2, vsel3); - sum30 += d0 * d; - sum31 += d1 * d; - - d0 = d1; - d1 = d2; - } - - sum0 += vec_perm(sum10, sum11, (vector unsigned char)vperm1); - sum1 += vec_perm(sum11, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum21, (vector unsigned char)vperm2); - sum1 += vec_perm(sum21, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum31, (vector unsigned char)vperm3); - sum1 += vec_perm(sum31, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - d1 = vec_vsx_ld(16, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - sum1 += d1 * d; - } - - vec_vsx_st(sum0, 0, autoc); - vec_vsx_st(sum1, 16, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} - -__attribute__((target("cpu=power8"))) -void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_4(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 4; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 4); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - - base += 4; - - for (i = 0; i <= (limit-1); i += 4) { - vector float d, d0_orig = d0; - - d1 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d1, vsel1); - sum10 += d0 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d1, vsel2); - sum20 += d0 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d1, vsel3); - sum30 += d0 * d; - - d0 = d1; - } - - sum0 += vec_perm(sum10, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - } - - vec_vsx_st(sum0, 0, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} -#endif /* FLAC__HAS_TARGET_POWER8 */ - -#ifdef FLAC__HAS_TARGET_POWER9 -__attribute__((target("cpu=power9"))) -void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 16; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum1 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum2 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum3 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum11 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum12 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum13 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum21 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum22 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum23 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum31 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum32 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum33 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1, d2, d3, d4; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 16); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - d1 = vec_vsx_ld(16, base); - d2 = vec_vsx_ld(32, base); - d3 = vec_vsx_ld(48, base); - - base += 16; - - for (i = 0; i <= (limit-4); i += 4) { - vector float d, d0_orig = d0; - - d4 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - sum3 += d3 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d4, vsel1); - sum10 += d0 * d; - sum11 += d1 * d; - sum12 += d2 * d; - sum13 += d3 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d4, vsel2); - sum20 += d0 * d; - sum21 += d1 * d; - sum22 += d2 * d; - sum23 += d3 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d4, vsel3); - sum30 += d0 * d; - sum31 += d1 * d; - sum32 += d2 * d; - sum33 += d3 * d; - - d0 = d1; - d1 = d2; - d2 = d3; - d3 = d4; - } - - sum0 += vec_perm(sum10, sum11, (vector unsigned char)vperm1); - sum1 += vec_perm(sum11, sum12, (vector unsigned char)vperm1); - sum2 += vec_perm(sum12, sum13, (vector unsigned char)vperm1); - sum3 += vec_perm(sum13, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum21, (vector unsigned char)vperm2); - sum1 += vec_perm(sum21, sum22, (vector unsigned char)vperm2); - sum2 += vec_perm(sum22, sum23, (vector unsigned char)vperm2); - sum3 += vec_perm(sum23, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum31, (vector unsigned char)vperm3); - sum1 += vec_perm(sum31, sum32, (vector unsigned char)vperm3); - sum2 += vec_perm(sum32, sum33, (vector unsigned char)vperm3); - sum3 += vec_perm(sum33, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - d1 = vec_vsx_ld(16, data+i); - d2 = vec_vsx_ld(32, data+i); - d3 = vec_vsx_ld(48, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - sum3 += d3 * d; - } - - vec_vsx_st(sum0, 0, autoc); - vec_vsx_st(sum1, 16, autoc); - vec_vsx_st(sum2, 32, autoc); - vec_vsx_st(sum3, 48, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} - -__attribute__((target("cpu=power9"))) -void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 12; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum1 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum2 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum11 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum12 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum21 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum22 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum31 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum32 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1, d2, d3; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 12); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - d1 = vec_vsx_ld(16, base); - d2 = vec_vsx_ld(32, base); - - base += 12; - - for (i = 0; i <= (limit-3); i += 4) { - vector float d, d0_orig = d0; - - d3 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d3, vsel1); - sum10 += d0 * d; - sum11 += d1 * d; - sum12 += d2 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d3, vsel2); - sum20 += d0 * d; - sum21 += d1 * d; - sum22 += d2 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d3, vsel3); - sum30 += d0 * d; - sum31 += d1 * d; - sum32 += d2 * d; - - d0 = d1; - d1 = d2; - d2 = d3; - } - - sum0 += vec_perm(sum10, sum11, (vector unsigned char)vperm1); - sum1 += vec_perm(sum11, sum12, (vector unsigned char)vperm1); - sum2 += vec_perm(sum12, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum21, (vector unsigned char)vperm2); - sum1 += vec_perm(sum21, sum22, (vector unsigned char)vperm2); - sum2 += vec_perm(sum22, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum31, (vector unsigned char)vperm3); - sum1 += vec_perm(sum31, sum32, (vector unsigned char)vperm3); - sum2 += vec_perm(sum32, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - d1 = vec_vsx_ld(16, data+i); - d2 = vec_vsx_ld(32, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - sum1 += d1 * d; - sum2 += d2 * d; - } - - vec_vsx_st(sum0, 0, autoc); - vec_vsx_st(sum1, 16, autoc); - vec_vsx_st(sum2, 32, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} - -__attribute__((target("cpu=power9"))) -void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 8; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum1 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum11 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum21 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum31 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1, d2; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 8); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - d1 = vec_vsx_ld(16, base); - - base += 8; - - for (i = 0; i <= (limit-2); i += 4) { - vector float d, d0_orig = d0; - - d2 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - sum1 += d1 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d2, vsel1); - sum10 += d0 * d; - sum11 += d1 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d2, vsel2); - sum20 += d0 * d; - sum21 += d1 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d2, vsel3); - sum30 += d0 * d; - sum31 += d1 * d; - - d0 = d1; - d1 = d2; - } - - sum0 += vec_perm(sum10, sum11, (vector unsigned char)vperm1); - sum1 += vec_perm(sum11, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum21, (vector unsigned char)vperm2); - sum1 += vec_perm(sum21, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum31, (vector unsigned char)vperm3); - sum1 += vec_perm(sum31, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - d1 = vec_vsx_ld(16, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - sum1 += d1 * d; - } - - vec_vsx_st(sum0, 0, autoc); - vec_vsx_st(sum1, 16, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} - -__attribute__((target("cpu=power9"))) -void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_4(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]) -{ - long i; - long limit = (long)data_len - 4; - const FLAC__real *base; - vector float sum0 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum10 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum20 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float sum30 = { 0.0f, 0.0f, 0.0f, 0.0f}; - vector float d0, d1; -#if WORDS_BIGENDIAN - vector unsigned int vsel1 = { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF }; - vector unsigned int vsel2 = { 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vsel3 = { 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; - vector unsigned int vperm1 = { 0x04050607, 0x08090A0B, 0x0C0D0E0F, 0x10111213 }; - vector unsigned int vperm2 = { 0x08090A0B, 0x0C0D0E0F, 0x10111213, 0x14151617 }; - vector unsigned int vperm3 = { 0x0C0D0E0F, 0x10111213, 0x14151617, 0x18191A1B }; -#else - vector unsigned int vsel1 = { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }; - vector unsigned int vsel2 = { 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000 }; - vector unsigned int vsel3 = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000 }; - vector unsigned int vperm1 = { 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x13121110 }; - vector unsigned int vperm2 = { 0x0B0A0908, 0x0F0E0D0C, 0x13121110, 0x17161514 }; - vector unsigned int vperm3 = { 0x0F0E0D0C, 0x13121110, 0x17161514, 0x1B1A1918 }; -#endif - - (void) lag; - FLAC__ASSERT(lag <= 4); - FLAC__ASSERT(lag <= data_len); - - base = data; - - d0 = vec_vsx_ld(0, base); - - base += 4; - - for (i = 0; i <= (limit-1); i += 4) { - vector float d, d0_orig = d0; - - d1 = vec_vsx_ld(0, base); - base += 4; - - d = vec_splat(d0_orig, 0); - sum0 += d0 * d; - - d = vec_splat(d0_orig, 1); - d0 = vec_sel(d0_orig, d1, vsel1); - sum10 += d0 * d; - - d = vec_splat(d0_orig, 2); - d0 = vec_sel(d0_orig, d1, vsel2); - sum20 += d0 * d; - - d = vec_splat(d0_orig, 3); - d0 = vec_sel(d0_orig, d1, vsel3); - sum30 += d0 * d; - - d0 = d1; - } - - sum0 += vec_perm(sum10, sum10, (vector unsigned char)vperm1); - - sum0 += vec_perm(sum20, sum20, (vector unsigned char)vperm2); - - sum0 += vec_perm(sum30, sum30, (vector unsigned char)vperm3); - - for (; i <= limit; i++) { - vector float d; - - d0 = vec_vsx_ld(0, data+i); - - d = vec_splat(d0, 0); - sum0 += d0 * d; - } - - vec_vsx_st(sum0, 0, autoc); - - for (; i < (long)data_len; i++) { - uint32_t coeff; - - FLAC__real d = data[i]; - for (coeff = 0; coeff < data_len - i; coeff++) - autoc[coeff] += d * data[i+coeff]; - } -} -#endif /* FLAC__HAS_TARGET_POWER9 */ - -#endif /* FLAC__CPU_PPC64 && FLAC__USE_VSX */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/md5.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/md5.c index ed15ba6d6c..1676bfbc4b 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/md5.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/md5.c @@ -54,7 +54,7 @@ */ static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16]) { - register FLAC__uint32 a, b, c, d; + FLAC__uint32 a, b, c, d; a = buf[0]; b = buf[1]; @@ -139,7 +139,7 @@ static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16]) //@@@@@@ OPT: use bswap/intrinsics static void byteSwap(FLAC__uint32 *buf, uint32_t words) { - register FLAC__uint32 x; + FLAC__uint32 x; do { x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); @@ -148,7 +148,7 @@ static void byteSwap(FLAC__uint32 *buf, uint32_t words) } static void byteSwapX16(FLAC__uint32 *buf) { - register FLAC__uint32 x; + FLAC__uint32 x; x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); @@ -500,8 +500,8 @@ FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const return false; if (ctx->capacity < bytes_needed) { - if (0 == (ctx->internal_buf.p8 = safe_realloc_(ctx->internal_buf.p8, bytes_needed))) { - if (0 == (ctx->internal_buf.p8 = safe_malloc_(bytes_needed))) { + if (0 == (ctx->internal_buf.p8 = (FLAC__byte*) safe_realloc_(ctx->internal_buf.p8, bytes_needed))) { + if (0 == (ctx->internal_buf.p8 = (FLAC__byte*) safe_malloc_(bytes_needed))) { ctx->capacity = 0; return false; } diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/memory.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/memory.c index 390f1dc5cc..bcf61d37a6 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/memory.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/memory.c @@ -76,7 +76,7 @@ FLAC__bool FLAC__memory_alloc_aligned_int32_array(size_t elements, FLAC__int32 * if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ return false; - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); + pu = (FLAC__int32*) FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); if(0 == pu) { return false; } @@ -105,7 +105,7 @@ FLAC__bool FLAC__memory_alloc_aligned_uint32_array(size_t elements, FLAC__uint32 if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ return false; - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); + pu = (FLAC__uint32*) FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); if(0 == pu) { return false; } @@ -134,7 +134,7 @@ FLAC__bool FLAC__memory_alloc_aligned_uint64_array(size_t elements, FLAC__uint64 if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ return false; - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); + pu = (FLAC__uint64*) FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); if(0 == pu) { return false; } @@ -163,7 +163,7 @@ FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(size_t elements, uint32_t * if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ return false; - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); + pu = (uint32_t*) FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); if(0 == pu) { return false; } @@ -194,7 +194,7 @@ FLAC__bool FLAC__memory_alloc_aligned_real_array(size_t elements, FLAC__real **u if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ return false; - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); + pu = (FLAC__real*) FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); if(0 == pu) { return false; } diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/metadata_iterators.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/metadata_iterators.c deleted file mode 100644 index 8eab2607af..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/metadata_iterators.c +++ /dev/null @@ -1,3487 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include /* for stat(), maybe chmod() */ - -#include "include/private/metadata.h" - -#include "../assert.h" -#include "../stream_decoder.h" -#include "../alloc.h" -#include "../compat.h" -#include "../macros.h" -#include "../safe_str.h" -#include "include/private/macros.h" -#include "include/private/memory.h" - -/* Alias the first (in share/alloc.h) to the second (in src/libFLAC/memory.c). */ -#define safe_malloc_mul_2op_ safe_malloc_mul_2op_p - -/**************************************************************************** - * - * Local function declarations - * - ***************************************************************************/ - -static void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes); -static void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes); -static void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, uint32_t bytes); -static FLAC__uint32 unpack_uint32_(FLAC__byte *b, uint32_t bytes); -static FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, uint32_t bytes); -static FLAC__uint64 unpack_uint64_(FLAC__byte *b, uint32_t bytes); - -static FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator); -static FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block); -static FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, uint32_t *length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, uint32_t max_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, uint32_t block_length); - -static FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block); -static FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, uint32_t block_length); -static FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, uint32_t block_length); -static FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block); -static FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block); -static FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block); -static FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block); -static FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, uint32_t block_length); - -static FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, uint32_t padding_length, FLAC__bool padding_is_last); -static FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append); - -static void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator); -static FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator); - -static uint32_t seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb); -static uint32_t seek_to_first_metadata_block_(FILE *f); - -static FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append); -static FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup); - -static FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status); - -static FLAC__bool open_tempfile_(const char *filename, const char *tempfile_path_prefix, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status); -static void cleanup_tempfile_(FILE **tempfile, char **tempfilename); - -static FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats); -static void set_file_stats_(const char *filename, struct flac_stat_s *stats); - -static int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence); -static FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle); - -static FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorStatus status); - - -#ifdef FLAC__VALGRIND_TESTING -static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#else -#define local__fwrite fwrite -#endif - -/**************************************************************************** - * - * Level 0 implementation - * - ***************************************************************************/ - -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); - -typedef struct { - FLAC__bool got_error; - FLAC__StreamMetadata *object; -} level0_client_data; - -static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC__MetadataType type) -{ - level0_client_data cd; - FLAC__StreamDecoder *decoder; - - FLAC__ASSERT(0 != filename); - - cd.got_error = false; - cd.object = 0; - - decoder = FLAC__stream_decoder_new(); - - if(0 == decoder) - return 0; - - FLAC__stream_decoder_set_md5_checking(decoder, false); - FLAC__stream_decoder_set_metadata_ignore_all(decoder); - FLAC__stream_decoder_set_metadata_respond(decoder, type); - - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - return 0; - } - - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder) || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - if(0 != cd.object) - FLAC__metadata_object_delete(cd.object); - return 0; - } - - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - - return cd.object; -} - -FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo) -{ - FLAC__StreamMetadata *object; - - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != streaminfo); - - object = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_STREAMINFO); - - if (object) { - /* can just copy the contents since STREAMINFO has no internal structure */ - *streaminfo = *object; - FLAC__metadata_object_delete(object); - return true; - } - else { - return false; - } -} - -FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != tags); - - *tags = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_VORBIS_COMMENT); - - return 0 != *tags; -} - -FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != cuesheet); - - *cuesheet = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_CUESHEET); - - return 0 != *cuesheet; -} - -FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - (void)decoder, (void)frame, (void)buffer, (void)client_data; - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - level0_client_data *cd = (level0_client_data *)client_data; - (void)decoder; - - /* - * we assume we only get here when the one metadata block we were - * looking for was passed to us - */ - if(!cd->got_error && 0 == cd->object) { - if(0 == (cd->object = FLAC__metadata_object_clone(metadata))) - cd->got_error = true; - } -} - -void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - level0_client_data *cd = (level0_client_data *)client_data; - (void)decoder; - - if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) - cd->got_error = true; -} - -FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors) -{ - FLAC__Metadata_SimpleIterator *it; - FLAC__uint64 max_area_seen = 0; - FLAC__uint64 max_depth_seen = 0; - - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != picture); - - *picture = 0; - - it = FLAC__metadata_simple_iterator_new(); - if(0 == it) - return false; - if(!FLAC__metadata_simple_iterator_init(it, filename, /*read_only=*/true, /*preserve_file_stats=*/true)) { - FLAC__metadata_simple_iterator_delete(it); - return false; - } - do { - if(FLAC__metadata_simple_iterator_get_block_type(it) == FLAC__METADATA_TYPE_PICTURE) { - FLAC__StreamMetadata *obj = FLAC__metadata_simple_iterator_get_block(it); - FLAC__uint64 area = (FLAC__uint64)obj->data.picture.width * (FLAC__uint64)obj->data.picture.height; - /* check constraints */ - if( - (type == (FLAC__StreamMetadata_Picture_Type)(-1) || type == obj->data.picture.type) && - (mime_type == 0 || !strcmp(mime_type, obj->data.picture.mime_type)) && - (description == 0 || !strcmp((const char *)description, (const char *)obj->data.picture.description)) && - obj->data.picture.width <= max_width && - obj->data.picture.height <= max_height && - obj->data.picture.depth <= max_depth && - obj->data.picture.colors <= max_colors && - (area > max_area_seen || (area == max_area_seen && obj->data.picture.depth > max_depth_seen)) - ) { - if(*picture) - FLAC__metadata_object_delete(*picture); - *picture = obj; - max_area_seen = area; - max_depth_seen = obj->data.picture.depth; - } - else { - FLAC__metadata_object_delete(obj); - } - } - } while(FLAC__metadata_simple_iterator_next(it)); - - FLAC__metadata_simple_iterator_delete(it); - - return (0 != *picture); -} - - -/**************************************************************************** - * - * Level 1 implementation - * - ***************************************************************************/ - -#define SIMPLE_ITERATOR_MAX_PUSH_DEPTH (1+4) -/* 1 for initial offset, +4 for our own personal use */ - -struct FLAC__Metadata_SimpleIterator { - FILE *file; - char *filename, *tempfile_path_prefix; - struct flac_stat_s stats; - FLAC__bool has_stats; - FLAC__bool is_writable; - FLAC__Metadata_SimpleIteratorStatus status; - FLAC__off_t offset[SIMPLE_ITERATOR_MAX_PUSH_DEPTH]; - FLAC__off_t first_offset; /* this is the offset to the STREAMINFO block */ - uint32_t depth; - /* this is the metadata block header of the current block we are pointing to: */ - FLAC__bool is_last; - FLAC__MetadataType type; - uint32_t length; -}; - -FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[] = { - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR" -}; - - -FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void) -{ - FLAC__Metadata_SimpleIterator *iterator = calloc(1, sizeof(FLAC__Metadata_SimpleIterator)); - - if(0 != iterator) { - iterator->file = 0; - iterator->filename = 0; - iterator->tempfile_path_prefix = 0; - iterator->has_stats = false; - iterator->is_writable = false; - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; - iterator->first_offset = iterator->offset[0] = -1; - iterator->depth = 0; - } - - return iterator; -} - -static void simple_iterator_free_guts_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - if(0 != iterator->file) { - fclose(iterator->file); - iterator->file = 0; - if(iterator->has_stats) - set_file_stats_(iterator->filename, &iterator->stats); - } - if(0 != iterator->filename) { - free(iterator->filename); - iterator->filename = 0; - } - if(0 != iterator->tempfile_path_prefix) { - free(iterator->tempfile_path_prefix); - iterator->tempfile_path_prefix = 0; - } -} - -FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - simple_iterator_free_guts_(iterator); - free(iterator); -} - -FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__Metadata_SimpleIteratorStatus status; - - FLAC__ASSERT(0 != iterator); - - status = iterator->status; - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; - return status; -} - -static FLAC__bool simple_iterator_prime_input_(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool read_only) -{ - uint32_t ret; - - FLAC__ASSERT(0 != iterator); - - if(read_only || 0 == (iterator->file = flac_fopen(iterator->filename, "r+b"))) { - iterator->is_writable = false; - if(read_only || errno == EACCES) { - if(0 == (iterator->file = flac_fopen(iterator->filename, "rb"))) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE; - return false; - } - } - else { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE; - return false; - } - } - else { - iterator->is_writable = true; - } - - ret = seek_to_first_metadata_block_(iterator->file); - switch(ret) { - case 0: - iterator->depth = 0; - iterator->first_offset = iterator->offset[iterator->depth] = ftello(iterator->file); - return read_metadata_block_header_(iterator); - case 1: - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - case 2: - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - case 3: - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE; - return false; - default: - FLAC__ASSERT(0); - return false; - } -} - -#if 0 -@@@ If we decide to finish implementing this, put this comment back in metadata.h -/* - * The 'tempfile_path_prefix' allows you to specify a directory where - * tempfiles should go. Remember that if your metadata edits cause the - * FLAC file to grow, the entire file will have to be rewritten. If - * 'tempfile_path_prefix' is NULL, the temp file will be written in the - * same directory as the original FLAC file. This makes replacing the - * original with the tempfile fast but requires extra space in the same - * partition for the tempfile. If space is a problem, you can pass a - * directory name belonging to a different partition in - * 'tempfile_path_prefix'. Note that you should use the forward slash - * '/' as the directory separator. A trailing slash is not needed; it - * will be added automatically. - */ -FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool preserve_file_stats, const char *tempfile_path_prefix); -#endif - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats) -{ - const char *tempfile_path_prefix = 0; /*@@@ search for comments near 'flac_rename(...)' for what it will take to finish implementing this */ - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != filename); - - simple_iterator_free_guts_(iterator); - - if(!read_only && preserve_file_stats) - iterator->has_stats = get_file_stats_(filename, &iterator->stats); - - if(0 == (iterator->filename = strdup(filename))) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - if(0 != tempfile_path_prefix && 0 == (iterator->tempfile_path_prefix = strdup(tempfile_path_prefix))) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - return simple_iterator_prime_input_(iterator, read_only); -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - return iterator->is_writable; -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - if(iterator->is_last) - return false; - - if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - iterator->offset[iterator->depth] = ftello(iterator->file); - - return read_metadata_block_header_(iterator); -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__off_t this_offset; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - if(iterator->offset[iterator->depth] == iterator->first_offset) - return false; - - if(0 != fseeko(iterator->file, iterator->first_offset, SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - this_offset = iterator->first_offset; - if(!read_metadata_block_header_(iterator)) - return false; - - /* we ignore any error from ftello() and catch it in fseeko() */ - while(ftello(iterator->file) + (FLAC__off_t)iterator->length < iterator->offset[iterator->depth]) { - if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - this_offset = ftello(iterator->file); - if(!read_metadata_block_header_(iterator)) - return false; - } - - iterator->offset[iterator->depth] = this_offset; - - return true; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - return iterator->is_last; -} - -/*@@@@add to tests*/ -FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - return iterator->offset[iterator->depth]; -} - -FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - return iterator->type; -} - -/*@@@@add to tests*/ -FLAC_API uint32_t FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - return iterator->length; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id) -{ - const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(0 != id); - - if(iterator->type != FLAC__METADATA_TYPE_APPLICATION) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - - if(fread(id, 1, id_bytes, iterator->file) != id_bytes) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - - /* back up */ - if(0 != fseeko(iterator->file, -((int)id_bytes), SEEK_CUR)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return true; -} - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__StreamMetadata *block = FLAC__metadata_object_new(iterator->type); - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - if(0 != block) { - block->is_last = iterator->is_last; - block->length = iterator->length; - - if(!read_metadata_block_data_(iterator, block)) { - FLAC__metadata_object_delete(block); - return 0; - } - - /* back up to the beginning of the block data to stay consistent */ - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH, SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - FLAC__metadata_object_delete(block); - return 0; - } - } - else - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - return block; -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding) -{ - FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];) - FLAC__bool ret; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(0 != block); - - if(!iterator->is_writable) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE; - return false; - } - - if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO || block->type == FLAC__METADATA_TYPE_STREAMINFO) { - if(iterator->type != block->type) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - } - - block->is_last = iterator->is_last; - - if(iterator->length == block->length) - return write_metadata_block_stationary_(iterator, block); - else if(iterator->length > block->length) { - if(use_padding && iterator->length >= FLAC__STREAM_METADATA_HEADER_LENGTH + block->length) { - ret = write_metadata_block_stationary_with_padding_(iterator, block, iterator->length - FLAC__STREAM_METADATA_HEADER_LENGTH - block->length, block->is_last); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - else { - ret = rewrite_whole_file_(iterator, block, /*append=*/false); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - } - else /* iterator->length < block->length */ { - uint32_t padding_leftover = 0; - FLAC__bool padding_is_last = false; - if(use_padding) { - /* first see if we can even use padding */ - if(iterator->is_last) { - use_padding = false; - } - else { - const uint32_t extra_padding_bytes_required = block->length - iterator->length; - simple_iterator_push_(iterator); - if(!FLAC__metadata_simple_iterator_next(iterator)) { - (void)simple_iterator_pop_(iterator); - return false; - } - if(iterator->type != FLAC__METADATA_TYPE_PADDING) { - use_padding = false; - } - else { - if(FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length == extra_padding_bytes_required) { - padding_leftover = 0; - block->is_last = iterator->is_last; - } - else if(iterator->length < extra_padding_bytes_required) - use_padding = false; - else { - padding_leftover = FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length - extra_padding_bytes_required; - padding_is_last = iterator->is_last; - block->is_last = false; - } - } - if(!simple_iterator_pop_(iterator)) - return false; - } - } - if(use_padding) { - if(padding_leftover == 0) { - ret = write_metadata_block_stationary_(iterator, block); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - else { - FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH); - ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - } - else { - ret = rewrite_whole_file_(iterator, block, /*append=*/false); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - } -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding) -{ - uint32_t padding_leftover = 0; - FLAC__bool padding_is_last = false; - - FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length;) - FLAC__bool ret; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(0 != block); - - if(!iterator->is_writable) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE; - return false; - } - - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - - block->is_last = iterator->is_last; - - if(use_padding) { - /* first see if we can even use padding */ - if(iterator->is_last) { - use_padding = false; - } - else { - simple_iterator_push_(iterator); - if(!FLAC__metadata_simple_iterator_next(iterator)) { - (void)simple_iterator_pop_(iterator); - return false; - } - if(iterator->type != FLAC__METADATA_TYPE_PADDING) { - use_padding = false; - } - else { - if(iterator->length == block->length) { - padding_leftover = 0; - block->is_last = iterator->is_last; - } - else if(iterator->length < FLAC__STREAM_METADATA_HEADER_LENGTH + block->length) - use_padding = false; - else { - padding_leftover = iterator->length - block->length; - padding_is_last = iterator->is_last; - block->is_last = false; - } - } - if(!simple_iterator_pop_(iterator)) - return false; - } - } - if(use_padding) { - /* move to the next block, which is suitable padding */ - if(!FLAC__metadata_simple_iterator_next(iterator)) - return false; - if(padding_leftover == 0) { - ret = write_metadata_block_stationary_(iterator, block); - FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - else { - FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH); - ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last); - FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - } - else { - ret = rewrite_whole_file_(iterator, block, /*append=*/true); - FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding) -{ - FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];) - FLAC__bool ret; - - if(!iterator->is_writable) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE; - return false; - } - - if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - - if(use_padding) { - FLAC__StreamMetadata *padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - if(0 == padding) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - padding->length = iterator->length; - if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false)) { - FLAC__metadata_object_delete(padding); - return false; - } - FLAC__metadata_object_delete(padding); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return false; - FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset); - return true; - } - else { - ret = rewrite_whole_file_(iterator, 0, /*append=*/false); - FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset); - return ret; - } -} - - - -/**************************************************************************** - * - * Level 2 implementation - * - ***************************************************************************/ - - -typedef struct FLAC__Metadata_Node { - FLAC__StreamMetadata *data; - struct FLAC__Metadata_Node *prev, *next; -} FLAC__Metadata_Node; - -struct FLAC__Metadata_Chain { - char *filename; /* will be NULL if using callbacks */ - FLAC__bool is_ogg; - FLAC__Metadata_Node *head; - FLAC__Metadata_Node *tail; - uint32_t nodes; - FLAC__Metadata_ChainStatus status; - FLAC__off_t first_offset, last_offset; - /* - * This is the length of the chain initially read from the FLAC file. - * it is used to compare against the current length to decide whether - * or not the whole file has to be rewritten. - */ - FLAC__off_t initial_length; - /* @@@ hacky, these are currently only needed by ogg reader */ - FLAC__IOHandle handle; - FLAC__IOCallback_Read read_cb; -}; - -struct FLAC__Metadata_Iterator { - FLAC__Metadata_Chain *chain; - FLAC__Metadata_Node *current; -}; - -FLAC_API const char * const FLAC__Metadata_ChainStatusString[] = { - "FLAC__METADATA_CHAIN_STATUS_OK", - "FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT", - "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE", - "FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE", - "FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE", - "FLAC__METADATA_CHAIN_STATUS_BAD_METADATA", - "FLAC__METADATA_CHAIN_STATUS_READ_ERROR", - "FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR", - "FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR", - "FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR", - "FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR", - "FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR", - "FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR", - "FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS", - "FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", - "FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL" -}; - - -static FLAC__Metadata_Node *node_new_(void) -{ - return calloc(1, sizeof(FLAC__Metadata_Node)); -} - -static void node_delete_(FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != node); - if(0 != node->data) - FLAC__metadata_object_delete(node->data); - free(node); -} - -static void chain_init_(FLAC__Metadata_Chain *chain) -{ - FLAC__ASSERT(0 != chain); - - chain->filename = 0; - chain->is_ogg = false; - chain->head = chain->tail = 0; - chain->nodes = 0; - chain->status = FLAC__METADATA_CHAIN_STATUS_OK; - chain->initial_length = 0; - chain->read_cb = 0; -} - -static void chain_clear_(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_Node *node, *next; - - FLAC__ASSERT(0 != chain); - - for(node = chain->head; node; ) { - next = node->next; - node_delete_(node); - node = next; - } - - if(0 != chain->filename) - free(chain->filename); - - chain_init_(chain); -} - -static void chain_append_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != node); - FLAC__ASSERT(0 != node->data); - - node->next = node->prev = 0; - node->data->is_last = true; - if(0 != chain->tail) - chain->tail->data->is_last = false; - - if(0 == chain->head) - chain->head = node; - else { - FLAC__ASSERT(0 != chain->tail); - chain->tail->next = node; - node->prev = chain->tail; - } - chain->tail = node; - chain->nodes++; -} - -static void chain_remove_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != node); - - if(node == chain->head) - chain->head = node->next; - else - node->prev->next = node->next; - - if(node == chain->tail) - chain->tail = node->prev; - else - node->next->prev = node->prev; - - if(0 != chain->tail) - chain->tail->data->is_last = true; - - chain->nodes--; -} - -static void chain_delete_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - chain_remove_node_(chain, node); - node_delete_(node); -} - -static FLAC__off_t chain_calculate_length_(FLAC__Metadata_Chain *chain) -{ - const FLAC__Metadata_Node *node; - FLAC__off_t length = 0; - for(node = chain->head; node; node = node->next) - length += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length); - return length; -} - -static void iterator_insert_node_(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != node); - FLAC__ASSERT(0 != node->data); - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != iterator->chain); - FLAC__ASSERT(0 != iterator->chain->head); - FLAC__ASSERT(0 != iterator->chain->tail); - - node->data->is_last = false; - - node->prev = iterator->current->prev; - node->next = iterator->current; - - if(0 == node->prev) - iterator->chain->head = node; - else - node->prev->next = node; - - iterator->current->prev = node; - - iterator->chain->nodes++; -} - -static void iterator_insert_node_after_(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != node); - FLAC__ASSERT(0 != node->data); - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != iterator->chain); - FLAC__ASSERT(0 != iterator->chain->head); - FLAC__ASSERT(0 != iterator->chain->tail); - - iterator->current->data->is_last = false; - - node->prev = iterator->current; - node->next = iterator->current->next; - - if(0 == node->next) - iterator->chain->tail = node; - else - node->next->prev = node; - - node->prev->next = node; - - iterator->chain->tail->data->is_last = true; - - iterator->chain->nodes++; -} - -/* return true iff node and node->next are both padding */ -static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - if(node->data->type == FLAC__METADATA_TYPE_PADDING && 0 != node->next && node->next->data->type == FLAC__METADATA_TYPE_PADDING) { - const uint32_t growth = FLAC__STREAM_METADATA_HEADER_LENGTH + node->next->data->length; - node->data->length += growth; /* new block size can be greater than max metadata block size, but it'll be fixed later in chain_prepare_for_write_() */ - - chain_delete_node_(chain, node->next); - return true; - } - else - return false; -} - -/* Returns the new length of the chain, or 0 if there was an error. */ -/* WATCHOUT: This can get called multiple times before a write, so - * it should still work when this happens. - */ -/* WATCHOUT: Make sure to also update the logic in - * FLAC__metadata_chain_check_if_tempfile_needed() if the logic here changes. - */ -static FLAC__off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding) -{ - FLAC__off_t current_length = chain_calculate_length_(chain); - - if(use_padding) { - /* if the metadata shrank and the last block is padding, we just extend the last padding block */ - if(current_length < chain->initial_length && chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) { - const FLAC__off_t delta = chain->initial_length - current_length; - chain->tail->data->length += delta; - current_length += delta; - FLAC__ASSERT(current_length == chain->initial_length); - } - /* if the metadata shrank more than 4 bytes then there's room to add another padding block */ - else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) { - FLAC__StreamMetadata *padding; - FLAC__Metadata_Node *node; - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return 0; - } - padding->length = chain->initial_length - (FLAC__STREAM_METADATA_HEADER_LENGTH + current_length); - if(0 == (node = node_new_())) { - FLAC__metadata_object_delete(padding); - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return 0; - } - node->data = padding; - chain_append_node_(chain, node); - current_length = chain_calculate_length_(chain); - FLAC__ASSERT(current_length == chain->initial_length); - } - /* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */ - else if(current_length > chain->initial_length) { - const FLAC__off_t delta = current_length - chain->initial_length; - if(chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) { - /* if the delta is exactly the size of the last padding block, remove the padding block */ - if((FLAC__off_t)chain->tail->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) { - chain_delete_node_(chain, chain->tail); - current_length = chain_calculate_length_(chain); - FLAC__ASSERT(current_length == chain->initial_length); - } - /* if there is at least 'delta' bytes of padding, trim the padding down */ - else if((FLAC__off_t)chain->tail->data->length >= delta) { - chain->tail->data->length -= delta; - current_length -= delta; - FLAC__ASSERT(current_length == chain->initial_length); - } - } - } - } - - /* check sizes of all metadata blocks; reduce padding size if necessary */ - { - FLAC__Metadata_Node *node; - for (node = chain->head; node; node = node->next) { - if(node->data->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) { - if(node->data->type == FLAC__METADATA_TYPE_PADDING) { - node->data->length = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1; - current_length = chain_calculate_length_(chain); - } else { - chain->status = FLAC__METADATA_CHAIN_STATUS_BAD_METADATA; - return 0; - } - } - } - } - - return current_length; -} - -static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Tell tell_cb) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - - /* we assume we're already at the beginning of the file */ - - switch(seek_to_first_metadata_block_cb_(handle, read_cb, seek_cb)) { - case 0: - break; - case 1: - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - case 2: - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - case 3: - chain->status = FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE; - return false; - default: - FLAC__ASSERT(0); - return false; - } - - { - FLAC__int64 pos = tell_cb(handle); - if(pos < 0) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - } - chain->first_offset = (FLAC__off_t)pos; - } - - { - FLAC__bool is_last; - FLAC__MetadataType type; - uint32_t length; - - do { - node = node_new_(); - if(0 == node) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - if(!read_metadata_block_header_cb_(handle, read_cb, &is_last, &type, &length)) { - node_delete_(node); - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - } - - node->data = FLAC__metadata_object_new(type); - if(0 == node->data) { - node_delete_(node); - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - node->data->is_last = is_last; - node->data->length = length; - - chain->status = get_equivalent_status_(read_metadata_block_data_cb_(handle, read_cb, seek_cb, node->data)); - if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) { - node_delete_(node); - return false; - } - chain_append_node_(chain, node); - } while(!is_last); - } - - { - FLAC__int64 pos = tell_cb(handle); - if(pos < 0) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - } - chain->last_offset = (FLAC__off_t)pos; - } - - chain->initial_length = chain_calculate_length_(chain); - - return true; -} - -static FLAC__StreamDecoderReadStatus chain_read_ogg_read_cb_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data; - (void)decoder; - if(*bytes > 0 && chain->status == FLAC__METADATA_CHAIN_STATUS_OK) { - *bytes = chain->read_cb(buffer, sizeof(FLAC__byte), *bytes, chain->handle); - if(*bytes == 0) - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; -} - -static FLAC__StreamDecoderWriteStatus chain_read_ogg_write_cb_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - (void)decoder, (void)frame, (void)buffer, (void)client_data; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; -} - -static void chain_read_ogg_metadata_cb_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data; - FLAC__Metadata_Node *node; - - (void)decoder; - - node = node_new_(); - if(0 == node) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return; - } - - node->data = FLAC__metadata_object_clone(metadata); - if(0 == node->data) { - node_delete_(node); - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return; - } - - chain_append_node_(chain, node); -} - -static void chain_read_ogg_error_cb_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data; - (void)decoder, (void)status; - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */ -} - -static FLAC__bool chain_read_ogg_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb) -{ - FLAC__StreamDecoder *decoder; - - FLAC__ASSERT(0 != chain); - - /* we assume we're already at the beginning of the file */ - - chain->handle = handle; - chain->read_cb = read_cb; - if(0 == (decoder = FLAC__stream_decoder_new())) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - FLAC__stream_decoder_set_metadata_respond_all(decoder); - if(FLAC__stream_decoder_init_ogg_stream(decoder, chain_read_ogg_read_cb_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, chain_read_ogg_write_cb_, chain_read_ogg_metadata_cb_, chain_read_ogg_error_cb_, chain) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - FLAC__stream_decoder_delete(decoder); - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */ - return false; - } - - chain->first_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */ - - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */ - if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) { - FLAC__stream_decoder_delete(decoder); - return false; - } - - FLAC__stream_decoder_delete(decoder); - - chain->last_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */ - - chain->initial_length = chain_calculate_length_(chain); - - return true; -} - -static FLAC__bool chain_rewrite_metadata_in_place_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, FLAC__IOCallback_Seek seek_cb) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != chain->head); - - if(0 != seek_cb(handle, chain->first_offset, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - - for(node = chain->head; node; node = node->next) { - if(!write_metadata_block_header_cb_(handle, write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - if(!write_metadata_block_data_cb_(handle, write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - } - - /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ - - chain->status = FLAC__METADATA_CHAIN_STATUS_OK; - return true; -} - -static FLAC__bool chain_rewrite_metadata_in_place_(FLAC__Metadata_Chain *chain) -{ - FILE *file; - FLAC__bool ret; - - FLAC__ASSERT(0 != chain->filename); - - if(0 == (file = flac_fopen(chain->filename, "r+b"))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - return false; - } - - /* chain_rewrite_metadata_in_place_cb_() sets chain->status for us */ - ret = chain_rewrite_metadata_in_place_cb_(chain, (FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, fseek_wrapper_); - - fclose(file); - - return ret; -} - -static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *tempfile_path_prefix) -{ - FILE *f, *tempfile = NULL; - char *tempfilename; - FLAC__Metadata_SimpleIteratorStatus status; - const FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != chain->filename); - FLAC__ASSERT(0 != chain->head); - - /* copy the file prefix (data up to first metadata block */ - if(0 == (f = flac_fopen(chain->filename, "rb"))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - return false; - } - if(!open_tempfile_(chain->filename, tempfile_path_prefix, &tempfile, &tempfilename, &status)) { - chain->status = get_equivalent_status_(status); - goto err; - } - if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) { - chain->status = get_equivalent_status_(status); - goto err; - } - - /* write the metadata */ - for(node = chain->head; node; node = node->next) { - if(!write_metadata_block_header_(tempfile, &status, node->data)) { - chain->status = get_equivalent_status_(status); - goto err; - } - if(!write_metadata_block_data_(tempfile, &status, node->data)) { - chain->status = get_equivalent_status_(status); - goto err; - } - } - /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ - - /* copy the file postfix (everything after the metadata) */ - if(0 != fseeko(f, chain->last_offset, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - goto err; - } - if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) { - chain->status = get_equivalent_status_(status); - goto err; - } - - /* move the tempfile on top of the original */ - (void)fclose(f); - if(!transport_tempfile_(chain->filename, &tempfile, &tempfilename, &status)) - return false; - - return true; - -err: - (void)fclose(f); - cleanup_tempfile_(&tempfile, &tempfilename); - return false; -} - -/* assumes 'handle' is already at beginning of file */ -static FLAC__bool chain_rewrite_file_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb) -{ - FLAC__Metadata_SimpleIteratorStatus status; - const FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 == chain->filename); - FLAC__ASSERT(0 != chain->head); - - /* copy the file prefix (data up to first metadata block */ - if(!copy_n_bytes_from_file_cb_(handle, read_cb, temp_handle, temp_write_cb, chain->first_offset, &status)) { - chain->status = get_equivalent_status_(status); - return false; - } - - /* write the metadata */ - for(node = chain->head; node; node = node->next) { - if(!write_metadata_block_header_cb_(temp_handle, temp_write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - if(!write_metadata_block_data_cb_(temp_handle, temp_write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - } - /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ - - /* copy the file postfix (everything after the metadata) */ - if(0 != seek_cb(handle, chain->last_offset, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - if(!copy_remaining_bytes_from_file_cb_(handle, read_cb, eof_cb, temp_handle, temp_write_cb, &status)) { - chain->status = get_equivalent_status_(status); - return false; - } - - return true; -} - -FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void) -{ - FLAC__Metadata_Chain *chain = calloc(1, sizeof(FLAC__Metadata_Chain)); - - if(0 != chain) - chain_init_(chain); - - return chain; -} - -FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain) -{ - FLAC__ASSERT(0 != chain); - - chain_clear_(chain); - - free(chain); -} - -FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_ChainStatus status; - - FLAC__ASSERT(0 != chain); - - status = chain->status; - chain->status = FLAC__METADATA_CHAIN_STATUS_OK; - return status; -} - -static FLAC__bool chain_read_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool is_ogg) -{ - FILE *file; - FLAC__bool ret; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != filename); - - chain_clear_(chain); - - if(0 == (chain->filename = strdup(filename))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - chain->is_ogg = is_ogg; - - if(0 == (file = flac_fopen(filename, "rb"))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - return false; - } - - /* the function also sets chain->status for us */ - ret = is_ogg? - chain_read_ogg_cb_(chain, file, (FLAC__IOCallback_Read)fread) : - chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_) - ; - - fclose(file); - - return ret; -} - -FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename) -{ - return chain_read_(chain, filename, /*is_ogg=*/false); -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename) -{ - return chain_read_(chain, filename, /*is_ogg=*/true); -} - -static FLAC__bool chain_read_with_callbacks_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__bool is_ogg) -{ - FLAC__bool ret; - - FLAC__ASSERT(0 != chain); - - chain_clear_(chain); - - if (0 == callbacks.read || 0 == callbacks.seek || 0 == callbacks.tell) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - - chain->is_ogg = is_ogg; - - /* rewind */ - if(0 != callbacks.seek(handle, 0, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - - /* the function also sets chain->status for us */ - ret = is_ogg? - chain_read_ogg_cb_(chain, handle, callbacks.read) : - chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell) - ; - - return ret; -} - -FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks) -{ - return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/false); -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks) -{ - return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/true); -} - -typedef enum { - LBS_NONE = 0, - LBS_SIZE_CHANGED, - LBS_BLOCK_ADDED, - LBS_BLOCK_REMOVED -} LastBlockState; - -FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding) -{ - /* This does all the same checks that are in chain_prepare_for_write_() - * but doesn't actually alter the chain. Make sure to update the logic - * here if chain_prepare_for_write_() changes. - */ - FLAC__off_t current_length; - LastBlockState lbs_state = LBS_NONE; - uint32_t lbs_size = 0; - - FLAC__ASSERT(0 != chain); - - current_length = chain_calculate_length_(chain); - - if(use_padding) { - const FLAC__Metadata_Node * const node = chain->tail; - /* if the metadata shrank and the last block is padding, we just extend the last padding block */ - if(current_length < chain->initial_length && node->data->type == FLAC__METADATA_TYPE_PADDING) { - lbs_state = LBS_SIZE_CHANGED; - lbs_size = node->data->length + (chain->initial_length - current_length); - } - /* if the metadata shrank more than 4 bytes then there's room to add another padding block */ - else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) { - lbs_state = LBS_BLOCK_ADDED; - lbs_size = chain->initial_length - (current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - } - /* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */ - else if(current_length > chain->initial_length) { - const FLAC__off_t delta = current_length - chain->initial_length; - if(node->data->type == FLAC__METADATA_TYPE_PADDING) { - /* if the delta is exactly the size of the last padding block, remove the padding block */ - if((FLAC__off_t)node->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) { - lbs_state = LBS_BLOCK_REMOVED; - lbs_size = 0; - } - /* if there is at least 'delta' bytes of padding, trim the padding down */ - else if((FLAC__off_t)node->data->length >= delta) { - lbs_state = LBS_SIZE_CHANGED; - lbs_size = node->data->length - delta; - } - } - } - } - - current_length = 0; - /* check sizes of all metadata blocks; reduce padding size if necessary */ - { - const FLAC__Metadata_Node *node; - for(node = chain->head; node; node = node->next) { - uint32_t block_len = node->data->length; - if(node == chain->tail) { - if(lbs_state == LBS_BLOCK_REMOVED) - continue; - else if(lbs_state == LBS_SIZE_CHANGED) - block_len = lbs_size; - } - if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) { - if(node->data->type == FLAC__METADATA_TYPE_PADDING) - block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1; - else - return false /* the return value doesn't matter */; - } - current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len); - } - - if(lbs_state == LBS_BLOCK_ADDED) { - /* test added padding block */ - uint32_t block_len = lbs_size; - if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1; - current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len); - } - } - - return (current_length != chain->initial_length); -} - -FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats) -{ - struct flac_stat_s stats; - const char *tempfile_path_prefix = 0; - FLAC__off_t current_length; - - FLAC__ASSERT(0 != chain); - - if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */ - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - return false; - } - - if (0 == chain->filename) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH; - return false; - } - - current_length = chain_prepare_for_write_(chain, use_padding); - - /* a return value of 0 means there was an error; chain->status is already set */ - if (0 == current_length) - return false; - - if(preserve_file_stats) - get_file_stats_(chain->filename, &stats); - - if(current_length == chain->initial_length) { - if(!chain_rewrite_metadata_in_place_(chain)) - return false; - } - else { - if(!chain_rewrite_file_(chain, tempfile_path_prefix)) - return false; - - /* recompute lengths and offsets */ - { - const FLAC__Metadata_Node *node; - chain->initial_length = current_length; - chain->last_offset = chain->first_offset; - for(node = chain->head; node; node = node->next) - chain->last_offset += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length); - } - } - - if(preserve_file_stats) - set_file_stats_(chain->filename, &stats); - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks) -{ - FLAC__off_t current_length; - - FLAC__ASSERT(0 != chain); - - if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */ - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - return false; - } - - if (0 != chain->filename) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH; - return false; - } - - if (0 == callbacks.write || 0 == callbacks.seek) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - - if (FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL; - return false; - } - - current_length = chain_prepare_for_write_(chain, use_padding); - - /* a return value of 0 means there was an error; chain->status is already set */ - if (0 == current_length) - return false; - - FLAC__ASSERT(current_length == chain->initial_length); - - return chain_rewrite_metadata_in_place_cb_(chain, handle, callbacks.write, callbacks.seek); -} - -FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks) -{ - FLAC__off_t current_length; - - FLAC__ASSERT(0 != chain); - - if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */ - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - return false; - } - - if (0 != chain->filename) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH; - return false; - } - - if (0 == callbacks.read || 0 == callbacks.seek || 0 == callbacks.eof) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - if (0 == temp_callbacks.write) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - - if (!FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL; - return false; - } - - current_length = chain_prepare_for_write_(chain, use_padding); - - /* a return value of 0 means there was an error; chain->status is already set */ - if (0 == current_length) - return false; - - FLAC__ASSERT(current_length != chain->initial_length); - - /* rewind */ - if(0 != callbacks.seek(handle, 0, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - - if(!chain_rewrite_file_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.eof, temp_handle, temp_callbacks.write)) - return false; - - /* recompute lengths and offsets */ - { - const FLAC__Metadata_Node *node; - chain->initial_length = current_length; - chain->last_offset = chain->first_offset; - for(node = chain->head; node; node = node->next) - chain->last_offset += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length); - } - - return true; -} - -FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - - for(node = chain->head; node; ) { - if(!chain_merge_adjacent_padding_(chain, node)) - node = node->next; - } -} - -FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_Node *node, *save; - uint32_t i; - - FLAC__ASSERT(0 != chain); - - /* - * Don't try and be too smart... this simple algo is good enough for - * the small number of nodes that we deal with. - */ - for(i = 0, node = chain->head; i < chain->nodes; i++) { - if(node->data->type == FLAC__METADATA_TYPE_PADDING) { - save = node->next; - chain_remove_node_(chain, node); - chain_append_node_(chain, node); - node = save; - } - else { - node = node->next; - } - } - - FLAC__metadata_chain_merge_padding(chain); -} - - -FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void) -{ - FLAC__Metadata_Iterator *iterator = calloc(1, sizeof(FLAC__Metadata_Iterator)); - - /* calloc() implies: - iterator->current = 0; - iterator->chain = 0; - */ - - return iterator; -} - -FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - free(iterator); -} - -FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != chain->head); - - iterator->chain = chain; - iterator->current = chain->head; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - if(0 == iterator->current || 0 == iterator->current->next) - return false; - - iterator->current = iterator->current->next; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - if(0 == iterator->current || 0 == iterator->current->prev) - return false; - - iterator->current = iterator->current->prev; - return true; -} - -FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != iterator->current->data); - - return iterator->current->data->type; -} - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - - return iterator->current->data; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != block); - return FLAC__metadata_iterator_delete_block(iterator, false) && FLAC__metadata_iterator_insert_block_after(iterator, block); -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding) -{ - FLAC__Metadata_Node *save; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - - if(0 == iterator->current->prev) { - FLAC__ASSERT(iterator->current->data->type == FLAC__METADATA_TYPE_STREAMINFO); - return false; - } - - save = iterator->current->prev; - - if(replace_with_padding) { - FLAC__metadata_object_delete_data(iterator->current->data); - iterator->current->data->type = FLAC__METADATA_TYPE_PADDING; - } - else { - chain_delete_node_(iterator->chain, iterator->current); - } - - iterator->current = save; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != block); - - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) - return false; - - if(0 == iterator->current->prev) { - FLAC__ASSERT(iterator->current->data->type == FLAC__METADATA_TYPE_STREAMINFO); - return false; - } - - if(0 == (node = node_new_())) - return false; - - node->data = block; - iterator_insert_node_(iterator, node); - iterator->current = node; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != block); - - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) - return false; - - if(0 == (node = node_new_())) - return false; - - node->data = block; - iterator_insert_node_after_(iterator, node); - iterator->current = node; - return true; -} - - -/**************************************************************************** - * - * Local function definitions - * - ***************************************************************************/ - -void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes) -{ - uint32_t i; - - b += bytes; - - for(i = 0; i < bytes; i++) { - *(--b) = (FLAC__byte)(val & 0xff); - val >>= 8; - } -} - -void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes) -{ - uint32_t i; - - for(i = 0; i < bytes; i++) { - *(b++) = (FLAC__byte)(val & 0xff); - val >>= 8; - } -} - -void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, uint32_t bytes) -{ - uint32_t i; - - b += bytes; - - for(i = 0; i < bytes; i++) { - *(--b) = (FLAC__byte)(val & 0xff); - val >>= 8; - } -} - -FLAC__uint32 unpack_uint32_(FLAC__byte *b, uint32_t bytes) -{ - FLAC__uint32 ret = 0; - uint32_t i; - - for(i = 0; i < bytes; i++) - ret = (ret << 8) | (FLAC__uint32)(*b++); - - return ret; -} - -FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, uint32_t bytes) -{ - FLAC__uint32 ret = 0; - uint32_t i; - - b += bytes; - - for(i = 0; i < bytes; i++) - ret = (ret << 8) | (FLAC__uint32)(*--b); - - return ret; -} - -FLAC__uint64 unpack_uint64_(FLAC__byte *b, uint32_t bytes) -{ - FLAC__uint64 ret = 0; - uint32_t i; - - for(i = 0; i < bytes; i++) - ret = (ret << 8) | (FLAC__uint64)(*b++); - - return ret; -} - -FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - if(!read_metadata_block_header_cb_((FLAC__IOHandle)iterator->file, (FLAC__IOCallback_Read)fread, &iterator->is_last, &iterator->type, &iterator->length)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - - return true; -} - -FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - iterator->status = read_metadata_block_data_cb_((FLAC__IOHandle)iterator->file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, block); - - return (iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); -} - -FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, uint32_t *length) -{ - FLAC__byte raw_header[FLAC__STREAM_METADATA_HEADER_LENGTH]; - - if(read_cb(raw_header, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, handle) != FLAC__STREAM_METADATA_HEADER_LENGTH) - return false; - - *is_last = raw_header[0] & 0x80? true : false; - *type = (FLAC__MetadataType)(raw_header[0] & 0x7f); - *length = unpack_uint32_(raw_header + 1, 3); - - /* Note that we don't check: - * if(iterator->type >= FLAC__METADATA_TYPE_UNDEFINED) - * we just will read in an opaque block - */ - - return true; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block) -{ - switch(block->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return read_metadata_block_data_streaminfo_cb_(handle, read_cb, &block->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return read_metadata_block_data_padding_cb_(handle, seek_cb, &block->data.padding, block->length); - case FLAC__METADATA_TYPE_APPLICATION: - return read_metadata_block_data_application_cb_(handle, read_cb, &block->data.application, block->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return read_metadata_block_data_seektable_cb_(handle, read_cb, &block->data.seek_table, block->length); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return read_metadata_block_data_vorbis_comment_cb_(handle, read_cb, seek_cb, &block->data.vorbis_comment, block->length); - case FLAC__METADATA_TYPE_CUESHEET: - return read_metadata_block_data_cuesheet_cb_(handle, read_cb, &block->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return read_metadata_block_data_picture_cb_(handle, read_cb, &block->data.picture); - default: - return read_metadata_block_data_unknown_cb_(handle, read_cb, &block->data.unknown, block->length); - } -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block) -{ - FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH], *b; - - if(read_cb(buffer, 1, FLAC__STREAM_METADATA_STREAMINFO_LENGTH, handle) != FLAC__STREAM_METADATA_STREAMINFO_LENGTH) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - b = buffer; - - /* we are using hardcoded numbers for simplicity but we should - * probably eventually write a bit-level unpacker and use the - * _STREAMINFO_ constants. - */ - block->min_blocksize = unpack_uint32_(b, 2); b += 2; - block->max_blocksize = unpack_uint32_(b, 2); b += 2; - block->min_framesize = unpack_uint32_(b, 3); b += 3; - block->max_framesize = unpack_uint32_(b, 3); b += 3; - block->sample_rate = (unpack_uint32_(b, 2) << 4) | ((uint32_t)(b[2] & 0xf0) >> 4); - block->channels = (uint32_t)((b[2] & 0x0e) >> 1) + 1; - block->bits_per_sample = ((((uint32_t)(b[2] & 0x01)) << 4) | (((uint32_t)(b[3] & 0xf0)) >> 4)) + 1; - block->total_samples = (((FLAC__uint64)(b[3] & 0x0f)) << 32) | unpack_uint64_(b+4, 4); - memcpy(block->md5sum, b+8, 16); - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, uint32_t block_length) -{ - (void)block; /* nothing to do; we don't care about reading the padding bytes */ - - if(0 != seek_cb(handle, block_length, SEEK_CUR)) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, uint32_t block_length) -{ - const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - - if(read_cb(block->id, 1, id_bytes, handle) != id_bytes) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - if(block_length < id_bytes) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - block_length -= id_bytes; - - if(block_length == 0) { - block->data = 0; - } - else { - if(0 == (block->data = malloc(block_length))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(read_cb(block->data, 1, block_length, handle) != block_length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, uint32_t block_length) -{ - uint32_t i; - FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH]; - - FLAC__ASSERT(block_length % FLAC__STREAM_METADATA_SEEKPOINT_LENGTH == 0); - - block->num_points = block_length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - - if(block->num_points == 0) - block->points = 0; - else if(0 == (block->points = safe_malloc_mul_2op_p(block->num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - for(i = 0; i < block->num_points; i++) { - if(read_cb(buffer, 1, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH, handle) != FLAC__STREAM_METADATA_SEEKPOINT_LENGTH) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - /* some MAGIC NUMBERs here */ - block->points[i].sample_number = unpack_uint64_(buffer, 8); - block->points[i].stream_offset = unpack_uint64_(buffer+8, 8); - block->points[i].frame_samples = unpack_uint32_(buffer+16, 2); - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, uint32_t max_length) -{ - const uint32_t entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8 == sizeof(buffer)); - - if(max_length < entry_length_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - - max_length -= entry_length_len; - if(read_cb(buffer, 1, entry_length_len, handle) != entry_length_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - entry->length = unpack_uint32_little_endian_(buffer, entry_length_len); - if(max_length < entry->length) { - entry->length = 0; - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - } else max_length -= entry->length; - - if(0 != entry->entry) - free(entry->entry); - - if(entry->length == 0) { - entry->entry = 0; - } - else { - if(0 == (entry->entry = safe_malloc_add_2op_(entry->length, /*+*/1))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(read_cb(entry->entry, 1, entry->length, handle) != entry->length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - entry->entry[entry->length] = '\0'; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, uint32_t block_length) -{ - uint32_t i; - FLAC__Metadata_SimpleIteratorStatus status; - const uint32_t num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8 == sizeof(buffer)); - - status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, &(block->vendor_string), block_length); - if(block_length >= 4) - block_length -= 4; - if(status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA) - goto skip; - else if(status != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - block_length -= block->vendor_string.length; - - if(block_length < num_comments_len) goto skip; else block_length -= num_comments_len; - if(read_cb(buffer, 1, num_comments_len, handle) != num_comments_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->num_comments = unpack_uint32_little_endian_(buffer, num_comments_len); - - if(block->num_comments == 0) { - block->comments = 0; - } - else if(0 == (block->comments = calloc(block->num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) { - block->num_comments = 0; - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - } - - for(i = 0; i < block->num_comments; i++) { - status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, block->comments + i, block_length); - if(block_length >= 4) block_length -= 4; - if(status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA) { - block->num_comments = i; - goto skip; - } - else if(status != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) return status; - block_length -= block->comments[i].length; - } - - skip: - if(block_length > 0) { - /* bad metadata */ - if(0 != seek_cb(handle, block_length, SEEK_CUR)) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track) -{ - uint32_t i, len; - FLAC__byte buffer[32]; /* asserted below that this is big enough */ - - FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64)); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->offset = unpack_uint64_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->number = (FLAC__byte)unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8; - if(read_cb(track->isrc, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN == 1); - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN == 1); - track->type = buffer[0] >> 7; - track->pre_emphasis = (buffer[0] >> 6) & 1; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->num_indices = (FLAC__byte)unpack_uint32_(buffer, len); - - if(track->num_indices == 0) { - track->indices = 0; - } - else if(0 == (track->indices = calloc(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - for(i = 0; i < track->num_indices; i++) { - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->indices[i].offset = unpack_uint64_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->indices[i].number = (FLAC__byte)unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block) -{ - uint32_t i, len; - FLAC__Metadata_SimpleIteratorStatus status; - FLAC__byte buffer[1024]; /* MSVC needs a constant expression so we put a magic number and assert */ - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN)/8 <= sizeof(buffer)); - FLAC__ASSERT(sizeof(FLAC__uint64) <= sizeof(buffer)); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8; - if(read_cb(block->media_catalog_number, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->lead_in = unpack_uint64_(buffer, len); - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->is_cd = buffer[0]&0x80? true : false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->num_tracks = unpack_uint32_(buffer, len); - - if(block->num_tracks == 0) { - block->tracks = 0; - } - else if(0 == (block->tracks = calloc(block->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - for(i = 0; i < block->num_tracks; i++) { - if(FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK != (status = read_metadata_block_data_cuesheet_track_cb_(handle, read_cb, block->tracks + i))) - return status; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cstring_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__byte **data, FLAC__uint32 *length, FLAC__uint32 length_len) -{ - FLAC__byte buffer[sizeof(FLAC__uint32)]; - - FLAC__ASSERT(0 != data); - FLAC__ASSERT(length_len%8 == 0); - - length_len /= 8; /* convert to bytes */ - - FLAC__ASSERT(sizeof(buffer) >= length_len); - - if(read_cb(buffer, 1, length_len, handle) != length_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - *length = unpack_uint32_(buffer, length_len); - - if(0 != *data) - free(*data); - - if(0 == (*data = safe_malloc_add_2op_(*length, /*+*/1))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(*length > 0) { - if(read_cb(*data, 1, *length, handle) != *length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - (*data)[*length] = '\0'; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block) -{ - FLAC__Metadata_SimpleIteratorStatus status; - FLAC__byte buffer[4]; /* asserted below that this is big enough */ - FLAC__uint32 len; - - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_TYPE_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->type = (FLAC__StreamMetadata_Picture_Type)unpack_uint32_(buffer, len); - - if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, (FLAC__byte**)(&(block->mime_type)), &len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - - if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->description), &len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->width = unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->height = unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->depth = unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_COLORS_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->colors = unpack_uint32_(buffer, len); - - /* for convenience we use read_metadata_block_data_picture_cstring_cb_() even though it adds an extra terminating NUL we don't use */ - if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->data), &(block->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, uint32_t block_length) -{ - if(block_length == 0) { - block->data = 0; - } - else { - if(0 == (block->data = malloc(block_length))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(read_cb(block->data, 1, block_length, handle) != block_length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != file); - FLAC__ASSERT(0 != status); - - if(!write_metadata_block_header_cb_((FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, block)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - - return true; -} - -FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != file); - FLAC__ASSERT(0 != status); - - if (write_metadata_block_data_cb_((FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, block)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; - return true; - } - else { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } -} - -FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block) -{ - FLAC__byte buffer[FLAC__STREAM_METADATA_HEADER_LENGTH]; - - FLAC__ASSERT(block->length < (1u << FLAC__STREAM_METADATA_LENGTH_LEN)); - /* double protection */ - if(block->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; - - buffer[0] = (block->is_last? 0x80 : 0) | (FLAC__byte)block->type; - pack_uint32_(block->length, buffer + 1, 3); - - if(write_cb(buffer, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, handle) != FLAC__STREAM_METADATA_HEADER_LENGTH) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != block); - - switch(block->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return write_metadata_block_data_streaminfo_cb_(handle, write_cb, &block->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return write_metadata_block_data_padding_cb_(handle, write_cb, &block->data.padding, block->length); - case FLAC__METADATA_TYPE_APPLICATION: - return write_metadata_block_data_application_cb_(handle, write_cb, &block->data.application, block->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return write_metadata_block_data_seektable_cb_(handle, write_cb, &block->data.seek_table); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return write_metadata_block_data_vorbis_comment_cb_(handle, write_cb, &block->data.vorbis_comment); - case FLAC__METADATA_TYPE_CUESHEET: - return write_metadata_block_data_cuesheet_cb_(handle, write_cb, &block->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return write_metadata_block_data_picture_cb_(handle, write_cb, &block->data.picture); - default: - return write_metadata_block_data_unknown_cb_(handle, write_cb, &block->data.unknown, block->length); - } -} - -FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block) -{ - FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH]; - const uint32_t channels1 = block->channels - 1; - const uint32_t bps1 = block->bits_per_sample - 1; - - /* we are using hardcoded numbers for simplicity but we should - * probably eventually write a bit-level packer and use the - * _STREAMINFO_ constants. - */ - pack_uint32_(block->min_blocksize, buffer, 2); - pack_uint32_(block->max_blocksize, buffer+2, 2); - pack_uint32_(block->min_framesize, buffer+4, 3); - pack_uint32_(block->max_framesize, buffer+7, 3); - buffer[10] = (block->sample_rate >> 12) & 0xff; - buffer[11] = (block->sample_rate >> 4) & 0xff; - buffer[12] = ((block->sample_rate & 0x0f) << 4) | (channels1 << 1) | (bps1 >> 4); - buffer[13] = (FLAC__byte)(((bps1 & 0x0f) << 4) | ((block->total_samples >> 32) & 0x0f)); - pack_uint32_((FLAC__uint32)block->total_samples, buffer+14, 4); - memcpy(buffer+18, block->md5sum, 16); - - if(write_cb(buffer, 1, FLAC__STREAM_METADATA_STREAMINFO_LENGTH, handle) != FLAC__STREAM_METADATA_STREAMINFO_LENGTH) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, uint32_t block_length) -{ - uint32_t i, n = block_length; - FLAC__byte buffer[1024]; - - (void)block; - - memset(buffer, 0, 1024); - - for(i = 0; i < n/1024; i++) - if(write_cb(buffer, 1, 1024, handle) != 1024) - return false; - - n %= 1024; - - if(write_cb(buffer, 1, n, handle) != n) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, uint32_t block_length) -{ - const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - - if(write_cb(block->id, 1, id_bytes, handle) != id_bytes) - return false; - - block_length -= id_bytes; - - if(write_cb(block->data, 1, block_length, handle) != block_length) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block) -{ - uint32_t i; - FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH]; - - for(i = 0; i < block->num_points; i++) { - /* some MAGIC NUMBERs here */ - pack_uint64_(block->points[i].sample_number, buffer, 8); - pack_uint64_(block->points[i].stream_offset, buffer+8, 8); - pack_uint32_(block->points[i].frame_samples, buffer+16, 2); - if(write_cb(buffer, 1, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH, handle) != FLAC__STREAM_METADATA_SEEKPOINT_LENGTH) - return false; - } - - return true; -} - -FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block) -{ - uint32_t i; - const uint32_t entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8; - const uint32_t num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(flac_max(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN, FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8 == sizeof(buffer)); - - pack_uint32_little_endian_(block->vendor_string.length, buffer, entry_length_len); - if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len) - return false; - if(write_cb(block->vendor_string.entry, 1, block->vendor_string.length, handle) != block->vendor_string.length) - return false; - - pack_uint32_little_endian_(block->num_comments, buffer, num_comments_len); - if(write_cb(buffer, 1, num_comments_len, handle) != num_comments_len) - return false; - - for(i = 0; i < block->num_comments; i++) { - pack_uint32_little_endian_(block->comments[i].length, buffer, entry_length_len); - if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len) - return false; - if(write_cb(block->comments[i].entry, 1, block->comments[i].length, handle) != block->comments[i].length) - return false; - } - - return true; -} - -FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block) -{ - uint32_t i, j, len; - FLAC__byte buffer[1024]; /* asserted below that this is big enough */ - - FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64)); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8; - if(write_cb(block->media_catalog_number, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8; - pack_uint64_(block->lead_in, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) / 8; - memset(buffer, 0, len); - if(block->is_cd) - buffer[0] |= 0x80; - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8; - pack_uint32_(block->num_tracks, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - for(i = 0; i < block->num_tracks; i++) { - FLAC__StreamMetadata_CueSheet_Track *track = block->tracks + i; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8; - pack_uint64_(track->offset, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8; - pack_uint32_(track->number, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8; - if(write_cb(track->isrc, 1, len, handle) != len) - return false; - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8; - memset(buffer, 0, len); - buffer[0] = (track->type << 7) | (track->pre_emphasis << 6); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8; - pack_uint32_(track->num_indices, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - for(j = 0; j < track->num_indices; j++) { - FLAC__StreamMetadata_CueSheet_Index *indx = track->indices + j; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8; - pack_uint64_(indx->offset, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8; - pack_uint32_(indx->number, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8; - memset(buffer, 0, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - } - } - - return true; -} - -FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block) -{ - uint32_t len; - size_t slen; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_TYPE_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_COLORS_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN%8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8); - - len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8; - pack_uint32_(block->type, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8; - slen = strlen(block->mime_type); - pack_uint32_(slen, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - if(write_cb(block->mime_type, 1, slen, handle) != slen) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN/8; - slen = strlen((const char *)block->description); - pack_uint32_(slen, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - if(write_cb(block->description, 1, slen, handle) != slen) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8; - pack_uint32_(block->width, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8; - pack_uint32_(block->height, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8; - pack_uint32_(block->depth, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8; - pack_uint32_(block->colors, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8; - pack_uint32_(block->data_length, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - if(write_cb(block->data, 1, block->data_length, handle) != block->data_length) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, uint32_t block_length) -{ - if(write_cb(block->data, 1, block_length, handle) != block_length) - return false; - - return true; -} - -FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block) -{ - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - if(!write_metadata_block_header_(iterator->file, &iterator->status, block)) - return false; - - if(!write_metadata_block_data_(iterator->file, &iterator->status, block)) - return false; - - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return read_metadata_block_header_(iterator); -} - -FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, uint32_t padding_length, FLAC__bool padding_is_last) -{ - FLAC__StreamMetadata *padding; - - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - block->is_last = false; - - if(!write_metadata_block_header_(iterator->file, &iterator->status, block)) - return false; - - if(!write_metadata_block_data_(iterator->file, &iterator->status, block)) - return false; - - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - padding->is_last = padding_is_last; - padding->length = padding_length; - - if(!write_metadata_block_header_(iterator->file, &iterator->status, padding)) { - FLAC__metadata_object_delete(padding); - return false; - } - - if(!write_metadata_block_data_(iterator->file, &iterator->status, padding)) { - FLAC__metadata_object_delete(padding); - return false; - } - - FLAC__metadata_object_delete(padding); - - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return read_metadata_block_header_(iterator); -} - -FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append) -{ - FILE *tempfile = NULL; - char *tempfilename = NULL; - int fixup_is_last_code = 0; /* 0 => no need to change any is_last flags */ - FLAC__off_t fixup_is_last_flag_offset = -1; - - FLAC__ASSERT(0 != block || append == false); - - if(iterator->is_last) { - if(append) { - fixup_is_last_code = 1; /* 1 => clear the is_last flag at the following offset */ - fixup_is_last_flag_offset = iterator->offset[iterator->depth]; - } - else if(0 == block) { - simple_iterator_push_(iterator); - if(!FLAC__metadata_simple_iterator_prev(iterator)) { - (void)simple_iterator_pop_(iterator); - return false; - } - fixup_is_last_code = -1; /* -1 => set the is_last the flag at the following offset */ - fixup_is_last_flag_offset = iterator->offset[iterator->depth]; - if(!simple_iterator_pop_(iterator)) - return false; - } - } - - if(!simple_iterator_copy_file_prefix_(iterator, &tempfile, &tempfilename, append)) - return false; - - if(0 != block) { - if(!write_metadata_block_header_(tempfile, &iterator->status, block)) { - cleanup_tempfile_(&tempfile, &tempfilename); - return false; - } - - if(!write_metadata_block_data_(tempfile, &iterator->status, block)) { - cleanup_tempfile_(&tempfile, &tempfilename); - return false; - } - } - - if(!simple_iterator_copy_file_postfix_(iterator, &tempfile, &tempfilename, fixup_is_last_code, fixup_is_last_flag_offset, block==0)) - return false; - - if(append) - return FLAC__metadata_simple_iterator_next(iterator); - - return true; -} - -void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(iterator->depth+1 < SIMPLE_ITERATOR_MAX_PUSH_DEPTH); - iterator->offset[iterator->depth+1] = iterator->offset[iterator->depth]; - iterator->depth++; -} - -FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(iterator->depth > 0); - iterator->depth--; - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return read_metadata_block_header_(iterator); -} - -/* return meanings: - * 0: ok - * 1: read error - * 2: seek error - * 3: not a FLAC file - */ -uint32_t seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb) -{ - FLAC__byte buffer[4]; - size_t n; - uint32_t i; - - FLAC__ASSERT(FLAC__STREAM_SYNC_LENGTH == sizeof(buffer)); - - /* skip any id3v2 tag */ - errno = 0; - n = read_cb(buffer, 1, 4, handle); - if(errno) - return 1; - else if(n != 4) - return 3; - else if(0 == memcmp(buffer, "ID3", 3)) { - uint32_t tag_length = 0; - - /* skip to the tag length */ - if(seek_cb(handle, 2, SEEK_CUR) < 0) - return 2; - - /* read the length */ - for(i = 0; i < 4; i++) { - if(read_cb(buffer, 1, 1, handle) < 1 || buffer[0] & 0x80) - return 1; - tag_length <<= 7; - tag_length |= (buffer[0] & 0x7f); - } - - /* skip the rest of the tag */ - if(seek_cb(handle, tag_length, SEEK_CUR) < 0) - return 2; - - /* read the stream sync code */ - errno = 0; - n = read_cb(buffer, 1, 4, handle); - if(errno) - return 1; - else if(n != 4) - return 3; - } - - /* check for the fLaC signature */ - if(0 == memcmp(FLAC__STREAM_SYNC_STRING, buffer, FLAC__STREAM_SYNC_LENGTH)) - return 0; - else - return 3; -} - -uint32_t seek_to_first_metadata_block_(FILE *f) -{ - return seek_to_first_metadata_block_cb_((FLAC__IOHandle)f, (FLAC__IOCallback_Read)fread, fseek_wrapper_); -} - -FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append) -{ - const FLAC__off_t offset_end = append? iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length : iterator->offset[iterator->depth]; - - if(0 != fseeko(iterator->file, 0, SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(!open_tempfile_(iterator->filename, iterator->tempfile_path_prefix, tempfile, tempfilename, &iterator->status)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - if(!copy_n_bytes_from_file_(iterator->file, *tempfile, offset_end, &iterator->status)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - - return true; -} - -FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup) -{ - FLAC__off_t save_offset = iterator->offset[iterator->depth]; - FLAC__ASSERT(0 != *tempfile); - - if(0 != fseeko(iterator->file, save_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length, SEEK_SET)) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(!copy_remaining_bytes_from_file_(iterator->file, *tempfile, &iterator->status)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - - if(fixup_is_last_code != 0) { - /* - * if code == 1, it means a block was appended to the end so - * we have to clear the is_last flag of the previous block - * if code == -1, it means the last block was deleted so - * we have to set the is_last flag of the previous block - */ - /* MAGIC NUMBERs here; we know the is_last flag is the high bit of the byte at this location */ - FLAC__byte x; - if(0 != fseeko(*tempfile, fixup_is_last_flag_offset, SEEK_SET)) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(fread(&x, 1, 1, *tempfile) != 1) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(fixup_is_last_code > 0) { - FLAC__ASSERT(x & 0x80); - x &= 0x7f; - } - else { - FLAC__ASSERT(!(x & 0x80)); - x |= 0x80; - } - if(0 != fseeko(*tempfile, fixup_is_last_flag_offset, SEEK_SET)) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(local__fwrite(&x, 1, 1, *tempfile) != 1) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - } - - (void)fclose(iterator->file); - - if(!transport_tempfile_(iterator->filename, tempfile, tempfilename, &iterator->status)) - return false; - - if(iterator->has_stats) - set_file_stats_(iterator->filename, &iterator->stats); - - if(!simple_iterator_prime_input_(iterator, !iterator->is_writable)) - return false; - if(backup) { - while(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length < save_offset) - if(!FLAC__metadata_simple_iterator_next(iterator)) - return false; - return true; - } - else { - /* move the iterator to it's original block faster by faking a push, then doing a pop_ */ - FLAC__ASSERT(iterator->depth == 0); - iterator->offset[0] = save_offset; - iterator->depth++; - return simple_iterator_pop_(iterator); - } -} - -FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - FLAC__ASSERT(bytes >= 0); - while(bytes > 0) { - n = flac_min(sizeof(buffer), (size_t)bytes); - if(fread(buffer, 1, n, file) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(local__fwrite(buffer, 1, n, tempfile) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - bytes -= n; - } - - return true; -} - -FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - FLAC__ASSERT(bytes >= 0); - while(bytes > 0) { - n = flac_min(sizeof(buffer), (size_t)bytes); - if(read_cb(buffer, 1, n, handle) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(temp_write_cb(buffer, 1, n, temp_handle) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - bytes -= n; - } - - return true; -} - -FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - while(!feof(file)) { - n = fread(buffer, 1, sizeof(buffer), file); - if(n == 0 && !feof(file)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(n > 0 && local__fwrite(buffer, 1, n, tempfile) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - } - - return true; -} - -FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - while(!eof_cb(handle)) { - n = read_cb(buffer, 1, sizeof(buffer), handle); - if(n == 0 && !eof_cb(handle)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(n > 0 && temp_write_cb(buffer, 1, n, temp_handle) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - } - - return true; -} - -static int -local_snprintf(char *str, size_t size, const char *fmt, ...) -{ - va_list va; - int rc; - -#if defined _MSC_VER - if (size == 0) - return 1024; -#endif - - va_start (va, fmt); - -#if defined _MSC_VER - rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); - if (rc < 0) - rc = size - 1; -#elif defined __MINGW32__ - rc = __mingw_vsnprintf (str, size, fmt, va); -#else - rc = vsnprintf (str, size, fmt, va); -#endif - va_end (va); - - return rc; -} - -FLAC__bool open_tempfile_(const char *filename, const char *tempfile_path_prefix, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status) -{ - static const char *tempfile_suffix = ".metadata_edit"; - if(0 == tempfile_path_prefix) { - size_t dest_len = strlen(filename) + strlen(tempfile_suffix) + 1; - if(0 == (*tempfilename = safe_malloc_(dest_len))) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - local_snprintf(*tempfilename, dest_len, "%s%s", filename, tempfile_suffix); - } - else { - const char *p = strrchr(filename, '/'); - size_t dest_len; - if(0 == p) - p = filename; - else - p++; - - dest_len = strlen(tempfile_path_prefix) + strlen(p) + strlen(tempfile_suffix) + 2; - - if(0 == (*tempfilename = safe_malloc_(dest_len))) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - local_snprintf(*tempfilename, dest_len, "%s/%s%s", tempfile_path_prefix, p, tempfile_suffix); - } - - if(0 == (*tempfile = flac_fopen(*tempfilename, "w+b"))) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE; - return false; - } - - return true; -} - -FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != tempfile); - FLAC__ASSERT(0 != *tempfile); - FLAC__ASSERT(0 != tempfilename); - FLAC__ASSERT(0 != *tempfilename); - FLAC__ASSERT(0 != status); - - (void)fclose(*tempfile); - *tempfile = 0; - -#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ || defined __EMX__ - /* on some flavors of windows, flac_rename() will fail if the destination already exists */ - if(flac_unlink(filename) < 0) { - cleanup_tempfile_(tempfile, tempfilename); - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR; - return false; - } -#endif - - /*@@@ to fully support the tempfile_path_prefix we need to update this piece to actually copy across filesystems instead of just flac_rename(): */ - if(0 != flac_rename(*tempfilename, filename)) { - cleanup_tempfile_(tempfile, tempfilename); - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR; - return false; - } - - cleanup_tempfile_(tempfile, tempfilename); - - return true; -} - -void cleanup_tempfile_(FILE **tempfile, char **tempfilename) -{ - if(0 != *tempfile) { - (void)fclose(*tempfile); - *tempfile = 0; - } - - if(0 != *tempfilename) { - (void)flac_unlink(*tempfilename); - free(*tempfilename); - *tempfilename = 0; - } -} - -FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - return (0 == flac_stat(filename, stats)); -} - -void set_file_stats_(const char *filename, struct flac_stat_s *stats) -{ -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) - struct timespec srctime[2] = {}; - srctime[0].tv_sec = stats->st_atime; - srctime[1].tv_sec = stats->st_mtime; -#else - struct utimbuf srctime; - srctime.actime = stats->st_atime; - srctime.modtime = stats->st_mtime; -#endif - - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - - (void)flac_chmod(filename, stats->st_mode); - (void)flac_utime(filename, &srctime); -#if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__ - FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1)); - FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid)); -#endif -} - -int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence) -{ - return fseeko((FILE*)handle, (FLAC__off_t)offset, whence); -} - -FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle) -{ - return ftello((FILE*)handle); -} - -FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorStatus status) -{ - switch(status) { - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK: - return FLAC__METADATA_CHAIN_STATUS_OK; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT: - return FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE: - return FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE: - return FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE: - return FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA: - return FLAC__METADATA_CHAIN_STATUS_BAD_METADATA; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR: - return FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR: - return FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR: - return FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR: - return FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR: - return FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR: - return FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR: - default: - return FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - } -} diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/metadata_object.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/metadata_object.c deleted file mode 100644 index 493025d0e5..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/metadata_object.c +++ /dev/null @@ -1,1821 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "include/private/metadata.h" -#include "include/private/memory.h" - -#include "../assert.h" -#include "../alloc.h" -#include "../compat.h" - -/* Alias the first (in share/alloc.h) to the second (in src/libFLAC/memory.c). */ -#define safe_malloc_mul_2op_ safe_malloc_mul_2op_p - - -/**************************************************************************** - * - * Local routines - * - ***************************************************************************/ - -/* copy bytes: - * from = NULL && bytes = 0 - * to <- NULL - * from != NULL && bytes > 0 - * to <- copy of from - * else ASSERT - * malloc error leaves 'to' unchanged - */ -static FLAC__bool copy_bytes_(FLAC__byte **to, const FLAC__byte *from, uint32_t bytes) -{ - FLAC__ASSERT(to != NULL); - if (bytes > 0 && from != NULL) { - FLAC__byte *x; - if ((x = safe_malloc_(bytes)) == NULL) - return false; - memcpy(x, from, bytes); - *to = x; - } - else { - *to = 0; - } - return true; -} - -#if 0 /* UNUSED */ -/* like copy_bytes_(), but free()s the original '*to' if the copy succeeds and the original '*to' is non-NULL */ -static FLAC__bool free_copy_bytes_(FLAC__byte **to, const FLAC__byte *from, uint32_t bytes) -{ - FLAC__byte *copy; - FLAC__ASSERT(to != NULL); - if (copy_bytes_(©, from, bytes)) { - free(*to); - *to = copy; - return true; - } - else - return false; -} -#endif - -/* reallocate entry to 1 byte larger and add a terminating NUL */ -/* realloc() failure leaves entry unchanged */ -static FLAC__bool ensure_null_terminated_(FLAC__byte **entry, uint32_t length) -{ - FLAC__byte *x = safe_realloc_add_2op_(*entry, length, /*+*/1); - if (x != NULL) { - x[length] = '\0'; - *entry = x; - return true; - } - else - return false; -} - -/* copies the NUL-terminated C-string 'from' to '*to', leaving '*to' - * unchanged if malloc fails, free()ing the original '*to' if it - * succeeds and the original '*to' was not NULL - */ -static FLAC__bool copy_cstring_(char **to, const char *from) -{ - char *copy = strdup(from); - FLAC__ASSERT(to != NULL); - if (copy) { - free(*to); - *to = copy; - return true; - } - else - return false; -} - -static FLAC__bool copy_vcentry_(FLAC__StreamMetadata_VorbisComment_Entry *to, const FLAC__StreamMetadata_VorbisComment_Entry *from) -{ - to->length = from->length; - if (from->entry == 0) { - FLAC__ASSERT(from->length == 0); - to->entry = 0; - } - else { - FLAC__byte *x; - FLAC__ASSERT(from->length > 0); - if ((x = safe_malloc_add_2op_(from->length, /*+*/1)) == NULL) - return false; - memcpy(x, from->entry, from->length); - x[from->length] = '\0'; - to->entry = x; - } - return true; -} - -static FLAC__bool copy_track_(FLAC__StreamMetadata_CueSheet_Track *to, const FLAC__StreamMetadata_CueSheet_Track *from) -{ - memcpy(to, from, sizeof(FLAC__StreamMetadata_CueSheet_Track)); - if (from->indices == 0) { - FLAC__ASSERT(from->num_indices == 0); - } - else { - FLAC__StreamMetadata_CueSheet_Index *x; - FLAC__ASSERT(from->num_indices > 0); - if ((x = safe_malloc_mul_2op_p(from->num_indices, /*times*/sizeof(FLAC__StreamMetadata_CueSheet_Index))) == NULL) - return false; - memcpy(x, from->indices, from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index)); - to->indices = x; - } - return true; -} - -static void seektable_calculate_length_(FLAC__StreamMetadata *object) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - object->length = object->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; -} - -static FLAC__StreamMetadata_SeekPoint *seekpoint_array_new_(uint32_t num_points) -{ - FLAC__StreamMetadata_SeekPoint *object_array; - - FLAC__ASSERT(num_points > 0); - - object_array = safe_malloc_mul_2op_p(num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)); - - if (object_array != NULL) { - uint32_t i; - for (i = 0; i < num_points; i++) { - object_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - object_array[i].stream_offset = 0; - object_array[i].frame_samples = 0; - } - } - - return object_array; -} - -static void vorbiscomment_calculate_length_(FLAC__StreamMetadata *object) -{ - uint32_t i; - - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - object->length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN) / 8; - object->length += object->data.vorbis_comment.vendor_string.length; - object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8; - for (i = 0; i < object->data.vorbis_comment.num_comments; i++) { - object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8); - object->length += object->data.vorbis_comment.comments[i].length; - } -} - -static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(uint32_t num_comments) -{ - FLAC__ASSERT(num_comments > 0); - - return safe_calloc_(num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)); -} - -static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, uint32_t num_comments) -{ - uint32_t i; - - FLAC__ASSERT(object_array != NULL && num_comments > 0); - - for (i = 0; i < num_comments; i++) - free(object_array[i].entry); - - free(object_array); -} - -static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_copy_(const FLAC__StreamMetadata_VorbisComment_Entry *object_array, uint32_t num_comments) -{ - FLAC__StreamMetadata_VorbisComment_Entry *return_array; - - FLAC__ASSERT(object_array != NULL); - FLAC__ASSERT(num_comments > 0); - - return_array = vorbiscomment_entry_array_new_(num_comments); - - if (return_array != NULL) { - uint32_t i; - - for (i = 0; i < num_comments; i++) { - if (!copy_vcentry_(return_array+i, object_array+i)) { - vorbiscomment_entry_array_delete_(return_array, num_comments); - return 0; - } - } - } - - return return_array; -} - -static FLAC__bool vorbiscomment_set_entry_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry *dest, const FLAC__StreamMetadata_VorbisComment_Entry *src, FLAC__bool copy) -{ - FLAC__byte *save; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(dest != NULL); - FLAC__ASSERT(src != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT((src->entry != NULL && src->length > 0) || (src->entry == NULL && src->length == 0)); - - save = dest->entry; - - if (src->entry != NULL) { - if (copy) { - /* do the copy first so that if we fail we leave the dest object untouched */ - if (!copy_vcentry_(dest, src)) - return false; - } - else { - /* we have to make sure that the string we're taking over is null-terminated */ - - /* - * Stripping the const from src->entry is OK since we're taking - * ownership of the pointer. This is a hack around a deficiency - * in the API where the same function is used for 'copy' and - * 'own', but the source entry is a const pointer. If we were - * precise, the 'own' flavor would be a separate function with a - * non-const source pointer. But it's not, so we hack away. - */ - if (!ensure_null_terminated_((FLAC__byte**)(&src->entry), src->length)) - return false; - *dest = *src; - } - } - else { - /* the src is null */ - *dest = *src; - } - - free(save); - - vorbiscomment_calculate_length_(object); - return true; -} - -static int vorbiscomment_find_entry_from_(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name, uint32_t field_name_length) -{ - uint32_t i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(field_name != NULL); - - for (i = offset; i < object->data.vorbis_comment.num_comments; i++) { - if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) - return (int)i; - } - - return -1; -} - -static void cuesheet_calculate_length_(FLAC__StreamMetadata *object) -{ - uint32_t i; - - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - object->length = ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8; - - object->length += object->data.cue_sheet.num_tracks * ( - FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN - ) / 8; - - for (i = 0; i < object->data.cue_sheet.num_tracks; i++) { - object->length += object->data.cue_sheet.tracks[i].num_indices * ( - FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN - ) / 8; - } -} - -static FLAC__StreamMetadata_CueSheet_Index *cuesheet_track_index_array_new_(uint32_t num_indices) -{ - FLAC__ASSERT(num_indices > 0); - - return safe_calloc_(num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)); -} - -static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_new_(uint32_t num_tracks) -{ - FLAC__ASSERT(num_tracks > 0); - - return safe_calloc_(num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)); -} - -static void cuesheet_track_array_delete_(FLAC__StreamMetadata_CueSheet_Track *object_array, uint32_t num_tracks) -{ - uint32_t i; - - FLAC__ASSERT(object_array != NULL && num_tracks > 0); - - for (i = 0; i < num_tracks; i++) { - if (object_array[i].indices != 0) { - FLAC__ASSERT(object_array[i].num_indices > 0); - free(object_array[i].indices); - } - } - - free(object_array); -} - -static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_copy_(const FLAC__StreamMetadata_CueSheet_Track *object_array, uint32_t num_tracks) -{ - FLAC__StreamMetadata_CueSheet_Track *return_array; - - FLAC__ASSERT(object_array != NULL); - FLAC__ASSERT(num_tracks > 0); - - return_array = cuesheet_track_array_new_(num_tracks); - - if (return_array != NULL) { - uint32_t i; - - for (i = 0; i < num_tracks; i++) { - if (!copy_track_(return_array+i, object_array+i)) { - cuesheet_track_array_delete_(return_array, num_tracks); - return 0; - } - } - } - - return return_array; -} - -static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_CueSheet_Track *dest, const FLAC__StreamMetadata_CueSheet_Track *src, FLAC__bool copy) -{ - FLAC__StreamMetadata_CueSheet_Index *save; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(dest != NULL); - FLAC__ASSERT(src != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT((src->indices != NULL && src->num_indices > 0) || (src->indices == NULL && src->num_indices == 0)); - - save = dest->indices; - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (!copy_track_(dest, src)) - return false; - } - else { - *dest = *src; - } - - free(save); - - cuesheet_calculate_length_(object); - return true; -} - - -/**************************************************************************** - * - * Metadata object routines - * - ***************************************************************************/ - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type) -{ - FLAC__StreamMetadata *object; - - if (type > FLAC__MAX_METADATA_TYPE) - return 0; - - object = calloc(1, sizeof(FLAC__StreamMetadata)); - if (object != NULL) { - object->is_last = false; - object->type = type; - switch(type) { - case FLAC__METADATA_TYPE_STREAMINFO: - object->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - break; - case FLAC__METADATA_TYPE_PADDING: - /* calloc() took care of this for us: - object->length = 0; - */ - break; - case FLAC__METADATA_TYPE_APPLICATION: - object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - /* calloc() took care of this for us: - object->data.application.data = 0; - */ - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - /* calloc() took care of this for us: - object->length = 0; - object->data.seek_table.num_points = 0; - object->data.seek_table.points = 0; - */ - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - object->data.vorbis_comment.vendor_string.length = (uint32_t)strlen(FLAC__VENDOR_STRING); - if (!copy_bytes_(&object->data.vorbis_comment.vendor_string.entry, (const FLAC__byte*)FLAC__VENDOR_STRING, object->data.vorbis_comment.vendor_string.length+1)) { - free(object); - return 0; - } - vorbiscomment_calculate_length_(object); - break; - case FLAC__METADATA_TYPE_CUESHEET: - cuesheet_calculate_length_(object); - break; - case FLAC__METADATA_TYPE_PICTURE: - object->length = ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* empty mime_type string */ - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* empty description string */ - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN + - 0 /* no data */ - ) / 8; - object->data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER; - object->data.picture.mime_type = 0; - object->data.picture.description = 0; - /* calloc() took care of this for us: - object->data.picture.width = 0; - object->data.picture.height = 0; - object->data.picture.depth = 0; - object->data.picture.colors = 0; - object->data.picture.data_length = 0; - object->data.picture.data = 0; - */ - /* now initialize mime_type and description with empty strings to make things easier on the client */ - if (!copy_cstring_(&object->data.picture.mime_type, "")) { - free(object); - return 0; - } - if (!copy_cstring_((char**)(&object->data.picture.description), "")) { - free(object->data.picture.mime_type); - free(object); - return 0; - } - break; - default: - /* calloc() took care of this for us: - object->length = 0; - object->data.unknown.data = 0; - */ - break; - } - } - - return object; -} - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object) -{ - FLAC__StreamMetadata *to; - - FLAC__ASSERT(object != NULL); - - if ((to = FLAC__metadata_object_new(object->type)) != NULL) { - to->is_last = object->is_last; - to->type = object->type; - to->length = object->length; - switch(to->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - memcpy(&to->data.stream_info, &object->data.stream_info, sizeof(FLAC__StreamMetadata_StreamInfo)); - break; - case FLAC__METADATA_TYPE_PADDING: - break; - case FLAC__METADATA_TYPE_APPLICATION: - if (to->length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) { /* underflow check */ - FLAC__metadata_object_delete(to); - return 0; - } - memcpy(&to->data.application.id, &object->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8); - if (!copy_bytes_(&to->data.application.data, object->data.application.data, object->length - FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - to->data.seek_table.num_points = object->data.seek_table.num_points; - if (to->data.seek_table.num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint)) { /* overflow check */ - FLAC__metadata_object_delete(to); - return 0; - } - if (!copy_bytes_((FLAC__byte**)&to->data.seek_table.points, (FLAC__byte*)object->data.seek_table.points, object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint))) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if (to->data.vorbis_comment.vendor_string.entry != NULL) { - free(to->data.vorbis_comment.vendor_string.entry); - to->data.vorbis_comment.vendor_string.entry = 0; - } - if (!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) { - FLAC__metadata_object_delete(to); - return 0; - } - if (object->data.vorbis_comment.num_comments == 0) { - to->data.vorbis_comment.comments = 0; - } - else { - to->data.vorbis_comment.comments = vorbiscomment_entry_array_copy_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments); - if (to->data.vorbis_comment.comments == NULL) { - to->data.vorbis_comment.num_comments = 0; - FLAC__metadata_object_delete(to); - return 0; - } - } - to->data.vorbis_comment.num_comments = object->data.vorbis_comment.num_comments; - break; - case FLAC__METADATA_TYPE_CUESHEET: - memcpy(&to->data.cue_sheet, &object->data.cue_sheet, sizeof(FLAC__StreamMetadata_CueSheet)); - if (object->data.cue_sheet.num_tracks == 0) { - FLAC__ASSERT(object->data.cue_sheet.tracks == NULL); - } - else { - FLAC__ASSERT(object->data.cue_sheet.tracks != 0); - to->data.cue_sheet.tracks = cuesheet_track_array_copy_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks); - if (to->data.cue_sheet.tracks == NULL) { - FLAC__metadata_object_delete(to); - return 0; - } - } - break; - case FLAC__METADATA_TYPE_PICTURE: - to->data.picture.type = object->data.picture.type; - if (!copy_cstring_(&to->data.picture.mime_type, object->data.picture.mime_type)) { - FLAC__metadata_object_delete(to); - return 0; - } - if (!copy_cstring_((char**)(&to->data.picture.description), (const char*)object->data.picture.description)) { - FLAC__metadata_object_delete(to); - return 0; - } - to->data.picture.width = object->data.picture.width; - to->data.picture.height = object->data.picture.height; - to->data.picture.depth = object->data.picture.depth; - to->data.picture.colors = object->data.picture.colors; - to->data.picture.data_length = object->data.picture.data_length; - if (!copy_bytes_((&to->data.picture.data), object->data.picture.data, object->data.picture.data_length)) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - default: - if (!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - } - } - - return to; -} - -void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object) -{ - FLAC__ASSERT(object != NULL); - - switch(object->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - case FLAC__METADATA_TYPE_PADDING: - break; - case FLAC__METADATA_TYPE_APPLICATION: - if (object->data.application.data != NULL) { - free(object->data.application.data); - object->data.application.data = NULL; - } - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - if (object->data.seek_table.points != NULL) { - free(object->data.seek_table.points); - object->data.seek_table.points = NULL; - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if (object->data.vorbis_comment.vendor_string.entry != NULL) { - free(object->data.vorbis_comment.vendor_string.entry); - object->data.vorbis_comment.vendor_string.entry = 0; - } - if (object->data.vorbis_comment.comments != NULL) { - FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0); - vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments); - object->data.vorbis_comment.comments = NULL; - object->data.vorbis_comment.num_comments = 0; - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - if (object->data.cue_sheet.tracks != NULL) { - FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0); - cuesheet_track_array_delete_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks); - object->data.cue_sheet.tracks = NULL; - object->data.cue_sheet.num_tracks = 0; - } - break; - case FLAC__METADATA_TYPE_PICTURE: - if (object->data.picture.mime_type != NULL) { - free(object->data.picture.mime_type); - object->data.picture.mime_type = NULL; - } - if (object->data.picture.description != NULL) { - free(object->data.picture.description); - object->data.picture.description = NULL; - } - if (object->data.picture.data != NULL) { - free(object->data.picture.data); - object->data.picture.data = NULL; - } - break; - default: - if (object->data.unknown.data != NULL) { - free(object->data.unknown.data); - object->data.unknown.data = NULL; - } - break; - } -} - -FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object) -{ - FLAC__metadata_object_delete_data(object); - free(object); -} - -static FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block1, const FLAC__StreamMetadata_StreamInfo *block2) -{ - if (block1->min_blocksize != block2->min_blocksize) - return false; - if (block1->max_blocksize != block2->max_blocksize) - return false; - if (block1->min_framesize != block2->min_framesize) - return false; - if (block1->max_framesize != block2->max_framesize) - return false; - if (block1->sample_rate != block2->sample_rate) - return false; - if (block1->channels != block2->channels) - return false; - if (block1->bits_per_sample != block2->bits_per_sample) - return false; - if (block1->total_samples != block2->total_samples) - return false; - if (memcmp(block1->md5sum, block2->md5sum, 16) != 0) - return false; - return true; -} - -static FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block1, const FLAC__StreamMetadata_Application *block2, uint32_t block_length) -{ - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - FLAC__ASSERT(block_length >= sizeof(block1->id)); - - if (memcmp(block1->id, block2->id, sizeof(block1->id)) != 0) - return false; - if (block1->data != NULL && block2->data != NULL) - return memcmp(block1->data, block2->data, block_length - sizeof(block1->id)) == 0; - else - return block1->data == block2->data; -} - -static FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block1, const FLAC__StreamMetadata_SeekTable *block2) -{ - uint32_t i; - - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - - if (block1->num_points != block2->num_points) - return false; - - if (block1->points != NULL && block2->points != NULL) { - for (i = 0; i < block1->num_points; i++) { - if (block1->points[i].sample_number != block2->points[i].sample_number) - return false; - if (block1->points[i].stream_offset != block2->points[i].stream_offset) - return false; - if (block1->points[i].frame_samples != block2->points[i].frame_samples) - return false; - } - return true; - } - else - return block1->points == block2->points; -} - -static FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block1, const FLAC__StreamMetadata_VorbisComment *block2) -{ - uint32_t i; - - if (block1->vendor_string.length != block2->vendor_string.length) - return false; - - if (block1->vendor_string.entry != NULL && block2->vendor_string.entry != NULL) { - if (memcmp(block1->vendor_string.entry, block2->vendor_string.entry, block1->vendor_string.length) != 0) - return false; - } - else if (block1->vendor_string.entry != block2->vendor_string.entry) - return false; - - if (block1->num_comments != block2->num_comments) - return false; - - for (i = 0; i < block1->num_comments; i++) { - if (block1->comments[i].entry != NULL && block2->comments[i].entry != NULL) { - if (memcmp(block1->comments[i].entry, block2->comments[i].entry, block1->comments[i].length) != 0) - return false; - } - else if (block1->comments[i].entry != block2->comments[i].entry) - return false; - } - return true; -} - -static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueSheet *block1, const FLAC__StreamMetadata_CueSheet *block2) -{ - uint32_t i, j; - - if (strcmp(block1->media_catalog_number, block2->media_catalog_number) != 0) - return false; - - if (block1->lead_in != block2->lead_in) - return false; - - if (block1->is_cd != block2->is_cd) - return false; - - if (block1->num_tracks != block2->num_tracks) - return false; - - if (block1->tracks != NULL && block2->tracks != NULL) { - FLAC__ASSERT(block1->num_tracks > 0); - for (i = 0; i < block1->num_tracks; i++) { - if (block1->tracks[i].offset != block2->tracks[i].offset) - return false; - if (block1->tracks[i].number != block2->tracks[i].number) - return false; - if (memcmp(block1->tracks[i].isrc, block2->tracks[i].isrc, sizeof(block1->tracks[i].isrc)) != 0) - return false; - if (block1->tracks[i].type != block2->tracks[i].type) - return false; - if (block1->tracks[i].pre_emphasis != block2->tracks[i].pre_emphasis) - return false; - if (block1->tracks[i].num_indices != block2->tracks[i].num_indices) - return false; - if (block1->tracks[i].indices != NULL && block2->tracks[i].indices != NULL) { - FLAC__ASSERT(block1->tracks[i].num_indices > 0); - for (j = 0; j < block1->tracks[i].num_indices; j++) { - if (block1->tracks[i].indices[j].offset != block2->tracks[i].indices[j].offset) - return false; - if (block1->tracks[i].indices[j].number != block2->tracks[i].indices[j].number) - return false; - } - } - else if (block1->tracks[i].indices != block2->tracks[i].indices) - return false; - } - } - else if (block1->tracks != block2->tracks) - return false; - return true; -} - -static FLAC__bool compare_block_data_picture_(const FLAC__StreamMetadata_Picture *block1, const FLAC__StreamMetadata_Picture *block2) -{ - if (block1->type != block2->type) - return false; - if (block1->mime_type != block2->mime_type && (block1->mime_type == 0 || block2->mime_type == 0 || strcmp(block1->mime_type, block2->mime_type))) - return false; - if (block1->description != block2->description && (block1->description == 0 || block2->description == 0 || strcmp((const char *)block1->description, (const char *)block2->description))) - return false; - if (block1->width != block2->width) - return false; - if (block1->height != block2->height) - return false; - if (block1->depth != block2->depth) - return false; - if (block1->colors != block2->colors) - return false; - if (block1->data_length != block2->data_length) - return false; - if (block1->data != block2->data && (block1->data == NULL || block2->data == NULL || memcmp(block1->data, block2->data, block1->data_length))) - return false; - return true; -} - -static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, uint32_t block_length) -{ - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - - if (block1->data != NULL && block2->data != NULL) - return memcmp(block1->data, block2->data, block_length) == 0; - else - return block1->data == block2->data; -} - -FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2) -{ - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - - if (block1->type != block2->type) { - return false; - } - if (block1->is_last != block2->is_last) { - return false; - } - if (block1->length != block2->length) { - return false; - } - switch(block1->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return compare_block_data_streaminfo_(&block1->data.stream_info, &block2->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return true; /* we don't compare the padding guts */ - case FLAC__METADATA_TYPE_APPLICATION: - return compare_block_data_application_(&block1->data.application, &block2->data.application, block1->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return compare_block_data_seektable_(&block1->data.seek_table, &block2->data.seek_table); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return compare_block_data_vorbiscomment_(&block1->data.vorbis_comment, &block2->data.vorbis_comment); - case FLAC__METADATA_TYPE_CUESHEET: - return compare_block_data_cuesheet_(&block1->data.cue_sheet, &block2->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return compare_block_data_picture_(&block1->data.picture, &block2->data.picture); - default: - return compare_block_data_unknown_(&block1->data.unknown, &block2->data.unknown, block1->length); - } -} - -FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, uint32_t length, FLAC__bool copy) -{ - FLAC__byte *save; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_APPLICATION); - FLAC__ASSERT((data != NULL && length > 0) || (data == NULL && length == 0 && copy == false)); - - save = object->data.application.data; - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (!copy_bytes_(&object->data.application.data, data, length)) - return false; - } - else { - object->data.application.data = data; - } - - free(save); - - object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 + length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, uint32_t new_num_points) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if (object->data.seek_table.points == 0) { - FLAC__ASSERT(object->data.seek_table.num_points == 0); - if (new_num_points == 0) - return true; - else if ((object->data.seek_table.points = seekpoint_array_new_(new_num_points)) == 0) - return false; - } - else { - const size_t old_size = object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint); - const size_t new_size = new_num_points * sizeof(FLAC__StreamMetadata_SeekPoint); - - /* overflow check */ - if (new_num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint)) - return false; - - FLAC__ASSERT(object->data.seek_table.num_points > 0); - - if (new_size == 0) { - free(object->data.seek_table.points); - object->data.seek_table.points = 0; - } - else if ((object->data.seek_table.points = safe_realloc_(object->data.seek_table.points, new_size)) == NULL) - return false; - - /* if growing, set new elements to placeholders */ - if (new_size > old_size) { - uint32_t i; - for (i = object->data.seek_table.num_points; i < new_num_points; i++) { - object->data.seek_table.points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - object->data.seek_table.points[i].stream_offset = 0; - object->data.seek_table.points[i].frame_samples = 0; - } - } - } - - object->data.seek_table.num_points = new_num_points; - - seektable_calculate_length_(object); - return true; -} - -FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(point_num < object->data.seek_table.num_points); - - object->data.seek_table.points[point_num] = point; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point) -{ - int i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(point_num <= object->data.seek_table.num_points); - - if (!FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points+1)) - return false; - - /* move all points >= point_num forward one space */ - for (i = (int)object->data.seek_table.num_points-1; i > (int)point_num; i--) - object->data.seek_table.points[i] = object->data.seek_table.points[i-1]; - - FLAC__metadata_object_seektable_set_point(object, point_num, point); - seektable_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, uint32_t point_num) -{ - uint32_t i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(point_num < object->data.seek_table.num_points); - - /* move all points > point_num backward one space */ - for (i = point_num; i < object->data.seek_table.num_points-1; i++) - object->data.seek_table.points[i] = object->data.seek_table.points[i+1]; - - return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points-1); -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - return FLAC__format_seektable_is_legal(&object->data.seek_table); -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, uint32_t num) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if (num > 0) - /* WATCHOUT: we rely on the fact that growing the array adds PLACEHOLDERS at the end */ - return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points + num); - else - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number) -{ - FLAC__StreamMetadata_SeekTable *seek_table; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - seek_table = &object->data.seek_table; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + 1)) - return false; - - seek_table->points[seek_table->num_points - 1].sample_number = sample_number; - seek_table->points[seek_table->num_points - 1].stream_offset = 0; - seek_table->points[seek_table->num_points - 1].frame_samples = 0; - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], uint32_t num) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(sample_numbers != 0 || num == 0); - - if (num > 0) { - FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table; - uint32_t i, j; - - i = seek_table->num_points; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num)) - return false; - - for (j = 0; j < num; i++, j++) { - seek_table->points[i].sample_number = sample_numbers[j]; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, uint32_t num, FLAC__uint64 total_samples) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(total_samples > 0); - - if (num > 0 && total_samples > 0) { - FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table; - uint32_t i, j; - - i = seek_table->num_points; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num)) - return false; - - for (j = 0; j < num; i++, j++) { - seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, uint32_t samples, FLAC__uint64 total_samples) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(samples > 0); - FLAC__ASSERT(total_samples > 0); - - if (samples > 0 && total_samples > 0) { - FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table; - uint32_t i, j; - FLAC__uint64 num, sample; - - num = 1 + total_samples / samples; /* 1+ for the first sample at 0 */ - /* now account for the fact that we don't place a seekpoint at "total_samples" since samples are number from 0: */ - if (total_samples % samples == 0) - num--; - - /* Put a strict upper bound on the number of allowed seek points. */ - if (num > 32768) { - /* Set the bound and recalculate samples accordingly. */ - num = 32768; - samples = total_samples / num; - } - - i = seek_table->num_points; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + (uint32_t)num)) - return false; - - sample = 0; - for (j = 0; j < num; i++, j++, sample += samples) { - seek_table->points[i].sample_number = sample; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact) -{ - uint32_t unique; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - unique = FLAC__format_seektable_sort(&object->data.seek_table); - - return !compact || FLAC__metadata_object_seektable_resize_points(object, unique); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - if (!FLAC__format_vorbiscomment_entry_value_is_legal(entry.entry, entry.length)) - return false; - return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.vendor_string, &entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, uint32_t new_num_comments) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if (object->data.vorbis_comment.comments == NULL) { - FLAC__ASSERT(object->data.vorbis_comment.num_comments == 0); - if (new_num_comments == 0) - return true; - else if ((object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)) == NULL) - return false; - } - else { - const size_t old_size = object->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry); - const size_t new_size = new_num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry); - - /* overflow check */ - if (new_num_comments > UINT32_MAX / sizeof(FLAC__StreamMetadata_VorbisComment_Entry)) - return false; - - FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0); - - /* if shrinking, free the truncated entries */ - if (new_num_comments < object->data.vorbis_comment.num_comments) { - uint32_t i; - for (i = new_num_comments; i < object->data.vorbis_comment.num_comments; i++) - if (object->data.vorbis_comment.comments[i].entry != NULL) - free(object->data.vorbis_comment.comments[i].entry); - } - - if (new_size == 0) { - free(object->data.vorbis_comment.comments); - object->data.vorbis_comment.comments = 0; - } - else { - FLAC__StreamMetadata_VorbisComment_Entry *oldptr = object->data.vorbis_comment.comments; - if ((object->data.vorbis_comment.comments = realloc(object->data.vorbis_comment.comments, new_size)) == NULL) { - vorbiscomment_entry_array_delete_(oldptr, object->data.vorbis_comment.num_comments); - object->data.vorbis_comment.num_comments = 0; - return false; - } - } - - /* if growing, zero all the length/pointers of new elements */ - if (new_size > old_size) - memset(object->data.vorbis_comment.comments + object->data.vorbis_comment.num_comments, 0, new_size - old_size); - } - - object->data.vorbis_comment.num_comments = new_num_comments; - - vorbiscomment_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.comments[comment_num], &entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - FLAC__StreamMetadata_VorbisComment *vc; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(comment_num <= object->data.vorbis_comment.num_comments); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - - vc = &object->data.vorbis_comment; - - if (!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1)) - return false; - - /* move all comments >= comment_num forward one space */ - memmove(&vc->comments[comment_num+1], &vc->comments[comment_num], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-1-comment_num)); - vc->comments[comment_num].length = 0; - vc->comments[comment_num].entry = 0; - - return FLAC__metadata_object_vorbiscomment_set_comment(object, comment_num, entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - return FLAC__metadata_object_vorbiscomment_insert_comment(object, object->data.vorbis_comment.num_comments, entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy) -{ - FLAC__ASSERT(entry.entry != NULL && entry.length > 0); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - - { - int i; - size_t field_name_length; - const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); - - if (eq == NULL) - return false; /* double protection */ - - field_name_length = eq-entry.entry; - - i = vorbiscomment_find_entry_from_(object, 0, (const char *)entry.entry, field_name_length); - if (i >= 0) { - uint32_t indx = (uint32_t)i; - if (!FLAC__metadata_object_vorbiscomment_set_comment(object, indx, entry, copy)) - return false; - entry = object->data.vorbis_comment.comments[indx]; - indx++; /* skip over replaced comment */ - if (all && indx < object->data.vorbis_comment.num_comments) { - i = vorbiscomment_find_entry_from_(object, indx, (const char *)entry.entry, field_name_length); - while (i >= 0) { - indx = (uint32_t)i; - if (!FLAC__metadata_object_vorbiscomment_delete_comment(object, indx)) - return false; - if (indx < object->data.vorbis_comment.num_comments) - i = vorbiscomment_find_entry_from_(object, indx, (const char *)entry.entry, field_name_length); - else - i = -1; - } - } - return true; - } - else - return FLAC__metadata_object_vorbiscomment_append_comment(object, entry, copy); - } -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, uint32_t comment_num) -{ - FLAC__StreamMetadata_VorbisComment *vc; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments); - - vc = &object->data.vorbis_comment; - - /* free the comment at comment_num */ - free(vc->comments[comment_num].entry); - - /* move all comments > comment_num backward one space */ - memmove(&vc->comments[comment_num], &vc->comments[comment_num+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-comment_num-1)); - vc->comments[vc->num_comments-1].length = 0; - vc->comments[vc->num_comments-1].entry = 0; - - return FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments-1); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value) -{ - FLAC__ASSERT(entry != NULL); - FLAC__ASSERT(field_name != NULL); - FLAC__ASSERT(field_value != NULL); - - if (!FLAC__format_vorbiscomment_entry_name_is_legal(field_name)) - return false; - if (!FLAC__format_vorbiscomment_entry_value_is_legal((const FLAC__byte *)field_value, (uint32_t)(-1))) - return false; - - { - const size_t nn = strlen(field_name); - const size_t nv = strlen(field_value); - entry->length = nn + 1 /*=*/ + nv; - if ((entry->entry = safe_malloc_add_4op_(nn, /*+*/1, /*+*/nv, /*+*/1)) == NULL) - return false; - memcpy(entry->entry, field_name, nn); - entry->entry[nn] = '='; - memcpy(entry->entry+nn+1, field_value, nv); - entry->entry[entry->length] = '\0'; - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value) -{ - FLAC__ASSERT(entry.entry != NULL && entry.length > 0); - FLAC__ASSERT(field_name != NULL); - FLAC__ASSERT(field_value != NULL); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - - { - const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); - const size_t nn = eq-entry.entry; - const size_t nv = entry.length-nn-1; /* -1 for the '=' */ - - if (eq == NULL) - return false; /* double protection */ - if ((*field_name = safe_malloc_add_2op_(nn, /*+*/1)) == NULL) - return false; - if ((*field_value = safe_malloc_add_2op_(nv, /*+*/1)) == NULL) { - free(*field_name); - return false; - } - memcpy(*field_name, entry.entry, nn); - memcpy(*field_value, entry.entry+nn+1, nv); - (*field_name)[nn] = '\0'; - (*field_value)[nv] = '\0'; - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, uint32_t field_name_length) -{ - FLAC__ASSERT(entry.entry != NULL && entry.length > 0); - { - const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); - return (eq != NULL && (uint32_t)(eq-entry.entry) == field_name_length && FLAC__STRNCASECMP(field_name, (const char *)entry.entry, field_name_length) == 0); - } -} - -FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name) -{ - FLAC__ASSERT(field_name != NULL); - - return vorbiscomment_find_entry_from_(object, offset, field_name, strlen(field_name)); -} - -FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name) -{ - const uint32_t field_name_length = strlen(field_name); - uint32_t i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - for (i = 0; i < object->data.vorbis_comment.num_comments; i++) { - if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) { - if (!FLAC__metadata_object_vorbiscomment_delete_comment(object, i)) - return -1; - else - return 1; - } - } - - return 0; -} - -FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name) -{ - FLAC__bool ok = true; - uint32_t matching = 0; - const uint32_t field_name_length = strlen(field_name); - int i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - /* must delete from end to start otherwise it will interfere with our iteration */ - for (i = (int)object->data.vorbis_comment.num_comments - 1; ok && i >= 0; i--) { - if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) { - matching++; - ok &= FLAC__metadata_object_vorbiscomment_delete_comment(object, (uint32_t)i); - } - } - - return ok? (int)matching : -1; -} - -FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void) -{ - return calloc(1, sizeof(FLAC__StreamMetadata_CueSheet_Track)); -} - -FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object) -{ - FLAC__StreamMetadata_CueSheet_Track *to; - - FLAC__ASSERT(object != NULL); - - if ((to = FLAC__metadata_object_cuesheet_track_new()) != NULL) { - if (!copy_track_(to, object)) { - FLAC__metadata_object_cuesheet_track_delete(to); - return 0; - } - } - - return to; -} - -void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object) -{ - FLAC__ASSERT(object != NULL); - - if (object->indices != NULL) { - FLAC__ASSERT(object->num_indices > 0); - free(object->indices); - } -} - -FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object) -{ - FLAC__metadata_object_cuesheet_track_delete_data(object); - free(object); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t new_num_indices) -{ - FLAC__StreamMetadata_CueSheet_Track *track; - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - - track = &object->data.cue_sheet.tracks[track_num]; - - if (track->indices == NULL) { - FLAC__ASSERT(track->num_indices == 0); - if (new_num_indices == 0) - return true; - else if ((track->indices = cuesheet_track_index_array_new_(new_num_indices)) == NULL) - return false; - } - else { - const size_t old_size = track->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index); - const size_t new_size = new_num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index); - - /* overflow check */ - if (new_num_indices > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Index)) - return false; - - FLAC__ASSERT(track->num_indices > 0); - - if (new_size == 0) { - free(track->indices); - track->indices = 0; - } - else if ((track->indices = safe_realloc_(track->indices, new_size)) == NULL) - return false; - - /* if growing, zero all the lengths/pointers of new elements */ - if (new_size > old_size) - memset(track->indices + track->num_indices, 0, new_size - old_size); - } - - track->num_indices = new_num_indices; - - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num, FLAC__StreamMetadata_CueSheet_Index indx) -{ - FLAC__StreamMetadata_CueSheet_Track *track; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num <= object->data.cue_sheet.tracks[track_num].num_indices); - - track = &object->data.cue_sheet.tracks[track_num]; - - if (!FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices+1)) - return false; - - /* move all indices >= index_num forward one space */ - memmove(&track->indices[index_num+1], &track->indices[index_num], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-1-index_num)); - - track->indices[index_num] = indx; - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num) -{ - FLAC__StreamMetadata_CueSheet_Index indx; - memset(&indx, 0, sizeof(indx)); - return FLAC__metadata_object_cuesheet_track_insert_index(object, track_num, index_num, indx); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num) -{ - FLAC__StreamMetadata_CueSheet_Track *track; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num < object->data.cue_sheet.tracks[track_num].num_indices); - - track = &object->data.cue_sheet.tracks[track_num]; - - /* move all indices > index_num backward one space */ - memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-index_num-1)); - - FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices-1); - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, uint32_t new_num_tracks) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - if (object->data.cue_sheet.tracks == NULL) { - FLAC__ASSERT(object->data.cue_sheet.num_tracks == 0); - if (new_num_tracks == 0) - return true; - else if ((object->data.cue_sheet.tracks = cuesheet_track_array_new_(new_num_tracks)) == NULL) - return false; - } - else { - const size_t old_size = object->data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track); - const size_t new_size = new_num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track); - - /* overflow check */ - if (new_num_tracks > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Track)) - return false; - - FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0); - - /* if shrinking, free the truncated entries */ - if (new_num_tracks < object->data.cue_sheet.num_tracks) { - uint32_t i; - for (i = new_num_tracks; i < object->data.cue_sheet.num_tracks; i++) - free(object->data.cue_sheet.tracks[i].indices); - } - - if (new_size == 0) { - free(object->data.cue_sheet.tracks); - object->data.cue_sheet.tracks = 0; - } - else if ((object->data.cue_sheet.tracks = safe_realloc_(object->data.cue_sheet.tracks, new_size)) == NULL) - return false; - - /* if growing, zero all the lengths/pointers of new elements */ - if (new_size > old_size) - memset(object->data.cue_sheet.tracks + object->data.cue_sheet.num_tracks, 0, new_size - old_size); - } - - object->data.cue_sheet.num_tracks = new_num_tracks; - - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - - return cuesheet_set_track_(object, object->data.cue_sheet.tracks + track_num, track, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy) -{ - FLAC__StreamMetadata_CueSheet *cs; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num <= object->data.cue_sheet.num_tracks); - - cs = &object->data.cue_sheet; - - if (!FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks+1)) - return false; - - /* move all tracks >= track_num forward one space */ - memmove(&cs->tracks[track_num+1], &cs->tracks[track_num], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-1-track_num)); - cs->tracks[track_num].num_indices = 0; - cs->tracks[track_num].indices = 0; - - return FLAC__metadata_object_cuesheet_set_track(object, track_num, track, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, uint32_t track_num) -{ - FLAC__StreamMetadata_CueSheet_Track track; - memset(&track, 0, sizeof(track)); - return FLAC__metadata_object_cuesheet_insert_track(object, track_num, &track, /*copy=*/false); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, uint32_t track_num) -{ - FLAC__StreamMetadata_CueSheet *cs; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - - cs = &object->data.cue_sheet; - - /* free the track at track_num */ - free(cs->tracks[track_num].indices); - - /* move all tracks > track_num backward one space */ - memmove(&cs->tracks[track_num], &cs->tracks[track_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-track_num-1)); - cs->tracks[cs->num_tracks-1].num_indices = 0; - cs->tracks[cs->num_tracks-1].indices = 0; - - return FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks-1); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - return FLAC__format_cuesheet_is_legal(&object->data.cue_sheet, check_cd_da_subset, violation); -} - -static FLAC__uint64 get_index_01_offset_(const FLAC__StreamMetadata_CueSheet *cs, uint32_t track) -{ - if (track >= (cs->num_tracks-1) || cs->tracks[track].num_indices < 1) - return 0; - else if (cs->tracks[track].indices[0].number == 1) - return cs->tracks[track].indices[0].offset + cs->tracks[track].offset + cs->lead_in; - else if (cs->tracks[track].num_indices < 2) - return 0; - else if (cs->tracks[track].indices[1].number == 1) - return cs->tracks[track].indices[1].offset + cs->tracks[track].offset + cs->lead_in; - else - return 0; -} - -static FLAC__uint32 cddb_add_digits_(FLAC__uint32 x) -{ - FLAC__uint32 n = 0; - while (x) { - n += (x%10); - x /= 10; - } - return n; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object) -{ - const FLAC__StreamMetadata_CueSheet *cs; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - cs = &object->data.cue_sheet; - - if (cs->num_tracks < 2) /* need at least one real track and the lead-out track */ - return 0; - - { - FLAC__uint32 i, length, sum = 0; - for (i = 0; i < (cs->num_tracks-1); i++) /* -1 to avoid counting the lead-out */ - sum += cddb_add_digits_((FLAC__uint32)(get_index_01_offset_(cs, i) / 44100)); - length = (FLAC__uint32)((cs->tracks[cs->num_tracks-1].offset+cs->lead_in) / 44100) - (FLAC__uint32)(get_index_01_offset_(cs, 0) / 44100); - - return (sum % 0xFF) << 24 | length << 8 | (FLAC__uint32)(cs->num_tracks-1); - } -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy) -{ - char *old; - size_t old_length, new_length; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - FLAC__ASSERT(mime_type != NULL); - - old = object->data.picture.mime_type; - old_length = old? strlen(old) : 0; - new_length = strlen(mime_type); - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (new_length >= SIZE_MAX) /* overflow check */ - return false; - if (!copy_bytes_((FLAC__byte**)(&object->data.picture.mime_type), (FLAC__byte*)mime_type, new_length+1)) - return false; - } - else { - object->data.picture.mime_type = mime_type; - } - - free(old); - - object->length -= old_length; - object->length += new_length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy) -{ - FLAC__byte *old; - size_t old_length, new_length; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - FLAC__ASSERT(description != NULL); - - old = object->data.picture.description; - old_length = old? strlen((const char *)old) : 0; - new_length = strlen((const char *)description); - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (new_length >= SIZE_MAX) /* overflow check */ - return false; - if (!copy_bytes_(&object->data.picture.description, description, new_length+1)) - return false; - } - else { - object->data.picture.description = description; - } - - free(old); - - object->length -= old_length; - object->length += new_length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy) -{ - FLAC__byte *old; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - FLAC__ASSERT((data != NULL && length > 0) || (data == NULL && length == 0 && copy == false)); - - old = object->data.picture.data; - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (!copy_bytes_(&object->data.picture.data, data, length)) - return false; - } - else { - object->data.picture.data = data; - } - - free(old); - - object->length -= object->data.picture.data_length; - object->data.picture.data_length = length; - object->length += length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - - return FLAC__format_picture_is_legal(&object->data.picture, violation); -} diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_decoder_aspect.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_decoder_aspect.c deleted file mode 100644 index 1fa642506b..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_decoder_aspect.c +++ /dev/null @@ -1,251 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for memcpy() */ -#include "../assert.h" -#include "include/private/ogg_decoder_aspect.h" -#include "include/private/ogg_mapping.h" -#include "include/private/macros.h" - - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect) -{ - /* we will determine the serial number later if necessary */ - if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0) - return false; - - if(ogg_sync_init(&aspect->sync_state) != 0) - return false; - - aspect->version_major = ~(0u); - aspect->version_minor = ~(0u); - - aspect->need_serial_number = aspect->use_first_serial_number; - - aspect->end_of_stream = false; - aspect->have_working_page = false; - - return true; -} - -void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect) -{ - (void)ogg_sync_clear(&aspect->sync_state); - (void)ogg_stream_clear(&aspect->stream_state); -} - -void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value) -{ - aspect->use_first_serial_number = false; - aspect->serial_number = value; -} - -void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect) -{ - aspect->use_first_serial_number = true; -} - -void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect) -{ - (void)ogg_stream_reset(&aspect->stream_state); - (void)ogg_sync_reset(&aspect->sync_state); - aspect->end_of_stream = false; - aspect->have_working_page = false; -} - -void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect) -{ - FLAC__ogg_decoder_aspect_flush(aspect); - - if(aspect->use_first_serial_number) - aspect->need_serial_number = true; -} - -FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], size_t *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data) -{ - static const size_t OGG_BYTES_CHUNK = 8192; - const size_t bytes_requested = *bytes; - - /* - * The FLAC decoding API uses pull-based reads, whereas Ogg decoding - * is push-based. In libFLAC, when you ask to decode a frame, the - * decoder will eventually call the read callback to supply some data, - * but how much it asks for depends on how much free space it has in - * its internal buffer. It does not try to grow its internal buffer - * to accommodate a whole frame because then the internal buffer size - * could not be limited, which is necessary in embedded applications. - * - * Ogg however grows its internal buffer until a whole page is present; - * only then can you get decoded data out. So we can't just ask for - * the same number of bytes from Ogg, then pass what's decoded down to - * libFLAC. If what libFLAC is asking for will not contain a whole - * page, then we will get no data from ogg_sync_pageout(), and at the - * same time cannot just read more data from the client for the purpose - * of getting a whole decoded page because the decoded size might be - * larger than libFLAC's internal buffer. - * - * Instead, whenever this read callback wrapper is called, we will - * continually request data from the client until we have at least one - * page, and manage pages internally so that we can send pieces of - * pages down to libFLAC in such a way that we obey its size - * requirement. To limit the amount of callbacks, we will always try - * to read in enough pages to return the full number of bytes - * requested. - */ - *bytes = 0; - while (*bytes < bytes_requested && !aspect->end_of_stream) { - if (aspect->have_working_page) { - if (aspect->have_working_packet) { - size_t n = bytes_requested - *bytes; - if ((size_t)aspect->working_packet.bytes <= n) { - /* the rest of the packet will fit in the buffer */ - n = aspect->working_packet.bytes; - memcpy(buffer, aspect->working_packet.packet, n); - *bytes += n; - buffer += n; - aspect->have_working_packet = false; - } - else { - /* only n bytes of the packet will fit in the buffer */ - memcpy(buffer, aspect->working_packet.packet, n); - *bytes += n; - buffer += n; - aspect->working_packet.packet += n; - aspect->working_packet.bytes -= n; - } - } - else { - /* try and get another packet */ - const int ret = ogg_stream_packetout(&aspect->stream_state, &aspect->working_packet); - if (ret > 0) { - aspect->have_working_packet = true; - /* if it is the first header packet, check for magic and a supported Ogg FLAC mapping version */ - if (aspect->working_packet.bytes > 0 && aspect->working_packet.packet[0] == FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE) { - const FLAC__byte *b = aspect->working_packet.packet; - const uint32_t header_length = - FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + - FLAC__OGG_MAPPING_MAGIC_LENGTH + - FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + - FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + - FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH; - if (aspect->working_packet.bytes < (long)header_length) - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; - b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH; - if (memcmp(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH)) - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; - b += FLAC__OGG_MAPPING_MAGIC_LENGTH; - aspect->version_major = (uint32_t)(*b); - b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH; - aspect->version_minor = (uint32_t)(*b); - if (aspect->version_major != 1) - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION; - aspect->working_packet.packet += header_length; - aspect->working_packet.bytes -= header_length; - } - } - else if (ret == 0) { - aspect->have_working_page = false; - } - else { /* ret < 0 */ - /* lost sync, we'll leave the working page for the next call */ - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; - } - } - } - else { - /* try and get another page */ - const int ret = ogg_sync_pageout(&aspect->sync_state, &aspect->working_page); - if (ret > 0) { - /* got a page, grab the serial number if necessary */ - if(aspect->need_serial_number) { - aspect->stream_state.serialno = aspect->serial_number = ogg_page_serialno(&aspect->working_page); - aspect->need_serial_number = false; - } - if(ogg_stream_pagein(&aspect->stream_state, &aspect->working_page) == 0) { - aspect->have_working_page = true; - aspect->have_working_packet = false; - } - /* else do nothing, could be a page from another stream */ - } - else if (ret == 0) { - /* need more data */ - const size_t ogg_bytes_to_read = flac_max(bytes_requested - *bytes, OGG_BYTES_CHUNK); - char *oggbuf = ogg_sync_buffer(&aspect->sync_state, ogg_bytes_to_read); - - if(0 == oggbuf) { - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR; - } - else { - size_t ogg_bytes_read = ogg_bytes_to_read; - - switch(read_callback(decoder, (FLAC__byte*)oggbuf, &ogg_bytes_read, client_data)) { - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: - break; - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: - aspect->end_of_stream = true; - break; - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; - default: - FLAC__ASSERT(0); - } - - if(ogg_sync_wrote(&aspect->sync_state, ogg_bytes_read) < 0) { - /* double protection; this will happen if the read callback returns more bytes than the max requested, which would overflow Ogg's internal buffer */ - FLAC__ASSERT(0); - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR; - } - } - } - else { /* ret < 0 */ - /* lost sync, bail out */ - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; - } - } - } - - if (aspect->end_of_stream && *bytes == 0) { - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; - } - - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; -} diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_encoder_aspect.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_encoder_aspect.c deleted file mode 100644 index db0d9d8ef3..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_encoder_aspect.c +++ /dev/null @@ -1,228 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for memset() */ -#include "../assert.h" -#include "include/private/ogg_encoder_aspect.h" -#include "include/private/ogg_mapping.h" - -static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MAJOR = 1; -static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MINOR = 0; - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect) -{ - /* we will determine the serial number later if necessary */ - if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0) - return false; - - aspect->seen_magic = false; - aspect->is_first_packet = true; - aspect->samples_written = 0; - - return true; -} - -void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect) -{ - (void)ogg_stream_clear(&aspect->stream_state); - /*@@@ what about the page? */ -} - -void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value) -{ - aspect->serial_number = value; -} - -FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, uint32_t value) -{ - if(value < (1u << FLAC__OGG_MAPPING_NUM_HEADERS_LEN)) { - aspect->num_metadata = value; - return true; - } - else - return false; -} - -void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect) -{ - aspect->serial_number = 0; - aspect->num_metadata = 0; -} - -/* - * The basic FLAC -> Ogg mapping goes like this: - * - * - 'fLaC' magic and STREAMINFO block get combined into the first - * packet. The packet is prefixed with - * + the one-byte packet type 0x7F - * + 'FLAC' magic - * + the 2 byte Ogg FLAC mapping version number - * + tne 2 byte big-endian # of header packets - * - The first packet is flushed to the first page. - * - Each subsequent metadata block goes into its own packet. - * - Each metadata packet is flushed to page (this is not required, - * the mapping only requires that a flush must occur after all - * metadata is written). - * - Each subsequent FLAC audio frame goes into its own packet. - * - * WATCHOUT: - * This depends on the behavior of FLAC__StreamEncoder that we get a - * separate write callback for the fLaC magic, and then separate write - * callbacks for each metadata block and audio frame. - */ -FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data) -{ - /* WATCHOUT: - * This depends on the behavior of FLAC__StreamEncoder that 'samples' - * will be 0 for metadata writes. - */ - const FLAC__bool is_metadata = (samples == 0); - - /* - * Treat fLaC magic packet specially. We will note when we see it, then - * wait until we get the STREAMINFO and prepend it in that packet - */ - if(aspect->seen_magic) { - ogg_packet packet; - FLAC__byte synthetic_first_packet_body[ - FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + - FLAC__OGG_MAPPING_MAGIC_LENGTH + - FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + - FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + - FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH + - FLAC__STREAM_SYNC_LENGTH + - FLAC__STREAM_METADATA_HEADER_LENGTH + - FLAC__STREAM_METADATA_STREAMINFO_LENGTH - ]; - - memset(&packet, 0, sizeof(packet)); - packet.granulepos = aspect->samples_written + samples; - - if(aspect->is_first_packet) { - FLAC__byte *b = synthetic_first_packet_body; - if(bytes != FLAC__STREAM_METADATA_HEADER_LENGTH + FLAC__STREAM_METADATA_STREAMINFO_LENGTH) { - /* - * If we get here, our assumption about the way write callbacks happen - * (explained above) is wrong - */ - FLAC__ASSERT(0); - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - /* add first header packet type */ - *b = FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; - b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH; - /* add 'FLAC' mapping magic */ - memcpy(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH); - b += FLAC__OGG_MAPPING_MAGIC_LENGTH; - /* add Ogg FLAC mapping major version number */ - memcpy(b, &FLAC__OGG_MAPPING_VERSION_MAJOR, FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH); - b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH; - /* add Ogg FLAC mapping minor version number */ - memcpy(b, &FLAC__OGG_MAPPING_VERSION_MINOR, FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH); - b += FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH; - /* add number of header packets */ - *b = (FLAC__byte)(aspect->num_metadata >> 8); - b++; - *b = (FLAC__byte)(aspect->num_metadata); - b++; - /* add native FLAC 'fLaC' magic */ - memcpy(b, FLAC__STREAM_SYNC_STRING, FLAC__STREAM_SYNC_LENGTH); - b += FLAC__STREAM_SYNC_LENGTH; - /* add STREAMINFO */ - memcpy(b, buffer, bytes); - FLAC__ASSERT(b + bytes - synthetic_first_packet_body == sizeof(synthetic_first_packet_body)); - packet.packet = (uint8_t *)synthetic_first_packet_body; - packet.bytes = sizeof(synthetic_first_packet_body); - - packet.b_o_s = 1; - aspect->is_first_packet = false; - } - else { - packet.packet = (uint8_t *)buffer; - packet.bytes = bytes; - } - - if(is_last_block) { - /* we used to check: - * FLAC__ASSERT(total_samples_estimate == 0 || total_samples_estimate == aspect->samples_written + samples); - * but it's really not useful since total_samples_estimate is an estimate and can be inexact - */ - packet.e_o_s = 1; - } - - if(ogg_stream_packetin(&aspect->stream_state, &packet) != 0) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - - /*@@@ can't figure out a way to pass a useful number for 'samples' to the write_callback, so we'll just pass 0 */ - if(is_metadata) { - while(ogg_stream_flush(&aspect->stream_state, &aspect->page) != 0) { - if(write_callback(encoder, aspect->page.header, aspect->page.header_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - if(write_callback(encoder, aspect->page.body, aspect->page.body_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - } - else { - while(ogg_stream_pageout(&aspect->stream_state, &aspect->page) != 0) { - if(write_callback(encoder, aspect->page.header, aspect->page.header_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - if(write_callback(encoder, aspect->page.body, aspect->page.body_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - } - } - else if(is_metadata && current_frame == 0 && samples == 0 && bytes == 4 && 0 == memcmp(buffer, FLAC__STREAM_SYNC_STRING, sizeof(FLAC__STREAM_SYNC_STRING))) { - aspect->seen_magic = true; - } - else { - /* - * If we get here, our assumption about the way write callbacks happen - * explained above is wrong - */ - FLAC__ASSERT(0); - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - - aspect->samples_written += samples; - - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_helper.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_helper.c deleted file mode 100644 index cc6c2c149d..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_helper.c +++ /dev/null @@ -1,210 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for malloc() */ -#include /* for memcmp(), memcpy() */ -#include "../assert.h" -#include "../alloc.h" -#include "include/private/ogg_helper.h" -#include "include/protected/stream_encoder.h" - - -static FLAC__bool full_read_(FLAC__StreamEncoder *encoder, FLAC__byte *buffer, size_t bytes, FLAC__StreamEncoderReadCallback read_callback, void *client_data) -{ - while(bytes > 0) { - size_t bytes_read = bytes; - switch(read_callback(encoder, buffer, &bytes_read, client_data)) { - case FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE: - bytes -= bytes_read; - buffer += bytes_read; - break; - case FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM: - if(bytes_read == 0) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - bytes -= bytes_read; - buffer += bytes_read; - break; - case FLAC__STREAM_ENCODER_READ_STATUS_ABORT: - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - case FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED: - return false; - default: - /* double protection: */ - FLAC__ASSERT(0); - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - } - - return true; -} - -void simple_ogg_page__init(ogg_page *page) -{ - page->header = 0; - page->header_len = 0; - page->body = 0; - page->body_len = 0; -} - -void simple_ogg_page__clear(ogg_page *page) -{ - if(page->header) - free(page->header); - if(page->body) - free(page->body); - simple_ogg_page__init(page); -} - -FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data) -{ - static const uint32_t OGG_HEADER_FIXED_PORTION_LEN = 27; - static const uint32_t OGG_MAX_HEADER_LEN = 27/*OGG_HEADER_FIXED_PORTION_LEN*/ + 255; - FLAC__byte crc[4]; - FLAC__StreamEncoderSeekStatus seek_status; - - FLAC__ASSERT(page->header == 0); - FLAC__ASSERT(page->header_len == 0); - FLAC__ASSERT(page->body == 0); - FLAC__ASSERT(page->body_len == 0); - - /* move the stream pointer to the supposed beginning of the page */ - if(0 == seek_callback) - return false; - if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - /* allocate space for the page header */ - if(0 == (page->header = safe_malloc_(OGG_MAX_HEADER_LEN))) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* read in the fixed part of the page header (up to but not including - * the segment table */ - if(!full_read_(encoder, page->header, OGG_HEADER_FIXED_PORTION_LEN, read_callback, client_data)) - return false; - - page->header_len = OGG_HEADER_FIXED_PORTION_LEN + page->header[26]; - - /* check to see if it's a correct, "simple" page (one packet only) */ - if( - memcmp(page->header, "OggS", 4) || /* doesn't start with OggS */ - (page->header[5] & 0x01) || /* continued packet */ - memcmp(page->header+6, "\0\0\0\0\0\0\0\0", 8) || /* granulepos is non-zero */ - page->header[26] == 0 /* packet is 0-size */ - ) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - - /* read in the segment table */ - if(!full_read_(encoder, page->header + OGG_HEADER_FIXED_PORTION_LEN, page->header[26], read_callback, client_data)) - return false; - - { - uint32_t i; - - /* check to see that it specifies a single packet */ - for(i = 0; i < (uint32_t)page->header[26] - 1; i++) { - if(page->header[i + OGG_HEADER_FIXED_PORTION_LEN] != 255) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - } - - page->body_len = 255 * i + page->header[i + OGG_HEADER_FIXED_PORTION_LEN]; - } - - /* allocate space for the page body */ - if(0 == (page->body = safe_malloc_(page->body_len))) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* read in the page body */ - if(!full_read_(encoder, page->body, page->body_len, read_callback, client_data)) - return false; - - /* check the CRC */ - memcpy(crc, page->header+22, 4); - ogg_page_checksum_set(page); - if(memcmp(crc, page->header+22, 4)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - - return true; -} - -FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data) -{ - FLAC__StreamEncoderSeekStatus seek_status; - - FLAC__ASSERT(page->header != 0); - FLAC__ASSERT(page->header_len != 0); - FLAC__ASSERT(page->body != 0); - FLAC__ASSERT(page->body_len != 0); - - /* move the stream pointer to the supposed beginning of the page */ - if(0 == seek_callback) - return false; - if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - ogg_page_checksum_set(page); - - /* re-write the page */ - if(write_callback((FLAC__StreamEncoder*)encoder, page->header, page->header_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - if(write_callback((FLAC__StreamEncoder*)encoder, page->body, page->body_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - return true; -} diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_mapping.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_mapping.c deleted file mode 100644 index c3e67a424f..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/ogg_mapping.c +++ /dev/null @@ -1,48 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/ogg_mapping.h" - -const uint32_t FLAC__OGG_MAPPING_PACKET_TYPE_LEN = 8; /* bits */ - -const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE = 0x7f; - -const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC = (const FLAC__byte * const)"FLAC"; - -const uint32_t FLAC__OGG_MAPPING_VERSION_MAJOR_LEN = 8; /* bits */ -const uint32_t FLAC__OGG_MAPPING_VERSION_MINOR_LEN = 8; /* bits */ - -const uint32_t FLAC__OGG_MAPPING_NUM_HEADERS_LEN = 16; /* bits */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_decoder.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_decoder.c index ad3ec0bca7..60628077d3 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_decoder.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_decoder.c @@ -52,7 +52,6 @@ #include "include/private/lpc.h" #include "include/private/md5.h" #include "include/private/memory.h" -#include "include/private/macros.h" /* technically this should be in an "export.c" but this is convenient enough */ @@ -74,7 +73,7 @@ static const FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' }; ***********************************************************************/ static void set_defaults_(FLAC__StreamDecoder *decoder); -static FILE *get_binary_stdin_(void); +//static FILE *get_binary_stdin_(void); static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_t channels); static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id); static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder); @@ -106,11 +105,11 @@ static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__u #if FLAC__HAS_OGG static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); #endif -static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); -static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data); +//static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); +//static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); +//static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); +//static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); +//static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data); /*********************************************************************** * @@ -245,18 +244,18 @@ FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void) FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ - decoder = calloc(1, sizeof(FLAC__StreamDecoder)); + decoder = (FLAC__StreamDecoder*) calloc(1, sizeof(FLAC__StreamDecoder)); if(decoder == 0) { return 0; } - decoder->protected_ = calloc(1, sizeof(FLAC__StreamDecoderProtected)); + decoder->protected_ = (FLAC__StreamDecoderProtected*) calloc(1, sizeof(FLAC__StreamDecoderProtected)); if(decoder->protected_ == 0) { free(decoder); return 0; } - decoder->private_ = calloc(1, sizeof(FLAC__StreamDecoderPrivate)); + decoder->private_ = (FLAC__StreamDecoderPrivate*) calloc(1, sizeof(FLAC__StreamDecoderPrivate)); if(decoder->private_ == 0) { free(decoder->protected_); free(decoder); @@ -272,7 +271,7 @@ FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void) } decoder->private_->metadata_filter_ids_capacity = 16; - if(0 == (decoder->private_->metadata_filter_ids = malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) { + if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*) malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) { FLAC__bitreader_delete(decoder->private_->input); free(decoder->private_); free(decoder->protected_); @@ -352,8 +351,10 @@ static FLAC__StreamDecoderInitStatus init_stream_internal_( if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - if(FLAC__HAS_OGG == 0 && is_ogg) + #if FLAC__HAS_OGG == 0 + if(is_ogg) return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER; + #endif if( 0 == read_callback || @@ -500,6 +501,7 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream( ); } +#if 0 static FLAC__StreamDecoderInitStatus init_FILE_internal_( FLAC__StreamDecoder *decoder, FILE *file, @@ -624,6 +626,7 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file( { return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true); } +#endif FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) { @@ -749,7 +752,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__ FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids); if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) { - if(0 == (decoder->private_->metadata_filter_ids = safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) { + if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*) safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -808,7 +811,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__S FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids); if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) { - if(0 == (decoder->private_->metadata_filter_ids = safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) { + if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*) safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1241,6 +1244,7 @@ void set_defaults_(FLAC__StreamDecoder *decoder) #endif } +#if 0 /* * This will forcibly set stdin to binary mode (for OSes that require it) */ @@ -1258,6 +1262,7 @@ FILE *get_binary_stdin_(void) return stdin; } +#endif FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_t channels) { @@ -1287,7 +1292,7 @@ FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_ * in front (at negative indices) for alignment purposes; * we use 4 to keep the data well-aligned. */ - tmp = safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/); + tmp = (FLAC__int32*) safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/); if(tmp == 0) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; @@ -1324,12 +1329,12 @@ FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id) FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder) { FLAC__uint32 x; - uint32_t i, id; + uint32_t i, id_; FLAC__bool first = true; FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - for(i = id = 0; i < 4; ) { + for(i = id_ = 0; i < 4; ) { if(decoder->private_->cached) { x = (FLAC__uint32)decoder->private_->lookahead; decoder->private_->cached = false; @@ -1341,23 +1346,23 @@ FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder) if(x == FLAC__STREAM_SYNC_STRING[i]) { first = true; i++; - id = 0; + id_ = 0; continue; } - if(id >= 3) + if(id_ >= 3) return false; - if(x == ID3V2_TAG_[id]) { - id++; + if(x == ID3V2_TAG_[id_]) { + id_++; i = 0; - if(id == 3) { + if(id_ == 3) { if(!skip_id3v2_tag_(decoder)) return false; /* skip_id3v2_tag_ sets the state for us */ } continue; } - id = 0; + id_ = 0; if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ decoder->private_->header_warmup[0] = (FLAC__byte)x; if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) @@ -1464,7 +1469,7 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder) case FLAC__METADATA_TYPE_APPLICATION: /* remember, we read the ID already */ if(real_length > 0) { - if(0 == (block.data.application.data = malloc(real_length))) { + if(0 == (block.data.application.data = (FLAC__byte*) malloc(real_length))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; ok = false; } @@ -1492,7 +1497,7 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder) break; default: if(real_length > 0) { - if(0 == (block.data.unknown.data = malloc(real_length))) { + if(0 == (block.data.unknown.data = (FLAC__byte*) malloc(real_length))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; ok = false; } @@ -1651,7 +1656,7 @@ FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_ decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; /* use realloc since we may pass through here several times (e.g. after seeking) */ - if(0 == (decoder->private_->seek_table.data.seek_table.points = safe_realloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) { + if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*) safe_realloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1699,7 +1704,7 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre } else length -= obj->vendor_string.length; - if (0 == (obj->vendor_string.entry = safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) { + if (0 == (obj->vendor_string.entry = (FLAC__byte*) safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1722,7 +1727,7 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre return false; } if (obj->num_comments > 0) { - if (0 == (obj->comments = safe_malloc_mul_2op_p(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) { + if (0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*) safe_malloc_mul_2op_p(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) { obj->num_comments = 0; decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; @@ -1750,7 +1755,7 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre } else length -= obj->comments[i].length; - if (0 == (obj->comments[i].entry = safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) { + if (0 == (obj->comments[i].entry = (FLAC__byte*) safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; obj->num_comments = i; return false; @@ -1812,7 +1817,7 @@ FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMet obj->num_tracks = x; if(obj->num_tracks > 0) { - if(0 == (obj->tracks = safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) { + if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*) safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1845,7 +1850,7 @@ FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMet track->num_indices = (FLAC__byte)x; if(track->num_indices > 0) { - if(0 == (track->indices = safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) { + if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*) safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1877,12 +1882,12 @@ FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMeta /* read type */ if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN)) return false; /* read_callback_ sets the state for us */ - obj->type = x; + obj->type = (FLAC__StreamMetadata_Picture_Type) x; /* read MIME type */ if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) return false; /* read_callback_ sets the state for us */ - if(0 == (obj->mime_type = safe_malloc_add_2op_(x, /*+*/1))) { + if(0 == (obj->mime_type = (char*) safe_malloc_add_2op_(x, /*+*/1))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1895,7 +1900,7 @@ FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMeta /* read description */ if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) return false; /* read_callback_ sets the state for us */ - if(0 == (obj->description = safe_malloc_add_2op_(x, /*+*/1))) { + if(0 == (obj->description = (FLAC__byte*) safe_malloc_add_2op_(x, /*+*/1))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -1924,7 +1929,7 @@ FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMeta /* read data */ if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) return false; /* read_callback_ sets the state for us */ - if(0 == (obj->data = safe_malloc_(obj->data_length))) { + if(0 == (obj->data = (FLAC__byte*) safe_malloc_(obj->data_length))) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -3382,6 +3387,7 @@ FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint } #endif +#if 0 FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) { (void)client_data; @@ -3447,6 +3453,7 @@ FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_d return feof(decoder->private_->file)? true : false; } +#endif void *get_client_data_from_decoder(FLAC__StreamDecoder *decoder) { diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder.c index 9a423b6fcf..c48ba8a686 100644 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder.c +++ b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder.c @@ -56,7 +56,6 @@ #include "include/private/lpc.h" #include "include/private/md5.h" #include "include/private/memory.h" -#include "include/private/macros.h" #if FLAC__HAS_OGG #include "include/private/ogg_helper.h" #include "include/private/ogg_mapping.h" @@ -65,7 +64,6 @@ #include "include/private/stream_encoder_framing.h" #include "include/private/window.h" #include "../alloc.h" -#include "../private.h" /* Exact Rice codeword length calculation is off by default. The simple @@ -300,11 +298,11 @@ static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamD static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); -static FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); -static FILE *get_binary_stdout_(void); +//static FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data); +//static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); +//static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); +//static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); +//static FILE *get_binary_stdout_(void); /*********************************************************************** @@ -508,18 +506,18 @@ FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void) FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ - encoder = calloc(1, sizeof(FLAC__StreamEncoder)); + encoder = (FLAC__StreamEncoder*) calloc(1, sizeof(FLAC__StreamEncoder)); if(encoder == 0) { return 0; } - encoder->protected_ = calloc(1, sizeof(FLAC__StreamEncoderProtected)); + encoder->protected_ = (FLAC__StreamEncoderProtected*) calloc(1, sizeof(FLAC__StreamEncoderProtected)); if(encoder->protected_ == 0) { free(encoder); return 0; } - encoder->private_ = calloc(1, sizeof(FLAC__StreamEncoderPrivate)); + encoder->private_ = (FLAC__StreamEncoderPrivate*) calloc(1, sizeof(FLAC__StreamEncoderPrivate)); if(encoder->private_ == 0) { free(encoder->protected_); free(encoder); @@ -633,8 +631,10 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_( if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - if(FLAC__HAS_OGG == 0 && is_ogg) + #if FLAC__HAS_OGG == 0 + if(is_ogg) return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER; + #endif if(0 == write_callback || (seek_callback && 0 == tell_callback)) return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS; @@ -1136,7 +1136,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_( */ encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_; for(i = 0; i < encoder->protected_->channels; i++) { - if(0 == (encoder->private_->verify.input_fifo.data[i] = safe_malloc_mul_2op_p(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) { + if(0 == (encoder->private_->verify.input_fifo.data[i] = (FLAC__int32*) safe_malloc_mul_2op_p(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) { encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; } @@ -1325,6 +1325,7 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream( ); } +#if 0 static FLAC__StreamEncoderInitStatus init_FILE_internal_( FLAC__StreamEncoder *encoder, FILE *file, @@ -1464,6 +1465,7 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file( { return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true); } +#endif FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) { @@ -1576,7 +1578,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncod return true; } -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value) +inline FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); @@ -1905,7 +1907,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__Stream FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; - value = flac_min(value, (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN) - 1); + value = flac_min(value, (FLAC__uint64) ((FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN) - 1)); encoder->protected_->total_samples_estimate = value; return true; } @@ -1929,7 +1931,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encod } if(num_blocks) { FLAC__StreamMetadata **m; - if(0 == (m = safe_malloc_mul_2op_p(sizeof(m[0]), /*times*/num_blocks))) + if(0 == (m = (FLAC__StreamMetadata**) safe_malloc_mul_2op_p(sizeof(m[0]), /*times*/num_blocks))) return false; memcpy(m, metadata, sizeof(m[0]) * num_blocks); encoder->protected_->metadata = m; @@ -1946,7 +1948,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encod * These three functions are not static, but not publicly exposed in * include/FLAC/ either. They are used by the test suite. */ -FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) +inline FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); @@ -1957,7 +1959,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__Stream return true; } -FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) +inline FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); @@ -1968,7 +1970,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEnc return true; } -FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) +inline FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); @@ -2044,7 +2046,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__Strea return encoder->protected_->streamable_subset; } -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder) +inline FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); @@ -2633,8 +2635,8 @@ FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, uint32_t samples, FLAC FLAC__bitwriter_clear(encoder->private_->frame); if(samples > 0) { - encoder->private_->streaminfo.data.stream_info.min_framesize = flac_min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize); - encoder->private_->streaminfo.data.stream_info.max_framesize = flac_max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize); + encoder->private_->streaminfo.data.stream_info.min_framesize = flac_min((uint32_t) bytes, encoder->private_->streaminfo.data.stream_info.min_framesize); + encoder->private_->streaminfo.data.stream_info.max_framesize = flac_max((uint32_t) bytes, encoder->private_->streaminfo.data.stream_info.max_framesize); } return true; @@ -2659,7 +2661,7 @@ FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const * Watch for the STREAMINFO block and first SEEKTABLE block to go by and store their offsets. */ if(samples == 0) { - FLAC__MetadataType type = (buffer[0] & 0x7f); + FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f); if(type == FLAC__METADATA_TYPE_STREAMINFO) encoder->protected_->streaminfo_offset = output_position; else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0) @@ -4129,14 +4131,14 @@ static inline uint32_t count_rice_bits_in_partition_( ) { return (uint32_t)(flac_min( // To make sure the return value doesn't overflow - FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */ + (uint32_t) (FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */ (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */ ( rice_parameter? (abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */ : (abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */ ) - - (partition_samples >> 1),(uint32_t)(-1))); + - (partition_samples >> 1)),(uint32_t)(-1))); /* -(partition_samples>>1) to subtract out extra contributions to the abs_residual_partition_sum. * The actual number of bits used is closer to the sum(for all i in the partition) of abs(residual[i])>>(rice_parameter-1) * By using the abs_residual_partition sum, we also add in bits in the LSBs that would normally be shifted out. @@ -4484,6 +4486,7 @@ void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; } +#if 0 FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) { (void)client_data; @@ -4585,3 +4588,4 @@ FILE *get_binary_stdout_(void) return stdout; } +#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_avx2.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_avx2.c deleted file mode 100644 index 9717c208be..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_avx2.c +++ /dev/null @@ -1,146 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/stream_encoder.h" -#include "include/private/bitmath.h" -#ifdef FLAC__AVX2_SUPPORTED - -#include /* for abs() */ -#include /* AVX2 */ -#include "../assert.h" - -FLAC__SSE_TARGET("avx2") -void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int32_t)predictor_order); - - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m256i sum256 = _mm256_setzero_si256(); - __m128i sum128; - end += default_partition_samples; - - for( ; (int)residual_sample < (int)end-7; residual_sample+=8) { - __m256i res256 = _mm256_abs_epi32(_mm256_loadu_si256((const __m256i*)(residual+residual_sample))); - sum256 = _mm256_add_epi32(sum256, res256); - } - - sum128 = _mm_add_epi32(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256)); - - for( ; (int)residual_sample < (int)end-3; residual_sample+=4) { - __m128i res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample))); - sum128 = _mm_add_epi32(sum128, res128); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i res128 = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - sum128 = _mm_add_epi32(sum128, res128); - } - - sum128 = _mm_add_epi32(sum128, _mm_shuffle_epi32(sum128, _MM_SHUFFLE(1,0,3,2))); - sum128 = _mm_add_epi32(sum128, _mm_shufflelo_epi16(sum128, _MM_SHUFFLE(1,0,3,2))); - abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(sum128); -/* workaround for MSVC bugs (at least versions 2015 and 2017 are affected) */ -#if (defined _MSC_VER) && (defined FLAC__CPU_X86_64) - abs_residual_partition_sums[partition] &= 0xFFFFFFFF; /**/ -#endif - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m256i sum256 = _mm256_setzero_si256(); - __m128i sum128; - end += default_partition_samples; - - for( ; (int)residual_sample < (int)end-3; residual_sample+=4) { - __m128i res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample))); - __m256i res256 = _mm256_cvtepu32_epi64(res128); - sum256 = _mm256_add_epi64(sum256, res256); - } - - sum128 = _mm_add_epi64(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256)); - - for( ; (int)residual_sample < (int)end-1; residual_sample+=2) { - __m128i res128 = _mm_abs_epi32(_mm_loadl_epi64((const __m128i*)(residual+residual_sample))); - res128 = _mm_cvtepu32_epi64(res128); - sum128 = _mm_add_epi64(sum128, res128); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i res128 = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - sum128 = _mm_add_epi64(sum128, res128); - } - - sum128 = _mm_add_epi64(sum128, _mm_srli_si128(sum128, 8)); - _mm_storel_epi64((__m128i*)(abs_residual_partition_sums+partition), sum128); - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } - _mm256_zeroupper(); -} - -#endif /* FLAC__AVX2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_sse2.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_sse2.c deleted file mode 100644 index fa4c41b375..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_sse2.c +++ /dev/null @@ -1,159 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/stream_encoder.h" -#include "include/private/bitmath.h" -#ifdef FLAC__SSE2_SUPPORTED - -#include /* for abs() */ -#include /* SSE2 */ -#include "../assert.h" -#include "../compat.h" - -FLAC__SSE_TARGET("sse2") -static inline __m128i local_abs_epi32(__m128i val) -{ - __m128i mask = _mm_srai_epi32(val, 31); - val = _mm_xor_si128(val, mask); - val = _mm_sub_epi32(val, mask); - return val; -} - - -FLAC__SSE_TARGET("sse2") -void FLAC__precompute_partition_info_sums_intrin_sse2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int32_t)predictor_order); - - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 3) & ~3; e3 = end & ~3; - if(e1 > end) - e1 = end; /* try flac -l 1 -b 16 and you'll be here */ - - /* assumption: residual[] is properly aligned so (residual + e1) is properly aligned too and _mm_loadu_si128() is fast */ - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=4) { - __m128i mm_res = local_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample))); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi32(mm_sum, _mm_shuffle_epi32(mm_sum, _MM_SHUFFLE(1,0,3,2))); - mm_sum = _mm_add_epi32(mm_sum, _mm_shufflelo_epi16(mm_sum, _MM_SHUFFLE(1,0,3,2))); - abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(mm_sum); -/* workaround for MSVC bugs (at least versions 2015 and 2017 are affected) */ -#if (defined _MSC_VER) && (defined FLAC__CPU_X86_64) - abs_residual_partition_sums[partition] &= 0xFFFFFFFF; -#endif - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 1) & ~1; e3 = end & ~1; - FLAC__ASSERT(e1 <= end); - - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); /* 0 0 0 |r0| == 00 |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=2) { - __m128i mm_res = local_abs_epi32(_mm_loadl_epi64((const __m128i*)(residual+residual_sample))); /* 0 0 |r1| |r0| */ - mm_res = _mm_shuffle_epi32(mm_res, _MM_SHUFFLE(3,1,2,0)); /* 0 |r1| 0 |r0| == |r1_64| |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi64(mm_sum, _mm_srli_si128(mm_sum, 8)); - _mm_storel_epi64((__m128i*)(abs_residual_partition_sums+partition), mm_sum); - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } -} - -#endif /* FLAC__SSE2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_ssse3.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_ssse3.c deleted file mode 100644 index f969a145b6..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/stream_encoder_intrin_ssse3.c +++ /dev/null @@ -1,148 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "include/private/cpu.h" - -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "include/private/stream_encoder.h" -#include "include/private/bitmath.h" -#ifdef FLAC__SSSE3_SUPPORTED - -#include /* for abs() */ -#include /* SSSE3 */ -#include "../assert.h" - -FLAC__SSE_TARGET("ssse3") -void FLAC__precompute_partition_info_sums_intrin_ssse3(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int32_t)predictor_order); - - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 3) & ~3; e3 = end & ~3; - if(e1 > end) - e1 = end; /* try flac -l 1 -b 16 and you'll be here */ - - /* assumption: residual[] is properly aligned so (residual + e1) is properly aligned too and _mm_loadu_si128() is fast */ - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=4) { - __m128i mm_res = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample))); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi32(mm_sum, _mm_shuffle_epi32(mm_sum, _MM_SHUFFLE(1,0,3,2))); - mm_sum = _mm_add_epi32(mm_sum, _mm_shufflelo_epi16(mm_sum, _MM_SHUFFLE(1,0,3,2))); - abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(mm_sum); -/* workaround for MSVC bugs (at least versions 2015 and 2017 are affected) */ -#if (defined _MSC_VER) && (defined FLAC__CPU_X86_64) - abs_residual_partition_sums[partition] &= 0xFFFFFFFF; -#endif - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 1) & ~1; e3 = end & ~1; - FLAC__ASSERT(e1 <= end); - - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); /* 0 0 0 |r0| == 00 |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=2) { - __m128i mm_res = _mm_abs_epi32(_mm_loadl_epi64((const __m128i*)(residual+residual_sample))); /* 0 0 |r1| |r0| */ - mm_res = _mm_shuffle_epi32(mm_res, _MM_SHUFFLE(3,1,2,0)); /* 0 |r1| 0 |r0| == |r1_64| |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi64(mm_sum, _mm_srli_si128(mm_sum, 8)); - _mm_storel_epi64((__m128i*)(abs_residual_partition_sums+partition), mm_sum); - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } -} - -#endif /* FLAC__SSSE3_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/window.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/window_flac.c similarity index 100% rename from modules/juce_audio_formats/codecs/flac_134/libFLAC/window.c rename to modules/juce_audio_formats/codecs/flac_134/libFLAC/window_flac.c diff --git a/modules/juce_audio_formats/codecs/flac_134/libFLAC/windows_unicode_filenames.c b/modules/juce_audio_formats/codecs/flac_134/libFLAC/windows_unicode_filenames.c deleted file mode 100644 index 9226071cee..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/libFLAC/windows_unicode_filenames.c +++ /dev/null @@ -1,187 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "../windows_unicode_filenames.h" - -/*** FIXME: KLUDGE: export these syms for flac.exe, metaflac.exe, etc. ***/ - -/* convert UTF-8 back to WCHAR. Caller is responsible for freeing memory */ -static wchar_t *wchar_from_utf8(const char *str) -{ - wchar_t *widestr; - int len; - - if (!str) - return NULL; - if ((len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) == 0) - return NULL; - if ((widestr = (wchar_t *)malloc(len*sizeof(wchar_t))) == NULL) - return NULL; - if (MultiByteToWideChar(CP_UTF8, 0, str, -1, widestr, len) == 0) { - free(widestr); - widestr = NULL; - } - - return widestr; -} - - -static FLAC__bool utf8_filenames = false; - - -FLAC_API void flac_internal_set_utf8_filenames(FLAC__bool flag) -{ - utf8_filenames = flag ? true : false; -} - -FLAC_API FLAC__bool flac_internal_get_utf8_filenames(void) -{ - return utf8_filenames; -} - -/* file functions */ - -FLAC_API FILE* flac_internal_fopen_utf8(const char *filename, const char *mode) -{ - if (!utf8_filenames) { - return fopen(filename, mode); - } else { - wchar_t *wname = NULL; - wchar_t *wmode = NULL; - FILE *f = NULL; - - do { - if (!(wname = wchar_from_utf8(filename))) break; - if (!(wmode = wchar_from_utf8(mode))) break; - f = _wfopen(wname, wmode); - } while(0); - - free(wname); - free(wmode); - - return f; - } -} - -FLAC_API int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer) -{ - if (!utf8_filenames) { - return _stat64(path, buffer); - } else { - wchar_t *wpath; - int ret; - - if (!(wpath = wchar_from_utf8(path))) return -1; - ret = _wstat64(wpath, buffer); - free(wpath); - - return ret; - } -} - -FLAC_API int flac_internal_chmod_utf8(const char *filename, int pmode) -{ - if (!utf8_filenames) { - return _chmod(filename, pmode); - } else { - wchar_t *wname; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ret = _wchmod(wname, pmode); - free(wname); - - return ret; - } -} - -FLAC_API int flac_internal_utime_utf8(const char *filename, struct utimbuf *times) -{ - if (!utf8_filenames) { - return utime(filename, times); - } else { - wchar_t *wname; - struct __utimbuf64 ut; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ut.actime = times->actime; - ut.modtime = times->modtime; - ret = _wutime64(wname, &ut); - free(wname); - - return ret; - } -} - -FLAC_API int flac_internal_unlink_utf8(const char *filename) -{ - if (!utf8_filenames) { - return _unlink(filename); - } else { - wchar_t *wname; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ret = _wunlink(wname); - free(wname); - - return ret; - } -} - -FLAC_API int flac_internal_rename_utf8(const char *oldname, const char *newname) -{ - if (!utf8_filenames) { - return rename(oldname, newname); - } else { - wchar_t *wold = NULL; - wchar_t *wnew = NULL; - int ret = -1; - - do { - if (!(wold = wchar_from_utf8(oldname))) break; - if (!(wnew = wchar_from_utf8(newname))) break; - ret = _wrename(wold, wnew); - } while(0); - - free(wold); - free(wnew); - - return ret; - } -} diff --git a/modules/juce_audio_formats/codecs/flac_134/macros.h b/modules/juce_audio_formats/codecs/flac_134/macros.h deleted file mode 100644 index 240c34a9c8..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/macros.h +++ /dev/null @@ -1,45 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -/* FLAC_CHECK_RETURN : Check the return value of the provided function and - * print an error message if it fails (ie returns a value < 0). - * - * Ideally, a library should not print anything, but this macro is only used - * for things that extremely unlikely to fail, like `chown` to a previoulsy - * saved `uid`. - */ - -#define FLAC_CHECK_RETURN(x) \ - { if ((x) < 0) \ - fprintf (stderr, "%s : %s\n", #x, strerror (errno)) ; \ - } diff --git a/modules/juce_audio_formats/codecs/flac_134/metadata.h b/modules/juce_audio_formats/codecs/flac_134/metadata.h index 01991c6f9c..ebba19d6ac 100644 --- a/modules/juce_audio_formats/codecs/flac_134/metadata.h +++ b/modules/juce_audio_formats/codecs/flac_134/metadata.h @@ -33,7 +33,6 @@ #ifndef FLAC__METADATA_H #define FLAC__METADATA_H -#include /* for off_t */ #include "export.h" #include "callback.h" #include "format.h" diff --git a/modules/juce_audio_formats/codecs/flac_134/msvc2005_int.h b/modules/juce_audio_formats/codecs/flac_134/msvc2005_int.h deleted file mode 100644 index af97e1386a..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/msvc2005_int.h +++ /dev/null @@ -1,53 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2017 Xiph.org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* This header file defines integer [u]intNN_t types. - * It is auto-included in all files via "Force Includes" (/FI) - * option in all *.vcproj files (Visual Studio 2005, 2008) - */ - -#ifndef FLAC__SHARE__MSVC2005_INT_H -#define FLAC__SHARE__MSVC2005_INT_H - -#if defined _MSC_VER && _MSC_VER < 1600 - -typedef signed __int8 int8_t; -typedef signed __int16 int16_t; -typedef signed __int32 int32_t; -typedef signed __int64 int64_t; -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; - -#endif - -#endif /* FLAC__SHARE__MSVC2005_INT_H */ diff --git a/modules/juce_audio_formats/codecs/flac_134/private.h b/modules/juce_audio_formats/codecs/flac_134/private.h deleted file mode 100644 index 9f709cb336..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/private.h +++ /dev/null @@ -1,45 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef FLAC__SHARE__PRIVATE_H -#define FLAC__SHARE__PRIVATE_H - -/* - * Unpublished debug routines from libFLAC. This should not be used from any - * client code other than code shipped with the FLAC sources. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder); - -#endif /* FLAC__SHARE__PRIVATE_H */ diff --git a/modules/juce_audio_formats/codecs/flac_134/replaygain_analysis.h b/modules/juce_audio_formats/codecs/flac_134/replaygain_analysis.h deleted file mode 100644 index 754e83e171..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/replaygain_analysis.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ReplayGainAnalysis - analyzes input samples and give the recommended dB change - * Copyright (C) 2001 David Robinson and Glen Sawyer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * concept and filter values by David Robinson (David@Robinson.org) - * -- blame him if you think the idea is flawed - * coding by Glen Sawyer (glensawyer@hotmail.com) 442 N 700 E, Provo, UT 84606 USA - * -- blame him if you think this runs too slowly, or the coding is otherwise flawed - * minor cosmetic tweaks to integrate with FLAC by Josh Coalson - * - * For an explanation of the concepts and the basic algorithms involved, go to: - * http://www.replaygain.org/ - */ - -#ifndef GAIN_ANALYSIS_H -#define GAIN_ANALYSIS_H - -#include - -#define GAIN_NOT_ENOUGH_SAMPLES -24601 -#define GAIN_ANALYSIS_ERROR 0 -#define GAIN_ANALYSIS_OK 1 - -#define INIT_GAIN_ANALYSIS_ERROR 0 -#define INIT_GAIN_ANALYSIS_OK 1 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef float flac_float_t; /* Type used for filtering */ - -extern flac_float_t ReplayGainReferenceLoudness; /* in dB SPL, currently == 89.0 */ - -int InitGainAnalysis ( long samplefreq ); -int ValidGainFrequency ( long samplefreq ); -int AnalyzeSamples ( const flac_float_t* left_samples, const flac_float_t* right_samples, size_t num_samples, int num_channels ); -flac_float_t GetTitleGain ( void ); -flac_float_t GetAlbumGain ( void ); - -#ifdef __cplusplus -} -#endif - -#endif /* GAIN_ANALYSIS_H */ diff --git a/modules/juce_audio_formats/codecs/flac_134/replaygain_synthesis.h b/modules/juce_audio_formats/codecs/flac_134/replaygain_synthesis.h deleted file mode 100644 index 09db23c8a0..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/replaygain_synthesis.h +++ /dev/null @@ -1,52 +0,0 @@ -/* replaygain_synthesis - Routines for applying ReplayGain to a signal - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2016 Xiph.Org Foundation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H -#define FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H - -#include /* for size_t */ -#include "format.h" - -#define FLAC_SHARE__MAX_SUPPORTED_CHANNELS FLAC__MAX_CHANNELS - -typedef enum { - NOISE_SHAPING_NONE = 0, - NOISE_SHAPING_LOW = 1, - NOISE_SHAPING_MEDIUM = 2, - NOISE_SHAPING_HIGH = 3 -} NoiseShaping; - -typedef struct { - const float* FilterCoeff; - FLAC__uint64 Mask; - double Add; - float Dither; - float ErrorHistory [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16]; /* 16th order Noise shaping */ - float DitherHistory [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16]; - int LastRandomNumber [FLAC_SHARE__MAX_SUPPORTED_CHANNELS]; - unsigned LastHistoryIndex; - NoiseShaping ShapingType; -} DitherContext; - -void FLAC__replaygain_synthesis__init_dither_context(DitherContext *dither, int bits, int shapingtype); - -/* scale = (float) pow(10., (double)replaygain * 0.05); */ -size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, FLAC__bool unsigned_data_out, const FLAC__int32 * const input[], uint32_t wide_samples, uint32_t channels, const uint32_t source_bps, const uint32_t target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context); - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/safe_str.h b/modules/juce_audio_formats/codecs/flac_134/safe_str.h deleted file mode 100644 index 26bef81d6a..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/safe_str.h +++ /dev/null @@ -1,71 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* Safe string handling functions to replace things like strcpy, strncpy, - * strcat, strncat etc. - * All of these functions guarantee a correctly NUL terminated string but - * the string may be truncated if the destination buffer was too short. - */ - -#ifndef FLAC__SHARE_SAFE_STR_H -#define FLAC__SHARE_SAFE_STR_H - -static inline char * -safe_strncat(char *dest, const char *src, size_t dest_size) -{ - char * ret; - - if (dest_size < 1) - return dest; - - /* Assume dist has space for a term character .. */ - ret = strncat(dest, src, dest_size - strlen (dest)); - /* .. but set it explicitly. */ - dest [dest_size - 1] = 0; - - return ret; -} - -static inline char * -safe_strncpy(char *dest, const char *src, size_t dest_size) -{ - char * ret; - - if (dest_size < 1) - return dest; - - ret = strncpy(dest, src, dest_size - 1); - dest [dest_size - 1] = 0; - - return ret; -} - -#endif /* FLAC__SHARE_SAFE_STR_H */ diff --git a/modules/juce_audio_formats/codecs/flac_134/stream_decoder.h b/modules/juce_audio_formats/codecs/flac_134/stream_decoder.h index b33cad6cc7..76eb12329f 100644 --- a/modules/juce_audio_formats/codecs/flac_134/stream_decoder.h +++ b/modules/juce_audio_formats/codecs/flac_134/stream_decoder.h @@ -33,7 +33,6 @@ #ifndef FLAC__STREAM_DECODER_H #define FLAC__STREAM_DECODER_H -#include /* for FILE */ #include "export.h" #include "format.h" diff --git a/modules/juce_audio_formats/codecs/flac_134/stream_encoder.h b/modules/juce_audio_formats/codecs/flac_134/stream_encoder.h index d603e1f218..c14528cb4e 100644 --- a/modules/juce_audio_formats/codecs/flac_134/stream_encoder.h +++ b/modules/juce_audio_formats/codecs/flac_134/stream_encoder.h @@ -33,7 +33,6 @@ #ifndef FLAC__STREAM_ENCODER_H #define FLAC__STREAM_ENCODER_H -#include /* for FILE */ #include "export.h" #include "format.h" #include "stream_decoder.h" diff --git a/modules/juce_audio_formats/codecs/flac_134/utf8.h b/modules/juce_audio_formats/codecs/flac_134/utf8.h deleted file mode 100644 index 5b292e297a..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/utf8.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SHARE__UTF8_H -#define SHARE__UTF8_H - -/* - * Convert a string between UTF-8 and the locale's charset. - * Invalid bytes are replaced by '#', and characters that are - * not available in the target encoding are replaced by '?'. - * - * If the locale's charset is not set explicitly then it is - * obtained using nl_langinfo(CODESET), where available, the - * environment variable CHARSET, or assumed to be US-ASCII. - * - * Return value of conversion functions: - * - * -1 : memory allocation failed - * 0 : data was converted exactly - * 1 : valid data was converted approximately (using '?') - * 2 : input was invalid (but still converted, using '#') - * 3 : unknown encoding (but still converted, using '?') - */ - -int utf8_encode(const char *from, char **to); -int utf8_decode(const char *from, char **to); - -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/win_utf8_io.h b/modules/juce_audio_formats/codecs/flac_134/win_utf8_io.h deleted file mode 100644 index 763bec2f58..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/win_utf8_io.h +++ /dev/null @@ -1,61 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 - -#ifndef flac__win_utf8_io_h -#define flac__win_utf8_io_h - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -size_t strlen_utf8(const char *str); -int win_get_console_width(void); - -int get_utf8_argv(int *argc, char ***argv); - -int printf_utf8(const char *format, ...); -int fprintf_utf8(FILE *stream, const char *format, ...); -int vfprintf_utf8(FILE *stream, const char *format, va_list argptr); - -#include -HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif -#endif diff --git a/modules/juce_audio_formats/codecs/flac_134/windows_unicode_filenames.h b/modules/juce_audio_formats/codecs/flac_134/windows_unicode_filenames.h deleted file mode 100644 index d93eceb20b..0000000000 --- a/modules/juce_audio_formats/codecs/flac_134/windows_unicode_filenames.h +++ /dev/null @@ -1,66 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2016 Xiph.Org Foundation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 - -#ifndef flac__windows_unicode_filenames_h -#define flac__windows_unicode_filenames_h - -#include -#include -#include -#include "ordinals.h" - -/***** FIXME: KLUDGE: export these syms for flac.exe, metaflac.exe, etc. *****/ -#include "export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -FLAC_API void flac_internal_set_utf8_filenames(FLAC__bool flag); -FLAC_API FLAC__bool flac_internal_get_utf8_filenames(void); -#define flac_set_utf8_filenames flac_internal_set_utf8_filenames -#define flac_get_utf8_filenames flac_internal_get_utf8_filenames - -FLAC_API FILE* flac_internal_fopen_utf8(const char *filename, const char *mode); -FLAC_API int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer); -FLAC_API int flac_internal_chmod_utf8(const char *filename, int pmode); -FLAC_API int flac_internal_utime_utf8(const char *filename, struct utimbuf *times); -FLAC_API int flac_internal_unlink_utf8(const char *filename); -FLAC_API int flac_internal_rename_utf8(const char *oldname, const char *newname); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif -#endif