mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
FLAC: Prepare 1.3.4 lib files for inclusion in the JUCE build
This commit is contained in:
parent
2ba2bc9677
commit
3810252ae2
56 changed files with 192 additions and 13392 deletions
51
modules/juce_audio_formats/codecs/flac_134/Flac Licence.txt
Normal file
51
modules/juce_audio_formats/codecs/flac_134/Flac Licence.txt
Normal file
|
|
@ -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.
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -41,11 +41,14 @@
|
|||
* before #including this file, otherwise SIZE_MAX might not be defined
|
||||
*/
|
||||
|
||||
#include <limits.h> /* for SIZE_MAX */
|
||||
#if HAVE_STDINT_H
|
||||
#include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
|
||||
#endif
|
||||
#include <stdlib.h> /* for size_t, malloc(), etc */
|
||||
// JUCE: removed as JUCE already includes standard headers and including
|
||||
// these in FlacNamespace will cause problems
|
||||
|
||||
//#include <limits.h> /* for SIZE_MAX */
|
||||
//#if HAVE_STDINT_H
|
||||
//#include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
|
||||
//#endif
|
||||
//#include <stdlib.h> /* for size_t, malloc(), etc */
|
||||
#include "compat.h"
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
|
|
|
|||
|
|
@ -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 <assert.h>
|
||||
// JUCE: removed as JUCE already includes standard headers and including
|
||||
// these in FlacNamespace will cause problems
|
||||
|
||||
//#include <assert.h>
|
||||
#define FLAC__ASSERT(x) assert(x)
|
||||
#define FLAC__ASSERT_DECLARATION(x) x
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -34,7 +34,10 @@
|
|||
#define FLAC__CALLBACK_H
|
||||
|
||||
#include "ordinals.h"
|
||||
#include <stdlib.h> /* for size_t */
|
||||
|
||||
// JUCE: removed as JUCE already includes this and including stdlib
|
||||
// in FlacNamespace will cause problems
|
||||
//#include <stdlib.h> /* for size_t */
|
||||
|
||||
/** \file include/FLAC/callback.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 <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
|
||||
#include <sys/types.h> /* 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 <inttypes.h>
|
||||
#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 <io.h> /* for _setmode(), chmod() */
|
||||
#include <fcntl.h> /* for _O_BINARY */
|
||||
#else
|
||||
#include <unistd.h> /* for chown(), unlink() */
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
|
||||
#if defined __BORLANDC__
|
||||
#include <utime.h> /* for utime() */
|
||||
#else
|
||||
#include <sys/utime.h> /* for utime() */
|
||||
#endif
|
||||
#else
|
||||
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
||||
#include <utime.h> /* for utime() */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER
|
||||
# if _MSC_VER >= 1800
|
||||
# include <inttypes.h>
|
||||
# elif _MSC_VER >= 1600
|
||||
/* Visual Studio 2010 has decent C99 support */
|
||||
# include <stdint.h>
|
||||
# define PRIu64 "llu"
|
||||
# define PRId64 "lld"
|
||||
# define PRIx64 "llx"
|
||||
# else
|
||||
# include <limits.h>
|
||||
# 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 <stdarg.h>
|
||||
#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 */
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ static inline unsigned short __builtin_bswap16(unsigned short a)
|
|||
|
||||
#elif defined HAVE_BYTESWAP_H /* Linux */
|
||||
|
||||
#include <byteswap.h>
|
||||
// JUCE: removed as JUCE already includes standard headers and including
|
||||
// these in FlacNamespace will cause problems
|
||||
//#include <byteswap.h>
|
||||
|
||||
#define ENDSWAP_16(x) (bswap_16 (x))
|
||||
#define ENDSWAP_32(x) (bswap_32 (x))
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
#include <string.h>
|
||||
#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);
|
||||
|
|
|
|||
|
|
@ -36,17 +36,17 @@
|
|||
|
||||
#include "include/private/cpu.h"
|
||||
#include "../compat.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
|
||||
#if defined _MSC_VER
|
||||
#include <intrin.h> /* for __cpuid() and _xgetbv() */
|
||||
//#include <intrin.h> /* for __cpuid() and _xgetbv() */
|
||||
#elif defined __GNUC__ && defined HAVE_CPUID_H
|
||||
#include <cpuid.h> /* for __get_cpuid() and __get_cpuid_max() */
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
#include <stdio.h>
|
||||
//#include <stdio.h>
|
||||
#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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <config.h>
|
||||
#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 <emmintrin.h> /* SSE2 */
|
||||
#include <math.h>
|
||||
#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 */
|
||||
|
|
@ -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 <config.h>
|
||||
#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 <tmmintrin.h> /* SSSE3 */
|
||||
#include <math.h>
|
||||
#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 */
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <sys/param.h>
|
||||
#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 <stdlib.h>
|
||||
#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
|
||||
|
|
@ -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 <ogg/ogg.h>
|
||||
|
||||
#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
|
||||
|
|
@ -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 <ogg/ogg.h>
|
||||
|
||||
#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
|
||||
|
|
@ -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 <ogg/ogg.h>
|
||||
#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
|
||||
|
|
@ -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
|
||||
|
|
@ -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 <stdio.h>
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -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 <config.h>
|
||||
#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 <xmmintrin.h> /* 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 */
|
||||
|
|
@ -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 <config.h>
|
||||
#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 <emmintrin.h> /* 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 */
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -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 <config.h>
|
||||
#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 <altivec.h>
|
||||
|
||||
#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 */
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h> /* 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;
|
||||
}
|
||||
|
|
@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h> /* 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;
|
||||
}
|
||||
|
|
@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* for malloc() */
|
||||
#include <string.h> /* 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;
|
||||
}
|
||||
|
|
@ -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 <config.h>
|
||||
#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 */
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <config.h>
|
||||
#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 <stdlib.h> /* for abs() */
|
||||
#include <immintrin.h> /* 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 */
|
||||
|
|
@ -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 <config.h>
|
||||
#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 <stdlib.h> /* for abs() */
|
||||
#include <emmintrin.h> /* 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 */
|
||||
|
|
@ -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 <config.h>
|
||||
#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 <stdlib.h> /* for abs() */
|
||||
#include <tmmintrin.h> /* 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 */
|
||||
|
|
@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <errno.h>
|
||||
|
||||
/* 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)) ; \
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@
|
|||
#ifndef FLAC__METADATA_H
|
||||
#define FLAC__METADATA_H
|
||||
|
||||
#include <sys/types.h> /* for off_t */
|
||||
#include "export.h"
|
||||
#include "callback.h"
|
||||
#include "format.h"
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
@ -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 <stddef.h>
|
||||
|
||||
#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 */
|
||||
|
|
@ -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 <stdlib.h> /* 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
|
||||
|
|
@ -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 */
|
||||
|
|
@ -33,7 +33,6 @@
|
|||
#ifndef FLAC__STREAM_DECODER_H
|
||||
#define FLAC__STREAM_DECODER_H
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
#include "export.h"
|
||||
#include "format.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
#ifndef FLAC__STREAM_ENCODER_H
|
||||
#define FLAC__STREAM_ENCODER_H
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
#include "export.h"
|
||||
#include "format.h"
|
||||
#include "stream_decoder.h"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#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 <windows.h>
|
||||
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
|
||||
|
|
@ -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 <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/utime.h>
|
||||
#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
|
||||
Loading…
Add table
Add a link
Reference in a new issue