OSDN Git Service

[flac] Update flac to 1.4.2
authorStarg <starg@users.osdn.me>
Sun, 13 Nov 2022 00:40:27 +0000 (09:40 +0900)
committerStarg <starg@users.osdn.me>
Sun, 13 Nov 2022 00:44:22 +0000 (09:44 +0900)
17 files changed:
FLAC/include/FLAC/all.h
FLAC/include/FLAC/format.h
FLAC/include/FLAC/metadata.h
FLAC/include/FLAC/stream_decoder.h
FLAC/include/FLAC/stream_encoder.h
FLAC/src/cpu.c
FLAC/src/deduplication/lpc_compute_autocorrelation_intrin.c
FLAC/src/fixed.c
FLAC/src/format.c
FLAC/src/lpc.c
FLAC/src/lpc_intrin_fma.c
FLAC/src/metadata_object.c
FLAC/src/private/cpu.h
FLAC/src/private/fixed.h
FLAC/src/private/lpc.h
FLAC/src/stream_decoder.c
FLAC/src/stream_encoder.c

index 8c6cdc3..a6a012f 100644 (file)
@@ -52,7 +52,7 @@
  * level idea of the structure and how to find the information you
  * need.  As a prerequisite you should have at least a basic
  * knowledge of the FLAC format, documented
- * <A HREF="../format.html">here</A>.
+ * <A HREF="https://xiph.org/flac/format.html">here</A>.
  *
  * \section c_api FLAC C API
  *
@@ -64,7 +64,7 @@
  *
  * By writing a little code and linking against libFLAC, it is
  * relatively easy to add FLAC support to another program.  The
- * library is licensed under <A HREF="../license.html">Xiph's BSD license</A>.
+ * library is licensed under <A HREF="https://xiph.org/flac/license.html">Xiph's BSD license</A>.
  * Complete source code of libFLAC as well as the command-line
  * encoder and plugins is available and is a useful source of
  * examples.
@@ -97,7 +97,7 @@
  * example /usr/include/FLAC++/...).
  *
  * libFLAC++ is also licensed under
- * <A HREF="../license.html">Xiph's BSD license</A>.
+ * <A HREF="https://xiph.org/flac/license.html">Xiph's BSD license</A>.
  *
  * \section getting_started Getting Started
  *
  * functions through the links in top bar across this page.
  *
  * If you prefer a more hands-on approach, you can jump right to some
- * <A HREF="../documentation_example_code.html">example code</A>.
+ * <A HREF="https://xiph.org/flac/documentation_example_code.html">example code</A>.
  *
  * \section porting_guide Porting Guide
  *
index 99d637f..2d54843 100644 (file)
@@ -60,7 +60,7 @@ extern "C" {
  *  structures used by the rest of the interfaces.
  *
  *  First, you should be familiar with the
- *  <A HREF="../format.html">FLAC format</A>.  Many of the values here
+ *  <A HREF="https://xiph.org/flac/format.html">FLAC format</A>.  Many of the values here
  *  follow directly from the specification.  As a user of libFLAC, the
  *  interesting parts really are the structures that describe the frame
  *  header and metadata blocks.
@@ -225,7 +225,7 @@ typedef struct {
         */
 } FLAC__EntropyCodingMethod_PartitionedRiceContents;
 
-/** Header for a Rice partitioned residual.  (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
+/** Header for a Rice partitioned residual.  (c.f. <A HREF="https://xiph.org/flac/format.html#partitioned_rice">format specification</A>)
  */
 typedef struct {
 
@@ -247,7 +247,7 @@ extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCA
 extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
 /**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
 
-/** Header for the entropy coding method.  (c.f. <A HREF="../format.html#residual">format specification</A>)
+/** Header for the entropy coding method.  (c.f. <A HREF="https://xiph.org/flac/format.html#residual">format specification</A>)
  */
 typedef struct {
        FLAC__EntropyCodingMethodType type;
@@ -276,7 +276,7 @@ typedef enum {
 extern FLAC_API const char * const FLAC__SubframeTypeString[];
 
 
-/** CONSTANT subframe.  (c.f. <A HREF="../format.html#subframe_constant">format specification</A>)
+/** CONSTANT subframe.  (c.f. <A HREF="https://xiph.org/flac/format.html#subframe_constant">format specification</A>)
  */
 typedef struct {
        FLAC__int64 value; /**< The constant signal value. */
@@ -289,7 +289,7 @@ typedef enum {
 } FLAC__VerbatimSubframeDataType;
 
 
-/** VERBATIM subframe.  (c.f. <A HREF="../format.html#subframe_verbatim">format specification</A>)
+/** VERBATIM subframe.  (c.f. <A HREF="https://xiph.org/flac/format.html#subframe_verbatim">format specification</A>)
  */
 typedef struct {
        union {
@@ -300,7 +300,7 @@ typedef struct {
 } FLAC__Subframe_Verbatim;
 
 
-/** FIXED subframe.  (c.f. <A HREF="../format.html#subframe_fixed">format specification</A>)
+/** FIXED subframe.  (c.f. <A HREF="https://xiph.org/flac/format.html#subframe_fixed">format specification</A>)
  */
 typedef struct {
        FLAC__EntropyCodingMethod entropy_coding_method;
@@ -317,7 +317,7 @@ typedef struct {
 } FLAC__Subframe_Fixed;
 
 
-/** LPC subframe.  (c.f. <A HREF="../format.html#subframe_lpc">format specification</A>)
+/** LPC subframe.  (c.f. <A HREF="https://xiph.org/flac/format.html#subframe_lpc">format specification</A>)
  */
 typedef struct {
        FLAC__EntropyCodingMethod entropy_coding_method;
@@ -346,7 +346,7 @@ extern FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**<
 extern FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
 
 
-/** FLAC subframe structure.  (c.f. <A HREF="../format.html#subframe">format specification</A>)
+/** FLAC subframe structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#subframe">format specification</A>)
  */
 typedef struct {
        FLAC__SubframeType type;
@@ -413,7 +413,7 @@ typedef enum {
 extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
 
 
-/** FLAC frame header structure.  (c.f. <A HREF="../format.html#frame_header">format specification</A>)
+/** FLAC frame header structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#frame_header">format specification</A>)
  */
 typedef struct {
        uint32_t blocksize;
@@ -462,7 +462,7 @@ extern FLAC_API const uint32_t FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit)
 extern FLAC_API const uint32_t FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
 
 
-/** FLAC frame footer structure.  (c.f. <A HREF="../format.html#frame_footer">format specification</A>)
+/** FLAC frame footer structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#frame_footer">format specification</A>)
  */
 typedef struct {
        FLAC__uint16 crc;
@@ -475,7 +475,7 @@ typedef struct {
 extern FLAC_API const uint32_t FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
 
 
-/** FLAC frame structure.  (c.f. <A HREF="../format.html#frame">format specification</A>)
+/** FLAC frame structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#frame">format specification</A>)
  */
 typedef struct {
        FLAC__FrameHeader header;
@@ -496,25 +496,25 @@ typedef struct {
 typedef enum {
 
        FLAC__METADATA_TYPE_STREAMINFO = 0,
-       /**< <A HREF="../format.html#metadata_block_streaminfo">STREAMINFO</A> block */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_streaminfo">STREAMINFO</A> block */
 
        FLAC__METADATA_TYPE_PADDING = 1,
-       /**< <A HREF="../format.html#metadata_block_padding">PADDING</A> block */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_padding">PADDING</A> block */
 
        FLAC__METADATA_TYPE_APPLICATION = 2,
-       /**< <A HREF="../format.html#metadata_block_application">APPLICATION</A> block */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_application">APPLICATION</A> block */
 
        FLAC__METADATA_TYPE_SEEKTABLE = 3,
-       /**< <A HREF="../format.html#metadata_block_seektable">SEEKTABLE</A> block */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_seektable">SEEKTABLE</A> block */
 
        FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
-       /**< <A HREF="../format.html#metadata_block_vorbis_comment">VORBISCOMMENT</A> block (a.k.a. FLAC tags) */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_vorbis_comment">VORBISCOMMENT</A> block (a.k.a. FLAC tags) */
 
        FLAC__METADATA_TYPE_CUESHEET = 5,
-       /**< <A HREF="../format.html#metadata_block_cuesheet">CUESHEET</A> block */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_cuesheet">CUESHEET</A> block */
 
        FLAC__METADATA_TYPE_PICTURE = 6,
-       /**< <A HREF="../format.html#metadata_block_picture">PICTURE</A> block */
+       /**< <A HREF="https://xiph.org/flac/format.html#metadata_block_picture">PICTURE</A> block */
 
        FLAC__METADATA_TYPE_UNDEFINED = 7,
        /**< marker to denote beginning of undefined type range; this number will increase as new metadata types are added */
@@ -531,7 +531,7 @@ typedef enum {
 extern FLAC_API const char * const FLAC__MetadataTypeString[];
 
 
-/** FLAC STREAMINFO structure.  (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
+/** FLAC STREAMINFO structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block_streaminfo">format specification</A>)
  */
 typedef struct {
        uint32_t min_blocksize, max_blocksize;
@@ -556,7 +556,7 @@ extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**<
 /** The total stream length of the STREAMINFO block in bytes. */
 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
 
-/** FLAC PADDING structure.  (c.f. <A HREF="../format.html#metadata_block_padding">format specification</A>)
+/** FLAC PADDING structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block_padding">format specification</A>)
  */
 typedef struct {
        int dummy;
@@ -567,7 +567,7 @@ typedef struct {
 } FLAC__StreamMetadata_Padding;
 
 
-/** FLAC APPLICATION structure.  (c.f. <A HREF="../format.html#metadata_block_application">format specification</A>)
+/** FLAC APPLICATION structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block_application">format specification</A>)
  */
 typedef struct {
        FLAC__byte id[4];
@@ -576,7 +576,7 @@ typedef struct {
 
 extern FLAC_API const uint32_t FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
 
-/** SeekPoint structure used in SEEKTABLE blocks.  (c.f. <A HREF="../format.html#seekpoint">format specification</A>)
+/** SeekPoint structure used in SEEKTABLE blocks.  (c.f. <A HREF="https://xiph.org/flac/format.html#seekpoint">format specification</A>)
  */
 typedef struct {
        FLAC__uint64 sample_number;
@@ -604,7 +604,7 @@ extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN
 extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
 
 
-/** FLAC SEEKTABLE structure.  (c.f. <A HREF="../format.html#metadata_block_seektable">format specification</A>)
+/** FLAC SEEKTABLE structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block_seektable">format specification</A>)
  *
  * \note From the format specification:
  * - The seek points must be sorted by ascending sample number.
@@ -622,7 +622,7 @@ typedef struct {
 } FLAC__StreamMetadata_SeekTable;
 
 
-/** Vorbis comment entry structure used in VORBIS_COMMENT blocks.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
+/** Vorbis comment entry structure used in VORBIS_COMMENT blocks.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block_vorbis_comment">format specification</A>)
  *
  *  For convenience, the APIs maintain a trailing NUL character at the end of
  *  \a entry which is not counted toward \a length, i.e.
@@ -636,7 +636,7 @@ typedef struct {
 extern FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
 
 
-/** FLAC VORBIS_COMMENT structure.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
+/** FLAC VORBIS_COMMENT structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block_vorbis_comment">format specification</A>)
  */
 typedef struct {
        FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
@@ -648,7 +648,7 @@ extern FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS
 
 
 /** FLAC CUESHEET track index structure.  (See the
- * <A HREF="../format.html#cuesheet_track_index">format specification</A> for
+ * <A HREF="https://xiph.org/flac/format.html#cuesheet_track_index">format specification</A> for
  * the full description of each field.)
  */
 typedef struct {
@@ -667,7 +667,7 @@ extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
 
 
 /** FLAC CUESHEET track structure.  (See the
- * <A HREF="../format.html#cuesheet_track">format specification</A> for
+ * <A HREF="https://xiph.org/flac/format.html#cuesheet_track">format specification</A> for
  * the full description of each field.)
  */
 typedef struct {
@@ -704,7 +704,7 @@ extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_
 
 
 /** FLAC CUESHEET structure.  (See the
- * <A HREF="../format.html#metadata_block_cuesheet">format specification</A>
+ * <A HREF="https://xiph.org/flac/format.html#metadata_block_cuesheet">format specification</A>
  * for the full description of each field.)
  */
 typedef struct {
@@ -770,7 +770,7 @@ typedef enum {
 extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
 
 /** FLAC PICTURE structure.  (See the
- * <A HREF="../format.html#metadata_block_picture">format specification</A>
+ * <A HREF="https://xiph.org/flac/format.html#metadata_block_picture">format specification</A>
  * for the full description of each field.)
  */
 typedef struct {
@@ -836,7 +836,7 @@ typedef struct {
 } FLAC__StreamMetadata_Unknown;
 
 
-/** FLAC metadata block structure.  (c.f. <A HREF="../format.html#metadata_block">format specification</A>)
+/** FLAC metadata block structure.  (c.f. <A HREF="https://xiph.org/flac/format.html#metadata_block">format specification</A>)
  */
 typedef struct FLAC__StreamMetadata {
        FLAC__MetadataType type;
index bf1bffe..651b740 100644 (file)
@@ -510,7 +510,7 @@ FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const
  * \retval uint32_t
  *    The length of the metadata block at the current iterator position.
  *    The is same length as that in the
- *    <a href="http://xiph.org/flac/format.html#metadata_block_header">metadata block header</a>,
+ *    <a href="http://xiph.org/flhttps://xiph.org/flac/format.html#metadata_block_header">metadata block header</a>,
  *    i.e. the length of the metadata body that follows the header.
  */
 FLAC_API uint32_t FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
index 2d285ae..f4e1648 100644 (file)
@@ -681,7 +681,7 @@ typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *
  *                  samples of length \a frame->header.blocksize.
  *                  Channels will be ordered according to the FLAC
  *                  specification; see the documentation for the
- *                  <A HREF="../format.html#frame_header">frame header</A>.
+ *                  <A HREF="https://xiph.org/flac/format.html#frame_header">frame header</A>.
  * \param  client_data  The callee's client data set through
  *                      FLAC__stream_decoder_init_*().
  * \retval FLAC__StreamDecoderWriteStatus
index 1d7bd25..4ab4dce 100644 (file)
@@ -129,8 +129,8 @@ extern "C" {
  * Unlike the decoders, the stream encoder has many options that can
  * affect the speed and compression ratio.  When setting these parameters
  * you should have some basic knowledge of the format (see the
- * <A HREF="../documentation_format_overview.html">user-level documentation</A>
- * or the <A HREF="../format.html">formal description</A>).  The
+ * <A HREF="https://xiph.org/flac/documentation_format_overview.html">user-level documentation</A>
+ * or the <A HREF="https://xiph.org/flac/format.html">formal description</A>).  The
  * FLAC__stream_encoder_set_*() functions themselves do not validate the
  * values as many are interdependent.  The FLAC__stream_encoder_init_*()
  * functions will do this, so make sure to pay attention to the state
@@ -330,7 +330,7 @@ typedef enum {
        /**< The specified block size is less than the maximum LPC order. */
 
        FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
-       /**< The encoder is bound to the <A HREF="../format.html#subset">Subset</A> but other settings violate it. */
+       /**< The encoder is bound to the <A HREF="https://xiph.org/flac/format.html#subset">Subset</A> but other settings violate it. */
 
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
        /**< The metadata input to the encoder is invalid, in one of the following ways:
@@ -742,7 +742,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncod
  */
 FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
 
-/** Set the <A HREF="../format.html#subset">Subset</A> flag.  If \c true,
+/** Set the <A HREF="https://xiph.org/flac/format.html#subset">Subset</A> flag.  If \c true,
  *  the encoder will comply with the Subset and will check the
  *  settings during FLAC__stream_encoder_init_*() to see if all settings
  *  comply.  If \c false, the settings may take advantage of the full
@@ -1295,7 +1295,7 @@ FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__St
  */
 FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
 
-/** Get the <A HREF="../format.html#subset>Subset</A> flag.
+/** Get the <A HREF="https://xiph.org/flac/format.html#subset">Subset</A> flag.
  *
  * \param  encoder  An encoder instance to query.
  * \assert
@@ -1781,7 +1781,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  *
  *  For applications where channel order is important, channels must
  *  follow the order as described in the
- *  <A HREF="../format.html#frame_header">frame header</A>.
+ *  <A HREF="https://xiph.org/flac/format.html#frame_header">frame header</A>.
  *
  * \param  encoder  An initialized encoder instance in the OK state.
  * \param  buffer   An array of pointers to each channel's signal.
@@ -1810,7 +1810,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
  *
  *  For applications where channel order is important, channels must
  *  follow the order as described in the
- *  <A HREF="../format.html#frame_header">frame header</A>.
+ *  <A HREF="https://xiph.org/flac/format.html#frame_header">frame header</A>.
  *
  * \param  encoder  An initialized encoder instance in the OK state.
  * \param  buffer   An array of channel-interleaved data (see above).
index 4b1b371..cba0ad0 100644 (file)
@@ -57,7 +57,7 @@
 #include <sys/auxv.h>
 #endif
 
-#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && (defined FLAC__HAS_NASM || FLAC__HAS_X86INTRIN) && !defined FLAC__NO_ASM
+#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN && !defined FLAC__NO_ASM
 
 /* these are flags in EDX of CPUID AX=00000001 */
 static const uint32_t FLAC__CPUINFO_X86_CPUID_CMOV    = 0x00008000;
@@ -97,8 +97,6 @@ cpu_have_cpuid(void)
 #if defined FLAC__CPU_X86_64 || defined __i686__ || defined __SSE__ || (defined _M_IX86_FP && _M_IX86_FP > 0)
        /* target CPU does have CPUID instruction */
        return 1;
-#elif defined FLAC__HAS_NASM
-       return FLAC__cpu_have_cpuid_asm_ia32();
 #elif defined __GNUC__ && defined HAVE_CPUID_H
        if (__get_cpuid_max(0, 0) != 0)
                return 1;
@@ -151,9 +149,6 @@ cpuinfo_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint
                __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
                return;
        }
-#elif defined FLAC__HAS_NASM && defined FLAC__CPU_IA32
-       FLAC__cpu_info_asm_ia32(level, eax, ebx, ecx, edx);
-       return;
 #endif
        *eax = *ebx = *ecx = *edx = 0;
 }
@@ -163,7 +158,7 @@ cpuinfo_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint
 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 (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN && !defined FLAC__NO_ASM
        FLAC__bool x86_osxsave = false;
        FLAC__bool os_avx = false;
        FLAC__uint32 flags_eax, flags_ebx, flags_ecx, flags_edx;
index 5843b00..76419db 100644 (file)
@@ -1,13 +1,14 @@
+       int i, j;
        (void) lag;
        FLAC__ASSERT(lag <= MAX_LAG);
 
-        for(int i = 0; i < MAX_LAG; i++)
+        for(i = 0; i < MAX_LAG; i++)
                 autoc[i] = 0.0;
 
-        for(int i = 0; i < MAX_LAG; i++)
-                for(int j = 0; j <= i; j++)
+        for(i = 0; i < MAX_LAG; i++)
+                for(j = 0; j <= i; j++)
                         autoc[j] += (double)data[i] * (double)data[i-j];
 
-        for(int i = MAX_LAG; i < (int)data_len; i++)
-               for(int j = 0; j < MAX_LAG; j++)
+        for(i = MAX_LAG; i < (int)data_len; i++)
+               for(j = 0; j < MAX_LAG; j++)
                        autoc[j] += (double)data[i] * (double)data[i-j];
index 7d826f1..da5c7da 100644 (file)
@@ -236,11 +236,12 @@ uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t d
        FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
        FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
        FLAC__int32 error, save;
+       uint32_t i;
        /* total_error_* are 64-bits to avoid overflow when encoding
         * erratic signals when the bits-per-sample and blocksize are
         * large.
         */
-       for(uint32_t i = 0; i < data_len; i++) {
+       for(i = 0; i < data_len; i++) {
                error  = data[i]     ; total_error_0 += local_abs(error);                      save = error;
                error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
                error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
@@ -248,7 +249,8 @@ uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t d
                error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
        }
 #else
-       for(int i = 0; i < (int)data_len; i++) {
+       int i;
+       for(i = 0; i < (int)data_len; i++) {
                total_error_0 += local_abs(data[i]);
                total_error_1 += local_abs(data[i] - data[i-1]);
                total_error_2 += local_abs(data[i] - 2 * data[i-1] + data[i-2]);
@@ -303,8 +305,9 @@ uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint3
 {
        FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
        uint32_t order;
+       int i;
 
-       for(int i = 0; i < (int)data_len; i++) {
+       for(i = 0; i < (int)data_len; i++) {
                total_error_0 += local_abs(data[i]);
                total_error_1 += local_abs(data[i] - data[i-1]);
                total_error_2 += local_abs(data[i] - 2 * data[i-1] + data[i-2]);
@@ -380,8 +383,9 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 dat
        FLAC__uint64 error_0, error_1, error_2, error_3, error_4;
        FLAC__bool order_0_is_valid = true, order_1_is_valid = true, order_2_is_valid = true, order_3_is_valid = true, order_4_is_valid = true;
        uint32_t order = 0;
+       int i;
 
-       for(int i = 0; i < (int)data_len; i++) {
+       for(i = 0; i < (int)data_len; i++) {
                error_0 = local_abs64((FLAC__int64)data[i]);
                error_1 = (i > 0) ? local_abs64((FLAC__int64)data[i] - data[i-1]) : 0 ;
                error_2 = (i > 1) ? local_abs64((FLAC__int64)data[i] - 2 * (FLAC__int64)data[i-1] + data[i-2]) : 0;
@@ -426,8 +430,9 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int
        FLAC__uint64 error_0, error_1, error_2, error_3, error_4;
        FLAC__bool order_0_is_valid = true, order_1_is_valid = true, order_2_is_valid = true, order_3_is_valid = true, order_4_is_valid = true;
        uint32_t order = 0;
+       int i;
 
-       for(int i = 0; i < (int)data_len; i++) {
+       for(i = 0; i < (int)data_len; i++) {
                error_0 = local_abs64(data[i]);
                error_1 = (i > 0) ? local_abs64(data[i] - data[i-1]) : 0 ;
                error_2 = (i > 1) ? local_abs64(data[i] - 2 * data[i-1] + data[i-2]) : 0;
index 77391d8..9db749c 100644 (file)
@@ -55,7 +55,7 @@ FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC git-" GIT_COMMIT_H
 #else
 /* PACKAGE_VERSION should come from configure */
 FLAC_API const char *FLAC__VERSION_STRING = PACKAGE_VERSION;
-FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " PACKAGE_VERSION " 20220922";
+FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " PACKAGE_VERSION " 20221022";
 #endif
 
 FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
index a090a87..9d9c7e3 100644 (file)
@@ -130,30 +130,47 @@ void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], uint32_t data_le
                autoc[lag] = d;
        }
 #endif
+       if (data_len < FLAC__MAX_LPC_ORDER || lag > 16) {
+               /*
+                * this version tends to run faster because of better data locality
+                * ('data_len' is usually much larger than 'lag')
+                */
+               double d;
+               uint32_t sample, coeff;
+               const uint32_t limit = data_len - lag;
+
+               FLAC__ASSERT(lag > 0);
+               FLAC__ASSERT(lag <= data_len);
 
-       /*
-        * this version tends to run faster because of better data locality
-        * ('data_len' is usually much larger than 'lag')
-        */
-       double d;
-       uint32_t sample, coeff;
-       const uint32_t limit = data_len - lag;
-
-       FLAC__ASSERT(lag > 0);
-       FLAC__ASSERT(lag <= data_len);
-
-       for(coeff = 0; coeff < lag; coeff++)
-               autoc[coeff] = 0.0;
-       for(sample = 0; sample <= limit; sample++) {
-               d = data[sample];
                for(coeff = 0; coeff < lag; coeff++)
-                       autoc[coeff] += d * data[sample+coeff];
+                       autoc[coeff] = 0.0;
+               for(sample = 0; sample <= limit; sample++) {
+                       d = data[sample];
+                       for(coeff = 0; coeff < lag; coeff++)
+                               autoc[coeff] += d * data[sample+coeff];
+               }
+               for(; sample < data_len; sample++) {
+                       d = data[sample];
+                       for(coeff = 0; coeff < data_len - sample; coeff++)
+                               autoc[coeff] += d * data[sample+coeff];
+               }
+       }
+       else if(lag <= 8) {
+               #undef MAX_LAG
+               #define MAX_LAG 8
+               #include "deduplication/lpc_compute_autocorrelation_intrin.c"
        }
-       for(; sample < data_len; sample++) {
-               d = data[sample];
-               for(coeff = 0; coeff < data_len - sample; coeff++)
-                       autoc[coeff] += d * data[sample+coeff];
+       else if(lag <= 12) {
+               #undef MAX_LAG
+               #define MAX_LAG 12
+               #include "deduplication/lpc_compute_autocorrelation_intrin.c"
        }
+       else if(lag <= 16) {
+               #undef MAX_LAG
+               #define MAX_LAG 16
+               #include "deduplication/lpc_compute_autocorrelation_intrin.c"
+       }
+
 }
 
 void FLAC__lpc_compute_lp_coefficients(const double autoc[], uint32_t *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], double error[])
@@ -929,7 +946,8 @@ uint32_t FLAC__lpc_max_prediction_before_shift_bps(uint32_t subframe_bps, const
         * predictor is known however, so taking the log2 of the sum of the absolute values
         * of all coefficients is a more accurate representation of the predictor */
        FLAC__int32 abs_sum_of_qlp_coeff = 0;
-       for(uint32_t i = 0; i < order; i++)
+       uint32_t i;
+       for(i = 0; i < order; i++)
                abs_sum_of_qlp_coeff += abs(qlp_coeff[i]);
        if(abs_sum_of_qlp_coeff == 0)
                abs_sum_of_qlp_coeff = 1;
index ad125c8..396ff30 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "FLAC/assert.h"
 
-FLAC__FAST_MATH_TARGET("fma")
+FLAC__SSE_TARGET("fma")
 void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[])
 {
 #undef MAX_LAG
@@ -51,14 +51,14 @@ void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_8(const FLAC__real data[],
 #include "deduplication/lpc_compute_autocorrelation_intrin.c"
 }
 
-FLAC__FAST_MATH_TARGET("fma")
+FLAC__SSE_TARGET("fma")
 void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[])
 {
 #undef MAX_LAG
 #define MAX_LAG 12
 #include "deduplication/lpc_compute_autocorrelation_intrin.c"
 }
-FLAC__FAST_MATH_TARGET("fma")
+FLAC__SSE_TARGET("fma")
 void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[])
 {
 #undef MAX_LAG
index c1e54ab..3f56b0e 100644 (file)
@@ -1179,9 +1179,10 @@ FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__St
                if (new_num_comments == 0)
                        return true;
                else {
+                       uint32_t i;
                        if ((object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)) == NULL)
                                return false;
-                       for (uint32_t i = 0; i < new_num_comments; i++) {
+                       for (i = 0; i < new_num_comments; i++) {
                                object->data.vorbis_comment.comments[i].length = 0;
                                if ((object->data.vorbis_comment.comments[i].entry = safe_malloc_(1)) == NULL) {
                                        object->data.vorbis_comment.num_comments = i+1;
@@ -1223,7 +1224,8 @@ FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__St
 
                /* if growing, zero all the length/pointers of new elements */
                if (new_size > old_size) {
-                       for (uint32_t i = object->data.vorbis_comment.num_comments; i < new_num_comments; i++) {
+                       uint32_t i;
+                       for (i = object->data.vorbis_comment.num_comments; i < new_num_comments; i++) {
                                object->data.vorbis_comment.comments[i].length = 0;
                                if ((object->data.vorbis_comment.comments[i].entry = safe_malloc_(1)) == NULL) {
                                        object->data.vorbis_comment.num_comments = i+1;
index 335b2f8..4f1d16c 100644 (file)
@@ -63,7 +63,6 @@
 /* SSE intrinsics support by ICC/MSVC/GCC */
 #if defined __INTEL_COMPILER
   #define FLAC__SSE_TARGET(x)
-  #define FLAC__FAST_MATH_TARGET(x)
   #define FLAC__SSE_SUPPORTED 1
   #define FLAC__SSE2_SUPPORTED 1
   #if (__INTEL_COMPILER >= 1000) /* Intel C++ Compiler 10.0 */
   #endif
 #elif defined __clang__ && __has_attribute(__target__) /* clang */
   #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x)))
-  #define FLAC__FAST_MATH_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
+  #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
-    #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
+    #define FLAC__AVX_SUPPORTED 1
+    #define FLAC__AVX2_SUPPORTED 1
+    #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__FAST_MATH_TARGET(x) __attribute__ ((__target__ (x), optimize("-ffast-math")))
   #define FLAC__SSE_SUPPORTED 1
   #define FLAC__SSE2_SUPPORTED 1
   #define FLAC__SSSE3_SUPPORTED 1
   #endif
 #elif defined _MSC_VER
   #define FLAC__SSE_TARGET(x)
-  #define FLAC__FAST_MATH_TARGET(x)
   #define FLAC__SSE_SUPPORTED 1
   #define FLAC__SSE2_SUPPORTED 1
   #if (_MSC_VER >= 1500) /* MS Visual Studio 2008 */
   #endif
 #else
   #define FLAC__SSE_TARGET(x)
-  #define FLAC__FAST_MATH_TARGET(x)
   #ifdef __SSE__
     #define FLAC__SSE_SUPPORTED 1
   #endif
index aa742ca..68024b0 100644 (file)
@@ -69,9 +69,6 @@ uint32_t FLAC__fixed_compute_best_predictor_intrin_ssse3(const FLAC__int32 data[
 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]);
 #   endif
 #  endif
-#  if defined FLAC__CPU_IA32 && defined FLAC__HAS_NASM
-uint32_t FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
-#  endif
 # endif
 #else
 uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
index 5212b35..8ff3b89 100644 (file)
@@ -174,13 +174,6 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_neon(const FLAC__in
 void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_neon(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
 #   endif
 
-#  ifdef FLAC__CPU_IA32
-#    ifdef FLAC__HAS_NASM
-void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_asm_ia32(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
-#    endif
-#  endif
 #  if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN
 #    ifdef FLAC__SSE2_SUPPORTED
 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[]);
index 73cb0ae..09bdada 100644 (file)
@@ -894,6 +894,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
        decoder->private_->samples_decoded = 0;
        decoder->private_->do_md5_checking = false;
        decoder->private_->last_seen_framesync = 0;
+       decoder->private_->last_frame_is_set = false;
 
 #if FLAC__HAS_OGG
        if(decoder->private_->is_ogg)
@@ -2746,7 +2747,8 @@ FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, uint32_t channel,
        /* decode the subframe */
        if(do_full_decode) {
                if(bps < 33){
-                       for(uint32_t i = 0; i < order; i++)
+                       uint32_t i;
+                       for(i = 0; i < order; i++)
                                decoder->private_->output[channel][i] = subframe->warmup[i];
                        if(bps+order <= 32)
                                FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
@@ -2848,7 +2850,8 @@ FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, uint32_t channel, ui
        /* decode the subframe */
        if(do_full_decode) {
                if(bps <= 32) {
-                       for(uint32_t i = 0; i < order; i++)
+                       uint32_t i;
+                       for(i = 0; i < order; i++)
                                decoder->private_->output[channel][i] = subframe->warmup[i];
                        if(FLAC__lpc_max_residual_bps(bps, subframe->qlp_coeff, order, subframe->quantization_level) <= 32 &&
                           FLAC__lpc_max_prediction_before_shift_bps(bps, subframe->qlp_coeff, order) <= 32)
@@ -3071,6 +3074,7 @@ FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
 __attribute__((no_sanitize("signed-integer-overflow")))
 #endif
 void undo_channel_coding(FLAC__StreamDecoder *decoder) {
+       uint32_t i;
        switch(decoder->private_->frame.header.channel_assignment) {
        case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
                /* do nothing */
@@ -3078,7 +3082,7 @@ void undo_channel_coding(FLAC__StreamDecoder *decoder) {
        case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
                FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
                FLAC__ASSERT(decoder->private_->side_subframe_in_use != /* logical XOR */ (decoder->private_->frame.header.bits_per_sample < 32));
-               for(uint32_t i = 0; i < decoder->private_->frame.header.blocksize; i++)
+               for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
                        if(decoder->private_->side_subframe_in_use)
                                decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->side_subframe[i];
                        else
@@ -3087,7 +3091,7 @@ void undo_channel_coding(FLAC__StreamDecoder *decoder) {
        case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
                FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
                FLAC__ASSERT(decoder->private_->side_subframe_in_use != /* logical XOR */ (decoder->private_->frame.header.bits_per_sample < 32));
-               for(uint32_t i = 0; i < decoder->private_->frame.header.blocksize; i++)
+               for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
                        if(decoder->private_->side_subframe_in_use)
                                decoder->private_->output[0][i] = decoder->private_->output[1][i] + decoder->private_->side_subframe[i];
                        else
@@ -3096,7 +3100,7 @@ void undo_channel_coding(FLAC__StreamDecoder *decoder) {
        case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
                FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
                FLAC__ASSERT(decoder->private_->side_subframe_in_use != /* logical XOR */ (decoder->private_->frame.header.bits_per_sample < 32));
-               for(uint32_t i = 0; i < decoder->private_->frame.header.blocksize; i++) {
+               for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
                        if(!decoder->private_->side_subframe_in_use){
                                FLAC__int32 mid, side;
                                mid = decoder->private_->output[0][i];
index 2879c51..4d5beaf 100644 (file)
@@ -949,20 +949,6 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
        if(encoder->private_->cpuinfo.use_asm) {
 #  ifdef FLAC__CPU_IA32
                FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
-#   ifdef FLAC__HAS_NASM
-               encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_asm_ia32; /* OPT_IA32: was really necessary for GCC < 4.9 */
-               if (encoder->private_->cpuinfo.x86.mmx) {
-                       encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
-                       encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
-               }
-               else {
-                       encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
-                       encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
-               }
-
-               if (encoder->private_->cpuinfo.x86.mmx && encoder->private_->cpuinfo.x86.cmov)
-                       encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
-#   endif /* FLAC__HAS_NASM */
 #   if FLAC__HAS_X86INTRIN
 #    ifdef FLAC__SSE2_SUPPORTED
                if (encoder->private_->cpuinfo.x86.sse2) {
@@ -1486,6 +1472,10 @@ FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
        if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
                if(encoder->private_->current_sample_number != 0) {
                        encoder->protected_->blocksize = encoder->private_->current_sample_number;
+                       if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
+                               /* the above function sets the state for us in case of an error */
+                               return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
+                       }
                        if(!process_frame_(encoder, /*is_last_block=*/true))
                                error = true;
                }
@@ -2560,83 +2550,89 @@ FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, uint32_t new_blocksize)
 
        FLAC__ASSERT(new_blocksize > 0);
        FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
-       FLAC__ASSERT(encoder->private_->current_sample_number == 0);
-
-       /* To avoid excessive malloc'ing, we only grow the buffer; no shrinking. */
-       if(new_blocksize <= encoder->private_->input_capacity)
-               return true;
 
        ok = true;
 
-       /* WATCHOUT: FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx() and ..._intrin_sse2()
-        * require that the input arrays (in our case the integer signals)
-        * have a buffer of up to 3 zeroes in front (at negative indices) for
-        * alignment purposes; we use 4 in front to keep the data well-aligned.
-        */
+       /* To avoid excessive malloc'ing, we only grow the buffer; no shrinking. */
+       if(new_blocksize > encoder->private_->input_capacity) {
+
+               /* WATCHOUT: FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx() and ..._intrin_sse2()
+                * require that the input arrays (in our case the integer signals)
+                * have a buffer of up to 3 zeroes in front (at negative indices) for
+                * alignment purposes; we use 4 in front to keep the data well-aligned.
+                */
 
-       for(i = 0; ok && i < encoder->protected_->channels; i++) {
-               ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
-               if(ok) {
-                       memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
-                       encoder->private_->integer_signal[i] += 4;
+               for(i = 0; ok && i < encoder->protected_->channels; i++) {
+                       ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
+                       if(ok) {
+                               memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
+                               encoder->private_->integer_signal[i] += 4;
+                       }
                }
-       }
-       for(i = 0; ok && i < 2; i++) {
-               ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]);
-               if(ok) {
-                       memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
-                       encoder->private_->integer_signal_mid_side[i] += 4;
+               for(i = 0; ok && i < 2; i++) {
+                       ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]);
+                       if(ok) {
+                               memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
+                               encoder->private_->integer_signal_mid_side[i] += 4;
+                       }
                }
-       }
-       ok = ok && FLAC__memory_alloc_aligned_int64_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_33bit_side_unaligned, &encoder->private_->integer_signal_33bit_side);
+               ok = ok && FLAC__memory_alloc_aligned_int64_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_33bit_side_unaligned, &encoder->private_->integer_signal_33bit_side);
 #ifndef FLAC__INTEGER_ONLY_LIBRARY
-       if(ok && encoder->protected_->max_lpc_order > 0) {
-               for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
-                       ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
-               ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
-       }
+               if(ok && encoder->protected_->max_lpc_order > 0) {
+                       for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
+                               ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
+                       ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
+               }
 #endif
-       for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
-               for(i = 0; ok && i < 2; i++) {
-                       ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
+               for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
+                       for(i = 0; ok && i < 2; i++) {
+                               ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
+                       }
                }
-       }
 
 
-       for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
-               for(i = 0; ok && i < 2; i++) {
-                       ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace[channel][i], encoder->protected_->max_residual_partition_order);
-                       ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace[channel][i], encoder->protected_->max_residual_partition_order);
+               for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
+                       for(i = 0; ok && i < 2; i++) {
+                               ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace[channel][i], encoder->protected_->max_residual_partition_order);
+                               ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace[channel][i], encoder->protected_->max_residual_partition_order);
+                       }
                }
-       }
 
-       for(channel = 0; ok && channel < 2; channel++) {
-               for(i = 0; ok && i < 2; i++) {
-                       ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]);
+               for(channel = 0; ok && channel < 2; channel++) {
+                       for(i = 0; ok && i < 2; i++) {
+                               ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]);
+                       }
+               }
+
+               for(channel = 0; ok && channel < 2; channel++) {
+                       for(i = 0; ok && i < 2; i++) {
+                               ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace_mid_side[channel][i], encoder->protected_->max_residual_partition_order);
+                       }
                }
-       }
 
-       for(channel = 0; ok && channel < 2; channel++) {
                for(i = 0; ok && i < 2; i++) {
-                       ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace_mid_side[channel][i], encoder->protected_->max_residual_partition_order);
+                       ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_extra[i], encoder->protected_->max_residual_partition_order);
                }
-       }
 
-       for(i = 0; ok && i < 2; i++) {
-               ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_extra[i], encoder->protected_->max_residual_partition_order);
-       }
 
+               /* the *2 is an approximation to the series 1 + 1/2 + 1/4 + ... that sums tree occupies in a flat array */
+               /*@@@ new_blocksize*2 is too pessimistic, but to fix, we need smarter logic because a smaller new_blocksize can actually increase the # of partitions; would require moving this out into a separate function, then checking its capacity against the need of the current blocksize&min/max_partition_order (and maybe predictor order) */
+               ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
+               if(encoder->protected_->do_escape_coding)
+                       ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
+}
+       if(ok)
+               encoder->private_->input_capacity = new_blocksize;
+       else {
+               encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
+               return ok;
+       }
 
-       /* the *2 is an approximation to the series 1 + 1/2 + 1/4 + ... that sums tree occupies in a flat array */
-       /*@@@ new_blocksize*2 is too pessimistic, but to fix, we need smarter logic because a smaller new_blocksize can actually increase the # of partitions; would require moving this out into a separate function, then checking its capacity against the need of the current blocksize&min/max_partition_order (and maybe predictor order) */
-       ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
-       if(encoder->protected_->do_escape_coding)
-               ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
 
        /* now adjust the windows if the blocksize has changed */
 #ifndef FLAC__INTEGER_ONLY_LIBRARY
-       if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
-               for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
+       if(encoder->protected_->max_lpc_order > 0 && new_blocksize > 1) {
+               for(i = 0; i < encoder->protected_->num_apodizations; i++) {
                        switch(encoder->protected_->apodizations[i].type) {
                                case FLAC__APODIZATION_BARTLETT:
                                        FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
@@ -2700,14 +2696,14 @@ FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, uint32_t new_blocksize)
                        }
                }
        }
+       if (new_blocksize <= FLAC__MAX_LPC_ORDER) {
+               /* intrinsics autocorrelation routines do not all handle cases in which lag might be
+                * larger than data_len. Lag is one larger than the LPC order */
+               encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
+       }
 #endif
 
-       if(ok)
-               encoder->private_->input_capacity = new_blocksize;
-       else
-               encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
-
-       return ok;
+       return true;
 }
 
 FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, uint32_t samples, FLAC__bool is_last_block)
@@ -3725,7 +3721,8 @@ FLAC__bool process_subframe_(
                                                                FLAC__lpc_window_data_wide(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
                                                        encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order_this_apodization+1, autoc);
                                                        if(encoder->protected_->apodizations[a].type == FLAC__APODIZATION_SUBDIVIDE_TUKEY){
-                                                               for(uint32_t i = 0; i < max_lpc_order_this_apodization; i++)
+                                                               uint32_t i;
+                                                               for(i = 0; i < max_lpc_order_this_apodization; i++)
                                                                        autoc_root[i] = autoc[i];
                                                                b++;
                                                        }else{
@@ -3734,14 +3731,14 @@ FLAC__bool process_subframe_(
                                                }
                                                else {
                                                        /* window part of subblock */
-                                                       if(max_lpc_order_this_apodization >= frame_header->blocksize/b) {
-                                                               max_lpc_order_this_apodization = frame_header->blocksize/b - 1;
-                                                               if(frame_header->blocksize/b > 0)
-                                                                       max_lpc_order_this_apodization = frame_header->blocksize/b - 1;
-                                                               else {
-                                                                       set_next_subdivide_tukey(encoder->protected_->apodizations[a].parameters.subdivide_tukey.parts, &a, &b, &c);
-                                                                       continue;
-                                                               }
+                                                       if(frame_header->blocksize/b <= FLAC__MAX_LPC_ORDER) {
+                                                               /* intrinsics autocorrelation routines do not all handle cases in which lag might be
+                                                                * larger than data_len, and some routines round lag up to the nearest multiple of 4
+                                                                * As little gain is expected from using LPC on part of a signal as small as 32 samples
+                                                                * and to enable widening this rounding up to larger values in the future, windowing
+                                                                * parts smaller than or equal to FLAC__MAX_LPC_ORDER (which is 32) samples is not supported */
+                                                               set_next_subdivide_tukey(encoder->protected_->apodizations[a].parameters.subdivide_tukey.parts, &a, &b, &c);
+                                                               continue;
                                                        }
                                                        if(!(c % 2)){
                                                                /* on even c, evaluate the (c/2)th partial window of size blocksize/b  */
@@ -3753,7 +3750,8 @@ FLAC__bool process_subframe_(
                                                        }else{
                                                                /* on uneven c, evaluate the root window (over the whole block) minus the previous partial window
                                                                 * similar to tukey_punchout apodization but more efficient     */
-                                                               for(uint32_t i = 0; i < max_lpc_order_this_apodization; i++)
+                                                               uint32_t i;
+                                                               for(i = 0; i < max_lpc_order_this_apodization; i++)
                                                                        autoc[i] = autoc_root[i] - autoc[i];
                                                        }
                                                        /* Next function sets a, b and c appropriate for next iteration */