ref: e55ee7fafd9c0abce539052339a64894e2161e3e
parent: ffd9c39d1c019c9592b8b8981a463afa040c7f98
author: Sigrid <[email protected]>
date: Sat Jan 11 08:25:02 EST 2020
libFLAC: 1.3.1 -> 1.3.3
--- a/sys/src/cmd/audio/libFLAC/FLAC/all.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/all.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -176,7 +176,7 @@
* #endif
* \endcode
*
- * The the source will work for multiple versions and the legacy code can
+ * The source will work for multiple versions and the legacy code can
* easily be removed when the transition is complete.
*
* Another available symbol is FLAC_API_SUPPORTS_OGG_FLAC (defined in
@@ -321,7 +321,7 @@
*
* The \a bytes parameter to FLAC__StreamDecoderReadCallback,
* FLAC__StreamEncoderReadCallback, and FLAC__StreamEncoderWriteCallback
- * is now \c size_t instead of \c unsigned.
+ * is now \c size_t instead of \c uint32_t.
*/
/** \defgroup porting_1_1_3_to_1_1_4 Porting from FLAC 1.1.3 to 1.1.4
--- a/sys/src/cmd/audio/libFLAC/FLAC/assert.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/assert.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -34,7 +34,7 @@
#define FLAC__ASSERT_H
/* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
-#ifdef DEBUG
+#ifndef NDEBUG
#include <assert.h>
#define FLAC__ASSERT(x) assert(x)
#define FLAC__ASSERT_DECLARATION(x) x
--- a/sys/src/cmd/audio/libFLAC/FLAC/callback.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/callback.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -165,7 +165,7 @@
* required may be set to NULL.
*
* If the seek requirement for an interface is optional, you can signify that
- * a data sorce is not seekable by setting the \a seek field to \c NULL.
+ * a data source is not seekable by setting the \a seek field to \c NULL.
*/
typedef struct {
FLAC__IOCallback_Read read;
--- a/sys/src/cmd/audio/libFLAC/FLAC/export.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/export.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/FLAC/format.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/format.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -173,10 +173,10 @@
/** The 32-bit integer big-endian representation of the beginning of
* a FLAC stream.
*/
-extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
+extern FLAC_API const uint32_t FLAC__STREAM_SYNC; /* = 0x664C6143 */
/** The length of the FLAC signature in bits. */
-extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
+extern FLAC_API const uint32_t FLAC__STREAM_SYNC_LEN; /* = 32 bits */
/** The length of the FLAC signature in bytes. */
#define FLAC__STREAM_SYNC_LENGTH (4u)
@@ -213,15 +213,15 @@
*/
typedef struct {
- unsigned *parameters;
+ uint32_t *parameters;
/**< The Rice parameters for each context. */
- unsigned *raw_bits;
+ uint32_t *raw_bits;
/**< Widths for escape-coded partitions. Will be non-zero for escaped
* partitions and zero for unescaped partitions.
*/
- unsigned capacity_by_order;
+ uint32_t capacity_by_order;
/**< The capacity of the \a parameters and \a raw_bits arrays
* specified as an order, i.e. the number of array elements
* allocated is 2 ^ \a capacity_by_order.
@@ -232,7 +232,7 @@
*/
typedef struct {
- unsigned order;
+ uint32_t order;
/**< The partition order, i.e. # of contexts = 2 ^ \a order. */
const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
@@ -240,14 +240,14 @@
} FLAC__EntropyCodingMethod_PartitionedRice;
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
+extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
+extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
+extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
+extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
+extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
/**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
+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>)
@@ -259,7 +259,7 @@
} data;
} FLAC__EntropyCodingMethod;
-extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
+extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
/*****************************************************************************/
@@ -299,7 +299,7 @@
FLAC__EntropyCodingMethod entropy_coding_method;
/**< The residual coding method. */
- unsigned order;
+ uint32_t order;
/**< The polynomial order. */
FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
@@ -316,10 +316,10 @@
FLAC__EntropyCodingMethod entropy_coding_method;
/**< The residual coding method. */
- unsigned order;
+ uint32_t order;
/**< The FIR order. */
- unsigned qlp_coeff_precision;
+ uint32_t qlp_coeff_precision;
/**< Quantized FIR filter coefficient precision in bits. */
int quantization_level;
@@ -335,8 +335,8 @@
/**< The residual signal, length == (blocksize minus order) samples. */
} FLAC__Subframe_LPC;
-extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
-extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
+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>)
@@ -349,7 +349,7 @@
FLAC__Subframe_LPC lpc;
FLAC__Subframe_Verbatim verbatim;
} data;
- unsigned wasted_bits;
+ uint32_t wasted_bits;
} FLAC__Subframe;
/** == 1 (bit)
@@ -359,14 +359,14 @@
* mandatory value of \c 0 but in the future may take on the value \c 0 or \c 1
* to mean something else.
*/
-extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
-extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
-extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_ZERO_PAD_LEN;
+extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
-extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
-extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
-extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
-extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
+extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
/*****************************************************************************/
@@ -409,19 +409,19 @@
/** FLAC frame header structure. (c.f. <A HREF="../format.html#frame_header">format specification</A>)
*/
typedef struct {
- unsigned blocksize;
+ uint32_t blocksize;
/**< The number of samples per subframe. */
- unsigned sample_rate;
+ uint32_t sample_rate;
/**< The sample rate in Hz. */
- unsigned channels;
+ uint32_t channels;
/**< The number of channels (== number of subframes). */
FLAC__ChannelAssignment channel_assignment;
/**< The channel assignment for the frame. */
- unsigned bits_per_sample;
+ uint32_t bits_per_sample;
/**< The sample resolution. */
FLAC__FrameNumberType number_type;
@@ -443,16 +443,16 @@
*/
} FLAC__FrameHeader;
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
-extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
+extern FLAC_API const uint32_t FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
+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>)
@@ -465,7 +465,7 @@
*/
} FLAC__FrameFooter;
-extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
+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>)
@@ -512,8 +512,8 @@
FLAC__METADATA_TYPE_UNDEFINED = 7,
/**< marker to denote beginning of undefined type range; this number will increase as new metadata types are added */
- FLAC__MAX_METADATA_TYPE = FLAC__MAX_METADATA_TYPE_CODE,
- /**< No type will ever be greater than this. There is not enough room in the protocol block. */
+ FLAC__MAX_METADATA_TYPE = FLAC__MAX_METADATA_TYPE_CODE,
+ /**< No type will ever be greater than this. There is not enough room in the protocol block. */
} FLAC__MetadataType;
/** Maps a FLAC__MetadataType to a C string.
@@ -527,24 +527,24 @@
/** FLAC STREAMINFO structure. (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
*/
typedef struct {
- unsigned min_blocksize, max_blocksize;
- unsigned min_framesize, max_framesize;
- unsigned sample_rate;
- unsigned channels;
- unsigned bits_per_sample;
+ uint32_t min_blocksize, max_blocksize;
+ uint32_t min_framesize, max_framesize;
+ uint32_t sample_rate;
+ uint32_t channels;
+ uint32_t bits_per_sample;
FLAC__uint64 total_samples;
FLAC__byte md5sum[16];
} FLAC__StreamMetadata_StreamInfo;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
/** The total stream length of the STREAMINFO block in bytes. */
#define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
@@ -567,7 +567,7 @@
FLAC__byte *data;
} FLAC__StreamMetadata_Application;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
+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>)
*/
@@ -579,13 +579,13 @@
/**< The offset, in bytes, of the target frame with respect to
* beginning of the first frame. */
- unsigned frame_samples;
+ uint32_t frame_samples;
/**< The number of samples in the target frame. */
} FLAC__StreamMetadata_SeekPoint;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
/** The total stream length of a seek point in bytes. */
#define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
@@ -610,7 +610,7 @@
* present in a stream.
*/
typedef struct {
- unsigned num_points;
+ uint32_t num_points;
FLAC__StreamMetadata_SeekPoint *points;
} FLAC__StreamMetadata_SeekTable;
@@ -626,7 +626,7 @@
FLAC__byte *entry;
} FLAC__StreamMetadata_VorbisComment_Entry;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
+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>)
@@ -637,7 +637,7 @@
FLAC__StreamMetadata_VorbisComment_Entry *comments;
} FLAC__StreamMetadata_VorbisComment;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
/** FLAC CUESHEET track index structure. (See the
@@ -654,9 +654,9 @@
/**< The index point number. */
} FLAC__StreamMetadata_CueSheet_Index;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
/** FLAC CUESHEET track structure. (See the
@@ -673,10 +673,10 @@
char isrc[13];
/**< Track ISRC. This is a 12-digit alphanumeric code plus a trailing \c NUL byte */
- unsigned type:1;
+ uint32_t type:1;
/**< The track type: 0 for audio, 1 for non-audio. */
- unsigned pre_emphasis:1;
+ uint32_t pre_emphasis:1;
/**< The pre-emphasis flag: 0 for no pre-emphasis, 1 for pre-emphasis. */
FLAC__byte num_indices;
@@ -687,13 +687,13 @@
} FLAC__StreamMetadata_CueSheet_Track;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
/** FLAC CUESHEET structure. (See the
@@ -713,7 +713,7 @@
FLAC__bool is_cd;
/**< \c true if CUESHEET corresponds to a Compact Disc, else \c false. */
- unsigned num_tracks;
+ uint32_t num_tracks;
/**< The number of tracks. */
FLAC__StreamMetadata_CueSheet_Track *tracks;
@@ -721,11 +721,11 @@
} FLAC__StreamMetadata_CueSheet;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
/** An enumeration of the PICTURE types (see FLAC__StreamMetadataPicture and id3 v2.4 APIC tag). */
@@ -810,14 +810,14 @@
} FLAC__StreamMetadata_Picture;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
/** Structure that is used when a metadata block of unknown type is loaded.
@@ -840,7 +840,7 @@
FLAC__bool is_last;
/**< \c true if this metadata block is the last, else \a false */
- unsigned length;
+ uint32_t length;
/**< Length, in bytes, of the block data as it appears in the stream. */
union {
@@ -857,9 +857,9 @@
* to use. */
} FLAC__StreamMetadata;
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
-extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
+extern FLAC_API const uint32_t FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
/** The total stream length of a metadata block header in bytes. */
#define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
@@ -880,7 +880,7 @@
* \c true if the given sample rate conforms to the specification, else
* \c false.
*/
-FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
+FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(uint32_t sample_rate);
/** Tests that a blocksize at the given sample rate is valid for the FLAC
* subset.
@@ -892,7 +892,7 @@
* \c true if the given blocksize conforms to the specification for the
* subset at the given sample rate, else \c false.
*/
-FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned blocksize, unsigned sample_rate);
+FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(uint32_t blocksize, uint32_t sample_rate);
/** Tests that a sample rate is valid for the FLAC subset. The subset rules
* for valid sample rates are slightly more complex since the rate has to
@@ -903,7 +903,7 @@
* \c true if the given sample rate conforms to the specification for the
* subset, else \c false.
*/
-FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
+FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(uint32_t sample_rate);
/** Check a Vorbis comment entry name to see if it conforms to the Vorbis
* comment specification.
@@ -926,7 +926,7 @@
*
* \param value A string to be checked.
* \param length A the length of \a value in bytes. May be
- * \c (unsigned)(-1) to indicate that \a value is a plain
+ * \c (uint32_t)(-1) to indicate that \a value is a plain
* UTF-8 NUL-terminated string.
* \assert
* \code value != NULL \endcode
@@ -933,7 +933,7 @@
* \retval FLAC__bool
* \c false if entry name is illegal, else \c true.
*/
-FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
+FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, uint32_t length);
/** Check a Vorbis comment entry to see if it conforms to the Vorbis
* comment specification.
@@ -950,7 +950,7 @@
* \retval FLAC__bool
* \c false if entry name is illegal, else \c true.
*/
-FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
+FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, uint32_t length);
/** Check a seek table to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
@@ -973,10 +973,10 @@
* \param seek_table A pointer to a seek table to be sorted.
* \assert
* \code seek_table != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* The number of duplicate seek points converted into placeholders.
*/
-FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
+FLAC_API uint32_t FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
/** Check a cue sheet to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
--- a/sys/src/cmd/audio/libFLAC/FLAC/metadata.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/metadata.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -93,7 +93,7 @@
* Efficient means the whole file is rewritten at most one time, and only
* when necessary. Level 1 is not efficient only in the case that you
* cause more than one metadata block to grow or shrink beyond what can
- * be accomodated by padding. In this case you should probably use level
+ * be accommodated by padding. In this case you should probably use level
* 2, which allows you to edit all the metadata for a file in memory and
* write it out all at once.
*
@@ -217,13 +217,13 @@
* matched exactly. Use \c NULL to mean "any
* description".
* \param max_width The maximum width in pixels desired. Use
- * \c (unsigned)(-1) to mean "any width".
+ * \c (uint32_t)(-1) to mean "any width".
* \param max_height The maximum height in pixels desired. Use
- * \c (unsigned)(-1) to mean "any height".
+ * \c (uint32_t)(-1) to mean "any height".
* \param max_depth The maximum color depth in bits-per-pixel desired.
- * Use \c (unsigned)(-1) to mean "any depth".
+ * Use \c (uint32_t)(-1) to mean "any depth".
* \param max_colors The maximum number of colors desired. Use
- * \c (unsigned)(-1) to mean "any number of colors".
+ * \c (uint32_t)(-1) to mean "any number of colors".
* \assert
* \code filename != NULL \endcode
* \code picture != NULL \endcode
@@ -234,7 +234,7 @@
* error, a file decoder error, or the file contained no PICTURE
* block, and \a *picture will be set to \c NULL.
*/
-FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors);
+FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors);
/* \} */
@@ -497,13 +497,13 @@
* \code iterator != NULL \endcode
* \a iterator has been successfully initialized with
* FLAC__metadata_simple_iterator_init()
- * \retval unsigned
+ * \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>,
* i.e. the length of the metadata body that follows the header.
*/
-FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
+FLAC_API uint32_t FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
/** Get the application ID of the \c APPLICATION block at the current
* position. This avoids reading the actual block data which can save
@@ -667,7 +667,7 @@
*
* - Create a new chain using FLAC__metadata_chain_new(). A chain is a
* linked list of FLAC metadata blocks.
- * - Read all metadata into the the chain from a FLAC file using
+ * - Read all metadata into the chain from a FLAC file using
* FLAC__metadata_chain_read() or FLAC__metadata_chain_read_ogg() and
* check the status.
* - Optionally, consolidate the padding using
@@ -764,7 +764,7 @@
FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
/**< FLAC__metadata_chain_write() was called on a chain read by
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
- * or
+ * or
* FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile()
* was called on a chain read by
* FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
@@ -1373,7 +1373,7 @@
* \retval FLAC__bool
* \c false if \a copy is \c true and malloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
+FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, uint32_t length, FLAC__bool copy);
/** Resize the seekpoint array.
*
@@ -1390,7 +1390,7 @@
* \retval FLAC__bool
* \c false if memory allocation error, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, uint32_t new_num_points);
/** Set a seekpoint in a seektable.
*
@@ -1402,7 +1402,7 @@
* \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
* \code object->data.seek_table.num_points > point_num \endcode
*/
-FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
+FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point);
/** Insert a seekpoint into a seektable.
*
@@ -1416,7 +1416,7 @@
* \retval FLAC__bool
* \c false if memory allocation error, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point);
/** Delete a seekpoint from a seektable.
*
@@ -1429,7 +1429,7 @@
* \retval FLAC__bool
* \c false if memory allocation error, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, uint32_t point_num);
/** Check a seektable to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
@@ -1459,7 +1459,7 @@
* \retval FLAC__bool
* \c false if memory allocation fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, uint32_t num);
/** Append a specific seek point template to the end of a seek table.
*
@@ -1494,7 +1494,7 @@
* \retval FLAC__bool
* \c false if memory allocation fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], uint32_t num);
/** Append a set of evenly-spaced seek point templates to the end of a
* seek table.
@@ -1516,7 +1516,7 @@
* \retval FLAC__bool
* \c false if memory allocation fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, uint32_t num, FLAC__uint64 total_samples);
/** Append a set of evenly-spaced seek point templates to the end of a
* seek table.
@@ -1544,7 +1544,7 @@
* \retval FLAC__bool
* \c false if memory allocation fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, uint32_t samples, FLAC__uint64 total_samples);
/** Sort a seek table's seek points according to the format specification,
* removing duplicates.
@@ -1603,7 +1603,7 @@
* \retval FLAC__bool
* \c false if memory allocation fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, uint32_t new_num_comments);
/** Sets a comment in a VORBIS_COMMENT block.
*
@@ -1630,7 +1630,7 @@
* \c false if memory allocation fails or \a entry does not comply with the
* Vorbis comment specification, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
/** Insert a comment in a VORBIS_COMMENT block at the given index.
*
@@ -1660,7 +1660,7 @@
* \c false if memory allocation fails or \a entry does not comply with the
* Vorbis comment specification, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
/** Appends a comment to a VORBIS_COMMENT block.
*
@@ -1692,7 +1692,7 @@
* For convenience, a trailing NUL is added to the entry if it doesn't have
* one already.
*
- * Depending on the the value of \a all, either all or just the first comment
+ * Depending on the value of \a all, either all or just the first comment
* whose field name(s) match the given entry's name will be replaced by the
* given entry. If no comments match, \a entry will simply be appended.
*
@@ -1733,7 +1733,7 @@
* \retval FLAC__bool
* \c false if realloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, uint32_t comment_num);
/** Creates a Vorbis comment entry from NUL-terminated name and value strings.
*
@@ -1789,7 +1789,7 @@
* \retval FLAC__bool
* \c true if the field names match, else \c false
*/
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, uint32_t field_name_length);
/** Find a Vorbis comment with the given field name.
*
@@ -1808,7 +1808,7 @@
* The offset in the comment array of the first comment whose field
* name matches \a field_name, or \c -1 if no match was found.
*/
-FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
+FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name);
/** Remove first Vorbis comment matching the given field name.
*
@@ -1886,7 +1886,7 @@
* \retval FLAC__bool
* \c false if memory allocation error, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t new_num_indices);
/** Insert an index point in a CUESHEET track at the given index.
*
@@ -1909,7 +1909,7 @@
* \retval FLAC__bool
* \c false if realloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num, FLAC__StreamMetadata_CueSheet_Index index);
/** Insert a blank index point in a CUESHEET track at the given index.
*
@@ -1933,7 +1933,7 @@
* \retval FLAC__bool
* \c false if realloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num);
/** Delete an index point in a CUESHEET track at the given index.
*
@@ -1952,7 +1952,7 @@
* \retval FLAC__bool
* \c false if realloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num);
/** Resize the track array.
*
@@ -1969,7 +1969,7 @@
* \retval FLAC__bool
* \c false if memory allocation error, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, uint32_t new_num_tracks);
/** Sets a track in a CUESHEET block.
*
@@ -1991,7 +1991,7 @@
* \retval FLAC__bool
* \c false if \a copy is \c true and malloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
/** Insert a track in a CUESHEET block at the given index.
*
@@ -2014,7 +2014,7 @@
* \retval FLAC__bool
* \c false if \a copy is \c true and malloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
/** Insert a blank track in a CUESHEET block at the given index.
*
@@ -2033,7 +2033,7 @@
* \retval FLAC__bool
* \c false if \a copy is \c true and malloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, uint32_t track_num);
/** Delete a track in a CUESHEET block at the given index.
*
@@ -2048,7 +2048,7 @@
* \retval FLAC__bool
* \c false if realloc() fails, else \c true.
*/
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, uint32_t track_num);
/** Check a cue sheet to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
--- a/sys/src/cmd/audio/libFLAC/FLAC/ordinals.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/ordinals.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -39,12 +39,11 @@
* the 1999 ISO C Standard header file <stdint.h>.
*/
-typedef __int8 FLAC__int8;
+typedef signed __int8 FLAC__int8;
+typedef signed __int16 FLAC__int16;
+typedef signed __int32 FLAC__int32;
+typedef signed __int64 FLAC__int64;
typedef unsigned __int8 FLAC__uint8;
-
-typedef __int16 FLAC__int16;
-typedef __int32 FLAC__int32;
-typedef __int64 FLAC__int64;
typedef unsigned __int16 FLAC__uint16;
typedef unsigned __int32 FLAC__uint32;
typedef unsigned __int64 FLAC__uint64;
--- a/sys/src/cmd/audio/libFLAC/FLAC/stream_decoder.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/stream_decoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -228,7 +228,7 @@
*/
FLAC__STREAM_DECODER_ABORTED,
- /**< The decoder was aborted by the read callback. */
+ /**< The decoder was aborted by the read or write callback. */
FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
/**< An error occurred allocating memory. The decoder is in an invalid
@@ -920,7 +920,7 @@
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See above.
*/
FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
@@ -932,10 +932,10 @@
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See above.
*/
-FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
+FLAC_API uint32_t FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
/** Get the current channel assignment in the stream being decoded.
* Will only be valid after decoding has started and will contain the
@@ -956,10 +956,10 @@
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See above.
*/
-FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
+FLAC_API uint32_t FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
/** Get the current sample rate in Hz of the stream being decoded.
* Will only be valid after decoding has started and will contain the
@@ -968,10 +968,10 @@
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See above.
*/
-FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
+FLAC_API uint32_t FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
/** Get the current blocksize of the stream being decoded.
* Will only be valid after decoding has started and will contain the
@@ -980,10 +980,10 @@
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See above.
*/
-FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
+FLAC_API uint32_t FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
/** Returns the decoder's current read position within the stream.
* The position is the byte offset from the start of the stream.
@@ -1184,7 +1184,7 @@
* Unless \a file is \c stdin, it will be closed
* when FLAC__stream_decoder_finish() is called.
* Note however that seeking will not work when
- * decoding from \c stdout since it is not seekable.
+ * decoding from \c stdin since it is not seekable.
* \param write_callback See FLAC__StreamDecoderWriteCallback. This
* pointer must not be \c NULL.
* \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
@@ -1234,7 +1234,7 @@
* Unless \a file is \c stdin, it will be closed
* when FLAC__stream_decoder_finish() is called.
* Note however that seeking will not work when
- * decoding from \c stdout since it is not seekable.
+ * decoding from \c stdin since it is not seekable.
* \param write_callback See FLAC__StreamDecoderWriteCallback. This
* pointer must not be \c NULL.
* \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
@@ -1403,8 +1403,7 @@
* and is not seekable (i.e. no seek callback was provided or the seek
* callback returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED), it
* is the duty of the client to start feeding data from the beginning of
- * the stream on the next FLAC__stream_decoder_process() or
- * FLAC__stream_decoder_process_interleaved() call.
+ * the stream on the next FLAC__stream_decoder_process_*() call.
*
* \param decoder A decoder instance.
* \assert
--- a/sys/src/cmd/audio/libFLAC/FLAC/stream_encoder.h
+++ b/sys/src/cmd/audio/libFLAC/FLAC/stream_encoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -554,7 +554,7 @@
* \retval FLAC__StreamEncoderWriteStatus
* The callee's return status.
*/
-typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
+typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data);
/** Signature for the seek callback.
*
@@ -675,7 +675,7 @@
* \param client_data The callee's client data set through
* FLAC__stream_encoder_init_*().
*/
-typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
+typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data);
/***********************************************************************
@@ -771,7 +771,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set the sample resolution of the input to be encoded.
*
@@ -787,7 +787,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set the sample rate (in Hz) of the input to be encoded.
*
@@ -799,7 +799,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set the compression level
*
@@ -862,7 +862,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set the blocksize to use while encoding.
*
@@ -877,13 +877,13 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set to \c true to enable mid-side encoding on stereo input. The
* number of channels must be 2 for this to have any effect. Set to
* \c false to use only independent channel coding.
*
- * \default \c false
+ * \default \c true
* \param encoder An encoder instance to set.
* \param value Flag value (see above).
* \assert
@@ -977,7 +977,7 @@
/** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
*
- * \default \c 0
+ * \default \c 8
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
@@ -985,7 +985,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set the precision, in bits, of the quantized linear predictor
* coefficients, or \c 0 to let the encoder select it based on the
@@ -1003,7 +1003,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set to \c false to use only the specified quantized linear predictor
* coefficient precision, or \c true to search neighboring precision
@@ -1066,7 +1066,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set the maximum partition order to search when coding the residual.
* This is used in tandem with
@@ -1081,7 +1081,7 @@
* all orders, using the mean of each context for its Rice parameter,
* and use the best.
*
- * \default \c 0
+ * \default \c 5
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
@@ -1089,7 +1089,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value);
/** Deprecated. Setting this value has no effect.
*
@@ -1101,7 +1101,7 @@
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, uint32_t value);
/** Set an estimate of the total samples that will be encoded.
* This is merely an estimate and may be set to \c 0 if unknown.
@@ -1200,7 +1200,7 @@
* \c false if the encoder is already initialized, or if
* \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
+FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, uint32_t num_blocks);
/** Get the current encoder state.
*
@@ -1254,7 +1254,7 @@
* \assert
* \code encoder != NULL \endcode
*/
-FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
+FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got);
/** Get the "verify" flag.
*
@@ -1281,10 +1281,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_channels().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
/** Get the input sample resolution setting.
*
@@ -1291,10 +1291,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_bits_per_sample().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
/** Get the input sample rate setting.
*
@@ -1301,10 +1301,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_sample_rate().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
/** Get the blocksize setting.
*
@@ -1311,10 +1311,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_blocksize().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
/** Get the "mid/side stereo coding" flag.
*
@@ -1341,10 +1341,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_max_lpc_order().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
/** Get the quantized linear predictor coefficient precision setting.
*
@@ -1351,10 +1351,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_qlp_coeff_precision().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
/** Get the qlp coefficient precision search flag.
*
@@ -1391,10 +1391,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_min_residual_partition_order().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
/** Get maximum residual partition order setting.
*
@@ -1401,10 +1401,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_max_residual_partition_order().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
/** Get the Rice parameter search distance setting.
*
@@ -1411,10 +1411,10 @@
* \param encoder An encoder instance to query.
* \assert
* \code encoder != NULL \endcode
- * \retval unsigned
+ * \retval uint32_t
* See FLAC__stream_encoder_set_rice_parameter_search_dist().
*/
-FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
+FLAC_API uint32_t FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
/** Get the previously set estimate of the total samples to be encoded.
* The encoder merely mimics back the value given to
@@ -1747,7 +1747,7 @@
* encoder state with FLAC__stream_encoder_get_state() to see what
* went wrong.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
+FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], uint32_t samples);
/** Submit data for encoding.
* This version allows you to supply the input data where the channels
@@ -1779,7 +1779,7 @@
* encoder state with FLAC__stream_encoder_get_state() to see what
* went wrong.
*/
-FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
+FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], uint32_t samples);
/* \} */
--- a/sys/src/cmd/audio/libFLAC/bitmath.c
+++ b/sys/src/cmd/audio/libFLAC/bitmath.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -60,50 +60,14 @@
* silog2( 9) = 5
* silog2( 10) = 5
*/
-unsigned FLAC__bitmath_silog2(int v)
+uint32_t FLAC__bitmath_silog2(FLAC__int64 v)
{
- while(1) {
- if(v == 0) {
- return 0;
- }
- else if(v > 0) {
- unsigned l = 0;
- while(v) {
- l++;
- v >>= 1;
- }
- return l+1;
- }
- else if(v == -1) {
- return 2;
- }
- else {
- v++;
- v = -v;
- }
- }
-}
+ if(v == 0)
+ return 0;
-unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
-{
- while(1) {
- if(v == 0) {
- return 0;
- }
- else if(v > 0) {
- unsigned l = 0;
- while(v) {
- l++;
- v >>= 1;
- }
- return l+1;
- }
- else if(v == -1) {
- return 2;
- }
- else {
- v++;
- v = -v;
- }
- }
+ if(v == -1)
+ return 2;
+
+ v = (v < 0) ? (-(v+1)) : v;
+ return FLAC__bitmath_ilog2_wide(v)+2;
}
--- a/sys/src/cmd/audio/libFLAC/bitreader.c
+++ b/sys/src/cmd/audio/libFLAC/bitreader.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * Copyright (C) 2011-2018 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -45,19 +45,44 @@
#include "share/endswap.h"
/* Things should be fastest when this matches the machine word size */
-/* WATCHOUT: if you change this you must also change the following #defines down to FLAC__clz_uint32 below to match */
-/* WATCHOUT: there are a few places where the code will not work unless uint32_t is >= 32 bits wide */
+/* WATCHOUT: if you change this you must also change the following #defines down to COUNT_ZERO_MSBS2 below to match */
+/* WATCHOUT: there are a few places where the code will not work unless brword is >= 32 bits wide */
/* also, some sections currently only have fast versions for 4 or 8 bytes per word */
-#define FLAC__BYTES_PER_WORD 4 /* sizeof uint32_t */
-#define FLAC__BITS_PER_WORD (8 * FLAC__BYTES_PER_WORD)
+
+#if (ENABLE_64_BIT_WORDS == 0)
+
+typedef FLAC__uint32 brword;
+#define FLAC__BYTES_PER_WORD 4 /* sizeof brword */
+#define FLAC__BITS_PER_WORD 32
#define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
-/* SWAP_BE_WORD_TO_HOST swaps bytes in a uint32_t (which is always big-endian) if necessary to match host byte order */
+/* SWAP_BE_WORD_TO_HOST swaps bytes in a brword (which is always big-endian) if necessary to match host byte order */
#if WORDS_BIGENDIAN
#define SWAP_BE_WORD_TO_HOST(x) (x)
#else
#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x)
#endif
+/* counts the # of zero MSBs in a word */
+#define COUNT_ZERO_MSBS(word) FLAC__clz_uint32(word)
+#define COUNT_ZERO_MSBS2(word) FLAC__clz2_uint32(word)
+#else
+
+typedef FLAC__uint64 brword;
+#define FLAC__BYTES_PER_WORD 8 /* sizeof brword */
+#define FLAC__BITS_PER_WORD 64
+#define FLAC__WORD_ALL_ONES ((FLAC__uint64)FLAC__U64L(0xffffffffffffffff))
+/* SWAP_BE_WORD_TO_HOST swaps bytes in a brword (which is always big-endian) if necessary to match host byte order */
+#if WORDS_BIGENDIAN
+#define SWAP_BE_WORD_TO_HOST(x) (x)
+#else
+#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_64(x)
+#endif
+/* counts the # of zero MSBs in a word */
+#define COUNT_ZERO_MSBS(word) FLAC__clz_uint64(word)
+#define COUNT_ZERO_MSBS2(word) FLAC__clz2_uint64(word)
+
+#endif
+
/*
* This should be at least twice as large as the largest number of words
* required to represent any 'number' (in any encoding) you are going to
@@ -72,60 +97,64 @@
* also depends on the CPU cache size and other factors; some twiddling
* may be necessary to squeeze out the best performance.
*/
-static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
+static const uint32_t FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
struct FLAC__BitReader {
/* any partially-consumed word at the head will stay right-justified as bits are consumed from the left */
/* any incomplete word at the tail will be left-justified, and bytes from the read callback are added on the right */
- uint32_t *buffer;
- unsigned capacity; /* in words */
- unsigned words; /* # of completed words in buffer */
- unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
- unsigned consumed_words; /* #words ... */
- unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
- unsigned read_crc16; /* the running frame CRC */
- unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
+ brword *buffer;
+ uint32_t capacity; /* in words */
+ uint32_t words; /* # of completed words in buffer */
+ uint32_t bytes; /* # of bytes in incomplete word at buffer[words] */
+ uint32_t consumed_words; /* #words ... */
+ uint32_t consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
+ uint32_t read_crc16; /* the running frame CRC */
+ uint32_t crc16_offset; /* the number of words in the current buffer that should not be CRC'd */
+ uint32_t crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
FLAC__BitReaderReadCallback read_callback;
void *client_data;
};
-static inline void crc16_update_word_(FLAC__BitReader *br, uint32_t word)
+static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
{
- register unsigned crc = br->read_crc16;
+ register uint32_t crc = br->read_crc16;
+
+ for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
+ crc = FLAC__CRC16_UPDATE((uint32_t)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
+
+ br->read_crc16 = crc;
+ br->crc16_align = 0;
+}
+
+static inline void crc16_update_block_(FLAC__BitReader *br)
+{
+ if(br->consumed_words > br->crc16_offset && br->crc16_align)
+ crc16_update_word_(br, br->buffer[br->crc16_offset++]);
+
#if FLAC__BYTES_PER_WORD == 4
- switch(br->crc16_align) {
- case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
- case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
- case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
- case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
- }
+ br->read_crc16 = FLAC__crc16_update_words32(br->buffer + br->crc16_offset, br->consumed_words - br->crc16_offset, br->read_crc16);
#elif FLAC__BYTES_PER_WORD == 8
- switch(br->crc16_align) {
- case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
- case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
- case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
- case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
- case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
- case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
- case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
- case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
- }
+ br->read_crc16 = FLAC__crc16_update_words64(br->buffer + br->crc16_offset, br->consumed_words - br->crc16_offset, br->read_crc16);
#else
- for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
- crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
- br->read_crc16 = crc;
+ unsigned i;
+
+ for(i = br->crc16_offset; i < br->consumed_words; i++)
+ crc16_update_word_(br, br->buffer[i]);
#endif
- br->crc16_align = 0;
+
+ br->crc16_offset = 0;
}
static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
{
- unsigned start, end;
+ uint32_t start, end;
size_t bytes;
FLAC__byte *target;
/* first shift the unconsumed buffer data toward the front as much as possible */
if(br->consumed_words > 0) {
+ crc16_update_block_(br); /* CRC consumed words */
+
start = br->consumed_words;
end = br->words + (br->bytes? 1:0);
memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
@@ -142,9 +171,9 @@
return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
- /* before reading, if the existing reader looks like this (say uint32_t is 32 bits wide)
+ /* before reading, if the existing reader looks like this (say brword is 32 bits wide)
* bitstream : 11 22 33 44 55 br->words=1 br->bytes=1 (partial tail word is left-justified)
- * buffer[BE]: 11 22 33 44 55 ?? ?? ?? (shown layed out as bytes sequentially in memory)
+ * buffer[BE]: 11 22 33 44 55 ?? ?? ?? (shown laid out as bytes sequentially in memory)
* buffer[LE]: 44 33 22 11 ?? ?? ?? 55 (?? being don't-care)
* ^^-------target, bytes=3
* on LE machines, have to byteswap the odd tail word so nothing is
@@ -175,7 +204,7 @@
*/
#if WORDS_BIGENDIAN
#else
- end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
+ end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + (uint32_t)bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
for(start = br->words; start < end; start++)
br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
#endif
@@ -186,7 +215,7 @@
* buffer[LE]: 44 33 22 11 88 77 66 55 CC BB AA 99 ?? FF EE DD
* finally we'll update the reader values:
*/
- end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
+ end = br->words*FLAC__BYTES_PER_WORD + br->bytes + (uint32_t)bytes;
br->words = end / FLAC__BYTES_PER_WORD;
br->bytes = end % FLAC__BYTES_PER_WORD;
@@ -236,7 +265,7 @@
br->words = br->bytes = 0;
br->consumed_words = br->consumed_bits = 0;
br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
- br->buffer = malloc(sizeof(uint32_t) * br->capacity);
+ br->buffer = malloc(sizeof(brword) * br->capacity);
if(br->buffer == 0)
return false;
br->read_callback = rcb;
@@ -268,7 +297,7 @@
void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
{
- unsigned i, j;
+ uint32_t i, j;
if(br == 0) {
fprintf(out, "bitreader is NULL\n");
}
@@ -281,7 +310,7 @@
if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
fprintf(out, ".");
else
- fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
+ fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
fprintf(out, "\n");
}
if(br->bytes > 0) {
@@ -290,7 +319,7 @@
if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
fprintf(out, ".");
else
- fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
+ fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0);
fprintf(out, "\n");
}
}
@@ -302,7 +331,8 @@
FLAC__ASSERT(0 != br->buffer);
FLAC__ASSERT((br->consumed_bits & 7) == 0);
- br->read_crc16 = (unsigned)seed;
+ br->read_crc16 = (uint32_t)seed;
+ br->crc16_offset = br->consumed_words;
br->crc16_align = br->consumed_bits;
}
@@ -310,14 +340,18 @@
{
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
+
+ /* CRC consumed words up to here */
+ crc16_update_block_(br);
+
FLAC__ASSERT((br->consumed_bits & 7) == 0);
FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
/* CRC any tail bytes in a partially-consumed word */
if(br->consumed_bits) {
- const uint32_t tail = br->buffer[br->consumed_words];
+ const brword tail = br->buffer[br->consumed_words];
for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
- br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
+ br->read_crc16 = FLAC__CRC16_UPDATE((uint32_t)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
}
return br->read_crc16;
}
@@ -327,17 +361,17 @@
return ((br->consumed_bits & 7) == 0);
}
-inline unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
+inline uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
{
return 8 - (br->consumed_bits & 7);
}
-inline unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
+inline uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
{
return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
}
-FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
+FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits)
{
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
@@ -362,35 +396,34 @@
/* OPT: taking out the consumed_bits==0 "else" case below might make things faster if less code allows the compiler to inline this function */
if(br->consumed_bits) {
/* this also works when consumed_bits==0, it's just a little slower than necessary for that case */
- const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
- const uint32_t word = br->buffer[br->consumed_words];
+ const uint32_t n = FLAC__BITS_PER_WORD - br->consumed_bits;
+ const brword word = br->buffer[br->consumed_words];
if(bits < n) {
- *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
+ *val = (FLAC__uint32)((word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits)); /* The result has <= 32 non-zero bits */
br->consumed_bits += bits;
return true;
}
- *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
+ /* (FLAC__BITS_PER_WORD - br->consumed_bits <= bits) ==> (FLAC__WORD_ALL_ONES >> br->consumed_bits) has no more than 'bits' non-zero bits */
+ *val = (FLAC__uint32)(word & (FLAC__WORD_ALL_ONES >> br->consumed_bits));
bits -= n;
- crc16_update_word_(br, word);
br->consumed_words++;
br->consumed_bits = 0;
if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
*val <<= bits;
- *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
+ *val |= (FLAC__uint32)(br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
br->consumed_bits = bits;
}
return true;
}
- else {
- const uint32_t word = br->buffer[br->consumed_words];
+ else { /* br->consumed_bits == 0 */
+ const brword word = br->buffer[br->consumed_words];
if(bits < FLAC__BITS_PER_WORD) {
- *val = word >> (FLAC__BITS_PER_WORD-bits);
+ *val = (FLAC__uint32)(word >> (FLAC__BITS_PER_WORD-bits));
br->consumed_bits = bits;
return true;
}
- /* at this point 'bits' must be == FLAC__BITS_PER_WORD; because of previous assertions, it can't be larger */
- *val = word;
- crc16_update_word_(br, word);
+ /* at this point bits == FLAC__BITS_PER_WORD == 32; because of previous assertions, it can't be larger */
+ *val = (FLAC__uint32)word;
br->consumed_words++;
return true;
}
@@ -404,12 +437,12 @@
if(br->consumed_bits) {
/* this also works when consumed_bits==0, it's just a little slower than necessary for that case */
FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
- *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
+ *val = (FLAC__uint32)((br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits));
br->consumed_bits += bits;
return true;
}
else {
- *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
+ *val = (FLAC__uint32)(br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
br->consumed_bits += bits;
return true;
}
@@ -416,18 +449,20 @@
}
}
-FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
+FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, uint32_t bits)
{
+ FLAC__uint32 uval, mask;
/* OPT: inline raw uint32 code here, or make into a macro if possible in the .h file */
- if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
+ if(!FLAC__bitreader_read_raw_uint32(br, &uval, bits))
return false;
- /* sign-extend: */
- *val <<= (32-bits);
- *val >>= (32-bits);
+ /* sign-extend *val assuming it is currently bits wide. */
+ /* From: https://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend */
+ mask = 1u << (bits - 1);
+ *val = (uval ^ mask) - mask;
return true;
}
-FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
+FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, uint32_t bits)
{
FLAC__uint32 hi, lo;
@@ -473,7 +508,7 @@
return true;
}
-FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
+FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, uint32_t bits)
{
/*
* OPT: a faster implementation is possible but probably not that useful
@@ -483,8 +518,8 @@
FLAC__ASSERT(0 != br->buffer);
if(bits > 0) {
- const unsigned n = br->consumed_bits & 7;
- unsigned m;
+ const uint32_t n = br->consumed_bits & 7;
+ uint32_t m;
FLAC__uint32 x;
if(n != 0) {
@@ -508,7 +543,7 @@
return true;
}
-FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
+FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, uint32_t nvals)
{
FLAC__uint32 x;
@@ -543,7 +578,7 @@
return true;
}
-FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
+FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, uint32_t nvals)
{
FLAC__uint32 x;
@@ -563,7 +598,7 @@
/* step 2: read whole words in chunks */
while(nvals >= FLAC__BYTES_PER_WORD) {
if(br->consumed_words < br->words) {
- const uint32_t word = br->buffer[br->consumed_words++];
+ const brword word = br->buffer[br->consumed_words++];
#if FLAC__BYTES_PER_WORD == 4
val[0] = (FLAC__byte)(word >> 24);
val[1] = (FLAC__byte)(word >> 16);
@@ -599,10 +634,10 @@
return true;
}
-FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
+FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *val)
#if 0 /* slow but readable version */
{
- unsigned bit;
+ uint32_t bit;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
@@ -620,7 +655,7 @@
}
#else
{
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
@@ -628,14 +663,13 @@
*val = 0;
while(1) {
while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
- uint32_t b = br->buffer[br->consumed_words] << br->consumed_bits;
+ brword b = br->buffer[br->consumed_words] << br->consumed_bits;
if(b) {
- i = FLAC__clz_uint32(b);
+ i = COUNT_ZERO_MSBS(b);
*val += i;
i++;
br->consumed_bits += i;
if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
- crc16_update_word_(br, br->buffer[br->consumed_words]);
br->consumed_words++;
br->consumed_bits = 0;
}
@@ -643,7 +677,6 @@
}
else {
*val += FLAC__BITS_PER_WORD - br->consumed_bits;
- crc16_update_word_(br, br->buffer[br->consumed_words]);
br->consumed_words++;
br->consumed_bits = 0;
/* didn't find stop bit yet, have to keep going... */
@@ -657,10 +690,10 @@
* be zero.
*/
if(br->bytes*8 > br->consumed_bits) {
- const unsigned end = br->bytes * 8;
- uint32_t b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
+ const uint32_t end = br->bytes * 8;
+ brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
if(b) {
- i = FLAC__clz_uint32(b);
+ i = COUNT_ZERO_MSBS(b);
*val += i;
i++;
br->consumed_bits += i;
@@ -680,10 +713,10 @@
}
#endif
-FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
+FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint32_t parameter)
{
FLAC__uint32 lsbs = 0, msbs = 0;
- unsigned uval;
+ uint32_t uval;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
@@ -708,14 +741,14 @@
}
/* this is by far the most heavily used reader call. it ain't pretty but it's fast */
-FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
+FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter)
{
/* try and get br->consumed_words and br->consumed_bits into register;
* must remember to flush them back to *br before calling other
* bitreader functions that use them, and before returning */
- unsigned cwords, words, lsbs, msbs, x, y;
- unsigned ucbits; /* keep track of the number of unconsumed bits in word */
- uint32_t b;
+ uint32_t cwords, words, lsbs, msbs, x, y;
+ uint32_t ucbits; /* keep track of the number of unconsumed bits in word */
+ brword b;
int *val, *end;
FLAC__ASSERT(0 != br);
@@ -756,16 +789,16 @@
while(val < end) {
/* read the unary MSBs and end bit */
- x = y = FLAC__clz2_uint32(b);
+ x = y = COUNT_ZERO_MSBS2(b);
if(x == FLAC__BITS_PER_WORD) {
x = ucbits;
do {
/* didn't find stop bit yet, have to keep going... */
- crc16_update_word_(br, br->buffer[cwords++]);
+ cwords++;
if (cwords >= words)
goto incomplete_msbs;
b = br->buffer[cwords];
- y = FLAC__clz2_uint32(b);
+ y = COUNT_ZERO_MSBS2(b);
x += y;
} while(y == FLAC__BITS_PER_WORD);
}
@@ -775,18 +808,18 @@
msbs = x;
/* read the binary LSBs */
- x = b >> (FLAC__BITS_PER_WORD - parameter);
+ x = (FLAC__uint32)(b >> (FLAC__BITS_PER_WORD - parameter)); /* parameter < 32, so we can cast to 32-bit uint32_t */
if(parameter <= ucbits) {
ucbits -= parameter;
b <<= parameter;
} else {
/* there are still bits left to read, they will all be in the next word */
- crc16_update_word_(br, br->buffer[cwords++]);
+ cwords++;
if (cwords >= words)
goto incomplete_lsbs;
b = br->buffer[cwords];
ucbits += FLAC__BITS_PER_WORD - parameter;
- x |= b >> ucbits;
+ x |= (FLAC__uint32)(b >> ucbits);
b <<= FLAC__BITS_PER_WORD - ucbits;
}
lsbs = x;
@@ -837,7 +870,7 @@
if(ucbits == 0 && cwords < words) {
/* don't leave the head word with no unconsumed bits */
- crc16_update_word_(br, br->buffer[cwords++]);
+ cwords++;
ucbits = FLAC__BITS_PER_WORD;
}
@@ -848,10 +881,10 @@
}
#if 0 /* UNUSED */
-FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
+FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter)
{
FLAC__uint32 lsbs = 0, msbs = 0;
- unsigned bit, uval, k;
+ uint32_t bit, uval, k;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
@@ -871,7 +904,7 @@
uval = (msbs << k) | lsbs;
}
else {
- unsigned d = (1 << (k+1)) - parameter;
+ uint32_t d = (1 << (k+1)) - parameter;
if(lsbs >= d) {
if(!FLAC__bitreader_read_bit(br, &bit))
return false;
@@ -883,7 +916,7 @@
uval = msbs * parameter + lsbs;
}
- /* unfold unsigned to signed */
+ /* unfold uint32_t to signed */
if(uval & 1)
*val = -((int)(uval >> 1)) - 1;
else
@@ -892,10 +925,10 @@
return true;
}
-FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
+FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, uint32_t *val, uint32_t parameter)
{
FLAC__uint32 lsbs, msbs = 0;
- unsigned bit, k;
+ uint32_t bit, k;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
@@ -915,7 +948,7 @@
*val = (msbs << k) | lsbs;
}
else {
- unsigned d = (1 << (k+1)) - parameter;
+ uint32_t d = (1 << (k+1)) - parameter;
if(lsbs >= d) {
if(!FLAC__bitreader_read_bit(br, &bit))
return false;
@@ -932,11 +965,11 @@
#endif /* UNUSED */
/* on return, if *val == 0xffffffff then the utf-8 sequence was invalid, but the return value will be true */
-FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
+FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, uint32_t *rawlen)
{
FLAC__uint32 v = 0;
FLAC__uint32 x;
- unsigned i;
+ uint32_t i;
if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
return false;
@@ -987,11 +1020,11 @@
}
/* on return, if *val == 0xffffffffffffffff then the utf-8 sequence was invalid, but the return value will be true */
-FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
+FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, uint32_t *rawlen)
{
FLAC__uint64 v = 0;
FLAC__uint32 x;
- unsigned i;
+ uint32_t i;
if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
return false;
@@ -1054,6 +1087,6 @@
* fix that we add extern declarations here.
*/
extern FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
-extern unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
-extern unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
+extern uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
+extern uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
extern FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val);
--- a/sys/src/cmd/audio/libFLAC/bitwriter.c
+++ b/sys/src/cmd/audio/libFLAC/bitwriter.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -46,11 +46,14 @@
/* Things should be fastest when this matches the machine word size */
/* WATCHOUT: if you change this you must also change the following #defines down to SWAP_BE_WORD_TO_HOST below to match */
-/* WATCHOUT: there are a few places where the code will not work unless uint32_t is >= 32 bits wide */
-#define FLAC__BYTES_PER_WORD 4
+/* WATCHOUT: there are a few places where the code will not work unless bwword is >= 32 bits wide */
+
+#if (ENABLE_64_BIT_WORDS == 0)
+
+typedef FLAC__uint32 bwword;
+#define FLAC__BYTES_PER_WORD 4 /* sizeof bwword */
#define FLAC__BITS_PER_WORD 32
-#define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
-/* SWAP_BE_WORD_TO_HOST swaps bytes in a uint32_t (which is always big-endian) if necessary to match host byte order */
+/* SWAP_BE_WORD_TO_HOST swaps bytes in a bwword (which is always big-endian) if necessary to match host byte order */
#if WORDS_BIGENDIAN
#define SWAP_BE_WORD_TO_HOST(x) (x)
#else
@@ -57,6 +60,20 @@
#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x)
#endif
+#else
+
+typedef FLAC__uint64 bwword;
+#define FLAC__BYTES_PER_WORD 8 /* sizeof bwword */
+#define FLAC__BITS_PER_WORD 64
+/* SWAP_BE_WORD_TO_HOST swaps bytes in a bwword (which is always big-endian) if necessary to match host byte order */
+#if WORDS_BIGENDIAN
+#define SWAP_BE_WORD_TO_HOST(x) (x)
+#else
+#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_64(x)
+#endif
+
+#endif
+
/*
* The default capacity here doesn't matter too much. The buffer always grows
* to hold whatever is written to it. Usually the encoder will stop adding at
@@ -63,19 +80,19 @@
* a frame or metadata block, then write that out and clear the buffer for the
* next one.
*/
-static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(uint32_t); /* size in words */
+static const uint32_t FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
/* When growing, increment 4K at a time */
-static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(uint32_t); /* size in words */
+static const uint32_t FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
#define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
#define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
struct FLAC__BitWriter {
- uint32_t *buffer;
- uint32_t accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
- unsigned capacity; /* capacity of buffer in words */
- unsigned words; /* # of complete words in buffer */
- unsigned bits; /* # of used bits in accum */
+ bwword *buffer;
+ bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
+ uint32_t capacity; /* capacity of buffer in words */
+ uint32_t words; /* # of complete words in buffer */
+ uint32_t bits; /* # of used bits in accum */
};
/* * WATCHOUT: The current implementation only grows the buffer. */
@@ -82,10 +99,10 @@
#ifndef __SUNPRO_C
static
#endif
-FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
+FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add)
{
- unsigned new_capacity;
- uint32_t *new_buffer;
+ uint32_t new_capacity;
+ bwword *new_buffer;
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
@@ -107,7 +124,7 @@
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(uint32_t), /*times*/new_capacity);
+ new_buffer = safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
if(new_buffer == 0)
return false;
bw->buffer = new_buffer;
@@ -149,7 +166,7 @@
bw->words = bw->bits = 0;
bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
- bw->buffer = malloc(sizeof(uint32_t) * bw->capacity);
+ bw->buffer = malloc(sizeof(bwword) * bw->capacity);
if(bw->buffer == 0)
return false;
@@ -174,7 +191,7 @@
void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
{
- unsigned i, j;
+ uint32_t i, j;
if(bw == 0) {
fprintf(out, "bitwriter is NULL\n");
}
@@ -184,13 +201,13 @@
for(i = 0; i < bw->words; i++) {
fprintf(out, "%08X: ", i);
for(j = 0; j < FLAC__BITS_PER_WORD; j++)
- fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
+ fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
fprintf(out, "\n");
}
if(bw->bits > 0) {
fprintf(out, "%08X: ", i);
for(j = 0; j < bw->bits; j++)
- fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
+ fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0);
fprintf(out, "\n");
}
}
@@ -231,7 +248,7 @@
return ((bw->bits & 7) == 0);
}
-unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
+uint32_t FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
{
return FLAC__TOTAL_BITS(bw);
}
@@ -264,9 +281,9 @@
(void)bw;
}
-inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
+inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits)
{
- unsigned n;
+ uint32_t n;
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
@@ -302,20 +319,24 @@
return true;
}
-inline FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
+static inline FLAC__bool FLAC__bitwriter_write_raw_uint32_nocheck(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits)
{
- register unsigned left;
+ register 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);
- FLAC__ASSERT(0 != bw);
- FLAC__ASSERT(0 != bw->buffer);
+ if(bw == 0 || bw->buffer == 0)
+ return false;
- FLAC__ASSERT(bits <= 32);
+ if (bits > 32)
+ return false;
+
if(bits == 0)
return true;
+ FLAC__ASSERT((bits == 32) || (val>>bits == 0));
+
/* slightly pessimistic size check but faster than "<= bw->words + (bw->bits+bits+FLAC__BITS_PER_WORD-1)/FLAC__BITS_PER_WORD" */
if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
return false;
@@ -330,33 +351,40 @@
bw->accum <<= left;
bw->accum |= val >> (bw->bits = bits - left);
bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
- bw->accum = val;
+ bw->accum = val; /* unused top bits can contain garbage */
}
- else {
- bw->accum = val;
- bw->bits = 0;
- bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
+ else { /* at this point bits == FLAC__BITS_PER_WORD == 32 and bw->bits == 0 */
+ bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST((bwword)val);
}
return true;
}
-inline FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
+inline FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits)
{
+ /* check that unused bits are unset */
+ if((bits < 32) && (val>>bits != 0))
+ return false;
+
+ return FLAC__bitwriter_write_raw_uint32_nocheck(bw, val, bits);
+}
+
+inline FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits)
+{
/* zero-out unused bits */
if(bits < 32)
val &= (~(0xffffffff << bits));
- return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
+ return FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)val, bits);
}
-inline FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
+inline FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits)
{
/* this could be a little faster but it's not used for much */
if(bits > 32) {
return
FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
- FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
+ FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)val, 32);
}
else
return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
@@ -366,25 +394,29 @@
{
/* this doesn't need to be that fast as currently it is only used for vorbis comments */
- if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
+ if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, val & 0xff, 8))
return false;
- if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
+ if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (val>>8) & 0xff, 8))
return false;
- if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
+ if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (val>>16) & 0xff, 8))
return false;
- if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
+ if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, val>>24, 8))
return false;
return true;
}
-inline FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
+inline FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals)
{
- unsigned i;
+ uint32_t i;
+ /* grow capacity upfront to prevent constant reallocation during writes */
+ if(bw->capacity <= bw->words + nvals / (FLAC__BITS_PER_WORD / 8) + 1 && !bitwriter_grow_(bw, nvals * 8))
+ return false;
+
/* this could be faster but currently we don't need it to be since it's only used for writing metadata */
for(i = 0; i < nvals; i++) {
- if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
+ if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)(vals[i]), 8))
return false;
}
@@ -391,41 +423,43 @@
return true;
}
-FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
+FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, uint32_t val)
{
if(val < 32)
- return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
+ return FLAC__bitwriter_write_raw_uint32_nocheck(bw, 1, ++val);
else
return
FLAC__bitwriter_write_zeroes(bw, val) &&
- FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
+ FLAC__bitwriter_write_raw_uint32_nocheck(bw, 1, 1);
}
-unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
+uint32_t FLAC__bitwriter_rice_bits(FLAC__int32 val, uint32_t parameter)
{
FLAC__uint32 uval;
- FLAC__ASSERT(parameter < sizeof(unsigned)*8);
+ FLAC__ASSERT(parameter < 32);
- /* fold signed to unsigned; actual formula is: negative(v)? -2v-1 : 2v */
- uval = (val<<1) ^ (val>>31);
+ /* fold signed to uint32_t; actual formula is: negative(v)? -2v-1 : 2v */
+ uval = val;
+ uval <<= 1;
+ uval ^= (val>>31);
return 1 + parameter + (uval >> parameter);
}
#if 0 /* UNUSED */
-unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
+uint32_t FLAC__bitwriter_golomb_bits_signed(int val, uint32_t parameter)
{
- unsigned bits, msbs, uval;
- unsigned k;
+ uint32_t bits, msbs, uval;
+ uint32_t k;
FLAC__ASSERT(parameter > 0);
- /* fold signed to unsigned */
+ /* fold signed to uint32_t */
if(val < 0)
- uval = (unsigned)(((-(++val)) << 1) + 1);
+ uval = (uint32_t)(((-(++val)) << 1) + 1);
else
- uval = (unsigned)(val << 1);
+ uval = (uint32_t)(val << 1);
k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
@@ -435,7 +469,7 @@
bits = 1 + k + msbs;
}
else {
- unsigned q, r, d;
+ uint32_t q, r, d;
d = (1 << (k+1)) - parameter;
q = uval / parameter;
@@ -448,10 +482,10 @@
return bits;
}
-unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
+uint32_t FLAC__bitwriter_golomb_bits_unsigned(uint32_t uval, uint32_t parameter)
{
- unsigned bits, msbs;
- unsigned k;
+ uint32_t bits, msbs;
+ uint32_t k;
FLAC__ASSERT(parameter > 0);
@@ -463,7 +497,7 @@
bits = 1 + k + msbs;
}
else {
- unsigned q, r, d;
+ uint32_t q, r, d;
d = (1 << (k+1)) - parameter;
q = uval / parameter;
@@ -477,17 +511,19 @@
}
#endif /* UNUSED */
-FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
+FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t parameter)
{
- unsigned total_bits, interesting_bits, msbs;
+ uint32_t total_bits, interesting_bits, msbs;
FLAC__uint32 uval, pattern;
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
- FLAC__ASSERT(parameter < 8*sizeof(uval));
+ FLAC__ASSERT(parameter < 32);
- /* fold signed to unsigned; actual formula is: negative(v)? -2v-1 : 2v */
- uval = (val<<1) ^ (val>>31);
+ /* fold signed to uint32_t; actual formula is: negative(v)? -2v-1 : 2v */
+ uval = val;
+ uval <<= 1;
+ uval ^= (val>>31);
msbs = uval >> parameter;
interesting_bits = 1 + parameter;
@@ -503,39 +539,42 @@
FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
}
-FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
+FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, uint32_t nvals, uint32_t parameter)
{
- const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
- const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
+ const FLAC__uint32 mask1 = (FLAC__uint32)0xffffffff << parameter; /* we val|=mask1 to set the stop bit above it... */
+ const FLAC__uint32 mask2 = (FLAC__uint32)0xffffffff >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2 */
FLAC__uint32 uval;
- unsigned left;
- const unsigned lsbits = 1 + parameter;
- unsigned msbits;
+ uint32_t left;
+ const uint32_t lsbits = 1 + parameter;
+ uint32_t msbits, total_bits;
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
- FLAC__ASSERT(parameter < 8*sizeof(uint32_t)-1);
+ FLAC__ASSERT(parameter < 31);
/* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */
FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
while(nvals) {
- /* fold signed to unsigned; actual formula is: negative(v)? -2v-1 : 2v */
- uval = (*vals<<1) ^ (*vals>>31);
+ /* fold signed to uint32_t; actual formula is: negative(v)? -2v-1 : 2v */
+ uval = *vals;
+ uval <<= 1;
+ uval ^= (*vals>>31);
msbits = uval >> parameter;
+ total_bits = lsbits + msbits;
- if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current uint32_t */
- /* ^^^ if bw->bits is 0 then we may have filled the buffer and have no free uint32_t to work in */
- bw->bits = bw->bits + msbits + lsbits;
+ if(bw->bits && bw->bits + total_bits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
+ /* ^^^ if bw->bits is 0 then we may have filled the buffer and have no free bwword to work in */
+ bw->bits += total_bits;
uval |= mask1; /* set stop bit */
uval &= mask2; /* mask off unused top bits */
- bw->accum <<= msbits + lsbits;
+ bw->accum <<= total_bits;
bw->accum |= uval;
}
else {
/* slightly pessimistic size check but faster than "<= bw->words + (bw->bits+msbits+lsbits+FLAC__BITS_PER_WORD-1)/FLAC__BITS_PER_WORD" */
/* OPT: pessimism may cause flurry of false calls to grow_ which eat up all savings before it */
- if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 uint32_t*/ && !bitwriter_grow_(bw, msbits+lsbits))
+ if(bw->capacity <= bw->words + bw->bits + msbits + 1 /* lsbits always fit in 1 bwword */ && !bitwriter_grow_(bw, total_bits))
return false;
if(msbits) {
@@ -585,7 +624,7 @@
bw->accum <<= left;
bw->accum |= uval >> (bw->bits = lsbits - left);
bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
- bw->accum = uval;
+ bw->accum = uval; /* unused top bits can contain garbage */
}
}
vals++;
@@ -595,24 +634,24 @@
}
#if 0 /* UNUSED */
-FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
+FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, uint32_t parameter)
{
- unsigned total_bits, msbs, uval;
- unsigned k;
+ uint32_t total_bits, msbs, uval;
+ uint32_t k;
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
FLAC__ASSERT(parameter > 0);
- /* fold signed to unsigned */
+ /* fold signed to uint32_t */
if(val < 0)
- uval = (unsigned)(((-(++val)) << 1) + 1);
+ uval = (uint32_t)(((-(++val)) << 1) + 1);
else
- uval = (unsigned)(val << 1);
+ uval = (uint32_t)(val << 1);
k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
- unsigned pattern;
+ uint32_t pattern;
FLAC__ASSERT(k <= 30);
@@ -635,7 +674,7 @@
}
}
else {
- unsigned q, r, d;
+ uint32_t q, r, d;
d = (1 << (k+1)) - parameter;
q = uval / parameter;
@@ -659,10 +698,10 @@
return true;
}
-FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
+FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, uint32_t uval, uint32_t parameter)
{
- unsigned total_bits, msbs;
- unsigned k;
+ uint32_t total_bits, msbs;
+ uint32_t k;
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
@@ -670,7 +709,7 @@
k = FLAC__bitmath_ilog2(parameter);
if(parameter == 1u<<k) {
- unsigned pattern;
+ uint32_t pattern;
FLAC__ASSERT(k <= 30);
@@ -693,7 +732,7 @@
}
}
else {
- unsigned q, r, d;
+ uint32_t q, r, d;
d = (1 << (k+1)) - parameter;
q = uval / parameter;
@@ -725,40 +764,41 @@
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
- FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
+ if((val & 0x80000000) != 0) /* this version only handles 31 bits */
+ return false;
if(val < 0x80) {
- return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
+ return FLAC__bitwriter_write_raw_uint32_nocheck(bw, val, 8);
}
else if(val < 0x800) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xC0 | (val>>6), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8);
}
else if(val < 0x10000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xE0 | (val>>12), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8);
}
else if(val < 0x200000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF0 | (val>>18), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8);
}
else if(val < 0x4000000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF8 | (val>>24), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>18)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8);
}
else {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xFC | (val>>30), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>24)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>18)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8);
}
return ok;
@@ -771,49 +811,50 @@
FLAC__ASSERT(0 != bw);
FLAC__ASSERT(0 != bw->buffer);
- FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
+ if((val & FLAC__U64L(0xFFFFFFF000000000)) != 0) /* this version only handles 36 bits */
+ return false;
if(val < 0x80) {
- return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
+ return FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)val, 8);
}
else if(val < 0x800) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
}
else if(val < 0x10000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
}
else if(val < 0x200000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
}
else if(val < 0x4000000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
}
else if(val < 0x80000000) {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
}
else {
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
- ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xFE, 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
+ ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
}
return ok;
@@ -836,8 +877,9 @@
* Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To
* fix that we add extern declarations here.
*/
-extern FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
-extern FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
-extern FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
+extern FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits);
+extern FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits);
+extern FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits);
+extern FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits);
extern FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val);
-extern FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
+extern FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals);
--- a/sys/src/cmd/audio/libFLAC/cpu.c
+++ b/sys/src/cmd/audio/libFLAC/cpu.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -35,384 +35,76 @@
#endif
#include "private/cpu.h"
-#include "private/memory.h"
+#include "share/compat.h"
#include <stdlib.h>
-#ifdef DEBUG
-# include <stdio.h>
-#endif
+#include <string.h>
-#if defined FLAC__CPU_IA32
-# include <signal.h>
-
-static void disable_sse(FLAC__CPUInfo *info)
-{
- info->ia32.sse = false;
- info->ia32.sse2 = false;
- info->ia32.sse3 = false;
- info->ia32.ssse3 = false;
- info->ia32.sse41 = false;
- info->ia32.sse42 = false;
-}
-
-static void disable_avx(FLAC__CPUInfo *info)
-{
- info->ia32.avx = false;
- info->ia32.avx2 = false;
- info->ia32.fma = false;
-}
-
-#elif defined FLAC__CPU_X86_64
-
-static void disable_avx(FLAC__CPUInfo *info)
-{
- info->x86.avx = false;
- info->x86.avx2 = false;
- info->x86.fma = false;
-}
+#if defined _MSC_VER
+#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
-#if defined (__NetBSD__) || defined(__OpenBSD__)
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <machine/cpu.h>
+#ifndef NDEBUG
+#include <stdio.h>
+#define dfprintf fprintf
+#else
+/* This is bad practice, it should be a static void empty function */
+#define dfprintf(file, format, ...)
#endif
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-#include <sys/types.h>
-#include <sys/sysctl.h>
+#if defined FLAC__CPU_PPC
+#include <sys/auxv.h>
#endif
-#if defined(__APPLE__)
-/* how to get sysctlbyname()? */
-#endif
+#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && (defined FLAC__HAS_NASM || FLAC__HAS_X86INTRIN) && !defined FLAC__NO_ASM
-#ifdef FLAC__CPU_IA32
/* these are flags in EDX of CPUID AX=00000001 */
-static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
-#endif
+static const uint32_t FLAC__CPUINFO_X86_CPUID_CMOV = 0x00008000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_MMX = 0x00800000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE = 0x02000000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE2 = 0x04000000;
/* these are flags in ECX of CPUID AX=00000001 */
-static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE41 = 0x00080000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE42 = 0x00100000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE3 = 0x00000001;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_SSSE3 = 0x00000200;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE41 = 0x00080000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE42 = 0x00100000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_OSXSAVE = 0x08000000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX = 0x10000000;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_FMA = 0x00001000;
-#if defined FLAC__AVX_SUPPORTED
-/* these are flags in ECX of CPUID AX=00000001 */
-static const unsigned FLAC__CPUINFO_IA32_CPUID_OSXSAVE = 0x08000000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_AVX = 0x10000000;
-static const unsigned FLAC__CPUINFO_IA32_CPUID_FMA = 0x00001000;
/* these are flags in EBX of CPUID AX=00000007 */
-static const unsigned FLAC__CPUINFO_IA32_CPUID_AVX2 = 0x00000020;
-#endif
+static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX2 = 0x00000020;
-/*
- * Extra stuff needed for detection of OS support for SSE on IA-32
- */
-#if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && (defined FLAC__HAS_NASM || defined FLAC__HAS_X86INTRIN) && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
-# if defined(__linux__)
-/*
- * If the OS doesn't support SSE, we will get here with a SIGILL. We
- * modify the return address to jump over the offending SSE instruction
- * and also the operation following it that indicates the instruction
- * executed successfully. In this way we use no global variables and
- * stay thread-safe.
- *
- * 3 + 3 + 6:
- * 3 bytes for "xorps xmm0,xmm0"
- * 3 bytes for estimate of how long the follwing "inc var" instruction is
- * 6 bytes extra in case our estimate is wrong
- * 12 bytes puts us in the NOP "landing zone"
- */
-# include <sys/ucontext.h>
- static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
- {
- (void)signal, (void)si;
- ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
- }
-# elif defined(_MSC_VER)
-# include <windows.h>
-# endif
-#endif
-
-
-void FLAC__cpu_info(FLAC__CPUInfo *info)
+static uint32_t
+cpu_xgetbv_x86(void)
{
-/*
- * IA32-specific
- */
-#ifdef FLAC__CPU_IA32
- FLAC__bool ia32_fxsr = false;
- FLAC__bool ia32_osxsave = false;
- (void) ia32_fxsr; (void) ia32_osxsave; /* to avoid warnings about unused variables */
- memset(info, 0, sizeof(*info));
- info->type = FLAC__CPUINFO_TYPE_IA32;
-#if !defined FLAC__NO_ASM && (defined FLAC__HAS_NASM || defined FLAC__HAS_X86INTRIN)
- info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
-#ifdef FLAC__HAS_X86INTRIN
- if(!FLAC__cpu_have_cpuid_x86())
- return;
+#if (defined _MSC_VER || defined __INTEL_COMPILER) && FLAC__AVX_SUPPORTED
+ return (uint32_t)_xgetbv(0);
+#elif defined __GNUC__
+ uint32_t lo, hi;
+ __asm__ volatile (".byte 0x0f, 0x01, 0xd0" : "=a"(lo), "=d"(hi) : "c" (0));
+ return lo;
#else
- if(!FLAC__cpu_have_cpuid_asm_ia32())
- return;
+ return 0;
#endif
- {
- /* http://www.sandpile.org/x86/cpuid.htm */
-#ifdef FLAC__HAS_X86INTRIN
- FLAC__uint32 flags_eax, flags_ebx, flags_ecx, flags_edx;
- FLAC__cpu_info_x86(1, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
-#else
- FLAC__uint32 flags_ecx, flags_edx;
- FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
-#endif
- info->ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
- info->ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
- ia32_fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
- info->ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
- info->ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
- info->ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
- info->ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
- info->ia32.sse41 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE41)? true : false;
- info->ia32.sse42 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE42)? true : false;
-#if defined FLAC__HAS_X86INTRIN && defined FLAC__AVX_SUPPORTED
- ia32_osxsave = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_OSXSAVE)? true : false;
- info->ia32.avx = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_AVX )? true : false;
- info->ia32.fma = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_FMA )? true : false;
- FLAC__cpu_info_x86(7, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
- info->ia32.avx2 = (flags_ebx & FLAC__CPUINFO_IA32_CPUID_AVX2 )? true : false;
-#endif
- }
-
-#ifdef DEBUG
- fprintf(stderr, "CPU info (IA-32):\n");
- fprintf(stderr, " CMOV ....... %c\n", info->ia32.cmov ? 'Y' : 'n');
- fprintf(stderr, " MMX ........ %c\n", info->ia32.mmx ? 'Y' : 'n');
- fprintf(stderr, " SSE ........ %c\n", info->ia32.sse ? 'Y' : 'n');
- fprintf(stderr, " SSE2 ....... %c\n", info->ia32.sse2 ? 'Y' : 'n');
- fprintf(stderr, " SSE3 ....... %c\n", info->ia32.sse3 ? 'Y' : 'n');
- fprintf(stderr, " SSSE3 ...... %c\n", info->ia32.ssse3 ? 'Y' : 'n');
- fprintf(stderr, " SSE41 ...... %c\n", info->ia32.sse41 ? 'Y' : 'n');
- fprintf(stderr, " SSE42 ...... %c\n", info->ia32.sse42 ? 'Y' : 'n');
-# if defined FLAC__HAS_X86INTRIN && defined FLAC__AVX_SUPPORTED
- fprintf(stderr, " AVX ........ %c\n", info->ia32.avx ? 'Y' : 'n');
- fprintf(stderr, " FMA ........ %c\n", info->ia32.fma ? 'Y' : 'n');
- fprintf(stderr, " AVX2 ....... %c\n", info->ia32.avx2 ? 'Y' : 'n');
-# endif
-#endif
-
- /*
- * now have to check for OS support of SSE instructions
- */
- if(info->ia32.sse) {
-#if defined FLAC__NO_SSE_OS
- /* assume user knows better than us; turn it off */
- disable_sse(info);
-#elif defined FLAC__SSE_OS
- /* assume user knows better than us; leave as detected above */
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
- int sse = 0;
- size_t len;
- /* at least one of these must work: */
- len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
- len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
- if(!sse)
- disable_sse(info);
-#elif defined(__NetBSD__) || defined (__OpenBSD__)
-# if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
- int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
- size_t len = sizeof(val);
- if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
- disable_sse(info);
- else { /* double-check SSE2 */
- mib[1] = CPU_SSE2;
- len = sizeof(val);
- if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val) {
- disable_sse(info);
- info->ia32.sse = true;
- }
- }
-# else
- disable_sse(info);
-# endif
-#elif defined(__linux__)
- int sse = 0;
- struct sigaction sigill_save;
- struct sigaction sigill_sse;
- sigill_sse.sa_sigaction = sigill_handler_sse_os;
- __sigemptyset(&sigill_sse.sa_mask);
- sigill_sse.sa_flags = SA_SIGINFO | SA_RESETHAND; /* SA_RESETHAND just in case our SIGILL return jump breaks, so we don't get stuck in a loop */
- if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
- {
- /* http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html */
- /* see sigill_handler_sse_os() for an explanation of the following: */
- asm volatile (
- "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
- "incl %0\n\t" /* SIGILL handler will jump over this */
- /* landing zone */
- "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
- "nop\n\t"
- "nop" /* SIGILL jump lands here if "inc" is 1 byte */
- : "=r"(sse)
- : "0"(sse)
- );
-
- sigaction(SIGILL, &sigill_save, NULL);
- }
-
- if(!sse)
- disable_sse(info);
-#elif defined(_MSC_VER)
- __try {
- __asm {
- xorps xmm0,xmm0
- }
- }
- __except(EXCEPTION_EXECUTE_HANDLER) {
- if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
- disable_sse(info);
- }
-#elif defined(__GNUC__) /* MinGW goes here */
- int sse = 0;
- /* Based on the idea described in Agner Fog's manual "Optimizing subroutines in assembly language" */
- /* In theory, not guaranteed to detect lack of OS SSE support on some future Intel CPUs, but in practice works (see the aforementioned manual) */
- if (ia32_fxsr) {
- struct {
- FLAC__uint32 buff[128];
- } __attribute__((aligned(16))) fxsr;
- FLAC__uint32 old_val, new_val;
-
- asm volatile ("fxsave %0" : "=m" (fxsr) : "m" (fxsr));
- old_val = fxsr.buff[50];
- fxsr.buff[50] ^= 0x0013c0de; /* change value in the buffer */
- asm volatile ("fxrstor %0" : "=m" (fxsr) : "m" (fxsr)); /* try to change SSE register */
- fxsr.buff[50] = old_val; /* restore old value in the buffer */
- asm volatile ("fxsave %0 " : "=m" (fxsr) : "m" (fxsr)); /* old value will be overwritten if SSE register was changed */
- new_val = fxsr.buff[50]; /* == old_val if FXRSTOR didn't change SSE register and (old_val ^ 0x0013c0de) otherwise */
- fxsr.buff[50] = old_val; /* again restore old value in the buffer */
- asm volatile ("fxrstor %0" : "=m" (fxsr) : "m" (fxsr)); /* restore old values of registers */
-
- if ((old_val^new_val) == 0x0013c0de)
- sse = 1;
- }
- if(!sse)
- disable_sse(info);
-#else
- /* no way to test, disable to be safe */
- disable_sse(info);
-#endif
-#ifdef DEBUG
- fprintf(stderr, " SSE OS sup . %c\n", info->ia32.sse ? 'Y' : 'n');
-#endif
- }
- else /* info->ia32.sse == false */
- disable_sse(info);
-
- /*
- * now have to check for OS support of AVX instructions
- */
- if(info->ia32.avx && ia32_osxsave) {
- FLAC__uint32 ecr = FLAC__cpu_xgetbv_x86();
- if ((ecr & 0x6) != 0x6)
- disable_avx(info);
-#ifdef DEBUG
- fprintf(stderr, " AVX OS sup . %c\n", info->ia32.avx ? 'Y' : 'n');
-#endif
- }
- else /* no OS AVX support*/
- disable_avx(info);
-#else
- info->use_asm = false;
-#endif
-
-/*
- * x86-64-specific
- */
-#elif defined FLAC__CPU_X86_64
- FLAC__bool x86_osxsave = false;
- (void) x86_osxsave; /* to avoid warnings about unused variables */
- memset(info, 0, sizeof(*info));
- info->type = FLAC__CPUINFO_TYPE_X86_64;
-#if !defined FLAC__NO_ASM && defined FLAC__HAS_X86INTRIN
- info->use_asm = true;
- {
- /* http://www.sandpile.org/x86/cpuid.htm */
- FLAC__uint32 flags_eax, flags_ebx, flags_ecx, flags_edx;
- FLAC__cpu_info_x86(1, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
- info->x86.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
- info->x86.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
- info->x86.sse41 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE41)? true : false;
- info->x86.sse42 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE42)? true : false;
-#if defined FLAC__AVX_SUPPORTED
- x86_osxsave = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_OSXSAVE)? true : false;
- info->x86.avx = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_AVX )? true : false;
- info->x86.fma = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_FMA )? true : false;
- FLAC__cpu_info_x86(7, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
- info->x86.avx2 = (flags_ebx & FLAC__CPUINFO_IA32_CPUID_AVX2 )? true : false;
-#endif
- }
-#ifdef DEBUG
- fprintf(stderr, "CPU info (x86-64):\n");
- fprintf(stderr, " SSE3 ....... %c\n", info->x86.sse3 ? 'Y' : 'n');
- fprintf(stderr, " SSSE3 ...... %c\n", info->x86.ssse3 ? 'Y' : 'n');
- fprintf(stderr, " SSE41 ...... %c\n", info->x86.sse41 ? 'Y' : 'n');
- fprintf(stderr, " SSE42 ...... %c\n", info->x86.sse42 ? 'Y' : 'n');
-# if defined FLAC__AVX_SUPPORTED
- fprintf(stderr, " AVX ........ %c\n", info->x86.avx ? 'Y' : 'n');
- fprintf(stderr, " FMA ........ %c\n", info->x86.fma ? 'Y' : 'n');
- fprintf(stderr, " AVX2 ....... %c\n", info->x86.avx2 ? 'Y' : 'n');
-# endif
-#endif
-
- /*
- * now have to check for OS support of AVX instructions
- */
- if(info->x86.avx && x86_osxsave) {
- FLAC__uint32 ecr = FLAC__cpu_xgetbv_x86();
- if ((ecr & 0x6) != 0x6)
- disable_avx(info);
-#ifdef DEBUG
- fprintf(stderr, " AVX OS sup . %c\n", info->x86.avx ? 'Y' : 'n');
-#endif
- }
- else /* no OS AVX support*/
- disable_avx(info);
-#else
- info->use_asm = false;
-#endif
-
-/*
- * unknown CPU
- */
-#else
- info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
- info->use_asm = false;
-#endif
}
-#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
-
-#if defined _MSC_VER
-#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
-
-FLAC__uint32 FLAC__cpu_have_cpuid_x86(void)
+static uint32_t
+cpu_have_cpuid(void)
{
-#ifdef FLAC__CPU_X86_64
+#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;
-#else
-# if defined _MSC_VER || defined __INTEL_COMPILER /* Do they support CPUs w/o CPUID support (or OSes that work on those CPUs)? */
+#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;
+ else
+ return 0;
+#elif defined _MSC_VER
FLAC__uint32 flags1, flags2;
__asm {
pushfd
@@ -431,57 +123,163 @@
return 1;
else
return 0;
-# elif defined __GNUC__ && defined HAVE_CPUID_H
- if (__get_cpuid_max(0, 0) != 0)
- return 1;
- else
- return 0;
-# else
+#else
return 0;
-# endif
#endif
}
-void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx)
+static void
+cpuinfo_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx)
{
-#if defined _MSC_VER || defined __INTEL_COMPILER
+#if defined _MSC_VER
int cpuinfo[4];
int ext = level & 0x80000000;
__cpuid(cpuinfo, ext);
- if((unsigned)cpuinfo[0] < level) {
- *eax = *ebx = *ecx = *edx = 0;
- return;
- }
-#if defined FLAC__AVX_SUPPORTED
- __cpuidex(cpuinfo, level, 0); /* for AVX2 detection */
+ if ((uint32_t)cpuinfo[0] >= level) {
+#if FLAC__AVX_SUPPORTED
+ __cpuidex(cpuinfo, level, 0); /* for AVX2 detection */
#else
- __cpuid(cpuinfo, level); /* some old compilers don't support __cpuidex */
+ __cpuid(cpuinfo, level); /* some old compilers don't support __cpuidex */
#endif
- *eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3];
+ *eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3];
+ return;
+ }
#elif defined __GNUC__ && defined HAVE_CPUID_H
FLAC__uint32 ext = level & 0x80000000;
__cpuid(ext, *eax, *ebx, *ecx, *edx);
- if (*eax < level) {
- *eax = *ebx = *ecx = *edx = 0;
+ if (*eax >= level) {
+ __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
return;
}
- __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
-#else
+#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;
+}
+
#endif
+
+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
+ FLAC__bool x86_osxsave = false;
+ FLAC__bool os_avx = false;
+ FLAC__uint32 flags_eax, flags_ebx, flags_ecx, flags_edx;
+
+ info->use_asm = true; /* we assume a minimum of 80386 */
+ if (!cpu_have_cpuid())
+ return;
+
+ cpuinfo_x86(0, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
+ info->x86.intel = (flags_ebx == 0x756E6547 && flags_edx == 0x49656E69 && flags_ecx == 0x6C65746E) ? true : false; /* GenuineIntel */
+ cpuinfo_x86(1, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
+
+ info->x86.cmov = (flags_edx & FLAC__CPUINFO_X86_CPUID_CMOV ) ? true : false;
+ info->x86.mmx = (flags_edx & FLAC__CPUINFO_X86_CPUID_MMX ) ? true : false;
+ info->x86.sse = (flags_edx & FLAC__CPUINFO_X86_CPUID_SSE ) ? true : false;
+ info->x86.sse2 = (flags_edx & FLAC__CPUINFO_X86_CPUID_SSE2 ) ? true : false;
+ info->x86.sse3 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSE3 ) ? true : false;
+ info->x86.ssse3 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSSE3) ? true : false;
+ 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 defined FLAC__CPU_IA32
+ dfprintf(stderr, "CPU info (IA-32):\n");
+#else
+ 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');
+ dfprintf(stderr, " SSE ........ %c\n", info->x86.sse ? 'Y' : 'n');
+ dfprintf(stderr, " SSE2 ....... %c\n", info->x86.sse2 ? 'Y' : 'n');
+ dfprintf(stderr, " SSE3 ....... %c\n", info->x86.sse3 ? 'Y' : 'n');
+ dfprintf(stderr, " SSSE3 ...... %c\n", info->x86.ssse3 ? 'Y' : 'n');
+ dfprintf(stderr, " SSE41 ...... %c\n", info->x86.sse41 ? 'Y' : 'n');
+ dfprintf(stderr, " SSE42 ...... %c\n", info->x86.sse42 ? 'Y' : 'n');
+
+ if (FLAC__AVX_SUPPORTED) {
+ dfprintf(stderr, " AVX ........ %c\n", info->x86.avx ? 'Y' : 'n');
+ dfprintf(stderr, " FMA ........ %c\n", info->x86.fma ? 'Y' : 'n');
+ dfprintf(stderr, " AVX2 ....... %c\n", info->x86.avx2 ? 'Y' : 'n');
+ }
+
+ /*
+ * now have to check for OS support of AVX instructions
+ */
+ if (FLAC__AVX_SUPPORTED && info->x86.avx && x86_osxsave && (cpu_xgetbv_x86() & 0x6) == 0x6) {
+ os_avx = true;
+ }
+ if (os_avx) {
+ dfprintf(stderr, " AVX OS sup . %c\n", info->x86.avx ? 'Y' : 'n');
+ }
+ if (!os_avx) {
+ /* no OS AVX support */
+ info->x86.avx = false;
+ info->x86.avx2 = false;
+ info->x86.fma = false;
+ }
+#else
+ info->use_asm = false;
+#endif
}
-FLAC__uint32 FLAC__cpu_xgetbv_x86(void)
+static void
+ppc_cpu_info (FLAC__CPUInfo *info)
{
-#if (defined _MSC_VER || defined __INTEL_COMPILER) && defined FLAC__AVX_SUPPORTED
- return (FLAC__uint32)_xgetbv(0);
-#elif defined __GNUC__
- FLAC__uint32 lo, hi;
- asm volatile (".byte 0x0f, 0x01, 0xd0" : "=a"(lo), "=d"(hi) : "c" (0));
- return lo;
+#if defined FLAC__CPU_PPC
+#ifndef PPC_FEATURE2_ARCH_3_00
+#define PPC_FEATURE2_ARCH_3_00 0x00800000
+#endif
+
+#ifndef PPC_FEATURE2_ARCH_2_07
+#define PPC_FEATURE2_ARCH_2_07 0x80000000
+#endif
+
+ if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_3_00) {
+ info->ppc.arch_3_00 = true;
+ } else if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07) {
+ info->ppc.arch_2_07 = true;
+ }
#else
- return 0;
+ info->ppc.arch_2_07 = false;
+ info->ppc.arch_3_00 = false;
#endif
}
-#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */
+void FLAC__cpu_info (FLAC__CPUInfo *info)
+{
+ memset(info, 0, sizeof(*info));
+
+#ifdef FLAC__CPU_IA32
+ info->type = FLAC__CPUINFO_TYPE_IA32;
+#elif defined FLAC__CPU_X86_64
+ info->type = FLAC__CPUINFO_TYPE_X86_64;
+#elif defined FLAC__CPU_PPC
+ info->type = FLAC__CPUINFO_TYPE_PPC;
+#else
+ info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
+#endif
+
+ switch (info->type) {
+ case FLAC__CPUINFO_TYPE_IA32: /* fallthrough */
+ case FLAC__CPUINFO_TYPE_X86_64:
+ x86_cpu_info (info);
+ break;
+ case FLAC__CPUINFO_TYPE_PPC:
+ ppc_cpu_info (info);
+ break;
+ default:
+ info->use_asm = false;
+ break;
+ }
+}
--- a/sys/src/cmd/audio/libFLAC/crc.c
+++ b/sys/src/cmd/audio/libFLAC/crc.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * Copyright (C) 2011-2018 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,7 +38,7 @@
/* CRC-8, poly = x^8 + x^2 + x^1 + x^0, init = 0 */
-FLAC__byte const FLAC__crc8_table[256] = {
+FLAC__uint8 const FLAC__crc8_table[256] = {
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
@@ -75,8 +75,8 @@
/* CRC-16, poly = x^16 + x^15 + x^2 + x^0, init = 0 */
-unsigned const FLAC__crc16_table[256] = {
- 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
+FLAC__uint16 const FLAC__crc16_table[8][256] = {
+ { 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
@@ -107,22 +107,263 @@
0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
- 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
-};
+ 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202 },
+ { 0x0000, 0x8603, 0x8c03, 0x0a00, 0x9803, 0x1e00, 0x1400, 0x9203,
+ 0xb003, 0x3600, 0x3c00, 0xba03, 0x2800, 0xae03, 0xa403, 0x2200,
+ 0xe003, 0x6600, 0x6c00, 0xea03, 0x7800, 0xfe03, 0xf403, 0x7200,
+ 0x5000, 0xd603, 0xdc03, 0x5a00, 0xc803, 0x4e00, 0x4400, 0xc203,
+ 0x4003, 0xc600, 0xcc00, 0x4a03, 0xd800, 0x5e03, 0x5403, 0xd200,
+ 0xf000, 0x7603, 0x7c03, 0xfa00, 0x6803, 0xee00, 0xe400, 0x6203,
+ 0xa000, 0x2603, 0x2c03, 0xaa00, 0x3803, 0xbe00, 0xb400, 0x3203,
+ 0x1003, 0x9600, 0x9c00, 0x1a03, 0x8800, 0x0e03, 0x0403, 0x8200,
+ 0x8006, 0x0605, 0x0c05, 0x8a06, 0x1805, 0x9e06, 0x9406, 0x1205,
+ 0x3005, 0xb606, 0xbc06, 0x3a05, 0xa806, 0x2e05, 0x2405, 0xa206,
+ 0x6005, 0xe606, 0xec06, 0x6a05, 0xf806, 0x7e05, 0x7405, 0xf206,
+ 0xd006, 0x5605, 0x5c05, 0xda06, 0x4805, 0xce06, 0xc406, 0x4205,
+ 0xc005, 0x4606, 0x4c06, 0xca05, 0x5806, 0xde05, 0xd405, 0x5206,
+ 0x7006, 0xf605, 0xfc05, 0x7a06, 0xe805, 0x6e06, 0x6406, 0xe205,
+ 0x2006, 0xa605, 0xac05, 0x2a06, 0xb805, 0x3e06, 0x3406, 0xb205,
+ 0x9005, 0x1606, 0x1c06, 0x9a05, 0x0806, 0x8e05, 0x8405, 0x0206,
+ 0x8009, 0x060a, 0x0c0a, 0x8a09, 0x180a, 0x9e09, 0x9409, 0x120a,
+ 0x300a, 0xb609, 0xbc09, 0x3a0a, 0xa809, 0x2e0a, 0x240a, 0xa209,
+ 0x600a, 0xe609, 0xec09, 0x6a0a, 0xf809, 0x7e0a, 0x740a, 0xf209,
+ 0xd009, 0x560a, 0x5c0a, 0xda09, 0x480a, 0xce09, 0xc409, 0x420a,
+ 0xc00a, 0x4609, 0x4c09, 0xca0a, 0x5809, 0xde0a, 0xd40a, 0x5209,
+ 0x7009, 0xf60a, 0xfc0a, 0x7a09, 0xe80a, 0x6e09, 0x6409, 0xe20a,
+ 0x2009, 0xa60a, 0xac0a, 0x2a09, 0xb80a, 0x3e09, 0x3409, 0xb20a,
+ 0x900a, 0x1609, 0x1c09, 0x9a0a, 0x0809, 0x8e0a, 0x840a, 0x0209,
+ 0x000f, 0x860c, 0x8c0c, 0x0a0f, 0x980c, 0x1e0f, 0x140f, 0x920c,
+ 0xb00c, 0x360f, 0x3c0f, 0xba0c, 0x280f, 0xae0c, 0xa40c, 0x220f,
+ 0xe00c, 0x660f, 0x6c0f, 0xea0c, 0x780f, 0xfe0c, 0xf40c, 0x720f,
+ 0x500f, 0xd60c, 0xdc0c, 0x5a0f, 0xc80c, 0x4e0f, 0x440f, 0xc20c,
+ 0x400c, 0xc60f, 0xcc0f, 0x4a0c, 0xd80f, 0x5e0c, 0x540c, 0xd20f,
+ 0xf00f, 0x760c, 0x7c0c, 0xfa0f, 0x680c, 0xee0f, 0xe40f, 0x620c,
+ 0xa00f, 0x260c, 0x2c0c, 0xaa0f, 0x380c, 0xbe0f, 0xb40f, 0x320c,
+ 0x100c, 0x960f, 0x9c0f, 0x1a0c, 0x880f, 0x0e0c, 0x040c, 0x820f },
-void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
-{
- *crc = FLAC__crc8_table[*crc ^ data];
-}
+ { 0x0000, 0x8017, 0x802b, 0x003c, 0x8053, 0x0044, 0x0078, 0x806f,
+ 0x80a3, 0x00b4, 0x0088, 0x809f, 0x00f0, 0x80e7, 0x80db, 0x00cc,
+ 0x8143, 0x0154, 0x0168, 0x817f, 0x0110, 0x8107, 0x813b, 0x012c,
+ 0x01e0, 0x81f7, 0x81cb, 0x01dc, 0x81b3, 0x01a4, 0x0198, 0x818f,
+ 0x8283, 0x0294, 0x02a8, 0x82bf, 0x02d0, 0x82c7, 0x82fb, 0x02ec,
+ 0x0220, 0x8237, 0x820b, 0x021c, 0x8273, 0x0264, 0x0258, 0x824f,
+ 0x03c0, 0x83d7, 0x83eb, 0x03fc, 0x8393, 0x0384, 0x03b8, 0x83af,
+ 0x8363, 0x0374, 0x0348, 0x835f, 0x0330, 0x8327, 0x831b, 0x030c,
+ 0x8503, 0x0514, 0x0528, 0x853f, 0x0550, 0x8547, 0x857b, 0x056c,
+ 0x05a0, 0x85b7, 0x858b, 0x059c, 0x85f3, 0x05e4, 0x05d8, 0x85cf,
+ 0x0440, 0x8457, 0x846b, 0x047c, 0x8413, 0x0404, 0x0438, 0x842f,
+ 0x84e3, 0x04f4, 0x04c8, 0x84df, 0x04b0, 0x84a7, 0x849b, 0x048c,
+ 0x0780, 0x8797, 0x87ab, 0x07bc, 0x87d3, 0x07c4, 0x07f8, 0x87ef,
+ 0x8723, 0x0734, 0x0708, 0x871f, 0x0770, 0x8767, 0x875b, 0x074c,
+ 0x86c3, 0x06d4, 0x06e8, 0x86ff, 0x0690, 0x8687, 0x86bb, 0x06ac,
+ 0x0660, 0x8677, 0x864b, 0x065c, 0x8633, 0x0624, 0x0618, 0x860f,
+ 0x8a03, 0x0a14, 0x0a28, 0x8a3f, 0x0a50, 0x8a47, 0x8a7b, 0x0a6c,
+ 0x0aa0, 0x8ab7, 0x8a8b, 0x0a9c, 0x8af3, 0x0ae4, 0x0ad8, 0x8acf,
+ 0x0b40, 0x8b57, 0x8b6b, 0x0b7c, 0x8b13, 0x0b04, 0x0b38, 0x8b2f,
+ 0x8be3, 0x0bf4, 0x0bc8, 0x8bdf, 0x0bb0, 0x8ba7, 0x8b9b, 0x0b8c,
+ 0x0880, 0x8897, 0x88ab, 0x08bc, 0x88d3, 0x08c4, 0x08f8, 0x88ef,
+ 0x8823, 0x0834, 0x0808, 0x881f, 0x0870, 0x8867, 0x885b, 0x084c,
+ 0x89c3, 0x09d4, 0x09e8, 0x89ff, 0x0990, 0x8987, 0x89bb, 0x09ac,
+ 0x0960, 0x8977, 0x894b, 0x095c, 0x8933, 0x0924, 0x0918, 0x890f,
+ 0x0f00, 0x8f17, 0x8f2b, 0x0f3c, 0x8f53, 0x0f44, 0x0f78, 0x8f6f,
+ 0x8fa3, 0x0fb4, 0x0f88, 0x8f9f, 0x0ff0, 0x8fe7, 0x8fdb, 0x0fcc,
+ 0x8e43, 0x0e54, 0x0e68, 0x8e7f, 0x0e10, 0x8e07, 0x8e3b, 0x0e2c,
+ 0x0ee0, 0x8ef7, 0x8ecb, 0x0edc, 0x8eb3, 0x0ea4, 0x0e98, 0x8e8f,
+ 0x8d83, 0x0d94, 0x0da8, 0x8dbf, 0x0dd0, 0x8dc7, 0x8dfb, 0x0dec,
+ 0x0d20, 0x8d37, 0x8d0b, 0x0d1c, 0x8d73, 0x0d64, 0x0d58, 0x8d4f,
+ 0x0cc0, 0x8cd7, 0x8ceb, 0x0cfc, 0x8c93, 0x0c84, 0x0cb8, 0x8caf,
+ 0x8c63, 0x0c74, 0x0c48, 0x8c5f, 0x0c30, 0x8c27, 0x8c1b, 0x0c0c },
-void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
+ { 0x0000, 0x9403, 0xa803, 0x3c00, 0xd003, 0x4400, 0x7800, 0xec03,
+ 0x2003, 0xb400, 0x8800, 0x1c03, 0xf000, 0x6403, 0x5803, 0xcc00,
+ 0x4006, 0xd405, 0xe805, 0x7c06, 0x9005, 0x0406, 0x3806, 0xac05,
+ 0x6005, 0xf406, 0xc806, 0x5c05, 0xb006, 0x2405, 0x1805, 0x8c06,
+ 0x800c, 0x140f, 0x280f, 0xbc0c, 0x500f, 0xc40c, 0xf80c, 0x6c0f,
+ 0xa00f, 0x340c, 0x080c, 0x9c0f, 0x700c, 0xe40f, 0xd80f, 0x4c0c,
+ 0xc00a, 0x5409, 0x6809, 0xfc0a, 0x1009, 0x840a, 0xb80a, 0x2c09,
+ 0xe009, 0x740a, 0x480a, 0xdc09, 0x300a, 0xa409, 0x9809, 0x0c0a,
+ 0x801d, 0x141e, 0x281e, 0xbc1d, 0x501e, 0xc41d, 0xf81d, 0x6c1e,
+ 0xa01e, 0x341d, 0x081d, 0x9c1e, 0x701d, 0xe41e, 0xd81e, 0x4c1d,
+ 0xc01b, 0x5418, 0x6818, 0xfc1b, 0x1018, 0x841b, 0xb81b, 0x2c18,
+ 0xe018, 0x741b, 0x481b, 0xdc18, 0x301b, 0xa418, 0x9818, 0x0c1b,
+ 0x0011, 0x9412, 0xa812, 0x3c11, 0xd012, 0x4411, 0x7811, 0xec12,
+ 0x2012, 0xb411, 0x8811, 0x1c12, 0xf011, 0x6412, 0x5812, 0xcc11,
+ 0x4017, 0xd414, 0xe814, 0x7c17, 0x9014, 0x0417, 0x3817, 0xac14,
+ 0x6014, 0xf417, 0xc817, 0x5c14, 0xb017, 0x2414, 0x1814, 0x8c17,
+ 0x803f, 0x143c, 0x283c, 0xbc3f, 0x503c, 0xc43f, 0xf83f, 0x6c3c,
+ 0xa03c, 0x343f, 0x083f, 0x9c3c, 0x703f, 0xe43c, 0xd83c, 0x4c3f,
+ 0xc039, 0x543a, 0x683a, 0xfc39, 0x103a, 0x8439, 0xb839, 0x2c3a,
+ 0xe03a, 0x7439, 0x4839, 0xdc3a, 0x3039, 0xa43a, 0x983a, 0x0c39,
+ 0x0033, 0x9430, 0xa830, 0x3c33, 0xd030, 0x4433, 0x7833, 0xec30,
+ 0x2030, 0xb433, 0x8833, 0x1c30, 0xf033, 0x6430, 0x5830, 0xcc33,
+ 0x4035, 0xd436, 0xe836, 0x7c35, 0x9036, 0x0435, 0x3835, 0xac36,
+ 0x6036, 0xf435, 0xc835, 0x5c36, 0xb035, 0x2436, 0x1836, 0x8c35,
+ 0x0022, 0x9421, 0xa821, 0x3c22, 0xd021, 0x4422, 0x7822, 0xec21,
+ 0x2021, 0xb422, 0x8822, 0x1c21, 0xf022, 0x6421, 0x5821, 0xcc22,
+ 0x4024, 0xd427, 0xe827, 0x7c24, 0x9027, 0x0424, 0x3824, 0xac27,
+ 0x6027, 0xf424, 0xc824, 0x5c27, 0xb024, 0x2427, 0x1827, 0x8c24,
+ 0x802e, 0x142d, 0x282d, 0xbc2e, 0x502d, 0xc42e, 0xf82e, 0x6c2d,
+ 0xa02d, 0x342e, 0x082e, 0x9c2d, 0x702e, 0xe42d, 0xd82d, 0x4c2e,
+ 0xc028, 0x542b, 0x682b, 0xfc28, 0x102b, 0x8428, 0xb828, 0x2c2b,
+ 0xe02b, 0x7428, 0x4828, 0xdc2b, 0x3028, 0xa42b, 0x982b, 0x0c28 },
+
+ { 0x0000, 0x807b, 0x80f3, 0x0088, 0x81e3, 0x0198, 0x0110, 0x816b,
+ 0x83c3, 0x03b8, 0x0330, 0x834b, 0x0220, 0x825b, 0x82d3, 0x02a8,
+ 0x8783, 0x07f8, 0x0770, 0x870b, 0x0660, 0x861b, 0x8693, 0x06e8,
+ 0x0440, 0x843b, 0x84b3, 0x04c8, 0x85a3, 0x05d8, 0x0550, 0x852b,
+ 0x8f03, 0x0f78, 0x0ff0, 0x8f8b, 0x0ee0, 0x8e9b, 0x8e13, 0x0e68,
+ 0x0cc0, 0x8cbb, 0x8c33, 0x0c48, 0x8d23, 0x0d58, 0x0dd0, 0x8dab,
+ 0x0880, 0x88fb, 0x8873, 0x0808, 0x8963, 0x0918, 0x0990, 0x89eb,
+ 0x8b43, 0x0b38, 0x0bb0, 0x8bcb, 0x0aa0, 0x8adb, 0x8a53, 0x0a28,
+ 0x9e03, 0x1e78, 0x1ef0, 0x9e8b, 0x1fe0, 0x9f9b, 0x9f13, 0x1f68,
+ 0x1dc0, 0x9dbb, 0x9d33, 0x1d48, 0x9c23, 0x1c58, 0x1cd0, 0x9cab,
+ 0x1980, 0x99fb, 0x9973, 0x1908, 0x9863, 0x1818, 0x1890, 0x98eb,
+ 0x9a43, 0x1a38, 0x1ab0, 0x9acb, 0x1ba0, 0x9bdb, 0x9b53, 0x1b28,
+ 0x1100, 0x917b, 0x91f3, 0x1188, 0x90e3, 0x1098, 0x1010, 0x906b,
+ 0x92c3, 0x12b8, 0x1230, 0x924b, 0x1320, 0x935b, 0x93d3, 0x13a8,
+ 0x9683, 0x16f8, 0x1670, 0x960b, 0x1760, 0x971b, 0x9793, 0x17e8,
+ 0x1540, 0x953b, 0x95b3, 0x15c8, 0x94a3, 0x14d8, 0x1450, 0x942b,
+ 0xbc03, 0x3c78, 0x3cf0, 0xbc8b, 0x3de0, 0xbd9b, 0xbd13, 0x3d68,
+ 0x3fc0, 0xbfbb, 0xbf33, 0x3f48, 0xbe23, 0x3e58, 0x3ed0, 0xbeab,
+ 0x3b80, 0xbbfb, 0xbb73, 0x3b08, 0xba63, 0x3a18, 0x3a90, 0xbaeb,
+ 0xb843, 0x3838, 0x38b0, 0xb8cb, 0x39a0, 0xb9db, 0xb953, 0x3928,
+ 0x3300, 0xb37b, 0xb3f3, 0x3388, 0xb2e3, 0x3298, 0x3210, 0xb26b,
+ 0xb0c3, 0x30b8, 0x3030, 0xb04b, 0x3120, 0xb15b, 0xb1d3, 0x31a8,
+ 0xb483, 0x34f8, 0x3470, 0xb40b, 0x3560, 0xb51b, 0xb593, 0x35e8,
+ 0x3740, 0xb73b, 0xb7b3, 0x37c8, 0xb6a3, 0x36d8, 0x3650, 0xb62b,
+ 0x2200, 0xa27b, 0xa2f3, 0x2288, 0xa3e3, 0x2398, 0x2310, 0xa36b,
+ 0xa1c3, 0x21b8, 0x2130, 0xa14b, 0x2020, 0xa05b, 0xa0d3, 0x20a8,
+ 0xa583, 0x25f8, 0x2570, 0xa50b, 0x2460, 0xa41b, 0xa493, 0x24e8,
+ 0x2640, 0xa63b, 0xa6b3, 0x26c8, 0xa7a3, 0x27d8, 0x2750, 0xa72b,
+ 0xad03, 0x2d78, 0x2df0, 0xad8b, 0x2ce0, 0xac9b, 0xac13, 0x2c68,
+ 0x2ec0, 0xaebb, 0xae33, 0x2e48, 0xaf23, 0x2f58, 0x2fd0, 0xafab,
+ 0x2a80, 0xaafb, 0xaa73, 0x2a08, 0xab63, 0x2b18, 0x2b90, 0xabeb,
+ 0xa943, 0x2938, 0x29b0, 0xa9cb, 0x28a0, 0xa8db, 0xa853, 0x2828 },
+
+ { 0x0000, 0xf803, 0x7003, 0x8800, 0xe006, 0x1805, 0x9005, 0x6806,
+ 0x4009, 0xb80a, 0x300a, 0xc809, 0xa00f, 0x580c, 0xd00c, 0x280f,
+ 0x8012, 0x7811, 0xf011, 0x0812, 0x6014, 0x9817, 0x1017, 0xe814,
+ 0xc01b, 0x3818, 0xb018, 0x481b, 0x201d, 0xd81e, 0x501e, 0xa81d,
+ 0x8021, 0x7822, 0xf022, 0x0821, 0x6027, 0x9824, 0x1024, 0xe827,
+ 0xc028, 0x382b, 0xb02b, 0x4828, 0x202e, 0xd82d, 0x502d, 0xa82e,
+ 0x0033, 0xf830, 0x7030, 0x8833, 0xe035, 0x1836, 0x9036, 0x6835,
+ 0x403a, 0xb839, 0x3039, 0xc83a, 0xa03c, 0x583f, 0xd03f, 0x283c,
+ 0x8047, 0x7844, 0xf044, 0x0847, 0x6041, 0x9842, 0x1042, 0xe841,
+ 0xc04e, 0x384d, 0xb04d, 0x484e, 0x2048, 0xd84b, 0x504b, 0xa848,
+ 0x0055, 0xf856, 0x7056, 0x8855, 0xe053, 0x1850, 0x9050, 0x6853,
+ 0x405c, 0xb85f, 0x305f, 0xc85c, 0xa05a, 0x5859, 0xd059, 0x285a,
+ 0x0066, 0xf865, 0x7065, 0x8866, 0xe060, 0x1863, 0x9063, 0x6860,
+ 0x406f, 0xb86c, 0x306c, 0xc86f, 0xa069, 0x586a, 0xd06a, 0x2869,
+ 0x8074, 0x7877, 0xf077, 0x0874, 0x6072, 0x9871, 0x1071, 0xe872,
+ 0xc07d, 0x387e, 0xb07e, 0x487d, 0x207b, 0xd878, 0x5078, 0xa87b,
+ 0x808b, 0x7888, 0xf088, 0x088b, 0x608d, 0x988e, 0x108e, 0xe88d,
+ 0xc082, 0x3881, 0xb081, 0x4882, 0x2084, 0xd887, 0x5087, 0xa884,
+ 0x0099, 0xf89a, 0x709a, 0x8899, 0xe09f, 0x189c, 0x909c, 0x689f,
+ 0x4090, 0xb893, 0x3093, 0xc890, 0xa096, 0x5895, 0xd095, 0x2896,
+ 0x00aa, 0xf8a9, 0x70a9, 0x88aa, 0xe0ac, 0x18af, 0x90af, 0x68ac,
+ 0x40a3, 0xb8a0, 0x30a0, 0xc8a3, 0xa0a5, 0x58a6, 0xd0a6, 0x28a5,
+ 0x80b8, 0x78bb, 0xf0bb, 0x08b8, 0x60be, 0x98bd, 0x10bd, 0xe8be,
+ 0xc0b1, 0x38b2, 0xb0b2, 0x48b1, 0x20b7, 0xd8b4, 0x50b4, 0xa8b7,
+ 0x00cc, 0xf8cf, 0x70cf, 0x88cc, 0xe0ca, 0x18c9, 0x90c9, 0x68ca,
+ 0x40c5, 0xb8c6, 0x30c6, 0xc8c5, 0xa0c3, 0x58c0, 0xd0c0, 0x28c3,
+ 0x80de, 0x78dd, 0xf0dd, 0x08de, 0x60d8, 0x98db, 0x10db, 0xe8d8,
+ 0xc0d7, 0x38d4, 0xb0d4, 0x48d7, 0x20d1, 0xd8d2, 0x50d2, 0xa8d1,
+ 0x80ed, 0x78ee, 0xf0ee, 0x08ed, 0x60eb, 0x98e8, 0x10e8, 0xe8eb,
+ 0xc0e4, 0x38e7, 0xb0e7, 0x48e4, 0x20e2, 0xd8e1, 0x50e1, 0xa8e2,
+ 0x00ff, 0xf8fc, 0x70fc, 0x88ff, 0xe0f9, 0x18fa, 0x90fa, 0x68f9,
+ 0x40f6, 0xb8f5, 0x30f5, 0xc8f6, 0xa0f0, 0x58f3, 0xd0f3, 0x28f0 },
+
+ { 0x0000, 0x8113, 0x8223, 0x0330, 0x8443, 0x0550, 0x0660, 0x8773,
+ 0x8883, 0x0990, 0x0aa0, 0x8bb3, 0x0cc0, 0x8dd3, 0x8ee3, 0x0ff0,
+ 0x9103, 0x1010, 0x1320, 0x9233, 0x1540, 0x9453, 0x9763, 0x1670,
+ 0x1980, 0x9893, 0x9ba3, 0x1ab0, 0x9dc3, 0x1cd0, 0x1fe0, 0x9ef3,
+ 0xa203, 0x2310, 0x2020, 0xa133, 0x2640, 0xa753, 0xa463, 0x2570,
+ 0x2a80, 0xab93, 0xa8a3, 0x29b0, 0xaec3, 0x2fd0, 0x2ce0, 0xadf3,
+ 0x3300, 0xb213, 0xb123, 0x3030, 0xb743, 0x3650, 0x3560, 0xb473,
+ 0xbb83, 0x3a90, 0x39a0, 0xb8b3, 0x3fc0, 0xbed3, 0xbde3, 0x3cf0,
+ 0xc403, 0x4510, 0x4620, 0xc733, 0x4040, 0xc153, 0xc263, 0x4370,
+ 0x4c80, 0xcd93, 0xcea3, 0x4fb0, 0xc8c3, 0x49d0, 0x4ae0, 0xcbf3,
+ 0x5500, 0xd413, 0xd723, 0x5630, 0xd143, 0x5050, 0x5360, 0xd273,
+ 0xdd83, 0x5c90, 0x5fa0, 0xdeb3, 0x59c0, 0xd8d3, 0xdbe3, 0x5af0,
+ 0x6600, 0xe713, 0xe423, 0x6530, 0xe243, 0x6350, 0x6060, 0xe173,
+ 0xee83, 0x6f90, 0x6ca0, 0xedb3, 0x6ac0, 0xebd3, 0xe8e3, 0x69f0,
+ 0xf703, 0x7610, 0x7520, 0xf433, 0x7340, 0xf253, 0xf163, 0x7070,
+ 0x7f80, 0xfe93, 0xfda3, 0x7cb0, 0xfbc3, 0x7ad0, 0x79e0, 0xf8f3,
+ 0x0803, 0x8910, 0x8a20, 0x0b33, 0x8c40, 0x0d53, 0x0e63, 0x8f70,
+ 0x8080, 0x0193, 0x02a3, 0x83b0, 0x04c3, 0x85d0, 0x86e0, 0x07f3,
+ 0x9900, 0x1813, 0x1b23, 0x9a30, 0x1d43, 0x9c50, 0x9f60, 0x1e73,
+ 0x1183, 0x9090, 0x93a0, 0x12b3, 0x95c0, 0x14d3, 0x17e3, 0x96f0,
+ 0xaa00, 0x2b13, 0x2823, 0xa930, 0x2e43, 0xaf50, 0xac60, 0x2d73,
+ 0x2283, 0xa390, 0xa0a0, 0x21b3, 0xa6c0, 0x27d3, 0x24e3, 0xa5f0,
+ 0x3b03, 0xba10, 0xb920, 0x3833, 0xbf40, 0x3e53, 0x3d63, 0xbc70,
+ 0xb380, 0x3293, 0x31a3, 0xb0b0, 0x37c3, 0xb6d0, 0xb5e0, 0x34f3,
+ 0xcc00, 0x4d13, 0x4e23, 0xcf30, 0x4843, 0xc950, 0xca60, 0x4b73,
+ 0x4483, 0xc590, 0xc6a0, 0x47b3, 0xc0c0, 0x41d3, 0x42e3, 0xc3f0,
+ 0x5d03, 0xdc10, 0xdf20, 0x5e33, 0xd940, 0x5853, 0x5b63, 0xda70,
+ 0xd580, 0x5493, 0x57a3, 0xd6b0, 0x51c3, 0xd0d0, 0xd3e0, 0x52f3,
+ 0x6e03, 0xef10, 0xec20, 0x6d33, 0xea40, 0x6b53, 0x6863, 0xe970,
+ 0xe680, 0x6793, 0x64a3, 0xe5b0, 0x62c3, 0xe3d0, 0xe0e0, 0x61f3,
+ 0xff00, 0x7e13, 0x7d23, 0xfc30, 0x7b43, 0xfa50, 0xf960, 0x7873,
+ 0x7783, 0xf690, 0xf5a0, 0x74b3, 0xf3c0, 0x72d3, 0x71e3, 0xf0f0 },
+
+ { 0x0000, 0x1006, 0x200c, 0x300a, 0x4018, 0x501e, 0x6014, 0x7012,
+ 0x8030, 0x9036, 0xa03c, 0xb03a, 0xc028, 0xd02e, 0xe024, 0xf022,
+ 0x8065, 0x9063, 0xa069, 0xb06f, 0xc07d, 0xd07b, 0xe071, 0xf077,
+ 0x0055, 0x1053, 0x2059, 0x305f, 0x404d, 0x504b, 0x6041, 0x7047,
+ 0x80cf, 0x90c9, 0xa0c3, 0xb0c5, 0xc0d7, 0xd0d1, 0xe0db, 0xf0dd,
+ 0x00ff, 0x10f9, 0x20f3, 0x30f5, 0x40e7, 0x50e1, 0x60eb, 0x70ed,
+ 0x00aa, 0x10ac, 0x20a6, 0x30a0, 0x40b2, 0x50b4, 0x60be, 0x70b8,
+ 0x809a, 0x909c, 0xa096, 0xb090, 0xc082, 0xd084, 0xe08e, 0xf088,
+ 0x819b, 0x919d, 0xa197, 0xb191, 0xc183, 0xd185, 0xe18f, 0xf189,
+ 0x01ab, 0x11ad, 0x21a7, 0x31a1, 0x41b3, 0x51b5, 0x61bf, 0x71b9,
+ 0x01fe, 0x11f8, 0x21f2, 0x31f4, 0x41e6, 0x51e0, 0x61ea, 0x71ec,
+ 0x81ce, 0x91c8, 0xa1c2, 0xb1c4, 0xc1d6, 0xd1d0, 0xe1da, 0xf1dc,
+ 0x0154, 0x1152, 0x2158, 0x315e, 0x414c, 0x514a, 0x6140, 0x7146,
+ 0x8164, 0x9162, 0xa168, 0xb16e, 0xc17c, 0xd17a, 0xe170, 0xf176,
+ 0x8131, 0x9137, 0xa13d, 0xb13b, 0xc129, 0xd12f, 0xe125, 0xf123,
+ 0x0101, 0x1107, 0x210d, 0x310b, 0x4119, 0x511f, 0x6115, 0x7113,
+ 0x8333, 0x9335, 0xa33f, 0xb339, 0xc32b, 0xd32d, 0xe327, 0xf321,
+ 0x0303, 0x1305, 0x230f, 0x3309, 0x431b, 0x531d, 0x6317, 0x7311,
+ 0x0356, 0x1350, 0x235a, 0x335c, 0x434e, 0x5348, 0x6342, 0x7344,
+ 0x8366, 0x9360, 0xa36a, 0xb36c, 0xc37e, 0xd378, 0xe372, 0xf374,
+ 0x03fc, 0x13fa, 0x23f0, 0x33f6, 0x43e4, 0x53e2, 0x63e8, 0x73ee,
+ 0x83cc, 0x93ca, 0xa3c0, 0xb3c6, 0xc3d4, 0xd3d2, 0xe3d8, 0xf3de,
+ 0x8399, 0x939f, 0xa395, 0xb393, 0xc381, 0xd387, 0xe38d, 0xf38b,
+ 0x03a9, 0x13af, 0x23a5, 0x33a3, 0x43b1, 0x53b7, 0x63bd, 0x73bb,
+ 0x02a8, 0x12ae, 0x22a4, 0x32a2, 0x42b0, 0x52b6, 0x62bc, 0x72ba,
+ 0x8298, 0x929e, 0xa294, 0xb292, 0xc280, 0xd286, 0xe28c, 0xf28a,
+ 0x82cd, 0x92cb, 0xa2c1, 0xb2c7, 0xc2d5, 0xd2d3, 0xe2d9, 0xf2df,
+ 0x02fd, 0x12fb, 0x22f1, 0x32f7, 0x42e5, 0x52e3, 0x62e9, 0x72ef,
+ 0x8267, 0x9261, 0xa26b, 0xb26d, 0xc27f, 0xd279, 0xe273, 0xf275,
+ 0x0257, 0x1251, 0x225b, 0x325d, 0x424f, 0x5249, 0x6243, 0x7245,
+ 0x0202, 0x1204, 0x220e, 0x3208, 0x421a, 0x521c, 0x6216, 0x7210,
+ 0x8232, 0x9234, 0xa23e, 0xb238, 0xc22a, 0xd22c, 0xe226, 0xf220 }
+};
+
+#if 0
+void FLAC__crc16_init_table(void)
{
- while(len--)
- *crc = FLAC__crc8_table[*crc ^ *data++];
+ int i, j;
+ FLAC__uint16 polynomial, crc;
+ polynomial = 0x8005;
+
+ for(i = 0; i <= 0xFF; i++){
+ crc = i << 8;
+
+ for(j = 0; j < 8; j++)
+ crc = (crc << 1) ^ (crc & (1 << 15) ? polynomial : 0);
+
+ FLAC__crc16_table[0][i] = crc;
+ }
+
+ for(i = 0; i <= 0xFF; i++)
+ for(j = 1; j < 8; j++)
+ FLAC__crc16_table[j][i] = FLAC__crc16_table[0][FLAC__crc16_table[j - 1][i] >> 8] ^ (FLAC__crc16_table[j - 1][i] << 8);
}
+#endif
-FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
+FLAC__uint8 FLAC__crc8(const FLAC__byte *data, uint32_t len)
{
FLAC__uint8 crc = 0;
@@ -132,12 +373,64 @@
return crc;
}
-unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
+FLAC__uint16 FLAC__crc16(const FLAC__byte *data, uint32_t len)
{
- unsigned crc = 0;
+ FLAC__uint16 crc = 0;
+ while(len >= 8){
+ crc ^= data[0] << 8 | data[1];
+
+ crc = FLAC__crc16_table[7][crc >> 8] ^ FLAC__crc16_table[6][crc & 0xFF] ^
+ FLAC__crc16_table[5][data[2] ] ^ FLAC__crc16_table[4][data[3] ] ^
+ FLAC__crc16_table[3][data[4] ] ^ FLAC__crc16_table[2][data[5] ] ^
+ FLAC__crc16_table[1][data[6] ] ^ FLAC__crc16_table[0][data[7] ];
+
+ data += 8;
+ len -= 8;
+ }
+
while(len--)
- crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
+ crc = (crc<<8) ^ FLAC__crc16_table[0][(crc>>8) ^ *data++];
+
+ return crc;
+}
+
+FLAC__uint16 FLAC__crc16_update_words32(const FLAC__uint32 *words, uint32_t len, FLAC__uint16 crc)
+{
+ while (len >= 2) {
+ crc ^= words[0] >> 16;
+
+ crc = FLAC__crc16_table[7][crc >> 8 ] ^ FLAC__crc16_table[6][crc & 0xFF ] ^
+ FLAC__crc16_table[5][(words[0] >> 8) & 0xFF] ^ FLAC__crc16_table[4][ words[0] & 0xFF] ^
+ FLAC__crc16_table[3][ words[1] >> 24 ] ^ FLAC__crc16_table[2][(words[1] >> 16) & 0xFF] ^
+ FLAC__crc16_table[1][(words[1] >> 8) & 0xFF] ^ FLAC__crc16_table[0][ words[1] & 0xFF];
+
+ words += 2;
+ len -= 2;
+ }
+
+ if (len) {
+ crc ^= words[0] >> 16;
+
+ crc = FLAC__crc16_table[3][crc >> 8 ] ^ FLAC__crc16_table[2][crc & 0xFF ] ^
+ FLAC__crc16_table[1][(words[0] >> 8) & 0xFF] ^ FLAC__crc16_table[0][words[0] & 0xFF];
+ }
+
+ return crc;
+}
+
+FLAC__uint16 FLAC__crc16_update_words64(const FLAC__uint64 *words, uint32_t len, FLAC__uint16 crc)
+{
+ while (len--) {
+ crc ^= words[0] >> 48;
+
+ crc = FLAC__crc16_table[7][crc >> 8 ] ^ FLAC__crc16_table[6][crc & 0xFF ] ^
+ FLAC__crc16_table[5][(words[0] >> 40) & 0xFF] ^ FLAC__crc16_table[4][(words[0] >> 32) & 0xFF] ^
+ FLAC__crc16_table[3][(words[0] >> 24) & 0xFF] ^ FLAC__crc16_table[2][(words[0] >> 16) & 0xFF] ^
+ FLAC__crc16_table[1][(words[0] >> 8) & 0xFF] ^ FLAC__crc16_table[0][ words[0] & 0xFF];
+
+ words++;
+ }
return crc;
}
--- a/sys/src/cmd/audio/libFLAC/fixed.c
+++ b/sys/src/cmd/audio/libFLAC/fixed.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -45,7 +45,7 @@
#ifdef local_abs
#undef local_abs
#endif
-#define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
+#define local_abs(x) ((uint32_t)((x)<0? -(x) : (x)))
#ifdef FLAC__INTEGER_ONLY_LIBRARY
/* rbps stands for residual bits per sample
@@ -57,7 +57,7 @@
static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
{
FLAC__uint32 rbps;
- unsigned bits; /* the number of bits required to represent a number */
+ uint32_t bits; /* the number of bits required to represent a number */
int fracbits; /* the number of bits of rbps that comprise the fractional part */
FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
@@ -105,7 +105,7 @@
}
}
- rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
+ rbps = FLAC__fixedpoint_log2(rbps, fracbits, (uint32_t)(-1));
if(rbps == 0)
return 0;
@@ -136,7 +136,7 @@
static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
{
FLAC__uint32 rbps;
- unsigned bits; /* the number of bits required to represent a number */
+ uint32_t bits; /* the number of bits required to represent a number */
int fracbits; /* the number of bits of rbps that comprise the fractional part */
FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
@@ -184,7 +184,7 @@
}
}
- rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
+ rbps = FLAC__fixedpoint_log2(rbps, fracbits, (uint32_t)(-1));
if(rbps == 0)
return 0;
@@ -214,9 +214,9 @@
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
+uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#else
-unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
+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])
#endif
{
FLAC__int32 last_error_0 = data[-1];
@@ -225,7 +225,7 @@
FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
FLAC__int32 error, save;
FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
- unsigned i, order;
+ uint32_t i, order;
for(i = 0; i < data_len; i++) {
error = data[i] ; total_error_0 += local_abs(error); save = error;
@@ -255,11 +255,11 @@
FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.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);
#else
residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
@@ -272,9 +272,9 @@
}
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
+uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#else
-unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
+uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
#endif
{
FLAC__int32 last_error_0 = data[-1];
@@ -287,7 +287,7 @@
* large.
*/
FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
- unsigned i, order;
+ uint32_t i, order;
for(i = 0; i < data_len; i++) {
error = data[i] ; total_error_0 += local_abs(error); save = error;
@@ -317,11 +317,11 @@
FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
- residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.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);
#else
residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
@@ -333,7 +333,7 @@
return order;
}
-void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
+void FLAC__fixed_compute_residual(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[])
{
const int idata_len = (int)data_len;
int i;
@@ -349,27 +349,15 @@
break;
case 2:
for(i = 0; i < idata_len; i++)
-#if 1 /* OPT: may be faster with some compilers on some systems */
- residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
-#else
residual[i] = data[i] - 2*data[i-1] + data[i-2];
-#endif
break;
case 3:
for(i = 0; i < idata_len; i++)
-#if 1 /* OPT: may be faster with some compilers on some systems */
- residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
-#else
residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
-#endif
break;
case 4:
for(i = 0; i < idata_len; i++)
-#if 1 /* OPT: may be faster with some compilers on some systems */
- residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
-#else
residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
-#endif
break;
default:
FLAC__ASSERT(0);
@@ -376,7 +364,7 @@
}
}
-void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
+void FLAC__fixed_restore_signal(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[])
{
int i, idata_len = (int)data_len;
@@ -391,27 +379,15 @@
break;
case 2:
for(i = 0; i < idata_len; i++)
-#if 1 /* OPT: may be faster with some compilers on some systems */
- data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
-#else
data[i] = residual[i] + 2*data[i-1] - data[i-2];
-#endif
break;
case 3:
for(i = 0; i < idata_len; i++)
-#if 1 /* OPT: may be faster with some compilers on some systems */
- data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
-#else
data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
-#endif
break;
case 4:
for(i = 0; i < idata_len; i++)
-#if 1 /* OPT: may be faster with some compilers on some systems */
- data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
-#else
data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
-#endif
break;
default:
FLAC__ASSERT(0);
--- a/sys/src/cmd/audio/libFLAC/float.c
+++ b/sys/src/cmd/audio/libFLAC/float.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -266,7 +266,7 @@
};
#endif
-FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
+FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, uint32_t fracbits, uint32_t precision)
{
const FLAC__uint32 ONE = (1u << fracbits);
const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
--- a/sys/src/cmd/audio/libFLAC/format.c
+++ b/sys/src/cmd/audio/libFLAC/format.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -39,92 +39,94 @@
#include <string.h> /* for memset() */
#include "FLAC/assert.h"
#include "FLAC/format.h"
+#include "share/alloc.h"
#include "share/compat.h"
#include "private/format.h"
#include "private/macros.h"
-/* VERSION should come from configure */
-FLAC_API const char *FLAC__VERSION_STRING = VERSION;
+#define PACKAGE_VERSION "1.3.3"
-FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20141125";
+FLAC_API const char *FLAC__VERSION_STRING = PACKAGE_VERSION;
+FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " PACKAGE_VERSION " 20190804";
+
FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
-FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
-FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_SYNC = 0x664C6143;
+FLAC_API const uint32_t FLAC__STREAM_SYNC_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
-FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
-FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
+FLAC_API const uint32_t FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
-FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
-FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC = 0x3ffe;
+FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
-FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
+FLAC_API const uint32_t FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
-FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
+FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
"PARTITIONED_RICE",
@@ -131,17 +133,17 @@
"PARTITIONED_RICE2"
};
-FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
-FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
+FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
+FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
-FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
-FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
-FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
+FLAC_API const uint32_t FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
+FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
+FLAC_API const uint32_t FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
-FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
-FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
-FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
-FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
+FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
+FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
+FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
+FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
FLAC_API const char * const FLAC__SubframeTypeString[] = {
"CONSTANT",
@@ -196,7 +198,7 @@
"Publisher/Studio logotype"
};
-FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
+FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(uint32_t sample_rate)
{
if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
return false;
@@ -205,7 +207,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned blocksize, unsigned sample_rate)
+FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(uint32_t blocksize, uint32_t sample_rate)
{
if(blocksize > 16384)
return false;
@@ -215,7 +217,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
+FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(uint32_t sample_rate)
{
if(
!FLAC__format_sample_rate_is_valid(sample_rate) ||
@@ -233,7 +235,7 @@
/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
{
- unsigned i;
+ uint32_t i;
FLAC__uint64 prev_sample_number = 0;
FLAC__bool got_prev = false;
@@ -267,13 +269,16 @@
}
/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
-FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
+FLAC_API uint32_t FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
{
- unsigned i, j;
+ uint32_t i, j;
FLAC__bool first;
FLAC__ASSERT(0 != seek_table);
+ if (seek_table->num_points == 0)
+ return 0;
+
/* sort the seekpoints */
qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
@@ -305,7 +310,7 @@
* and a more clear explanation at the end of this section:
* http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
*/
-static unsigned utf8len_(const FLAC__byte *utf8)
+static uint32_t utf8len_(const FLAC__byte *utf8)
{
FLAC__ASSERT(0 != utf8);
if ((utf8[0] & 0x80) == 0) {
@@ -355,11 +360,11 @@
return true;
}
-FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
+FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, uint32_t length)
{
- if(length == (unsigned)(-1)) {
+ if(length == (uint32_t)(-1)) {
while(*value) {
- unsigned n = utf8len_(value);
+ uint32_t n = utf8len_(value);
if(n == 0)
return false;
value += n;
@@ -368,7 +373,7 @@
else {
const FLAC__byte *end = value + length;
while(value < end) {
- unsigned n = utf8len_(value);
+ uint32_t n = utf8len_(value);
if(n == 0)
return false;
value += n;
@@ -379,7 +384,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
+FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, uint32_t length)
{
const FLAC__byte *s, *end;
@@ -393,7 +398,7 @@
s++; /* skip '=' */
while(s < end) {
- unsigned n = utf8len_(s);
+ uint32_t n = utf8len_(s);
if(n == 0)
return false;
s += n;
@@ -407,7 +412,7 @@
/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
{
- unsigned i, j;
+ uint32_t i, j;
if(check_cd_da_subset) {
if(cue_sheet->lead_in < 2 * 44100) {
@@ -497,7 +502,7 @@
}
for(b = picture->description; *b; ) {
- unsigned n = utf8len_(b);
+ uint32_t n = utf8len_(b);
if(n == 0) {
if(violation) *violation = "description string must be valid UTF-8";
return false;
@@ -511,7 +516,7 @@
/*
* These routines are private to libFLAC
*/
-unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
+uint32_t FLAC__format_get_max_rice_partition_order(uint32_t blocksize, uint32_t predictor_order)
{
return
FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
@@ -521,9 +526,9 @@
);
}
-unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
+uint32_t FLAC__format_get_max_rice_partition_order_from_blocksize(uint32_t blocksize)
{
- unsigned max_rice_partition_order = 0;
+ uint32_t max_rice_partition_order = 0;
while(!(blocksize & 1)) {
max_rice_partition_order++;
blocksize >>= 1;
@@ -531,9 +536,9 @@
return flac_min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
}
-unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
+uint32_t FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(uint32_t limit, uint32_t blocksize, uint32_t predictor_order)
{
- unsigned max_rice_partition_order = limit;
+ uint32_t max_rice_partition_order = limit;
while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
max_rice_partition_order--;
@@ -566,7 +571,7 @@
FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
}
-FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
+FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, uint32_t max_partition_order)
{
FLAC__ASSERT(0 != object);
@@ -573,11 +578,11 @@
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 = realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
+ if(0 == (object->parameters = safe_realloc_(object->parameters, sizeof(uint32_t)*(1 << max_partition_order))))
return false;
- if(0 == (object->raw_bits = realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
+ if(0 == (object->raw_bits = safe_realloc_(object->raw_bits, sizeof(uint32_t)*(1 << max_partition_order))))
return false;
- memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
+ memset(object->raw_bits, 0, sizeof(uint32_t)*(1 << max_partition_order));
object->capacity_by_order = max_partition_order;
}
--- a/sys/src/cmd/audio/libFLAC/lpc.c
+++ b/sys/src/cmd/audio/libFLAC/lpc.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -42,7 +42,7 @@
#include "private/bitmath.h"
#include "private/lpc.h"
#include "private/macros.h"
-#if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
+#if !defined(NDEBUG) || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
#include <stdio.h>
#endif
@@ -51,34 +51,33 @@
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-#if !defined(HAVE_LROUND)
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && (_MSC_VER < 1800)
#include <float.h>
-#define copysign _copysign
-#elif defined(__GNUC__)
-#define copysign __builtin_copysign
#elif defined(Plan9)
#define copysign(x,y) ((x > 0.0 && y < 0.0) || (x < 0.0 && y > 0.0)) ? -x : x
-#endif
static inline long int lround(double x) {
- return (long)(x + copysign (0.5, x));
+ return (long)(x + copysign(0.5, x));
}
+#elif !defined(HAVE_LROUND) && defined(__GNUC__)
+static inline long int lround(double x) {
+ return (long)(x + __builtin_copysign(0.5, x));
+}
/* If this fails, we are in the presence of a mid 90's compiler, move along... */
#endif
-void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
+void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len)
{
- unsigned i;
+ uint32_t i;
for(i = 0; i < data_len; i++)
out[i] = in[i] * window[i];
}
-void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
+void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[])
{
/* a readable, but slower, version */
#if 0
FLAC__real d;
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(lag > 0);
FLAC__ASSERT(lag <= data_len);
@@ -102,8 +101,8 @@
* ('data_len' is usually much larger than 'lag')
*/
FLAC__real d;
- unsigned sample, coeff;
- const unsigned limit = data_len - lag;
+ uint32_t sample, coeff;
+ const uint32_t limit = data_len - lag;
FLAC__ASSERT(lag > 0);
FLAC__ASSERT(lag <= data_len);
@@ -122,10 +121,10 @@
}
}
-void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
+void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], uint32_t *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], double error[])
{
- unsigned i, j;
- FLAC__double r, err, lpc[FLAC__MAX_LPC_ORDER];
+ uint32_t i, j;
+ double r, err, lpc[FLAC__MAX_LPC_ORDER];
FLAC__ASSERT(0 != max_order);
FLAC__ASSERT(0 < *max_order);
@@ -144,7 +143,7 @@
/* Update LPC coefficients and total error. */
lpc[i]=r;
for(j = 0; j < (i>>1); j++) {
- FLAC__double tmp = lpc[j];
+ double tmp = lpc[j];
lpc[j] += r * lpc[i-1-j];
lpc[i-1-j] += r * tmp;
}
@@ -166,10 +165,10 @@
}
}
-int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
+int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], uint32_t order, uint32_t precision, FLAC__int32 qlp_coeff[], int *shift)
{
- unsigned i;
- FLAC__double cmax;
+ uint32_t i;
+ double cmax;
FLAC__int32 qmax, qmin;
FLAC__ASSERT(precision > 0);
@@ -184,7 +183,7 @@
/* calc cmax = max( |lp_coeff[i]| ) */
cmax = 0.0;
for(i = 0; i < order; i++) {
- const FLAC__double d = fabs(lp_coeff[i]);
+ const double d = fabs(lp_coeff[i]);
if(d > cmax)
cmax = d;
}
@@ -209,7 +208,7 @@
}
if(*shift >= 0) {
- FLAC__double error = 0.0;
+ double error = 0.0;
FLAC__int32 q;
for(i = 0; i < order; i++) {
error += lp_coeff[i] * (1 << *shift);
@@ -230,14 +229,14 @@
}
}
/* negative shift is very rare but due to design flaw, negative shift is
- * a NOP in the decoder, so it must be handled specially by scaling down
- * coeffs
+ * not allowed in the decoder, so it must be handled specially by scaling
+ * down coeffs
*/
else {
const int nshift = -(*shift);
- FLAC__double error = 0.0;
+ double error = 0.0;
FLAC__int32 q;
-#ifdef DEBUG
+#ifndef NDEBUG
fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
#endif
for(i = 0; i < order; i++) {
@@ -267,11 +266,11 @@
#pragma warning ( disable : 4028 )
#endif
-void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 * flac_restrict data, unsigned data_len, const FLAC__int32 * flac_restrict qlp_coeff, unsigned order, int lp_quantization, FLAC__int32 * flac_restrict residual)
+void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{
FLAC__int64 sumo;
- unsigned i, j;
+ uint32_t i, j;
FLAC__int32 sum;
const FLAC__int32 *history;
@@ -290,6 +289,7 @@
for(j = 0; j < order; j++) {
sum += qlp_coeff[j] * (*(--history));
sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
+ if(sumo > 2147483647ll || sumo < -2147483648ll)
fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%" PRId64 "\n",i,j,qlp_coeff[j],*history,sumo);
}
*(residual++) = *(data++) - (sum >> lp_quantization);
@@ -488,25 +488,25 @@
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
- case 32: sum += qlp_coeff[31] * data[i-32];
- case 31: sum += qlp_coeff[30] * data[i-31];
- case 30: sum += qlp_coeff[29] * data[i-30];
- case 29: sum += qlp_coeff[28] * data[i-29];
- case 28: sum += qlp_coeff[27] * data[i-28];
- case 27: sum += qlp_coeff[26] * data[i-27];
- case 26: sum += qlp_coeff[25] * data[i-26];
- case 25: sum += qlp_coeff[24] * data[i-25];
- case 24: sum += qlp_coeff[23] * data[i-24];
- case 23: sum += qlp_coeff[22] * data[i-23];
- case 22: sum += qlp_coeff[21] * data[i-22];
- case 21: sum += qlp_coeff[20] * data[i-21];
- case 20: sum += qlp_coeff[19] * data[i-20];
- case 19: sum += qlp_coeff[18] * data[i-19];
- case 18: sum += qlp_coeff[17] * data[i-18];
- case 17: sum += qlp_coeff[16] * data[i-17];
- case 16: sum += qlp_coeff[15] * data[i-16];
- case 15: sum += qlp_coeff[14] * data[i-15];
- case 14: sum += qlp_coeff[13] * data[i-14];
+ 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];
@@ -527,10 +527,10 @@
}
#endif
-void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 * flac_restrict data, unsigned data_len, const FLAC__int32 * flac_restrict qlp_coeff, unsigned order, int lp_quantization, FLAC__int32 * flac_restrict residual)
+void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{
- unsigned i, j;
+ uint32_t i, j;
FLAC__int64 sum;
const FLAC__int32 *history;
@@ -547,11 +547,11 @@
history = data;
for(j = 0; j < order; j++)
sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
- if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
+ if(FLAC__bitmath_silog2(sum >> lp_quantization) > 32) {
fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%" PRId64 "\n", i, (sum >> lp_quantization));
break;
}
- if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
+ if(FLAC__bitmath_silog2((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%" PRId64 ", residual=%" PRId64 "\n", i, *data, (int64_t)(sum >> lp_quantization), ((FLAC__int64)(*data) - (sum >> lp_quantization)));
break;
}
@@ -742,25 +742,25 @@
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
- case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
- case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
- case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
- case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
- case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
- case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
- case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
- case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
- case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
- case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
- case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
- case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
- case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
- case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
- case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
- case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
- case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
- case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
- case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
+ case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */
+ case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */
+ case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */
+ case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */
+ case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */
+ case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */
+ case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */
+ case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */
+ case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */
+ case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */
+ case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */
+ case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */
+ case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */
+ case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */
+ case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */
+ case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */
+ case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */
+ case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */
+ case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */
case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
@@ -783,11 +783,11 @@
#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
-void FLAC__lpc_restore_signal(const FLAC__int32 * flac_restrict residual, unsigned data_len, const FLAC__int32 * flac_restrict qlp_coeff, unsigned order, int lp_quantization, FLAC__int32 * flac_restrict data)
+void FLAC__lpc_restore_signal(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict data)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{
FLAC__int64 sumo;
- unsigned i, j;
+ uint32_t i, j;
FLAC__int32 sum;
const FLAC__int32 *r = residual, *history;
@@ -1005,25 +1005,25 @@
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
- case 32: sum += qlp_coeff[31] * data[i-32];
- case 31: sum += qlp_coeff[30] * data[i-31];
- case 30: sum += qlp_coeff[29] * data[i-30];
- case 29: sum += qlp_coeff[28] * data[i-29];
- case 28: sum += qlp_coeff[27] * data[i-28];
- case 27: sum += qlp_coeff[26] * data[i-27];
- case 26: sum += qlp_coeff[25] * data[i-26];
- case 25: sum += qlp_coeff[24] * data[i-25];
- case 24: sum += qlp_coeff[23] * data[i-24];
- case 23: sum += qlp_coeff[22] * data[i-23];
- case 22: sum += qlp_coeff[21] * data[i-22];
- case 21: sum += qlp_coeff[20] * data[i-21];
- case 20: sum += qlp_coeff[19] * data[i-20];
- case 19: sum += qlp_coeff[18] * data[i-19];
- case 18: sum += qlp_coeff[17] * data[i-18];
- case 17: sum += qlp_coeff[16] * data[i-17];
- case 16: sum += qlp_coeff[15] * data[i-16];
- case 15: sum += qlp_coeff[14] * data[i-15];
- case 14: sum += qlp_coeff[13] * data[i-14];
+ 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];
@@ -1044,10 +1044,10 @@
}
#endif
-void FLAC__lpc_restore_signal_wide(const FLAC__int32 * flac_restrict residual, unsigned data_len, const FLAC__int32 * flac_restrict qlp_coeff, unsigned order, int lp_quantization, FLAC__int32 * flac_restrict data)
+void FLAC__lpc_restore_signal_wide(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict data)
#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
{
- unsigned i, j;
+ uint32_t i, j;
FLAC__int64 sum;
const FLAC__int32 *r = residual, *history;
@@ -1064,11 +1064,11 @@
history = data;
for(j = 0; j < order; j++)
sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
- if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
+ if(FLAC__bitmath_silog2(sum >> lp_quantization) > 32) {
fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%" PRId64 "\n", i, (sum >> lp_quantization));
break;
}
- if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
+ if(FLAC__bitmath_silog2((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%" PRId64 ", data=%" PRId64 "\n", i, *r, (sum >> lp_quantization), ((FLAC__int64)(*r) + (sum >> lp_quantization)));
break;
}
@@ -1259,25 +1259,25 @@
for(i = 0; i < (int)data_len; i++) {
sum = 0;
switch(order) {
- case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
- case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
- case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
- case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
- case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
- case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
- case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
- case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
- case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
- case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
- case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
- case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
- case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
- case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
- case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
- case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
- case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
- case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
- case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
+ case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */
+ case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */
+ case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */
+ case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */
+ case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */
+ case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */
+ case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */
+ case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */
+ case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */
+ case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */
+ case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */
+ case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */
+ case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */
+ case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */
+ case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */
+ case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */
+ case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */
+ case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */
+ case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */
case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
@@ -1304,21 +1304,21 @@
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
+double FLAC__lpc_compute_expected_bits_per_residual_sample(double lpc_error, uint32_t total_samples)
{
- FLAC__double error_scale;
+ double error_scale;
FLAC__ASSERT(total_samples > 0);
- error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
+ error_scale = 0.5 / (double)total_samples;
return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
}
-FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
+double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(double lpc_error, double error_scale)
{
if(lpc_error > 0.0) {
- FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
+ double bps = (double)0.5 * log(error_scale * lpc_error) / M_LN2;
if(bps >= 0.0)
return bps;
else
@@ -1332,21 +1332,21 @@
}
}
-unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
+uint32_t FLAC__lpc_compute_best_order(const double lpc_error[], uint32_t max_order, uint32_t total_samples, uint32_t overhead_bits_per_order)
{
- unsigned order, indx, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
- FLAC__double bits, best_bits, error_scale;
+ uint32_t order, indx, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
+ double bits, best_bits, error_scale;
FLAC__ASSERT(max_order > 0);
FLAC__ASSERT(total_samples > 0);
- error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
+ error_scale = 0.5 / (double)total_samples;
best_index = 0;
- best_bits = (unsigned)(-1);
+ best_bits = (uint32_t)(-1);
for(indx = 0, order = 1; indx < max_order; indx++, order++) {
- bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[indx], error_scale) * (FLAC__double)(total_samples - order) + (FLAC__double)(order * overhead_bits_per_order);
+ bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[indx], error_scale) * (double)(total_samples - order) + (double)(order * overhead_bits_per_order);
if(bits < best_bits) {
best_index = indx;
best_bits = bits;
--- a/sys/src/cmd/audio/libFLAC/md5.c
+++ b/sys/src/cmd/audio/libFLAC/md5.c
@@ -7,6 +7,7 @@
#include "private/md5.h"
#include "share/alloc.h"
+#include "share/compat.h"
#include "share/endswap.h"
/*
@@ -136,7 +137,7 @@
#if WORDS_BIGENDIAN
//@@@@@@ OPT: use bswap/intrinsics
-static void byteSwap(FLAC__uint32 *buf, unsigned words)
+static void byteSwap(FLAC__uint32 *buf, uint32_t words)
{
register FLAC__uint32 x;
do {
@@ -175,7 +176,7 @@
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
-static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
+static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, uint32_t len)
{
FLAC__uint32 t;
@@ -224,7 +225,7 @@
ctx->bytes[0] = 0;
ctx->bytes[1] = 0;
- ctx->internal_buf.p8= 0;
+ ctx->internal_buf.p8 = 0;
ctx->capacity = 0;
}
@@ -262,7 +263,7 @@
memcpy(digest, ctx->buf, 16);
if (0 != ctx->internal_buf.p8) {
free(ctx->internal_buf.p8);
- ctx->internal_buf.p8= 0;
+ ctx->internal_buf.p8 = 0;
ctx->capacity = 0;
}
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
@@ -271,13 +272,13 @@
/*
* Convert the incoming audio signal to a byte stream
*/
-static void format_input_(FLAC__multibyte *mbuf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
+static void format_input_(FLAC__multibyte *mbuf, const FLAC__int32 * const signal[], uint32_t channels, uint32_t samples, uint32_t bytes_per_sample)
{
FLAC__byte *buf_ = mbuf->p8;
FLAC__int16 *buf16 = mbuf->p16;
FLAC__int32 *buf32 = mbuf->p32;
FLAC__int32 a_word;
- unsigned channel, sample;
+ uint32_t channel, sample;
/* Storage in the output buffer, buf, is little endian. */
@@ -488,7 +489,7 @@
/*
* Convert the incoming audio signal to a byte stream and FLAC__MD5Update it.
*/
-FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
+FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], uint32_t channels, uint32_t samples, uint32_t bytes_per_sample)
{
const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
@@ -499,14 +500,12 @@
return false;
if (ctx->capacity < bytes_needed) {
- FLAC__byte *tmp = realloc(ctx->internal_buf.p8, bytes_needed);
- if (0 == tmp) {
- free(ctx->internal_buf.p8);
- if (0 == (ctx->internal_buf.p8= safe_malloc_(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))) {
+ ctx->capacity = 0;
return false;
+ }
}
- else
- ctx->internal_buf.p8= tmp;
ctx->capacity = bytes_needed;
}
--- a/sys/src/cmd/audio/libFLAC/memory.c
+++ b/sys/src/cmd/audio/libFLAC/memory.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -40,6 +40,7 @@
#include "private/memory.h"
#include "FLAC/assert.h"
+#include "share/compat.h"
#include "share/alloc.h"
void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
@@ -146,11 +147,11 @@
}
}
-FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(size_t elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
+FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(size_t elements, uint32_t **unaligned_pointer, uint32_t **aligned_pointer)
{
- unsigned *pu; /* unaligned pointer */
+ uint32_t *pu; /* unaligned pointer */
union { /* union needed to comply with C99 pointer aliasing rules */
- unsigned *pa; /* aligned pointer */
+ uint32_t *pa; /* aligned pointer */
void *pv; /* aligned pointer alias */
} u;
--- a/sys/src/cmd/audio/libFLAC/metadata_iterators.c
+++ b/sys/src/cmd/audio/libFLAC/metadata_iterators.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -62,27 +62,27 @@
*
***************************************************************************/
-static void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes);
-static void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes);
-static void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, unsigned bytes);
-static FLAC__uint32 unpack_uint32_(FLAC__byte *b, unsigned bytes);
-static FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, unsigned bytes);
-static FLAC__uint64 unpack_uint64_(FLAC__byte *b, unsigned bytes);
+static void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes);
+static void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes);
+static void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, uint32_t bytes);
+static FLAC__uint32 unpack_uint32_(FLAC__byte *b, uint32_t bytes);
+static FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, uint32_t bytes);
+static FLAC__uint64 unpack_uint64_(FLAC__byte *b, uint32_t bytes);
static FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator);
static FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block);
-static FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, unsigned *length);
+static FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, uint32_t *length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block);
-static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, unsigned block_length);
-static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, unsigned block_length);
-static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, unsigned block_length);
-static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, unsigned max_length);
-static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, unsigned block_length);
+static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, uint32_t block_length);
+static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, uint32_t block_length);
+static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, uint32_t block_length);
+static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, uint32_t max_length);
+static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, uint32_t block_length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block);
-static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, unsigned block_length);
+static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, uint32_t block_length);
static FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block);
@@ -89,23 +89,23 @@
static FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block);
-static FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, unsigned block_length);
-static FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, unsigned block_length);
+static FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, uint32_t block_length);
+static FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, uint32_t block_length);
static FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block);
static FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block);
static FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block);
static FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block);
-static FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, unsigned block_length);
+static FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, uint32_t block_length);
static FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block);
-static FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, unsigned padding_length, FLAC__bool padding_is_last);
+static FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, uint32_t padding_length, FLAC__bool padding_is_last);
static FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append);
static void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator);
static FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator);
-static unsigned seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb);
-static unsigned seek_to_first_metadata_block_(FILE *f);
+static uint32_t seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb);
+static uint32_t seek_to_first_metadata_block_(FILE *f);
static FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append);
static FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup);
@@ -265,7 +265,7 @@
cd->got_error = true;
}
-FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors)
+FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors)
{
FLAC__Metadata_SimpleIterator *it;
FLAC__uint64 max_area_seen = 0;
@@ -334,11 +334,11 @@
FLAC__Metadata_SimpleIteratorStatus status;
FLAC__off_t offset[SIMPLE_ITERATOR_MAX_PUSH_DEPTH];
FLAC__off_t first_offset; /* this is the offset to the STREAMINFO block */
- unsigned depth;
+ uint32_t depth;
/* this is the metadata block header of the current block we are pointing to: */
FLAC__bool is_last;
FLAC__MetadataType type;
- unsigned length;
+ uint32_t length;
};
FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[] = {
@@ -417,7 +417,7 @@
static FLAC__bool simple_iterator_prime_input_(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool read_only)
{
- unsigned ret;
+ uint32_t ret;
FLAC__ASSERT(0 != iterator);
@@ -588,7 +588,7 @@
}
/*@@@@add to tests*/
-FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator)
+FLAC_API uint32_t FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
@@ -599,7 +599,7 @@
/*@@@@add to tests*/
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id)
{
- const unsigned id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
+ const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
@@ -693,7 +693,7 @@
}
}
else /* iterator->length < block->length */ {
- unsigned padding_leftover = 0;
+ uint32_t padding_leftover = 0;
FLAC__bool padding_is_last = false;
if(use_padding) {
/* first see if we can even use padding */
@@ -701,7 +701,7 @@
use_padding = false;
}
else {
- const unsigned extra_padding_bytes_required = block->length - iterator->length;
+ const uint32_t extra_padding_bytes_required = block->length - iterator->length;
simple_iterator_push_(iterator);
if(!FLAC__metadata_simple_iterator_next(iterator)) {
(void)simple_iterator_pop_(iterator);
@@ -753,7 +753,7 @@
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding)
{
- unsigned padding_leftover = 0;
+ uint32_t padding_leftover = 0;
FLAC__bool padding_is_last = false;
FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length;)
@@ -837,6 +837,11 @@
FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];)
FLAC__bool ret;
+ if(!iterator->is_writable) {
+ iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE;
+ return false;
+ }
+
if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT;
return false;
@@ -887,7 +892,7 @@
FLAC__bool is_ogg;
FLAC__Metadata_Node *head;
FLAC__Metadata_Node *tail;
- unsigned nodes;
+ uint32_t nodes;
FLAC__Metadata_ChainStatus status;
FLAC__off_t first_offset, last_offset;
/*
@@ -1084,8 +1089,8 @@
static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node)
{
if(node->data->type == FLAC__METADATA_TYPE_PADDING && 0 != node->next && node->next->data->type == FLAC__METADATA_TYPE_PADDING) {
- const unsigned growth = FLAC__STREAM_METADATA_HEADER_LENGTH + node->next->data->length;
- node->data->length += growth;
+ const uint32_t growth = FLAC__STREAM_METADATA_HEADER_LENGTH + node->next->data->length;
+ node->data->length += growth; /* new block size can be greater than max metadata block size, but it'll be fixed later in chain_prepare_for_write_() */
chain_delete_node_(chain, node->next);
return true;
@@ -1152,6 +1157,22 @@
}
}
+ /* check sizes of all metadata blocks; reduce padding size if necessary */
+ {
+ FLAC__Metadata_Node *node;
+ for (node = chain->head; node; node = node->next) {
+ if(node->data->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) {
+ if(node->data->type == FLAC__METADATA_TYPE_PADDING) {
+ node->data->length = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1;
+ current_length = chain_calculate_length_(chain);
+ } else {
+ chain->status = FLAC__METADATA_CHAIN_STATUS_BAD_METADATA;
+ return 0;
+ }
+ }
+ }
+ }
+
return current_length;
}
@@ -1192,7 +1213,7 @@
{
FLAC__bool is_last;
FLAC__MetadataType type;
- unsigned length;
+ uint32_t length;
do {
node = node_new_();
@@ -1597,6 +1618,13 @@
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/true);
}
+typedef enum {
+ LBS_NONE = 0,
+ LBS_SIZE_CHANGED,
+ LBS_BLOCK_ADDED,
+ LBS_BLOCK_REMOVED
+} LastBlockState;
+
FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
{
/* This does all the same checks that are in chain_prepare_for_write_()
@@ -1603,31 +1631,74 @@
* but doesn't actually alter the chain. Make sure to update the logic
* here if chain_prepare_for_write_() changes.
*/
- const FLAC__off_t current_length = chain_calculate_length_(chain);
+ FLAC__off_t current_length;
+ LastBlockState lbs_state = LBS_NONE;
+ uint32_t lbs_size = 0;
FLAC__ASSERT(0 != chain);
+ current_length = chain_calculate_length_(chain);
+
if(use_padding) {
+ const FLAC__Metadata_Node * const node = chain->tail;
/* if the metadata shrank and the last block is padding, we just extend the last padding block */
- if(current_length < chain->initial_length && chain->tail->data->type == FLAC__METADATA_TYPE_PADDING)
- return false;
+ if(current_length < chain->initial_length && node->data->type == FLAC__METADATA_TYPE_PADDING) {
+ lbs_state = LBS_SIZE_CHANGED;
+ lbs_size = node->data->length + (chain->initial_length - current_length);
+ }
/* if the metadata shrank more than 4 bytes then there's room to add another padding block */
- else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length)
- return false;
+ else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) {
+ lbs_state = LBS_BLOCK_ADDED;
+ lbs_size = chain->initial_length - (current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
+ }
/* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */
else if(current_length > chain->initial_length) {
const FLAC__off_t delta = current_length - chain->initial_length;
- if(chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) {
+ if(node->data->type == FLAC__METADATA_TYPE_PADDING) {
/* if the delta is exactly the size of the last padding block, remove the padding block */
- if((FLAC__off_t)chain->tail->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta)
- return false;
+ if((FLAC__off_t)node->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) {
+ lbs_state = LBS_BLOCK_REMOVED;
+ lbs_size = 0;
+ }
/* if there is at least 'delta' bytes of padding, trim the padding down */
- else if((FLAC__off_t)chain->tail->data->length >= delta)
- return false;
+ else if((FLAC__off_t)node->data->length >= delta) {
+ lbs_state = LBS_SIZE_CHANGED;
+ lbs_size = node->data->length - delta;
+ }
}
}
}
+ current_length = 0;
+ /* check sizes of all metadata blocks; reduce padding size if necessary */
+ {
+ const FLAC__Metadata_Node *node;
+ for(node = chain->head; node; node = node->next) {
+ uint32_t block_len = node->data->length;
+ if(node == chain->tail) {
+ if(lbs_state == LBS_BLOCK_REMOVED)
+ continue;
+ else if(lbs_state == LBS_SIZE_CHANGED)
+ block_len = lbs_size;
+ }
+ if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) {
+ if(node->data->type == FLAC__METADATA_TYPE_PADDING)
+ block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1;
+ else
+ return false /* the return value doesn't matter */;
+ }
+ current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len);
+ }
+
+ if(lbs_state == LBS_BLOCK_ADDED) {
+ /* test added padding block */
+ uint32_t block_len = lbs_size;
+ if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
+ block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1;
+ current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len);
+ }
+ }
+
return (current_length != chain->initial_length);
}
@@ -1793,7 +1864,7 @@
FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain)
{
FLAC__Metadata_Node *node, *save;
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(0 != chain);
@@ -1970,9 +2041,9 @@
*
***************************************************************************/
-void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes)
+void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes)
{
- unsigned i;
+ uint32_t i;
b += bytes;
@@ -1982,9 +2053,9 @@
}
}
-void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes)
+void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes)
{
- unsigned i;
+ uint32_t i;
for(i = 0; i < bytes; i++) {
*(b++) = (FLAC__byte)(val & 0xff);
@@ -1992,9 +2063,9 @@
}
}
-void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, unsigned bytes)
+void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, uint32_t bytes)
{
- unsigned i;
+ uint32_t i;
b += bytes;
@@ -2004,10 +2075,10 @@
}
}
-FLAC__uint32 unpack_uint32_(FLAC__byte *b, unsigned bytes)
+FLAC__uint32 unpack_uint32_(FLAC__byte *b, uint32_t bytes)
{
FLAC__uint32 ret = 0;
- unsigned i;
+ uint32_t i;
for(i = 0; i < bytes; i++)
ret = (ret << 8) | (FLAC__uint32)(*b++);
@@ -2015,10 +2086,10 @@
return ret;
}
-FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, unsigned bytes)
+FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, uint32_t bytes)
{
FLAC__uint32 ret = 0;
- unsigned i;
+ uint32_t i;
b += bytes;
@@ -2028,10 +2099,10 @@
return ret;
}
-FLAC__uint64 unpack_uint64_(FLAC__byte *b, unsigned bytes)
+FLAC__uint64 unpack_uint64_(FLAC__byte *b, uint32_t bytes)
{
FLAC__uint64 ret = 0;
- unsigned i;
+ uint32_t i;
for(i = 0; i < bytes; i++)
ret = (ret << 8) | (FLAC__uint64)(*b++);
@@ -2062,7 +2133,7 @@
return (iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK);
}
-FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, unsigned *length)
+FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, uint32_t *length)
{
FLAC__byte raw_header[FLAC__STREAM_METADATA_HEADER_LENGTH];
@@ -2120,9 +2191,9 @@
block->max_blocksize = unpack_uint32_(b, 2); b += 2;
block->min_framesize = unpack_uint32_(b, 3); b += 3;
block->max_framesize = unpack_uint32_(b, 3); b += 3;
- block->sample_rate = (unpack_uint32_(b, 2) << 4) | ((unsigned)(b[2] & 0xf0) >> 4);
- block->channels = (unsigned)((b[2] & 0x0e) >> 1) + 1;
- block->bits_per_sample = ((((unsigned)(b[2] & 0x01)) << 4) | (((unsigned)(b[3] & 0xf0)) >> 4)) + 1;
+ block->sample_rate = (unpack_uint32_(b, 2) << 4) | ((uint32_t)(b[2] & 0xf0) >> 4);
+ block->channels = (uint32_t)((b[2] & 0x0e) >> 1) + 1;
+ block->bits_per_sample = ((((uint32_t)(b[2] & 0x01)) << 4) | (((uint32_t)(b[3] & 0xf0)) >> 4)) + 1;
block->total_samples = (((FLAC__uint64)(b[3] & 0x0f)) << 32) | unpack_uint64_(b+4, 4);
memcpy(block->md5sum, b+8, 16);
@@ -2129,7 +2200,7 @@
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
-FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, unsigned block_length)
+FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, uint32_t block_length)
{
(void)block; /* nothing to do; we don't care about reading the padding bytes */
@@ -2139,9 +2210,9 @@
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
-FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, unsigned block_length)
+FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, uint32_t block_length)
{
- const unsigned id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
+ const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
if(read_cb(block->id, 1, id_bytes, handle) != id_bytes)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
@@ -2165,9 +2236,9 @@
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
-FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, unsigned block_length)
+FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, uint32_t block_length)
{
- unsigned i;
+ uint32_t i;
FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH];
FLAC__ASSERT(block_length % FLAC__STREAM_METADATA_SEEKPOINT_LENGTH == 0);
@@ -2191,9 +2262,9 @@
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
-FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, unsigned max_length)
+FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, uint32_t max_length)
{
- const unsigned entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
+ const uint32_t entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8 == sizeof(buffer));
@@ -2229,11 +2300,11 @@
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
-FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, unsigned block_length)
+FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, uint32_t block_length)
{
- unsigned i;
+ uint32_t i;
FLAC__Metadata_SimpleIteratorStatus status;
- const unsigned num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
+ const uint32_t num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8 == sizeof(buffer));
@@ -2255,8 +2326,10 @@
if(block->num_comments == 0) {
block->comments = 0;
}
- else if(0 == (block->comments = calloc(block->num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry))))
+ else if(0 == (block->comments = calloc(block->num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
+ block->num_comments = 0;
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
+ }
for(i = 0; i < block->num_comments; i++) {
status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, block->comments + i, block_length);
@@ -2281,7 +2354,7 @@
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track)
{
- unsigned i, len;
+ uint32_t i, len;
FLAC__byte buffer[32]; /* asserted below that this is big enough */
FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64));
@@ -2350,7 +2423,7 @@
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block)
{
- unsigned i, len;
+ uint32_t i, len;
FLAC__Metadata_SimpleIteratorStatus status;
FLAC__byte buffer[1024]; /* MSVC needs a constant expression so we put a magic number and assert */
@@ -2480,7 +2553,7 @@
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
-FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, unsigned block_length)
+FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, uint32_t block_length)
{
if(block_length == 0) {
block->data = 0;
@@ -2529,6 +2602,9 @@
FLAC__byte buffer[FLAC__STREAM_METADATA_HEADER_LENGTH];
FLAC__ASSERT(block->length < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
+ /* double protection */
+ if(block->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
+ return false;
buffer[0] = (block->is_last? 0x80 : 0) | (FLAC__byte)block->type;
pack_uint32_(block->length, buffer + 1, 3);
@@ -2566,8 +2642,8 @@
FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block)
{
FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
- const unsigned channels1 = block->channels - 1;
- const unsigned bps1 = block->bits_per_sample - 1;
+ const uint32_t channels1 = block->channels - 1;
+ const uint32_t bps1 = block->bits_per_sample - 1;
/* we are using hardcoded numbers for simplicity but we should
* probably eventually write a bit-level packer and use the
@@ -2590,9 +2666,9 @@
return true;
}
-FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, unsigned block_length)
+FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, uint32_t block_length)
{
- unsigned i, n = block_length;
+ uint32_t i, n = block_length;
FLAC__byte buffer[1024];
(void)block;
@@ -2611,9 +2687,9 @@
return true;
}
-FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, unsigned block_length)
+FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, uint32_t block_length)
{
- const unsigned id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
+ const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
if(write_cb(block->id, 1, id_bytes, handle) != id_bytes)
return false;
@@ -2628,7 +2704,7 @@
FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block)
{
- unsigned i;
+ uint32_t i;
FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH];
for(i = 0; i < block->num_points; i++) {
@@ -2645,9 +2721,9 @@
FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block)
{
- unsigned i;
- const unsigned entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
- const unsigned num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
+ uint32_t i;
+ const uint32_t entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
+ const uint32_t num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(flac_max(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN, FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8 == sizeof(buffer));
@@ -2675,7 +2751,7 @@
FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block)
{
- unsigned i, j, len;
+ uint32_t i, j, len;
FLAC__byte buffer[1024]; /* asserted below that this is big enough */
FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64));
@@ -2769,7 +2845,7 @@
FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block)
{
- unsigned len;
+ uint32_t len;
size_t slen;
FLAC__byte buffer[4]; /* magic number is asserted below */
@@ -2841,7 +2917,7 @@
return true;
}
-FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, unsigned block_length)
+FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, uint32_t block_length)
{
if(write_cb(block->data, 1, block_length, handle) != block_length)
return false;
@@ -2870,7 +2946,7 @@
return read_metadata_block_header_(iterator);
}
-FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, unsigned padding_length, FLAC__bool padding_is_last)
+FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, uint32_t padding_length, FLAC__bool padding_is_last)
{
FLAC__StreamMetadata *padding;
@@ -2989,11 +3065,11 @@
* 2: seek error
* 3: not a FLAC file
*/
-unsigned seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb)
+uint32_t seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb)
{
FLAC__byte buffer[4];
size_t n;
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(FLAC__STREAM_SYNC_LENGTH == sizeof(buffer));
@@ -3005,7 +3081,7 @@
else if(n != 4)
return 3;
else if(0 == memcmp(buffer, "ID3", 3)) {
- unsigned tag_length = 0;
+ uint32_t tag_length = 0;
/* skip to the tag length */
if(seek_cb(handle, 2, SEEK_CUR) < 0)
@@ -3039,7 +3115,7 @@
return 3;
}
-unsigned seek_to_first_metadata_block_(FILE *f)
+uint32_t seek_to_first_metadata_block_(FILE *f)
{
return seek_to_first_metadata_block_cb_((FLAC__IOHandle)f, (FLAC__IOCallback_Read)fread, fseek_wrapper_);
}
@@ -3233,11 +3309,14 @@
va_list va;
int rc;
- va_start (va, fmt);
-
#if defined _MSC_VER
if (size == 0)
return 1024;
+#endif
+
+ va_start (va, fmt);
+
+#if defined _MSC_VER
rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va);
if (rc < 0)
rc = size - 1;
--- a/sys/src/cmd/audio/libFLAC/metadata_object.c
+++ b/sys/src/cmd/audio/libFLAC/metadata_object.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -62,19 +62,17 @@
* else ASSERT
* malloc error leaves 'to' unchanged
*/
-static FLAC__bool copy_bytes_(FLAC__byte **to, const FLAC__byte *from, unsigned bytes)
+static FLAC__bool copy_bytes_(FLAC__byte **to, const FLAC__byte *from, uint32_t bytes)
{
- FLAC__ASSERT(0 != to);
- if(bytes > 0 && 0 != from) {
+ FLAC__ASSERT(to != NULL);
+ if (bytes > 0 && from != NULL) {
FLAC__byte *x;
- if(0 == (x = safe_malloc_(bytes)))
+ if ((x = safe_malloc_(bytes)) == NULL)
return false;
memcpy(x, from, bytes);
*to = x;
}
else {
- FLAC__ASSERT(0 == from);
- FLAC__ASSERT(bytes == 0);
*to = 0;
}
return true;
@@ -82,13 +80,12 @@
#if 0 /* UNUSED */
/* like copy_bytes_(), but free()s the original '*to' if the copy succeeds and the original '*to' is non-NULL */
-static FLAC__bool free_copy_bytes_(FLAC__byte **to, const FLAC__byte *from, unsigned bytes)
+static FLAC__bool free_copy_bytes_(FLAC__byte **to, const FLAC__byte *from, uint32_t bytes)
{
FLAC__byte *copy;
- FLAC__ASSERT(0 != to);
- if(copy_bytes_(©, from, bytes)) {
- if(*to)
- free(*to);
+ FLAC__ASSERT(to != NULL);
+ if (copy_bytes_(©, from, bytes)) {
+ free(*to);
*to = copy;
return true;
}
@@ -99,10 +96,10 @@
/* reallocate entry to 1 byte larger and add a terminating NUL */
/* realloc() failure leaves entry unchanged */
-static FLAC__bool ensure_null_terminated_(FLAC__byte **entry, unsigned length)
+static FLAC__bool ensure_null_terminated_(FLAC__byte **entry, uint32_t length)
{
FLAC__byte *x = safe_realloc_add_2op_(*entry, length, /*+*/1);
- if(0 != x) {
+ if (x != NULL) {
x[length] = '\0';
*entry = x;
return true;
@@ -118,10 +115,9 @@
static FLAC__bool copy_cstring_(char **to, const char *from)
{
char *copy = strdup(from);
- FLAC__ASSERT(to);
- if(copy) {
- if(*to)
- free(*to);
+ FLAC__ASSERT(to != NULL);
+ if (copy) {
+ free(*to);
*to = copy;
return true;
}
@@ -132,7 +128,7 @@
static FLAC__bool copy_vcentry_(FLAC__StreamMetadata_VorbisComment_Entry *to, const FLAC__StreamMetadata_VorbisComment_Entry *from)
{
to->length = from->length;
- if(0 == from->entry) {
+ if (from->entry == 0) {
FLAC__ASSERT(from->length == 0);
to->entry = 0;
}
@@ -139,7 +135,7 @@
else {
FLAC__byte *x;
FLAC__ASSERT(from->length > 0);
- if(0 == (x = safe_malloc_add_2op_(from->length, /*+*/1)))
+ if ((x = safe_malloc_add_2op_(from->length, /*+*/1)) == NULL)
return false;
memcpy(x, from->entry, from->length);
x[from->length] = '\0';
@@ -151,13 +147,13 @@
static FLAC__bool copy_track_(FLAC__StreamMetadata_CueSheet_Track *to, const FLAC__StreamMetadata_CueSheet_Track *from)
{
memcpy(to, from, sizeof(FLAC__StreamMetadata_CueSheet_Track));
- if(0 == from->indices) {
+ if (from->indices == 0) {
FLAC__ASSERT(from->num_indices == 0);
}
else {
FLAC__StreamMetadata_CueSheet_Index *x;
FLAC__ASSERT(from->num_indices > 0);
- if(0 == (x = safe_malloc_mul_2op_p(from->num_indices, /*times*/sizeof(FLAC__StreamMetadata_CueSheet_Index))))
+ if ((x = safe_malloc_mul_2op_p(from->num_indices, /*times*/sizeof(FLAC__StreamMetadata_CueSheet_Index))) == NULL)
return false;
memcpy(x, from->indices, from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
to->indices = x;
@@ -167,13 +163,13 @@
static void seektable_calculate_length_(FLAC__StreamMetadata *object)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
object->length = object->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
}
-static FLAC__StreamMetadata_SeekPoint *seekpoint_array_new_(unsigned num_points)
+static FLAC__StreamMetadata_SeekPoint *seekpoint_array_new_(uint32_t num_points)
{
FLAC__StreamMetadata_SeekPoint *object_array;
@@ -181,9 +177,9 @@
object_array = safe_malloc_mul_2op_p(num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint));
- if(0 != object_array) {
- unsigned i;
- for(i = 0; i < num_points; i++) {
+ if (object_array != NULL) {
+ uint32_t i;
+ for (i = 0; i < num_points; i++) {
object_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
object_array[i].stream_offset = 0;
object_array[i].frame_samples = 0;
@@ -195,7 +191,7 @@
static void vorbiscomment_calculate_length_(FLAC__StreamMetadata *object)
{
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
@@ -202,13 +198,13 @@
object->length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN) / 8;
object->length += object->data.vorbis_comment.vendor_string.length;
object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8;
- for(i = 0; i < object->data.vorbis_comment.num_comments; i++) {
+ for (i = 0; i < object->data.vorbis_comment.num_comments; i++) {
object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8);
object->length += object->data.vorbis_comment.comments[i].length;
}
}
-static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(unsigned num_comments)
+static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(uint32_t num_comments)
{
FLAC__ASSERT(num_comments > 0);
@@ -215,34 +211,32 @@
return safe_calloc_(num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
}
-static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
+static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, uint32_t num_comments)
{
- unsigned i;
+ uint32_t i;
- FLAC__ASSERT(0 != object_array && num_comments > 0);
+ FLAC__ASSERT(object_array != NULL && num_comments > 0);
- for(i = 0; i < num_comments; i++)
- if(0 != object_array[i].entry)
- free(object_array[i].entry);
+ for (i = 0; i < num_comments; i++)
+ free(object_array[i].entry);
- if(0 != object_array)
- free(object_array);
+ free(object_array);
}
-static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_copy_(const FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
+static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_copy_(const FLAC__StreamMetadata_VorbisComment_Entry *object_array, uint32_t num_comments)
{
FLAC__StreamMetadata_VorbisComment_Entry *return_array;
- FLAC__ASSERT(0 != object_array);
+ FLAC__ASSERT(object_array != NULL);
FLAC__ASSERT(num_comments > 0);
return_array = vorbiscomment_entry_array_new_(num_comments);
- if(0 != return_array) {
- unsigned i;
+ if (return_array != NULL) {
+ uint32_t i;
- for(i = 0; i < num_comments; i++) {
- if(!copy_vcentry_(return_array+i, object_array+i)) {
+ for (i = 0; i < num_comments; i++) {
+ if (!copy_vcentry_(return_array+i, object_array+i)) {
vorbiscomment_entry_array_delete_(return_array, num_comments);
return 0;
}
@@ -256,18 +250,18 @@
{
FLAC__byte *save;
- FLAC__ASSERT(0 != object);
- FLAC__ASSERT(0 != dest);
- FLAC__ASSERT(0 != src);
+ FLAC__ASSERT(object != NULL);
+ FLAC__ASSERT(dest != NULL);
+ FLAC__ASSERT(src != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
- FLAC__ASSERT((0 != src->entry && src->length > 0) || (0 == src->entry && src->length == 0));
+ FLAC__ASSERT((src->entry != NULL && src->length > 0) || (src->entry == NULL && src->length == 0));
save = dest->entry;
- if(0 != src->entry) {
- if(copy) {
+ if (src->entry != NULL) {
+ if (copy) {
/* do the copy first so that if we fail we leave the dest object untouched */
- if(!copy_vcentry_(dest, src))
+ if (!copy_vcentry_(dest, src))
return false;
}
else {
@@ -281,7 +275,7 @@
* precise, the 'own' flavor would be a separate function with a
* non-const source pointer. But it's not, so we hack away.
*/
- if(!ensure_null_terminated_((FLAC__byte**)(&src->entry), src->length))
+ if (!ensure_null_terminated_((FLAC__byte**)(&src->entry), src->length))
return false;
*dest = *src;
}
@@ -291,23 +285,22 @@
*dest = *src;
}
- if(0 != save)
- free(save);
+ free(save);
vorbiscomment_calculate_length_(object);
return true;
}
-static int vorbiscomment_find_entry_from_(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name, unsigned field_name_length)
+static int vorbiscomment_find_entry_from_(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name, uint32_t field_name_length)
{
- unsigned i;
+ uint32_t i;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
- FLAC__ASSERT(0 != field_name);
+ FLAC__ASSERT(field_name != NULL);
- for(i = offset; i < object->data.vorbis_comment.num_comments; i++) {
- if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length))
+ for (i = offset; i < object->data.vorbis_comment.num_comments; i++) {
+ if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length))
return (int)i;
}
@@ -316,7 +309,7 @@
static void cuesheet_calculate_length_(FLAC__StreamMetadata *object)
{
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
@@ -338,7 +331,7 @@
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
) / 8;
- for(i = 0; i < object->data.cue_sheet.num_tracks; i++) {
+ for (i = 0; i < object->data.cue_sheet.num_tracks; i++) {
object->length += object->data.cue_sheet.tracks[i].num_indices * (
FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
@@ -347,7 +340,7 @@
}
}
-static FLAC__StreamMetadata_CueSheet_Index *cuesheet_track_index_array_new_(unsigned num_indices)
+static FLAC__StreamMetadata_CueSheet_Index *cuesheet_track_index_array_new_(uint32_t num_indices)
{
FLAC__ASSERT(num_indices > 0);
@@ -354,7 +347,7 @@
return safe_calloc_(num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index));
}
-static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_new_(unsigned num_tracks)
+static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_new_(uint32_t num_tracks)
{
FLAC__ASSERT(num_tracks > 0);
@@ -361,37 +354,36 @@
return safe_calloc_(num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track));
}
-static void cuesheet_track_array_delete_(FLAC__StreamMetadata_CueSheet_Track *object_array, unsigned num_tracks)
+static void cuesheet_track_array_delete_(FLAC__StreamMetadata_CueSheet_Track *object_array, uint32_t num_tracks)
{
- unsigned i;
+ uint32_t i;
- FLAC__ASSERT(0 != object_array && num_tracks > 0);
+ FLAC__ASSERT(object_array != NULL && num_tracks > 0);
- for(i = 0; i < num_tracks; i++) {
- if(0 != object_array[i].indices) {
+ for (i = 0; i < num_tracks; i++) {
+ if (object_array[i].indices != 0) {
FLAC__ASSERT(object_array[i].num_indices > 0);
free(object_array[i].indices);
}
}
- if(0 != object_array)
- free(object_array);
+ free(object_array);
}
-static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_copy_(const FLAC__StreamMetadata_CueSheet_Track *object_array, unsigned num_tracks)
+static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_copy_(const FLAC__StreamMetadata_CueSheet_Track *object_array, uint32_t num_tracks)
{
FLAC__StreamMetadata_CueSheet_Track *return_array;
- FLAC__ASSERT(0 != object_array);
+ FLAC__ASSERT(object_array != NULL);
FLAC__ASSERT(num_tracks > 0);
return_array = cuesheet_track_array_new_(num_tracks);
- if(0 != return_array) {
- unsigned i;
+ if (return_array != NULL) {
+ uint32_t i;
- for(i = 0; i < num_tracks; i++) {
- if(!copy_track_(return_array+i, object_array+i)) {
+ for (i = 0; i < num_tracks; i++) {
+ if (!copy_track_(return_array+i, object_array+i)) {
cuesheet_track_array_delete_(return_array, num_tracks);
return 0;
}
@@ -405,17 +397,17 @@
{
FLAC__StreamMetadata_CueSheet_Index *save;
- FLAC__ASSERT(0 != object);
- FLAC__ASSERT(0 != dest);
- FLAC__ASSERT(0 != src);
+ FLAC__ASSERT(object != NULL);
+ FLAC__ASSERT(dest != NULL);
+ FLAC__ASSERT(src != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
- FLAC__ASSERT((0 != src->indices && src->num_indices > 0) || (0 == src->indices && src->num_indices == 0));
+ FLAC__ASSERT((src->indices != NULL && src->num_indices > 0) || (src->indices == NULL && src->num_indices == 0));
save = dest->indices;
/* do the copy first so that if we fail we leave the object untouched */
- if(copy) {
- if(!copy_track_(dest, src))
+ if (copy) {
+ if (!copy_track_(dest, src))
return false;
}
else {
@@ -422,8 +414,7 @@
*dest = *src;
}
- if(0 != save)
- free(save);
+ free(save);
cuesheet_calculate_length_(object);
return true;
@@ -440,11 +431,11 @@
{
FLAC__StreamMetadata *object;
- if(type > FLAC__MAX_METADATA_TYPE)
+ if (type > FLAC__MAX_METADATA_TYPE)
return 0;
object = calloc(1, sizeof(FLAC__StreamMetadata));
- if(0 != object) {
+ if (object != NULL) {
object->is_last = false;
object->type = type;
switch(type) {
@@ -470,8 +461,8 @@
*/
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
- object->data.vorbis_comment.vendor_string.length = (unsigned)strlen(FLAC__VENDOR_STRING);
- if(!copy_bytes_(&object->data.vorbis_comment.vendor_string.entry, (const FLAC__byte*)FLAC__VENDOR_STRING, object->data.vorbis_comment.vendor_string.length+1)) {
+ object->data.vorbis_comment.vendor_string.length = (uint32_t)strlen(FLAC__VENDOR_STRING);
+ if (!copy_bytes_(&object->data.vorbis_comment.vendor_string.entry, (const FLAC__byte*)FLAC__VENDOR_STRING, object->data.vorbis_comment.vendor_string.length+1)) {
free(object);
return 0;
}
@@ -504,13 +495,12 @@
object->data.picture.data = 0;
*/
/* now initialize mime_type and description with empty strings to make things easier on the client */
- if(!copy_cstring_(&object->data.picture.mime_type, "")) {
+ if (!copy_cstring_(&object->data.picture.mime_type, "")) {
free(object);
return 0;
}
- if(!copy_cstring_((char**)(&object->data.picture.description), "")) {
- if(object->data.picture.mime_type)
- free(object->data.picture.mime_type);
+ if (!copy_cstring_((char**)(&object->data.picture.description), "")) {
+ free(object->data.picture.mime_type);
free(object);
return 0;
}
@@ -531,9 +521,9 @@
{
FLAC__StreamMetadata *to;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
- if(0 != (to = FLAC__metadata_object_new(object->type))) {
+ if ((to = FLAC__metadata_object_new(object->type)) != NULL) {
to->is_last = object->is_last;
to->type = object->type;
to->length = object->length;
@@ -544,12 +534,12 @@
case FLAC__METADATA_TYPE_PADDING:
break;
case FLAC__METADATA_TYPE_APPLICATION:
- if(to->length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) { /* underflow check */
+ if (to->length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) { /* underflow check */
FLAC__metadata_object_delete(to);
return 0;
}
memcpy(&to->data.application.id, &object->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8);
- if(!copy_bytes_(&to->data.application.data, object->data.application.data, object->length - FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) {
+ if (!copy_bytes_(&to->data.application.data, object->data.application.data, object->length - FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) {
FLAC__metadata_object_delete(to);
return 0;
}
@@ -556,32 +546,31 @@
break;
case FLAC__METADATA_TYPE_SEEKTABLE:
to->data.seek_table.num_points = object->data.seek_table.num_points;
- if(to->data.seek_table.num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint)) { /* overflow check */
+ if (to->data.seek_table.num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint)) { /* overflow check */
FLAC__metadata_object_delete(to);
return 0;
}
- if(!copy_bytes_((FLAC__byte**)&to->data.seek_table.points, (FLAC__byte*)object->data.seek_table.points, object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint))) {
+ if (!copy_bytes_((FLAC__byte**)&to->data.seek_table.points, (FLAC__byte*)object->data.seek_table.points, object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint))) {
FLAC__metadata_object_delete(to);
return 0;
}
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
- if(0 != to->data.vorbis_comment.vendor_string.entry) {
+ if (to->data.vorbis_comment.vendor_string.entry != NULL) {
free(to->data.vorbis_comment.vendor_string.entry);
to->data.vorbis_comment.vendor_string.entry = 0;
}
- if(!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) {
+ if (!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) {
FLAC__metadata_object_delete(to);
return 0;
}
- if(object->data.vorbis_comment.num_comments == 0) {
- FLAC__ASSERT(0 == object->data.vorbis_comment.comments);
+ if (object->data.vorbis_comment.num_comments == 0) {
to->data.vorbis_comment.comments = 0;
}
else {
- FLAC__ASSERT(0 != object->data.vorbis_comment.comments);
to->data.vorbis_comment.comments = vorbiscomment_entry_array_copy_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
- if(0 == to->data.vorbis_comment.comments) {
+ if (to->data.vorbis_comment.comments == NULL) {
+ to->data.vorbis_comment.num_comments = 0;
FLAC__metadata_object_delete(to);
return 0;
}
@@ -590,13 +579,13 @@
break;
case FLAC__METADATA_TYPE_CUESHEET:
memcpy(&to->data.cue_sheet, &object->data.cue_sheet, sizeof(FLAC__StreamMetadata_CueSheet));
- if(object->data.cue_sheet.num_tracks == 0) {
- FLAC__ASSERT(0 == object->data.cue_sheet.tracks);
+ if (object->data.cue_sheet.num_tracks == 0) {
+ FLAC__ASSERT(object->data.cue_sheet.tracks == NULL);
}
else {
- FLAC__ASSERT(0 != object->data.cue_sheet.tracks);
+ FLAC__ASSERT(object->data.cue_sheet.tracks != 0);
to->data.cue_sheet.tracks = cuesheet_track_array_copy_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks);
- if(0 == to->data.cue_sheet.tracks) {
+ if (to->data.cue_sheet.tracks == NULL) {
FLAC__metadata_object_delete(to);
return 0;
}
@@ -604,11 +593,11 @@
break;
case FLAC__METADATA_TYPE_PICTURE:
to->data.picture.type = object->data.picture.type;
- if(!copy_cstring_(&to->data.picture.mime_type, object->data.picture.mime_type)) {
+ if (!copy_cstring_(&to->data.picture.mime_type, object->data.picture.mime_type)) {
FLAC__metadata_object_delete(to);
return 0;
}
- if(!copy_cstring_((char**)(&to->data.picture.description), (const char*)object->data.picture.description)) {
+ if (!copy_cstring_((char**)(&to->data.picture.description), (const char*)object->data.picture.description)) {
FLAC__metadata_object_delete(to);
return 0;
}
@@ -617,13 +606,13 @@
to->data.picture.depth = object->data.picture.depth;
to->data.picture.colors = object->data.picture.colors;
to->data.picture.data_length = object->data.picture.data_length;
- if(!copy_bytes_((&to->data.picture.data), object->data.picture.data, object->data.picture.data_length)) {
+ if (!copy_bytes_((&to->data.picture.data), object->data.picture.data, object->data.picture.data_length)) {
FLAC__metadata_object_delete(to);
return 0;
}
break;
default:
- if(!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) {
+ if (!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) {
FLAC__metadata_object_delete(to);
return 0;
}
@@ -636,7 +625,7 @@
void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
switch(object->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
@@ -643,51 +632,55 @@
case FLAC__METADATA_TYPE_PADDING:
break;
case FLAC__METADATA_TYPE_APPLICATION:
- if(0 != object->data.application.data) {
+ if (object->data.application.data != NULL) {
free(object->data.application.data);
- object->data.application.data = 0;
+ object->data.application.data = NULL;
}
break;
case FLAC__METADATA_TYPE_SEEKTABLE:
- if(0 != object->data.seek_table.points) {
+ if (object->data.seek_table.points != NULL) {
free(object->data.seek_table.points);
- object->data.seek_table.points = 0;
+ object->data.seek_table.points = NULL;
}
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
- if(0 != object->data.vorbis_comment.vendor_string.entry) {
+ if (object->data.vorbis_comment.vendor_string.entry != NULL) {
free(object->data.vorbis_comment.vendor_string.entry);
object->data.vorbis_comment.vendor_string.entry = 0;
}
- if(0 != object->data.vorbis_comment.comments) {
+ if (object->data.vorbis_comment.comments != NULL) {
FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
+ object->data.vorbis_comment.comments = NULL;
+ object->data.vorbis_comment.num_comments = 0;
}
break;
case FLAC__METADATA_TYPE_CUESHEET:
- if(0 != object->data.cue_sheet.tracks) {
+ if (object->data.cue_sheet.tracks != NULL) {
FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0);
cuesheet_track_array_delete_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks);
+ object->data.cue_sheet.tracks = NULL;
+ object->data.cue_sheet.num_tracks = 0;
}
break;
case FLAC__METADATA_TYPE_PICTURE:
- if(0 != object->data.picture.mime_type) {
+ if (object->data.picture.mime_type != NULL) {
free(object->data.picture.mime_type);
- object->data.picture.mime_type = 0;
+ object->data.picture.mime_type = NULL;
}
- if(0 != object->data.picture.description) {
+ if (object->data.picture.description != NULL) {
free(object->data.picture.description);
- object->data.picture.description = 0;
+ object->data.picture.description = NULL;
}
- if(0 != object->data.picture.data) {
+ if (object->data.picture.data != NULL) {
free(object->data.picture.data);
- object->data.picture.data = 0;
+ object->data.picture.data = NULL;
}
break;
default:
- if(0 != object->data.unknown.data) {
+ if (object->data.unknown.data != NULL) {
free(object->data.unknown.data);
- object->data.unknown.data = 0;
+ object->data.unknown.data = NULL;
}
break;
}
@@ -701,37 +694,37 @@
static FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block1, const FLAC__StreamMetadata_StreamInfo *block2)
{
- if(block1->min_blocksize != block2->min_blocksize)
+ if (block1->min_blocksize != block2->min_blocksize)
return false;
- if(block1->max_blocksize != block2->max_blocksize)
+ if (block1->max_blocksize != block2->max_blocksize)
return false;
- if(block1->min_framesize != block2->min_framesize)
+ if (block1->min_framesize != block2->min_framesize)
return false;
- if(block1->max_framesize != block2->max_framesize)
+ if (block1->max_framesize != block2->max_framesize)
return false;
- if(block1->sample_rate != block2->sample_rate)
+ if (block1->sample_rate != block2->sample_rate)
return false;
- if(block1->channels != block2->channels)
+ if (block1->channels != block2->channels)
return false;
- if(block1->bits_per_sample != block2->bits_per_sample)
+ if (block1->bits_per_sample != block2->bits_per_sample)
return false;
- if(block1->total_samples != block2->total_samples)
+ if (block1->total_samples != block2->total_samples)
return false;
- if(0 != memcmp(block1->md5sum, block2->md5sum, 16))
+ if (memcmp(block1->md5sum, block2->md5sum, 16) != 0)
return false;
return true;
}
-static FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block1, const FLAC__StreamMetadata_Application *block2, unsigned block_length)
+static FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block1, const FLAC__StreamMetadata_Application *block2, uint32_t block_length)
{
- FLAC__ASSERT(0 != block1);
- FLAC__ASSERT(0 != block2);
+ FLAC__ASSERT(block1 != NULL);
+ FLAC__ASSERT(block2 != NULL);
FLAC__ASSERT(block_length >= sizeof(block1->id));
- if(0 != memcmp(block1->id, block2->id, sizeof(block1->id)))
+ if (memcmp(block1->id, block2->id, sizeof(block1->id)) != 0)
return false;
- if(0 != block1->data && 0 != block2->data)
- return 0 == memcmp(block1->data, block2->data, block_length - sizeof(block1->id));
+ if (block1->data != NULL && block2->data != NULL)
+ return memcmp(block1->data, block2->data, block_length - sizeof(block1->id)) == 0;
else
return block1->data == block2->data;
}
@@ -738,21 +731,21 @@
static FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block1, const FLAC__StreamMetadata_SeekTable *block2)
{
- unsigned i;
+ uint32_t i;
- FLAC__ASSERT(0 != block1);
- FLAC__ASSERT(0 != block2);
+ FLAC__ASSERT(block1 != NULL);
+ FLAC__ASSERT(block2 != NULL);
- if(block1->num_points != block2->num_points)
+ if (block1->num_points != block2->num_points)
return false;
- if(0 != block1->points && 0 != block2->points) {
- for(i = 0; i < block1->num_points; i++) {
- if(block1->points[i].sample_number != block2->points[i].sample_number)
+ if (block1->points != NULL && block2->points != NULL) {
+ for (i = 0; i < block1->num_points; i++) {
+ if (block1->points[i].sample_number != block2->points[i].sample_number)
return false;
- if(block1->points[i].stream_offset != block2->points[i].stream_offset)
+ if (block1->points[i].stream_offset != block2->points[i].stream_offset)
return false;
- if(block1->points[i].frame_samples != block2->points[i].frame_samples)
+ if (block1->points[i].frame_samples != block2->points[i].frame_samples)
return false;
}
return true;
@@ -763,27 +756,27 @@
static FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block1, const FLAC__StreamMetadata_VorbisComment *block2)
{
- unsigned i;
+ uint32_t i;
- if(block1->vendor_string.length != block2->vendor_string.length)
+ if (block1->vendor_string.length != block2->vendor_string.length)
return false;
- if(0 != block1->vendor_string.entry && 0 != block2->vendor_string.entry) {
- if(0 != memcmp(block1->vendor_string.entry, block2->vendor_string.entry, block1->vendor_string.length))
+ if (block1->vendor_string.entry != NULL && block2->vendor_string.entry != NULL) {
+ if (memcmp(block1->vendor_string.entry, block2->vendor_string.entry, block1->vendor_string.length) != 0)
return false;
}
- else if(block1->vendor_string.entry != block2->vendor_string.entry)
+ else if (block1->vendor_string.entry != block2->vendor_string.entry)
return false;
- if(block1->num_comments != block2->num_comments)
+ if (block1->num_comments != block2->num_comments)
return false;
- for(i = 0; i < block1->num_comments; i++) {
- if(0 != block1->comments[i].entry && 0 != block2->comments[i].entry) {
- if(0 != memcmp(block1->comments[i].entry, block2->comments[i].entry, block1->comments[i].length))
+ for (i = 0; i < block1->num_comments; i++) {
+ if (block1->comments[i].entry != NULL && block2->comments[i].entry != NULL) {
+ if (memcmp(block1->comments[i].entry, block2->comments[i].entry, block1->comments[i].length) != 0)
return false;
}
- else if(block1->comments[i].entry != block2->comments[i].entry)
+ else if (block1->comments[i].entry != block2->comments[i].entry)
return false;
}
return true;
@@ -791,49 +784,49 @@
static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueSheet *block1, const FLAC__StreamMetadata_CueSheet *block2)
{
- unsigned i, j;
+ uint32_t i, j;
- if(0 != strcmp(block1->media_catalog_number, block2->media_catalog_number))
+ if (strcmp(block1->media_catalog_number, block2->media_catalog_number) != 0)
return false;
- if(block1->lead_in != block2->lead_in)
+ if (block1->lead_in != block2->lead_in)
return false;
- if(block1->is_cd != block2->is_cd)
+ if (block1->is_cd != block2->is_cd)
return false;
- if(block1->num_tracks != block2->num_tracks)
+ if (block1->num_tracks != block2->num_tracks)
return false;
- if(0 != block1->tracks && 0 != block2->tracks) {
+ if (block1->tracks != NULL && block2->tracks != NULL) {
FLAC__ASSERT(block1->num_tracks > 0);
- for(i = 0; i < block1->num_tracks; i++) {
- if(block1->tracks[i].offset != block2->tracks[i].offset)
+ for (i = 0; i < block1->num_tracks; i++) {
+ if (block1->tracks[i].offset != block2->tracks[i].offset)
return false;
- if(block1->tracks[i].number != block2->tracks[i].number)
+ if (block1->tracks[i].number != block2->tracks[i].number)
return false;
- if(0 != memcmp(block1->tracks[i].isrc, block2->tracks[i].isrc, sizeof(block1->tracks[i].isrc)))
+ if (memcmp(block1->tracks[i].isrc, block2->tracks[i].isrc, sizeof(block1->tracks[i].isrc)) != 0)
return false;
- if(block1->tracks[i].type != block2->tracks[i].type)
+ if (block1->tracks[i].type != block2->tracks[i].type)
return false;
- if(block1->tracks[i].pre_emphasis != block2->tracks[i].pre_emphasis)
+ if (block1->tracks[i].pre_emphasis != block2->tracks[i].pre_emphasis)
return false;
- if(block1->tracks[i].num_indices != block2->tracks[i].num_indices)
+ if (block1->tracks[i].num_indices != block2->tracks[i].num_indices)
return false;
- if(0 != block1->tracks[i].indices && 0 != block2->tracks[i].indices) {
+ if (block1->tracks[i].indices != NULL && block2->tracks[i].indices != NULL) {
FLAC__ASSERT(block1->tracks[i].num_indices > 0);
- for(j = 0; j < block1->tracks[i].num_indices; j++) {
- if(block1->tracks[i].indices[j].offset != block2->tracks[i].indices[j].offset)
+ for (j = 0; j < block1->tracks[i].num_indices; j++) {
+ if (block1->tracks[i].indices[j].offset != block2->tracks[i].indices[j].offset)
return false;
- if(block1->tracks[i].indices[j].number != block2->tracks[i].indices[j].number)
+ if (block1->tracks[i].indices[j].number != block2->tracks[i].indices[j].number)
return false;
}
}
- else if(block1->tracks[i].indices != block2->tracks[i].indices)
+ else if (block1->tracks[i].indices != block2->tracks[i].indices)
return false;
}
}
- else if(block1->tracks != block2->tracks)
+ else if (block1->tracks != block2->tracks)
return false;
return true;
}
@@ -840,34 +833,34 @@
static FLAC__bool compare_block_data_picture_(const FLAC__StreamMetadata_Picture *block1, const FLAC__StreamMetadata_Picture *block2)
{
- if(block1->type != block2->type)
+ if (block1->type != block2->type)
return false;
- if(block1->mime_type != block2->mime_type && (0 == block1->mime_type || 0 == block2->mime_type || strcmp(block1->mime_type, block2->mime_type)))
+ if (block1->mime_type != block2->mime_type && (block1->mime_type == 0 || block2->mime_type == 0 || strcmp(block1->mime_type, block2->mime_type)))
return false;
- if(block1->description != block2->description && (0 == block1->description || 0 == block2->description || strcmp((const char *)block1->description, (const char *)block2->description)))
+ if (block1->description != block2->description && (block1->description == 0 || block2->description == 0 || strcmp((const char *)block1->description, (const char *)block2->description)))
return false;
- if(block1->width != block2->width)
+ if (block1->width != block2->width)
return false;
- if(block1->height != block2->height)
+ if (block1->height != block2->height)
return false;
- if(block1->depth != block2->depth)
+ if (block1->depth != block2->depth)
return false;
- if(block1->colors != block2->colors)
+ if (block1->colors != block2->colors)
return false;
- if(block1->data_length != block2->data_length)
+ if (block1->data_length != block2->data_length)
return false;
- if(block1->data != block2->data && (0 == block1->data || 0 == block2->data || memcmp(block1->data, block2->data, block1->data_length)))
+ if (block1->data != block2->data && (block1->data == NULL || block2->data == NULL || memcmp(block1->data, block2->data, block1->data_length)))
return false;
return true;
}
-static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, unsigned block_length)
+static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, uint32_t block_length)
{
- FLAC__ASSERT(0 != block1);
- FLAC__ASSERT(0 != block2);
+ FLAC__ASSERT(block1 != NULL);
+ FLAC__ASSERT(block2 != NULL);
- if(0 != block1->data && 0 != block2->data)
- return 0 == memcmp(block1->data, block2->data, block_length);
+ if (block1->data != NULL && block2->data != NULL)
+ return memcmp(block1->data, block2->data, block_length) == 0;
else
return block1->data == block2->data;
}
@@ -874,16 +867,16 @@
FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2)
{
- FLAC__ASSERT(0 != block1);
- FLAC__ASSERT(0 != block2);
+ FLAC__ASSERT(block1 != NULL);
+ FLAC__ASSERT(block2 != NULL);
- if(block1->type != block2->type) {
+ if (block1->type != block2->type) {
return false;
}
- if(block1->is_last != block2->is_last) {
+ if (block1->is_last != block2->is_last) {
return false;
}
- if(block1->length != block2->length) {
+ if (block1->length != block2->length) {
return false;
}
switch(block1->type) {
@@ -906,19 +899,19 @@
}
}
-FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy)
+FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, uint32_t length, FLAC__bool copy)
{
FLAC__byte *save;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_APPLICATION);
- FLAC__ASSERT((0 != data && length > 0) || (0 == data && length == 0 && copy == false));
+ FLAC__ASSERT((data != NULL && length > 0) || (data == NULL && length == 0 && copy == false));
save = object->data.application.data;
/* do the copy first so that if we fail we leave the object untouched */
- if(copy) {
- if(!copy_bytes_(&object->data.application.data, data, length))
+ if (copy) {
+ if (!copy_bytes_(&object->data.application.data, data, length))
return false;
}
else {
@@ -925,23 +918,22 @@
object->data.application.data = data;
}
- if(0 != save)
- free(save);
+ free(save);
object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 + length;
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, uint32_t new_num_points)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
- if(0 == object->data.seek_table.points) {
+ if (object->data.seek_table.points == 0) {
FLAC__ASSERT(object->data.seek_table.num_points == 0);
- if(0 == new_num_points)
+ if (new_num_points == 0)
return true;
- else if(0 == (object->data.seek_table.points = seekpoint_array_new_(new_num_points)))
+ else if ((object->data.seek_table.points = seekpoint_array_new_(new_num_points)) == 0)
return false;
}
else {
@@ -949,22 +941,22 @@
const size_t new_size = new_num_points * sizeof(FLAC__StreamMetadata_SeekPoint);
/* overflow check */
- if(new_num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint))
+ if (new_num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint))
return false;
FLAC__ASSERT(object->data.seek_table.num_points > 0);
- if(new_size == 0) {
+ if (new_size == 0) {
free(object->data.seek_table.points);
object->data.seek_table.points = 0;
}
- else if(0 == (object->data.seek_table.points = realloc(object->data.seek_table.points, new_size)))
+ else if ((object->data.seek_table.points = safe_realloc_(object->data.seek_table.points, new_size)) == NULL)
return false;
/* if growing, set new elements to placeholders */
- if(new_size > old_size) {
- unsigned i;
- for(i = object->data.seek_table.num_points; i < new_num_points; i++) {
+ if (new_size > old_size) {
+ uint32_t i;
+ for (i = object->data.seek_table.num_points; i < new_num_points; i++) {
object->data.seek_table.points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
object->data.seek_table.points[i].stream_offset = 0;
object->data.seek_table.points[i].frame_samples = 0;
@@ -978,9 +970,9 @@
return true;
}
-FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point)
+FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
FLAC__ASSERT(point_num < object->data.seek_table.num_points);
@@ -987,19 +979,19 @@
object->data.seek_table.points[point_num] = point;
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point)
{
int i;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
FLAC__ASSERT(point_num <= object->data.seek_table.num_points);
- if(!FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points+1))
+ if (!FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points+1))
return false;
/* move all points >= point_num forward one space */
- for(i = (int)object->data.seek_table.num_points-1; i > (int)point_num; i--)
+ for (i = (int)object->data.seek_table.num_points-1; i > (int)point_num; i--)
object->data.seek_table.points[i] = object->data.seek_table.points[i-1];
FLAC__metadata_object_seektable_set_point(object, point_num, point);
@@ -1007,16 +999,16 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, uint32_t point_num)
{
- unsigned i;
+ uint32_t i;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
FLAC__ASSERT(point_num < object->data.seek_table.num_points);
/* move all points > point_num backward one space */
- for(i = point_num; i < object->data.seek_table.num_points-1; i++)
+ for (i = point_num; i < object->data.seek_table.num_points-1; i++)
object->data.seek_table.points[i] = object->data.seek_table.points[i+1];
return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points-1);
@@ -1024,18 +1016,18 @@
FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
return FLAC__format_seektable_is_legal(&object->data.seek_table);
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, uint32_t num)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
- if(num > 0)
+ if (num > 0)
/* WATCHOUT: we rely on the fact that growing the array adds PLACEHOLDERS at the end */
return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points + num);
else
@@ -1046,12 +1038,12 @@
{
FLAC__StreamMetadata_SeekTable *seek_table;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
seek_table = &object->data.seek_table;
- if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + 1))
+ if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + 1))
return false;
seek_table->points[seek_table->num_points - 1].sample_number = sample_number;
@@ -1061,22 +1053,22 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], uint32_t num)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
- FLAC__ASSERT(0 != sample_numbers || num == 0);
+ FLAC__ASSERT(sample_numbers != 0 || num == 0);
- if(num > 0) {
+ if (num > 0) {
FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
- unsigned i, j;
+ uint32_t i, j;
i = seek_table->num_points;
- if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
+ if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
return false;
- for(j = 0; j < num; i++, j++) {
+ for (j = 0; j < num; i++, j++) {
seek_table->points[i].sample_number = sample_numbers[j];
seek_table->points[i].stream_offset = 0;
seek_table->points[i].frame_samples = 0;
@@ -1086,22 +1078,22 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, uint32_t num, FLAC__uint64 total_samples)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
FLAC__ASSERT(total_samples > 0);
- if(num > 0 && total_samples > 0) {
+ if (num > 0 && total_samples > 0) {
FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
- unsigned i, j;
+ uint32_t i, j;
i = seek_table->num_points;
- if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
+ if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
return false;
- for(j = 0; j < num; i++, j++) {
+ for (j = 0; j < num; i++, j++) {
seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num;
seek_table->points[i].stream_offset = 0;
seek_table->points[i].frame_samples = 0;
@@ -1111,30 +1103,37 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples)
+FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, uint32_t samples, FLAC__uint64 total_samples)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
FLAC__ASSERT(samples > 0);
FLAC__ASSERT(total_samples > 0);
- if(samples > 0 && total_samples > 0) {
+ if (samples > 0 && total_samples > 0) {
FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
- unsigned i, j;
+ uint32_t i, j;
FLAC__uint64 num, sample;
num = 1 + total_samples / samples; /* 1+ for the first sample at 0 */
/* now account for the fact that we don't place a seekpoint at "total_samples" since samples are number from 0: */
- if(total_samples % samples == 0)
+ if (total_samples % samples == 0)
num--;
+ /* Put a strict upper bound on the number of allowed seek points. */
+ if (num > 32768) {
+ /* Set the bound and recalculate samples accordingly. */
+ num = 32768;
+ samples = total_samples / num;
+ }
+
i = seek_table->num_points;
- if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + (unsigned)num))
+ if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + (uint32_t)num))
return false;
sample = 0;
- for(j = 0; j < num; i++, j++, sample += samples) {
+ for (j = 0; j < num; i++, j++, sample += samples) {
seek_table->points[i].sample_number = sample;
seek_table->points[i].stream_offset = 0;
seek_table->points[i].frame_samples = 0;
@@ -1146,9 +1145,9 @@
FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact)
{
- unsigned unique;
+ uint32_t unique;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
unique = FLAC__format_seektable_sort(&object->data.seek_table);
@@ -1158,21 +1157,21 @@
FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
{
- if(!FLAC__format_vorbiscomment_entry_value_is_legal(entry.entry, entry.length))
+ if (!FLAC__format_vorbiscomment_entry_value_is_legal(entry.entry, entry.length))
return false;
return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.vendor_string, &entry, copy);
}
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments)
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, uint32_t new_num_comments)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
- if(0 == object->data.vorbis_comment.comments) {
+ if (object->data.vorbis_comment.comments == NULL) {
FLAC__ASSERT(object->data.vorbis_comment.num_comments == 0);
- if(0 == new_num_comments)
+ if (new_num_comments == 0)
return true;
- else if(0 == (object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)))
+ else if ((object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)) == NULL)
return false;
}
else {
@@ -1180,28 +1179,34 @@
const size_t new_size = new_num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry);
/* overflow check */
- if(new_num_comments > UINT32_MAX / sizeof(FLAC__StreamMetadata_VorbisComment_Entry))
+ if (new_num_comments > UINT32_MAX / sizeof(FLAC__StreamMetadata_VorbisComment_Entry))
return false;
FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
/* if shrinking, free the truncated entries */
- if(new_num_comments < object->data.vorbis_comment.num_comments) {
- unsigned i;
- for(i = new_num_comments; i < object->data.vorbis_comment.num_comments; i++)
- if(0 != object->data.vorbis_comment.comments[i].entry)
+ if (new_num_comments < object->data.vorbis_comment.num_comments) {
+ uint32_t i;
+ for (i = new_num_comments; i < object->data.vorbis_comment.num_comments; i++)
+ if (object->data.vorbis_comment.comments[i].entry != NULL)
free(object->data.vorbis_comment.comments[i].entry);
}
- if(new_size == 0) {
+ if (new_size == 0) {
free(object->data.vorbis_comment.comments);
object->data.vorbis_comment.comments = 0;
}
- else if(0 == (object->data.vorbis_comment.comments = realloc(object->data.vorbis_comment.comments, new_size)))
- return false;
+ else {
+ FLAC__StreamMetadata_VorbisComment_Entry *oldptr = object->data.vorbis_comment.comments;
+ if ((object->data.vorbis_comment.comments = realloc(object->data.vorbis_comment.comments, new_size)) == NULL) {
+ vorbiscomment_entry_array_delete_(oldptr, object->data.vorbis_comment.num_comments);
+ object->data.vorbis_comment.num_comments = 0;
+ return false;
+ }
+ }
/* if growing, zero all the length/pointers of new elements */
- if(new_size > old_size)
+ if (new_size > old_size)
memset(object->data.vorbis_comment.comments + object->data.vorbis_comment.num_comments, 0, new_size - old_size);
}
@@ -1211,30 +1216,30 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments);
- if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
+ if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
return false;
return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.comments[comment_num], &entry, copy);
}
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
{
FLAC__StreamMetadata_VorbisComment *vc;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
FLAC__ASSERT(comment_num <= object->data.vorbis_comment.num_comments);
- if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
+ if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
return false;
vc = &object->data.vorbis_comment;
- if(!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1))
+ if (!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1))
return false;
/* move all comments >= comment_num forward one space */
@@ -1247,7 +1252,7 @@
FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
return FLAC__metadata_object_vorbiscomment_insert_comment(object, object->data.vorbis_comment.num_comments, entry, copy);
}
@@ -1254,9 +1259,9 @@
FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy)
{
- FLAC__ASSERT(0 != entry.entry && entry.length > 0);
+ FLAC__ASSERT(entry.entry != NULL && entry.length > 0);
- if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
+ if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
return false;
{
@@ -1264,27 +1269,25 @@
size_t field_name_length;
const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length);
- FLAC__ASSERT(0 != eq);
-
- if(0 == eq)
+ if (eq == NULL)
return false; /* double protection */
field_name_length = eq-entry.entry;
i = vorbiscomment_find_entry_from_(object, 0, (const char *)entry.entry, field_name_length);
- if(i >= 0) {
- unsigned indx = (unsigned)i;
- if(!FLAC__metadata_object_vorbiscomment_set_comment(object, indx, entry, copy))
+ if (i >= 0) {
+ uint32_t indx = (uint32_t)i;
+ if (!FLAC__metadata_object_vorbiscomment_set_comment(object, indx, entry, copy))
return false;
entry = object->data.vorbis_comment.comments[indx];
indx++; /* skip over replaced comment */
- if(all && indx < object->data.vorbis_comment.num_comments) {
+ if (all && indx < object->data.vorbis_comment.num_comments) {
i = vorbiscomment_find_entry_from_(object, indx, (const char *)entry.entry, field_name_length);
- while(i >= 0) {
- indx = (unsigned)i;
- if(!FLAC__metadata_object_vorbiscomment_delete_comment(object, indx))
+ while (i >= 0) {
+ indx = (uint32_t)i;
+ if (!FLAC__metadata_object_vorbiscomment_delete_comment(object, indx))
return false;
- if(indx < object->data.vorbis_comment.num_comments)
+ if (indx < object->data.vorbis_comment.num_comments)
i = vorbiscomment_find_entry_from_(object, indx, (const char *)entry.entry, field_name_length);
else
i = -1;
@@ -1297,11 +1300,11 @@
}
}
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num)
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, uint32_t comment_num)
{
FLAC__StreamMetadata_VorbisComment *vc;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments);
@@ -1308,8 +1311,7 @@
vc = &object->data.vorbis_comment;
/* free the comment at comment_num */
- if(0 != vc->comments[comment_num].entry)
- free(vc->comments[comment_num].entry);
+ free(vc->comments[comment_num].entry);
/* move all comments > comment_num backward one space */
memmove(&vc->comments[comment_num], &vc->comments[comment_num+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-comment_num-1));
@@ -1321,13 +1323,13 @@
FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value)
{
- FLAC__ASSERT(0 != entry);
- FLAC__ASSERT(0 != field_name);
- FLAC__ASSERT(0 != field_value);
+ FLAC__ASSERT(entry != NULL);
+ FLAC__ASSERT(field_name != NULL);
+ FLAC__ASSERT(field_value != NULL);
- if(!FLAC__format_vorbiscomment_entry_name_is_legal(field_name))
+ if (!FLAC__format_vorbiscomment_entry_name_is_legal(field_name))
return false;
- if(!FLAC__format_vorbiscomment_entry_value_is_legal((const FLAC__byte *)field_value, (unsigned)(-1)))
+ if (!FLAC__format_vorbiscomment_entry_value_is_legal((const FLAC__byte *)field_value, (uint32_t)(-1)))
return false;
{
@@ -1334,7 +1336,7 @@
const size_t nn = strlen(field_name);
const size_t nv = strlen(field_value);
entry->length = nn + 1 /*=*/ + nv;
- if(0 == (entry->entry = safe_malloc_add_4op_(nn, /*+*/1, /*+*/nv, /*+*/1)))
+ if ((entry->entry = safe_malloc_add_4op_(nn, /*+*/1, /*+*/nv, /*+*/1)) == NULL)
return false;
memcpy(entry->entry, field_name, nn);
entry->entry[nn] = '=';
@@ -1347,11 +1349,11 @@
FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value)
{
- FLAC__ASSERT(0 != entry.entry && entry.length > 0);
- FLAC__ASSERT(0 != field_name);
- FLAC__ASSERT(0 != field_value);
+ FLAC__ASSERT(entry.entry != NULL && entry.length > 0);
+ FLAC__ASSERT(field_name != NULL);
+ FLAC__ASSERT(field_value != NULL);
- if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
+ if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
return false;
{
@@ -1358,12 +1360,12 @@
const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length);
const size_t nn = eq-entry.entry;
const size_t nv = entry.length-nn-1; /* -1 for the '=' */
- FLAC__ASSERT(0 != eq);
- if(0 == eq)
+
+ if (eq == NULL)
return false; /* double protection */
- if(0 == (*field_name = safe_malloc_add_2op_(nn, /*+*/1)))
+ if ((*field_name = safe_malloc_add_2op_(nn, /*+*/1)) == NULL)
return false;
- if(0 == (*field_value = safe_malloc_add_2op_(nv, /*+*/1))) {
+ if ((*field_value = safe_malloc_add_2op_(nv, /*+*/1)) == NULL) {
free(*field_name);
return false;
}
@@ -1376,18 +1378,18 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length)
+FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, uint32_t field_name_length)
{
- FLAC__ASSERT(0 != entry.entry && entry.length > 0);
+ FLAC__ASSERT(entry.entry != NULL && entry.length > 0);
{
const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length);
- return (0 != eq && (unsigned)(eq-entry.entry) == field_name_length && 0 == FLAC__STRNCASECMP(field_name, (const char *)entry.entry, field_name_length));
+ return (eq != NULL && (uint32_t)(eq-entry.entry) == field_name_length && FLAC__STRNCASECMP(field_name, (const char *)entry.entry, field_name_length) == 0);
}
}
-FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name)
+FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name)
{
- FLAC__ASSERT(0 != field_name);
+ FLAC__ASSERT(field_name != NULL);
return vorbiscomment_find_entry_from_(object, offset, field_name, strlen(field_name));
}
@@ -1394,15 +1396,15 @@
FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name)
{
- const unsigned field_name_length = strlen(field_name);
- unsigned i;
+ const uint32_t field_name_length = strlen(field_name);
+ uint32_t i;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
- for(i = 0; i < object->data.vorbis_comment.num_comments; i++) {
- if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) {
- if(!FLAC__metadata_object_vorbiscomment_delete_comment(object, i))
+ for (i = 0; i < object->data.vorbis_comment.num_comments; i++) {
+ if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) {
+ if (!FLAC__metadata_object_vorbiscomment_delete_comment(object, i))
return -1;
else
return 1;
@@ -1415,18 +1417,18 @@
FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name)
{
FLAC__bool ok = true;
- unsigned matching = 0;
- const unsigned field_name_length = strlen(field_name);
+ uint32_t matching = 0;
+ const uint32_t field_name_length = strlen(field_name);
int i;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
/* must delete from end to start otherwise it will interfere with our iteration */
- for(i = (int)object->data.vorbis_comment.num_comments - 1; ok && i >= 0; i--) {
- if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) {
+ for (i = (int)object->data.vorbis_comment.num_comments - 1; ok && i >= 0; i--) {
+ if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) {
matching++;
- ok &= FLAC__metadata_object_vorbiscomment_delete_comment(object, (unsigned)i);
+ ok &= FLAC__metadata_object_vorbiscomment_delete_comment(object, (uint32_t)i);
}
}
@@ -1442,10 +1444,10 @@
{
FLAC__StreamMetadata_CueSheet_Track *to;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
- if(0 != (to = FLAC__metadata_object_cuesheet_track_new())) {
- if(!copy_track_(to, object)) {
+ if ((to = FLAC__metadata_object_cuesheet_track_new()) != NULL) {
+ if (!copy_track_(to, object)) {
FLAC__metadata_object_cuesheet_track_delete(to);
return 0;
}
@@ -1456,9 +1458,9 @@
void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
- if(0 != object->indices) {
+ if (object->indices != NULL) {
FLAC__ASSERT(object->num_indices > 0);
free(object->indices);
}
@@ -1470,20 +1472,20 @@
free(object);
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t new_num_indices)
{
FLAC__StreamMetadata_CueSheet_Track *track;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
track = &object->data.cue_sheet.tracks[track_num];
- if(0 == track->indices) {
+ if (track->indices == NULL) {
FLAC__ASSERT(track->num_indices == 0);
- if(0 == new_num_indices)
+ if (new_num_indices == 0)
return true;
- else if(0 == (track->indices = cuesheet_track_index_array_new_(new_num_indices)))
+ else if ((track->indices = cuesheet_track_index_array_new_(new_num_indices)) == NULL)
return false;
}
else {
@@ -1491,20 +1493,20 @@
const size_t new_size = new_num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index);
/* overflow check */
- if(new_num_indices > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Index))
+ if (new_num_indices > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Index))
return false;
FLAC__ASSERT(track->num_indices > 0);
- if(new_size == 0) {
+ if (new_size == 0) {
free(track->indices);
track->indices = 0;
}
- else if(0 == (track->indices = realloc(track->indices, new_size)))
+ else if ((track->indices = safe_realloc_(track->indices, new_size)) == NULL)
return false;
/* if growing, zero all the lengths/pointers of new elements */
- if(new_size > old_size)
+ if (new_size > old_size)
memset(track->indices + track->num_indices, 0, new_size - old_size);
}
@@ -1514,11 +1516,11 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index indx)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num, FLAC__StreamMetadata_CueSheet_Index indx)
{
FLAC__StreamMetadata_CueSheet_Track *track;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
FLAC__ASSERT(index_num <= object->data.cue_sheet.tracks[track_num].num_indices);
@@ -1525,7 +1527,7 @@
track = &object->data.cue_sheet.tracks[track_num];
- if(!FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices+1))
+ if (!FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices+1))
return false;
/* move all indices >= index_num forward one space */
@@ -1536,7 +1538,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num)
{
FLAC__StreamMetadata_CueSheet_Index indx;
memset(&indx, 0, sizeof(indx));
@@ -1543,11 +1545,11 @@
return FLAC__metadata_object_cuesheet_track_insert_index(object, track_num, index_num, indx);
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num)
{
FLAC__StreamMetadata_CueSheet_Track *track;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
FLAC__ASSERT(index_num < object->data.cue_sheet.tracks[track_num].num_indices);
@@ -1562,16 +1564,16 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, uint32_t new_num_tracks)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
- if(0 == object->data.cue_sheet.tracks) {
+ if (object->data.cue_sheet.tracks == NULL) {
FLAC__ASSERT(object->data.cue_sheet.num_tracks == 0);
- if(0 == new_num_tracks)
+ if (new_num_tracks == 0)
return true;
- else if(0 == (object->data.cue_sheet.tracks = cuesheet_track_array_new_(new_num_tracks)))
+ else if ((object->data.cue_sheet.tracks = cuesheet_track_array_new_(new_num_tracks)) == NULL)
return false;
}
else {
@@ -1579,28 +1581,27 @@
const size_t new_size = new_num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track);
/* overflow check */
- if(new_num_tracks > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Track))
+ if (new_num_tracks > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Track))
return false;
FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0);
/* if shrinking, free the truncated entries */
- if(new_num_tracks < object->data.cue_sheet.num_tracks) {
- unsigned i;
- for(i = new_num_tracks; i < object->data.cue_sheet.num_tracks; i++)
- if(0 != object->data.cue_sheet.tracks[i].indices)
- free(object->data.cue_sheet.tracks[i].indices);
+ if (new_num_tracks < object->data.cue_sheet.num_tracks) {
+ uint32_t i;
+ for (i = new_num_tracks; i < object->data.cue_sheet.num_tracks; i++)
+ free(object->data.cue_sheet.tracks[i].indices);
}
- if(new_size == 0) {
+ if (new_size == 0) {
free(object->data.cue_sheet.tracks);
object->data.cue_sheet.tracks = 0;
}
- else if(0 == (object->data.cue_sheet.tracks = realloc(object->data.cue_sheet.tracks, new_size)))
+ else if ((object->data.cue_sheet.tracks = safe_realloc_(object->data.cue_sheet.tracks, new_size)) == NULL)
return false;
/* if growing, zero all the lengths/pointers of new elements */
- if(new_size > old_size)
+ if (new_size > old_size)
memset(object->data.cue_sheet.tracks + object->data.cue_sheet.num_tracks, 0, new_size - old_size);
}
@@ -1610,25 +1611,25 @@
return true;
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
return cuesheet_set_track_(object, object->data.cue_sheet.tracks + track_num, track, copy);
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
{
FLAC__StreamMetadata_CueSheet *cs;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
FLAC__ASSERT(track_num <= object->data.cue_sheet.num_tracks);
cs = &object->data.cue_sheet;
- if(!FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks+1))
+ if (!FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks+1))
return false;
/* move all tracks >= track_num forward one space */
@@ -1639,7 +1640,7 @@
return FLAC__metadata_object_cuesheet_set_track(object, track_num, track, copy);
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, uint32_t track_num)
{
FLAC__StreamMetadata_CueSheet_Track track;
memset(&track, 0, sizeof(track));
@@ -1646,11 +1647,11 @@
return FLAC__metadata_object_cuesheet_insert_track(object, track_num, &track, /*copy=*/false);
}
-FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num)
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, uint32_t track_num)
{
FLAC__StreamMetadata_CueSheet *cs;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
@@ -1657,8 +1658,7 @@
cs = &object->data.cue_sheet;
/* free the track at track_num */
- if(0 != cs->tracks[track_num].indices)
- free(cs->tracks[track_num].indices);
+ free(cs->tracks[track_num].indices);
/* move all tracks > track_num backward one space */
memmove(&cs->tracks[track_num], &cs->tracks[track_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-track_num-1));
@@ -1670,13 +1670,13 @@
FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
return FLAC__format_cuesheet_is_legal(&object->data.cue_sheet, check_cd_da_subset, violation);
}
-static FLAC__uint64 get_index_01_offset_(const FLAC__StreamMetadata_CueSheet *cs, unsigned track)
+static FLAC__uint64 get_index_01_offset_(const FLAC__StreamMetadata_CueSheet *cs, uint32_t track)
{
if (track >= (cs->num_tracks-1) || cs->tracks[track].num_indices < 1)
return 0;
@@ -1705,7 +1705,7 @@
{
const FLAC__StreamMetadata_CueSheet *cs;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
cs = &object->data.cue_sheet;
@@ -1728,9 +1728,9 @@
char *old;
size_t old_length, new_length;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
- FLAC__ASSERT(0 != mime_type);
+ FLAC__ASSERT(mime_type != NULL);
old = object->data.picture.mime_type;
old_length = old? strlen(old) : 0;
@@ -1737,10 +1737,10 @@
new_length = strlen(mime_type);
/* do the copy first so that if we fail we leave the object untouched */
- if(copy) {
- if(new_length >= SIZE_MAX) /* overflow check */
+ if (copy) {
+ if (new_length >= SIZE_MAX) /* overflow check */
return false;
- if(!copy_bytes_((FLAC__byte**)(&object->data.picture.mime_type), (FLAC__byte*)mime_type, new_length+1))
+ if (!copy_bytes_((FLAC__byte**)(&object->data.picture.mime_type), (FLAC__byte*)mime_type, new_length+1))
return false;
}
else {
@@ -1747,8 +1747,7 @@
object->data.picture.mime_type = mime_type;
}
- if(0 != old)
- free(old);
+ free(old);
object->length -= old_length;
object->length += new_length;
@@ -1760,9 +1759,9 @@
FLAC__byte *old;
size_t old_length, new_length;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
- FLAC__ASSERT(0 != description);
+ FLAC__ASSERT(description != NULL);
old = object->data.picture.description;
old_length = old? strlen((const char *)old) : 0;
@@ -1769,10 +1768,10 @@
new_length = strlen((const char *)description);
/* do the copy first so that if we fail we leave the object untouched */
- if(copy) {
- if(new_length >= SIZE_MAX) /* overflow check */
+ if (copy) {
+ if (new_length >= SIZE_MAX) /* overflow check */
return false;
- if(!copy_bytes_(&object->data.picture.description, description, new_length+1))
+ if (!copy_bytes_(&object->data.picture.description, description, new_length+1))
return false;
}
else {
@@ -1779,8 +1778,7 @@
object->data.picture.description = description;
}
- if(0 != old)
- free(old);
+ free(old);
object->length -= old_length;
object->length += new_length;
@@ -1791,15 +1789,15 @@
{
FLAC__byte *old;
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
- FLAC__ASSERT((0 != data && length > 0) || (0 == data && length == 0 && copy == false));
+ FLAC__ASSERT((data != NULL && length > 0) || (data == NULL && length == 0 && copy == false));
old = object->data.picture.data;
/* do the copy first so that if we fail we leave the object untouched */
- if(copy) {
- if(!copy_bytes_(&object->data.picture.data, data, length))
+ if (copy) {
+ if (!copy_bytes_(&object->data.picture.data, data, length))
return false;
}
else {
@@ -1806,8 +1804,7 @@
object->data.picture.data = data;
}
- if(0 != old)
- free(old);
+ free(old);
object->length -= object->data.picture.data_length;
object->data.picture.data_length = length;
@@ -1817,7 +1814,7 @@
FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation)
{
- FLAC__ASSERT(0 != object);
+ FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
return FLAC__format_picture_is_legal(&object->data.picture, violation);
--- a/sys/src/cmd/audio/libFLAC/ogg_decoder_aspect.c
+++ b/sys/src/cmd/audio/libFLAC/ogg_decoder_aspect.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -111,7 +111,7 @@
* 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 accomodate a whole frame because then the internal buffer size
+ * 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;
@@ -161,7 +161,7 @@
/* 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 unsigned header_length =
+ const uint32_t header_length =
FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
FLAC__OGG_MAPPING_MAGIC_LENGTH +
FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
@@ -173,9 +173,9 @@
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 = (unsigned)(*b);
+ aspect->version_major = (uint32_t)(*b);
b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH;
- aspect->version_minor = (unsigned)(*b);
+ 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;
--- a/sys/src/cmd/audio/libFLAC/ogg_encoder_aspect.c
+++ b/sys/src/cmd/audio/libFLAC/ogg_encoder_aspect.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -72,7 +72,7 @@
aspect->serial_number = value;
}
-FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, unsigned 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;
@@ -109,7 +109,7 @@
* 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, unsigned samples, unsigned current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, 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)
{
/* WATCHOUT:
* This depends on the behavior of FLAC__StreamEncoder that 'samples'
@@ -170,7 +170,7 @@
/* add STREAMINFO */
memcpy(b, buffer, bytes);
FLAC__ASSERT(b + bytes - synthetic_first_packet_body == sizeof(synthetic_first_packet_body));
- packet.packet = (unsigned char *)synthetic_first_packet_body;
+ packet.packet = (uint8_t *)synthetic_first_packet_body;
packet.bytes = sizeof(synthetic_first_packet_body);
packet.b_o_s = 1;
@@ -177,7 +177,7 @@
aspect->is_first_packet = false;
}
else {
- packet.packet = (unsigned char *)buffer;
+ packet.packet = (uint8_t *)buffer;
packet.bytes = bytes;
}
--- a/sys/src/cmd/audio/libFLAC/ogg_helper.c
+++ b/sys/src/cmd/audio/libFLAC/ogg_helper.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -94,8 +94,8 @@
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 unsigned OGG_HEADER_FIXED_PORTION_LEN = 27;
- static const unsigned OGG_MAX_HEADER_LEN = 27/*OGG_HEADER_FIXED_PORTION_LEN*/ + 255;
+ 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;
@@ -142,10 +142,10 @@
return false;
{
- unsigned i;
+ uint32_t i;
/* check to see that it specifies a single packet */
- for(i = 0; i < (unsigned)page->header[26] - 1; i++) {
+ 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;
--- a/sys/src/cmd/audio/libFLAC/ogg_mapping.c
+++ b/sys/src/cmd/audio/libFLAC/ogg_mapping.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -36,13 +36,13 @@
#include "private/ogg_mapping.h"
-const unsigned FLAC__OGG_MAPPING_PACKET_TYPE_LEN = 8; /* bits */
+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 unsigned FLAC__OGG_MAPPING_VERSION_MAJOR_LEN = 8; /* bits */
-const unsigned FLAC__OGG_MAPPING_VERSION_MINOR_LEN = 8; /* bits */
+const uint32_t FLAC__OGG_MAPPING_VERSION_MAJOR_LEN = 8; /* bits */
+const uint32_t FLAC__OGG_MAPPING_VERSION_MINOR_LEN = 8; /* bits */
-const unsigned FLAC__OGG_MAPPING_NUM_HEADERS_LEN = 16; /* bits */
+const uint32_t FLAC__OGG_MAPPING_NUM_HEADERS_LEN = 16; /* bits */
--- a/sys/src/cmd/audio/libFLAC/private/all.h
+++ b/sys/src/cmd/audio/libFLAC/private/all.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/private/bitmath.h
+++ b/sys/src/cmd/audio/libFLAC/private/bitmath.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -36,71 +36,100 @@
#include "FLAC/ordinals.h"
#include "FLAC/assert.h"
-/* for CHAR_BIT */
-#include <limits.h>
#include "share/compat.h"
-#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#if defined(_MSC_VER)
#include <intrin.h> /* for _BitScanReverse* */
#endif
/* Will never be emitted for MSVC, GCC, Intel compilers */
-static inline unsigned int FLAC__clz_soft_uint32(unsigned int word)
+static inline uint32_t FLAC__clz_soft_uint32(FLAC__uint32 word)
{
- static const unsigned char byte_to_unary_table[] = {
- 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- };
+ static const uint8_t byte_to_unary_table[] = {
+ 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ };
- return (word) > 0xffffff ? byte_to_unary_table[(word) >> 24] :
- (word) > 0xffff ? byte_to_unary_table[(word) >> 16] + 8 :
- (word) > 0xff ? byte_to_unary_table[(word) >> 8] + 16 :
- byte_to_unary_table[(word)] + 24;
+ return word > 0xffffff ? byte_to_unary_table[word >> 24] :
+ word > 0xffff ? byte_to_unary_table[word >> 16] + 8 :
+ word > 0xff ? byte_to_unary_table[word >> 8] + 16 :
+ byte_to_unary_table[word] + 24;
}
-static inline unsigned int FLAC__clz_uint32(FLAC__uint32 v)
+static inline uint32_t FLAC__clz_uint32(FLAC__uint32 v)
{
/* Never used with input 0 */
- FLAC__ASSERT(v > 0);
+ FLAC__ASSERT(v > 0);
#if defined(__INTEL_COMPILER)
- return _bit_scan_reverse(v) ^ 31U;
+ return _bit_scan_reverse(v) ^ 31U;
#elif defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
/* This will translate either to (bsr ^ 31U), clz , ctlz, cntlz, lzcnt depending on
* -march= setting or to a software routine in exotic machines. */
- return __builtin_clz(v);
-#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
- {
- unsigned long idx;
- _BitScanReverse(&idx, v);
- return idx ^ 31U;
- }
+ return __builtin_clz(v);
+#elif defined(_MSC_VER)
+ {
+ uint32_t idx;
+ _BitScanReverse(&idx, v);
+ return idx ^ 31U;
+ }
#else
- return FLAC__clz_soft_uint32(v);
+ return FLAC__clz_soft_uint32(v);
#endif
}
-/* This one works with input 0 */
-static inline unsigned int FLAC__clz2_uint32(FLAC__uint32 v)
+/* Used when 64-bit bsr/clz is unavailable; can use 32-bit bsr/clz when possible */
+static inline uint32_t FLAC__clz_soft_uint64(FLAC__uint64 word)
{
- if (!v)
- return 32;
- return FLAC__clz_uint32(v);
+ return (FLAC__uint32)(word>>32) ? FLAC__clz_uint32((FLAC__uint32)(word>>32)) :
+ FLAC__clz_uint32((FLAC__uint32)word) + 32;
}
+static inline uint32_t FLAC__clz_uint64(FLAC__uint64 v)
+{
+ /* Never used with input 0 */
+ FLAC__ASSERT(v > 0);
+#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+ return __builtin_clzll(v);
+#elif (defined(__INTEL_COMPILER) || defined(_MSC_VER)) && (defined(_M_IA64) || defined(_M_X64))
+ {
+ uint32_t idx;
+ _BitScanReverse64(&idx, v);
+ return idx ^ 63U;
+ }
+#else
+ return FLAC__clz_soft_uint64(v);
+#endif
+}
+
+/* These two functions work with input 0 */
+static inline uint32_t FLAC__clz2_uint32(FLAC__uint32 v)
+{
+ if (!v)
+ return 32;
+ return FLAC__clz_uint32(v);
+}
+
+static inline uint32_t FLAC__clz2_uint64(FLAC__uint64 v)
+{
+ if (!v)
+ return 64;
+ return FLAC__clz_uint64(v);
+}
+
/* An example of what FLAC__bitmath_ilog2() computes:
*
* ilog2( 0) = assertion failure
@@ -124,63 +153,58 @@
* ilog2(18) = 4
*/
-static inline unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
+static inline uint32_t FLAC__bitmath_ilog2(FLAC__uint32 v)
{
- FLAC__ASSERT(v > 0);
+ FLAC__ASSERT(v > 0);
#if defined(__INTEL_COMPILER)
- return _bit_scan_reverse(v);
-#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
- {
- unsigned long idx;
- _BitScanReverse(&idx, v);
- return idx;
- }
+ return _bit_scan_reverse(v);
+#elif defined(_MSC_VER)
+ {
+ uint32_t idx;
+ _BitScanReverse(&idx, v);
+ return idx;
+ }
#else
- return sizeof(FLAC__uint32) * CHAR_BIT - 1 - FLAC__clz_uint32(v);
+ return FLAC__clz_uint32(v) ^ 31U;
#endif
}
-
-#ifdef FLAC__INTEGER_ONLY_LIBRARY /* Unused otherwise */
-
-static inline unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
+static inline uint32_t FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
{
- FLAC__ASSERT(v > 0);
+ FLAC__ASSERT(v > 0);
#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
- return sizeof(FLAC__uint64) * CHAR_BIT - 1 - __builtin_clzll(v);
+ return __builtin_clzll(v) ^ 63U;
/* Sorry, only supported in x64/Itanium.. and both have fast FPU which makes integer-only encoder pointless */
-#elif (defined(_MSC_VER) && (_MSC_VER >= 1400)) && (defined(_M_IA64) || defined(_M_X64))
- {
- unsigned long idx;
- _BitScanReverse64(&idx, v);
- return idx;
- }
+#elif (defined(__INTEL_COMPILER) || defined(_MSC_VER)) && (defined(_M_IA64) || defined(_M_X64))
+ {
+ uint32_t idx;
+ _BitScanReverse64(&idx, v);
+ return idx;
+ }
#else
/* Brain-damaged compilers will use the fastest possible way that is,
- de Bruijn sequences (http://supertech.csail.mit.edu/papers/debruijn.pdf)
- (C) Timothy B. Terriberry ([email protected]) 2001-2009 CC0 (Public domain).
+ de Bruijn sequences (http://supertech.csail.mit.edu/papers/debruijn.pdf)
+ (C) Timothy B. Terriberry ([email protected]) 2001-2009 CC0 (Public domain).
*/
- {
- static const unsigned char DEBRUIJN_IDX64[64]={
- 0, 1, 2, 7, 3,13, 8,19, 4,25,14,28, 9,34,20,40,
- 5,17,26,38,15,46,29,48,10,31,35,54,21,50,41,57,
- 63, 6,12,18,24,27,33,39,16,37,45,47,30,53,49,56,
- 62,11,23,32,36,44,52,55,61,22,43,51,60,42,59,58
- };
- v|= v>>1;
- v|= v>>2;
- v|= v>>4;
- v|= v>>8;
- v|= v>>16;
- v|= v>>32;
- v= (v>>1)+1;
- return DEBRUIJN_IDX64[v*0x218A392CD3D5DBF>>58&0x3F];
- }
+ {
+ static const uint8_t DEBRUIJN_IDX64[64]={
+ 0, 1, 2, 7, 3,13, 8,19, 4,25,14,28, 9,34,20,40,
+ 5,17,26,38,15,46,29,48,10,31,35,54,21,50,41,57,
+ 63, 6,12,18,24,27,33,39,16,37,45,47,30,53,49,56,
+ 62,11,23,32,36,44,52,55,61,22,43,51,60,42,59,58
+ };
+ v|= v>>1;
+ v|= v>>2;
+ v|= v>>4;
+ v|= v>>8;
+ v|= v>>16;
+ v|= v>>32;
+ v= (v>>1)+1;
+ return DEBRUIJN_IDX64[v*FLAC__U64L(0x218A392CD3D5DBF)>>58&0x3F];
+ }
#endif
}
-#endif
-unsigned FLAC__bitmath_silog2(int v);
-unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
+uint32_t FLAC__bitmath_silog2(FLAC__int64 v);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/bitreader.h
+++ b/sys/src/cmd/audio/libFLAC/private/bitreader.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -65,27 +65,27 @@
* info functions
*/
FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
-unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
-unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
+uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
+uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
/*
* read functions
*/
-FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
-FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
-FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
+FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits);
+FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, uint32_t bits);
+FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, uint32_t bits);
FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
-FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
-FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
-FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
-FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
-FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
-FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
+FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, uint32_t bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
+FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, uint32_t nvals); /* WATCHOUT: does not CRC the read data! */
+FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, uint32_t nvals); /* WATCHOUT: does not CRC the read data! */
+FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *val);
+FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint32_t parameter);
+FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter);
#if 0 /* UNUSED */
-FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
-FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
+FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter);
+FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, uint32_t *val, uint32_t parameter);
#endif
-FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
-FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
+FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, uint32_t *rawlen);
+FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, uint32_t *rawlen);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/bitwriter.h
+++ b/sys/src/cmd/audio/libFLAC/private/bitwriter.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -64,7 +64,7 @@
* info functions
*/
FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
-unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
+uint32_t FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
/*
* direct buffer access
@@ -79,23 +79,23 @@
/*
* write functions
*/
-FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
-FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
-FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
-FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
+FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits);
+FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits);
+FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits);
+FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits);
FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
-FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
-FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
-unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
+FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals);
+FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, uint32_t val);
+uint32_t FLAC__bitwriter_rice_bits(FLAC__int32 val, uint32_t parameter);
#if 0 /* UNUSED */
-unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
-unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
+uint32_t FLAC__bitwriter_golomb_bits_signed(int val, uint32_t parameter);
+uint32_t FLAC__bitwriter_golomb_bits_unsigned(uint32_t val, uint32_t parameter);
#endif
-FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
-FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
+FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t parameter);
+FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, uint32_t nvals, uint32_t parameter);
#if 0 /* UNUSED */
-FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
-FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
+FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, uint32_t parameter);
+FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, uint32_t val, uint32_t parameter);
#endif
FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
--- a/sys/src/cmd/audio/libFLAC/private/cpu.h
+++ b/sys/src/cmd/audio/libFLAC/private/cpu.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -39,7 +39,27 @@
#include <config.h>
#endif
-#if defined FLAC__HAS_X86INTRIN
+#ifndef FLAC__CPU_X86_64
+
+#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
+#define FLAC__CPU_X86_64
+#endif
+
+#endif
+
+#ifndef FLAC__CPU_IA32
+
+#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)
+#define FLAC__CPU_IA32
+#endif
+
+#endif
+
+#ifndef __has_attribute
+#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)
@@ -56,6 +76,34 @@
#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_pabsd256)
+ #define FLAC__AVX2_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
@@ -71,51 +119,47 @@
#define FLAC__AVX2_SUPPORTED 1
#define FLAC__FMA_SUPPORTED 1
#endif
-#elif defined __GNUC__
- #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* since GCC 4.9 -msse.. compiler options aren't necessary */
- #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x)))
+#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
- #else /* for GCC older than 4.9 */
- #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 /* GCC version */
+ #endif
#endif /* compiler version */
#endif /* intrinsics support */
+
+#ifndef FLAC__AVX_SUPPORTED
+#define FLAC__AVX_SUPPORTED 0
+#endif
+
typedef enum {
FLAC__CPUINFO_TYPE_IA32,
FLAC__CPUINFO_TYPE_X86_64,
+ FLAC__CPUINFO_TYPE_PPC,
FLAC__CPUINFO_TYPE_UNKNOWN
} FLAC__CPUInfo_Type;
-#if defined FLAC__CPU_IA32
typedef struct {
+ FLAC__bool intel;
+
FLAC__bool cmov;
FLAC__bool mmx;
FLAC__bool sse;
@@ -128,41 +172,24 @@
FLAC__bool avx;
FLAC__bool avx2;
FLAC__bool fma;
-} FLAC__CPUInfo_IA32;
-#elif defined FLAC__CPU_X86_64
-typedef struct {
- FLAC__bool sse3;
- FLAC__bool ssse3;
- FLAC__bool sse41;
- FLAC__bool sse42;
- FLAC__bool avx;
- FLAC__bool avx2;
- FLAC__bool fma;
} FLAC__CPUInfo_x86;
-#endif
typedef struct {
+ FLAC__bool arch_3_00;
+ FLAC__bool arch_2_07;
+} FLAC__CPUInfo_ppc;
+
+typedef struct {
FLAC__bool use_asm;
FLAC__CPUInfo_Type type;
-#if defined FLAC__CPU_IA32
- FLAC__CPUInfo_IA32 ia32;
-#elif defined FLAC__CPU_X86_64
FLAC__CPUInfo_x86 x86;
-#endif
+ FLAC__CPUInfo_ppc ppc;
} FLAC__CPUInfo;
void FLAC__cpu_info(FLAC__CPUInfo *info);
-#ifndef FLAC__NO_ASM
-# if defined FLAC__CPU_IA32 && defined FLAC__HAS_NASM
FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
-void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
-# endif
-# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
-FLAC__uint32 FLAC__cpu_have_cpuid_x86(void);
-void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx);
-FLAC__uint32 FLAC__cpu_xgetbv_x86(void);
-# endif
-#endif
+
+void FLAC__cpu_info_asm_ia32(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/crc.h
+++ b/sys/src/cmd/audio/libFLAC/private/crc.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * Copyright (C) 2011-2018 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,24 +39,22 @@
** polynomial = x^8 + x^2 + x^1 + x^0
** init = 0
*/
-extern FLAC__byte const FLAC__crc8_table[256];
-#define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
-void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
-void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
-FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
+FLAC__uint8 FLAC__crc8(const FLAC__byte *data, uint32_t len);
/* 16 bit CRC generator, MSB shifted first
** polynomial = x^16 + x^15 + x^2 + x^0
** init = 0
*/
-extern unsigned const FLAC__crc16_table[256];
+extern FLAC__uint16 const FLAC__crc16_table[8][256];
-#define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)])
+#define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[0][((crc)>>8) ^ (data)])
/* this alternate may be faster on some systems/compilers */
#if 0
-#define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
+#define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[0][((crc)>>8) ^ (data)]) & 0xffff)
#endif
-unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
+FLAC__uint16 FLAC__crc16(const FLAC__byte *data, uint32_t len);
+FLAC__uint16 FLAC__crc16_update_words32(const FLAC__uint32 *words, uint32_t len, FLAC__uint16 crc);
+FLAC__uint16 FLAC__crc16_update_words64(const FLAC__uint64 *words, uint32_t len, FLAC__uint16 crc);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/fixed.h
+++ b/sys/src/cmd/audio/libFLAC/private/fixed.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -54,26 +54,26 @@
* OUT residual_bits_per_sample[0,FLAC__MAX_FIXED_ORDER]
*/
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
-unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
# ifndef FLAC__NO_ASM
-# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
+# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN
# ifdef FLAC__SSE2_SUPPORTED
-unsigned FLAC__fixed_compute_best_predictor_intrin_sse2(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]);
-unsigned FLAC__fixed_compute_best_predictor_wide_intrin_sse2(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]);
+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]);
+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]);
# endif
# ifdef FLAC__SSSE3_SUPPORTED
-unsigned FLAC__fixed_compute_best_predictor_intrin_ssse3(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
-unsigned FLAC__fixed_compute_best_predictor_wide_intrin_ssse3(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]);
+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]);
+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
-unsigned FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+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
-unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
-unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+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]);
+uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
#endif
/*
@@ -87,7 +87,7 @@
* IN order <= FLAC__MAX_FIXED_ORDER fixed-predictor order
* OUT residual[0,data_len-1] residual signal
*/
-void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
+void FLAC__fixed_compute_residual(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]);
/*
* FLAC__fixed_restore_signal()
@@ -102,6 +102,6 @@
* IN data[-order,-1] previously-reconstructed historical samples
* OUT data[0,data_len-1] original signal
*/
-void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
+void FLAC__fixed_restore_signal(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[]);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/float.h
+++ b/sys/src/cmd/audio/libFLAC/private/float.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -40,18 +40,15 @@
#include "FLAC/ordinals.h"
/*
- * These typedefs make it easier to ensure that integer versions of
- * the library really only contain integer operations. All the code
- * in libFLAC should use FLAC__float and FLAC__double in place of
- * float and double, and be protected by checks of the macro
+ * All the code in libFLAC that uses float and double
+ * should be protected by checks of the macro
* FLAC__INTEGER_ONLY_LIBRARY.
*
- * FLAC__real is the basic floating point type used in LPC analysis.
*/
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-typedef double FLAC__double;
-typedef float FLAC__float;
/*
+ * FLAC__real is the basic floating point type used in LPC analysis.
+ *
* WATCHOUT: changing FLAC__real will change the signatures of many
* functions that have assembly language equivalents and break them.
*/
@@ -84,7 +81,7 @@
* be < 32 and evenly divisible by 4 (0 is OK but not very precise).
*
* 'precision' roughly limits the number of iterations that are done;
- * use (unsigned)(-1) for maximum precision.
+ * use (uint32_t)(-1) for maximum precision.
*
* If 'x' is less than one -- that is, x < (1<<fracbits) -- then this
* function will punt and return 0.
@@ -91,7 +88,7 @@
*
* The return value will also have 'fracbits' fractional bits.
*/
-FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
+FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, uint32_t fracbits, uint32_t precision);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/format.h
+++ b/sys/src/cmd/audio/libFLAC/private/format.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -35,11 +35,11 @@
#include "FLAC/format.h"
-unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
-unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
-unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
+uint32_t FLAC__format_get_max_rice_partition_order(uint32_t blocksize, uint32_t predictor_order);
+uint32_t FLAC__format_get_max_rice_partition_order_from_blocksize(uint32_t blocksize);
+uint32_t FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(uint32_t limit, uint32_t blocksize, uint32_t predictor_order);
void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
-FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
+FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, uint32_t max_partition_order);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/lpc.h
+++ b/sys/src/cmd/audio/libFLAC/private/lpc.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -54,7 +54,7 @@
* OUT out[0,lag-1]
* IN data_len
*/
-void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
+void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len);
/*
* FLAC__lpc_compute_autocorrelation()
@@ -68,26 +68,44 @@
* IN 0 < lag <= data_len
* OUT autoc[0,lag-1]
*/
-void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
#ifndef FLAC__NO_ASM
# ifdef FLAC__CPU_IA32
# ifdef FLAC__HAS_NASM
-void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_16(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_16_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
# endif
# endif
-# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
+# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN
# ifdef FLAC__SSE_SUPPORTED
-void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
-void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_old(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_new(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
# endif
# endif
+#if defined(FLAC__CPU_PPC64) && defined(FLAC__USE_VSX)
+#ifdef FLAC__HAS_TARGET_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[]);
+void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
#endif
+#ifdef FLAC__HAS_TARGET_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[]);
+void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+void FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+#endif
+#endif
+#endif
/*
* FLAC__lpc_compute_lp_coefficients()
@@ -110,7 +128,7 @@
* in lp_coeff[8][0,8], the LP coefficients for order 8 will be
* in lp_coeff[7][0,7], etc.
*/
-void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
+void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], uint32_t *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], double error[]);
/*
* FLAC__lpc_quantize_coefficients()
@@ -132,7 +150,7 @@
* 2 => coefficients are all zero, which is bad. 'shift' is
* unset.
*/
-int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
+int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], uint32_t order, uint32_t precision, FLAC__int32 qlp_coeff[], int *shift);
/*
* FLAC__lpc_compute_residual_from_qlp_coefficients()
@@ -147,29 +165,29 @@
* IN lp_quantization quantization of LP coefficients in bits
* OUT residual[0,data_len-1] residual signal
*/
-void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients(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(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
#ifndef FLAC__NO_ASM
# ifdef FLAC__CPU_IA32
# ifdef FLAC__HAS_NASM
-void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+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) && defined FLAC__HAS_X86INTRIN
+# 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, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+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[]);
+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[]);
# endif
# ifdef FLAC__SSE4_1_SUPPORTED
-void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
# endif
# ifdef FLAC__AVX2_SUPPORTED
-void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
-void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
# endif
# endif
#endif
@@ -191,22 +209,21 @@
* IN data[-order,-1] previously-reconstructed historical samples
* OUT data[0,data_len-1] original signal
*/
-void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
-void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
#ifndef FLAC__NO_ASM
# ifdef FLAC__CPU_IA32
# ifdef FLAC__HAS_NASM
-void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
-void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
-void FLAC__lpc_restore_signal_wide_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_wide_asm_ia32(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
# endif /* FLAC__HAS_NASM */
# endif /* FLAC__CPU_IA32 */
-# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
-# ifdef FLAC__SSE2_SUPPORTED
-void FLAC__lpc_restore_signal_16_intrin_sse2(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
-# endif
+# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN
# ifdef FLAC__SSE4_1_SUPPORTED
-void FLAC__lpc_restore_signal_wide_intrin_sse41(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_intrin_sse41(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_16_intrin_sse41(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
+void FLAC__lpc_restore_signal_wide_intrin_sse41(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
# endif
# endif
#endif /* FLAC__NO_ASM */
@@ -223,8 +240,8 @@
* IN total_samples > 0 # of samples in residual signal
* RETURN expected bits per sample
*/
-FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
-FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
+double FLAC__lpc_compute_expected_bits_per_residual_sample(double lpc_error, uint32_t total_samples);
+double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(double lpc_error, double error_scale);
/*
* FLAC__lpc_compute_best_order()
@@ -239,7 +256,7 @@
* (includes warmup sample size and quantized LP coefficient)
* RETURN [1,max_order] best order
*/
-unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
+uint32_t FLAC__lpc_compute_best_order(const double lpc_error[], uint32_t max_order, uint32_t total_samples, uint32_t overhead_bits_per_order);
#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
--- a/sys/src/cmd/audio/libFLAC/private/macros.h
+++ b/sys/src/cmd/audio/libFLAC/private/macros.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2012-2014 Xiph.org Foundation
+ * 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
@@ -32,24 +32,19 @@
#ifndef FLAC__PRIVATE__MACROS_H
#define FLAC__PRIVATE__MACROS_H
-#ifdef Plan9
-#define flac_min(x,y) MIN(x,y)
-#define flac_max(x,y) MAX(x,y)
-#endif
-
#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; })
+ ({ __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); \
- })
+ __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__)
@@ -66,12 +61,12 @@
#define flac_min(a,b) __min(a,b)
#endif
-#ifndef MIN
-#define MIN(x,y) ((x) <= (y) ? (x) : (y))
+#ifndef flac_min
+#define flac_min(x,y) ((x) <= (y) ? (x) : (y))
#endif
-#ifndef MAX
-#define MAX(x,y) ((x) >= (y) ? (x) : (y))
+#ifndef flac_max
+#define flac_max(x,y) ((x) >= (y) ? (x) : (y))
#endif
#endif
--- a/sys/src/cmd/audio/libFLAC/private/md5.h
+++ b/sys/src/cmd/audio/libFLAC/private/md5.h
@@ -45,6 +45,6 @@
void FLAC__MD5Init(FLAC__MD5Context *context);
void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
-FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
+FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], uint32_t channels, uint32_t samples, uint32_t bytes_per_sample);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/memory.h
+++ b/sys/src/cmd/audio/libFLAC/private/memory.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -49,7 +49,7 @@
FLAC__bool FLAC__memory_alloc_aligned_int32_array(size_t elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
FLAC__bool FLAC__memory_alloc_aligned_uint32_array(size_t elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
FLAC__bool FLAC__memory_alloc_aligned_uint64_array(size_t elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
-FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(size_t elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
+FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(size_t elements, uint32_t **unaligned_pointer, uint32_t **aligned_pointer);
#ifndef FLAC__INTEGER_ONLY_LIBRARY
FLAC__bool FLAC__memory_alloc_aligned_real_array(size_t elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/metadata.h
+++ b/sys/src/cmd/audio/libFLAC/private/metadata.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/private/ogg_decoder_aspect.h
+++ b/sys/src/cmd/audio/libFLAC/private/ogg_decoder_aspect.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -46,7 +46,7 @@
/* these are for internal state related to Ogg decoding */
ogg_stream_state stream_state;
ogg_sync_state sync_state;
- unsigned version_major, version_minor;
+ 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 */
--- a/sys/src/cmd/audio/libFLAC/private/ogg_encoder_aspect.h
+++ b/sys/src/cmd/audio/libFLAC/private/ogg_encoder_aspect.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -41,7 +41,7 @@
typedef struct FLAC__OggEncoderAspect {
/* these are storage for values that can be set through the API */
long serial_number;
- unsigned num_metadata;
+ uint32_t num_metadata;
/* these are for internal state related to Ogg encoding */
ogg_stream_state stream_state;
@@ -52,12 +52,12 @@
} 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, unsigned 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, unsigned samples, unsigned current_frame, void *client_data);
+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, unsigned samples, unsigned current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, 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
--- a/sys/src/cmd/audio/libFLAC/private/ogg_helper.h
+++ b/sys/src/cmd/audio/libFLAC/private/ogg_helper.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/private/ogg_mapping.h
+++ b/sys/src/cmd/audio/libFLAC/private/ogg_mapping.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -38,7 +38,7 @@
/** The length of the packet type field in bytes. */
#define FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH (1u)
-extern const unsigned FLAC__OGG_MAPPING_PACKET_TYPE_LEN; /* = 8 bits */
+extern const uint32_t FLAC__OGG_MAPPING_PACKET_TYPE_LEN; /* = 8 bits */
extern const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */
@@ -47,8 +47,8 @@
extern const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC; /* = "FLAC" */
-extern const unsigned FLAC__OGG_MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */
-extern const unsigned FLAC__OGG_MAPPING_VERSION_MINOR_LEN; /* = 8 bits */
+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)
@@ -56,7 +56,7 @@
/** The length of the Ogg FLAC mapping minor version number in bytes. */
#define FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH (1u)
-extern const unsigned FLAC__OGG_MAPPING_NUM_HEADERS_LEN; /* = 16 bits */
+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)
--- a/sys/src/cmd/audio/libFLAC/private/stream_encoder.h
+++ b/sys/src/cmd/audio/libFLAC/private/stream_encoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -49,17 +49,17 @@
#ifdef FLAC__SSE2_SUPPORTED
extern void FLAC__precompute_partition_info_sums_intrin_sse2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[],
- unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps);
+ uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps);
#endif
#ifdef FLAC__SSSE3_SUPPORTED
extern void FLAC__precompute_partition_info_sums_intrin_ssse3(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[],
- unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps);
+ uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps);
#endif
#ifdef FLAC__AVX2_SUPPORTED
extern void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[],
- unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps);
+ uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps);
#endif
#endif
--- a/sys/src/cmd/audio/libFLAC/private/stream_encoder_framing.h
+++ b/sys/src/cmd/audio/libFLAC/private/stream_encoder_framing.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -38,9 +38,9 @@
FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
-FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
-FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
-FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
-FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
+FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw);
+FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw);
+FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw);
+FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, uint32_t samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw);
#endif
--- a/sys/src/cmd/audio/libFLAC/private/window.h
+++ b/sys/src/cmd/audio/libFLAC/private/window.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2006-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/protected/all.h
+++ b/sys/src/cmd/audio/libFLAC/protected/all.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/protected/stream_decoder.h
+++ b/sys/src/cmd/audio/libFLAC/protected/stream_decoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -41,11 +41,11 @@
typedef struct FLAC__StreamDecoderProtected {
FLAC__StreamDecoderState state;
FLAC__StreamDecoderInitStatus initstate;
- unsigned channels;
+ uint32_t channels;
FLAC__ChannelAssignment channel_assignment;
- unsigned bits_per_sample;
- unsigned sample_rate; /* in Hz */
- unsigned blocksize; /* in samples (per channel) */
+ uint32_t bits_per_sample;
+ uint32_t sample_rate; /* in Hz */
+ uint32_t blocksize; /* in samples (per channel) */
FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
#if FLAC__HAS_OGG
FLAC__OggDecoderAspect ogg_decoder_aspect;
@@ -55,6 +55,11 @@
/*
* return the number of input bytes consumed
*/
-unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
+uint32_t FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
+
+/*
+ * return client_data from decoder
+ */
+FLAC_API void *get_client_data_from_decoder(FLAC__StreamDecoder *decoder);
#endif
--- a/sys/src/cmd/audio/libFLAC/protected/stream_encoder.h
+++ b/sys/src/cmd/audio/libFLAC/protected/stream_encoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -81,7 +81,7 @@
} parameters;
} FLAC__ApodizationSpecification;
-#endif
+#endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
typedef struct FLAC__StreamEncoderProtected {
FLAC__StreamEncoderState state;
@@ -90,25 +90,25 @@
FLAC__bool do_md5;
FLAC__bool do_mid_side_stereo;
FLAC__bool loose_mid_side_stereo;
- unsigned channels;
- unsigned bits_per_sample;
- unsigned sample_rate;
- unsigned blocksize;
+ uint32_t channels;
+ uint32_t bits_per_sample;
+ uint32_t sample_rate;
+ uint32_t blocksize;
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- unsigned num_apodizations;
+ uint32_t num_apodizations;
FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
#endif
- unsigned max_lpc_order;
- unsigned qlp_coeff_precision;
+ uint32_t max_lpc_order;
+ uint32_t qlp_coeff_precision;
FLAC__bool do_qlp_coeff_prec_search;
FLAC__bool do_exhaustive_model_search;
FLAC__bool do_escape_coding;
- unsigned min_residual_partition_order;
- unsigned max_residual_partition_order;
- unsigned rice_parameter_search_dist;
+ uint32_t min_residual_partition_order;
+ uint32_t max_residual_partition_order;
+ uint32_t rice_parameter_search_dist;
FLAC__uint64 total_samples_estimate;
FLAC__StreamMetadata **metadata;
- unsigned num_metadata_blocks;
+ uint32_t num_metadata_blocks;
FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
#if FLAC__HAS_OGG
FLAC__OggEncoderAspect ogg_encoder_aspect;
--- a/sys/src/cmd/audio/libFLAC/share/alloc.h
+++ b/sys/src/cmd/audio/libFLAC/share/alloc.h
@@ -1,6 +1,6 @@
/* alloc - Convenience routines for safely allocating memory
* Copyright (C) 2007-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -52,7 +52,7 @@
# ifndef SIZE_T_MAX
# ifdef _MSC_VER
# ifdef _WIN64
-# define SIZE_T_MAX 0xffffffffffffffffui64
+# define SIZE_T_MAX FLAC__U64L(0xffffffffffffffff)
# else
# define SIZE_T_MAX 0xffffffff
# endif
@@ -153,11 +153,21 @@
return malloc(size1*size2);
}
+static inline void *safe_realloc_(void *ptr, size_t size)
+{
+ void *oldptr = ptr;
+ void *newptr = realloc(ptr, size);
+ if(size > 0 && newptr == 0)
+ free(oldptr);
+ return newptr;
+}
static inline void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
{
size2 += size1;
- if(size2 < size1)
+ if(size2 < size1) {
+ free(ptr);
return 0;
+ }
return realloc(ptr, size2);
}
@@ -192,7 +202,7 @@
return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
if(size1 > SIZE_MAX / size2)
return 0;
- return realloc(ptr, size1*size2);
+ return safe_realloc_(ptr, size1*size2);
}
/* size1 * (size2 + size3) */
--- a/sys/src/cmd/audio/libFLAC/share/compat.h
+++ b/sys/src/cmd/audio/libFLAC/share/compat.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2012-2014 Xiph.org Foundation
+ * 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
@@ -29,7 +29,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* This is the prefered location of all CPP hackery to make $random_compiler
+/* This is the preferred location of all CPP hackery to make $random_compiler
* work like something approaching a C99 (or maybe more accurately GNU99)
* compiler.
*
@@ -72,7 +72,7 @@
#define strtoull _strtoui64
#endif
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && !defined(__cplusplus)
#define inline __inline
#endif
@@ -87,7 +87,10 @@
#define FLAC__U64L(x) x##ULL
-#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
+#if defined _MSC_VER || defined __MINGW32__
+#define FLAC__STRCASECMP _stricmp
+#define FLAC__STRNCASECMP _strnicmp
+#elif defined __BORLANDC__
#define FLAC__STRCASECMP stricmp
#define FLAC__STRNCASECMP strnicmp
#else
@@ -95,7 +98,7 @@
#define FLAC__STRNCASECMP strncasecmp
#endif
-#if defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ || defined __EMX__
+#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__
#include <io.h> /* for _setmode(), chmod() */
#include <fcntl.h> /* for _O_BINARY */
#else
@@ -114,7 +117,9 @@
#endif
#if defined _MSC_VER
-# if _MSC_VER >= 1600
+# if _MSC_VER >= 1800
+# include <inttypes.h>
+# elif _MSC_VER >= 1600
/* Visual Studio 2010 has decent C99 support */
# include <stdint.h>
# define PRIu64 "llu"
@@ -125,14 +130,6 @@
# ifndef UINT32_MAX
# define UINT32_MAX _UI32_MAX
# endif
- typedef unsigned __int64 uint64_t;
- typedef unsigned __int32 uint32_t;
- typedef unsigned __int16 uint16_t;
- typedef unsigned __int8 uint8_t;
- typedef __int64 int64_t;
- typedef __int32 int32_t;
- typedef __int16 int16_t;
- typedef __int8 int8_t;
# define PRIu64 "I64u"
# define PRId64 "I64d"
# define PRIx64 "I64x"
@@ -141,23 +138,26 @@
#ifdef _WIN32
/* All char* strings are in UTF-8 format. Added to support Unicode files on Windows */
-#include "share/win_utf8_io.h"
+#include "share/win_utf8_io.h"
#define flac_printf printf_utf8
#define flac_fprintf fprintf_utf8
#define flac_vfprintf vfprintf_utf8
-#define flac_fopen fopen_utf8
-#define flac_chmod chmod_utf8
-#define flac_utime utime_utf8
-#define flac_unlink unlink_utf8
-#define flac_rename rename_utf8
-#define flac_stat _stat64_utf8
+#include "share/windows_unicode_filenames.h"
+#define flac_fopen flac_internal_fopen_utf8
+#define flac_chmod flac_internal_chmod_utf8
+#define flac_utime flac_internal_utime_utf8
+#define flac_unlink flac_internal_unlink_utf8
+#define flac_rename flac_internal_rename_utf8
+#define flac_stat flac_internal_stat64_utf8
+
#else
#define flac_printf printf
#define flac_fprintf fprintf
#define flac_vfprintf vfprintf
+
#define flac_fopen fopen
#define flac_chmod chmod
#define flac_utime utime
@@ -175,6 +175,10 @@
#define flac_fstat fstat
#endif
+#ifdef ANDROID
+#include <limits.h>
+#endif
+
#ifndef M_LN2
#define M_LN2 0.69314718055994530942
#endif
@@ -186,7 +190,7 @@
* snprintf as well as Microsoft Visual Studio which has an non-standards
* conformant snprint_s function.
*
- * This function wraps the MS version to behave more like the the ISO version.
+ * This function wraps the MS version to behave more like the ISO version.
*/
#include <stdarg.h>
#ifdef __cplusplus
--- a/sys/src/cmd/audio/libFLAC/share/endswap.h
+++ b/sys/src/cmd/audio/libFLAC/share/endswap.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2012-2014 Xiph.org Foundation
+ * 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
@@ -43,11 +43,15 @@
#define ENDSWAP_16(x) (__builtin_bswap16 (x))
#define ENDSWAP_32(x) (__builtin_bswap32 (x))
+#define ENDSWAP_64(x) (__builtin_bswap64 (x))
-#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
+#elif defined _MSC_VER /* Windows */
+#include <stdlib.h>
+
#define ENDSWAP_16(x) (_byteswap_ushort (x))
#define ENDSWAP_32(x) (_byteswap_ulong (x))
+#define ENDSWAP_64(x) (_byteswap_uint64 (x))
#elif defined HAVE_BYTESWAP_H /* Linux */
@@ -55,16 +59,18 @@
#define ENDSWAP_16(x) (bswap_16 (x))
#define ENDSWAP_32(x) (bswap_32 (x))
+#define ENDSWAP_64(x) (bswap_64 (x))
#else
#define ENDSWAP_16(x) ((((x) >> 8) & 0xFF) | (((x) & 0xFF) << 8))
#define ENDSWAP_32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) & 0xFF00) << 8) | (((x) & 0xFF) << 24))
+#define ENDSWAP_64(x) ((ENDSWAP_32(((x) >> 32) & 0xFFFFFFFF)) | (ENDSWAP_32((x) & 0xFFFFFFFF) << 32))
#endif
-/* Host to little-endian byte swapping. */
+/* Host to little-endian byte swapping (for MD5 calculation) */
#if CPU_IS_BIG_ENDIAN
#define H2LE_16(x) ENDSWAP_16 (x)
--- a/sys/src/cmd/audio/libFLAC/share/macros.h
+++ b/sys/src/cmd/audio/libFLAC/share/macros.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2013-2014 Xiph.org Foundation
+ * 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
@@ -31,11 +31,15 @@
#include <errno.h>
-/* FLAC_CHECK_RETURN : Check the return value of of the provided function and
- * print and error message if it fails (ie returns a value < 0).
+/* 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) \
- printf ("%s : %s\n", #x, strerror (errno)) ; \
+ fprintf (stderr, "%s : %s\n", #x, strerror (errno)) ; \
}
--- a/sys/src/cmd/audio/libFLAC/share/private.h
+++ b/sys/src/cmd/audio/libFLAC/share/private.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2013-2014 Xiph.org Foundation
+ * 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
@@ -33,7 +33,7 @@
#define FLAC__SHARE__PRIVATE_H
/*
- * Unpublished debug routines from libFLAC> This should not be used from any
+ * 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);
--- a/sys/src/cmd/audio/libFLAC/share/safe_str.h
+++ b/sys/src/cmd/audio/libFLAC/share/safe_str.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2013-2014 Xiph.org Foundation
+ * 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
--- a/sys/src/cmd/audio/libFLAC/stream_decoder.c
+++ b/sys/src/cmd/audio/libFLAC/stream_decoder.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -56,13 +56,7 @@
/* technically this should be in an "export.c" but this is convenient enough */
-FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
-#if FLAC__HAS_OGG
- 1
-#else
- 0
-#endif
-;
+FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = FLAC__HAS_OGG;
/***********************************************************************
@@ -81,13 +75,13 @@
static void set_defaults_(FLAC__StreamDecoder *decoder);
static FILE *get_binary_stdin_(void);
-static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
+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);
static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
-static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
-static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
-static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj, unsigned length);
+static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length);
+static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length);
+static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj, uint32_t length);
static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
@@ -94,12 +88,12 @@
static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
-static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
-static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
-static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
-static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
-static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
-static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended);
+static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode);
+static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode);
+static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode);
+static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode);
+static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode);
+static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_t predictor_order, uint32_t partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended);
static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
#if FLAC__HAS_OGG
@@ -125,9 +119,7 @@
***********************************************************************/
typedef struct FLAC__StreamDecoderPrivate {
-#if FLAC__HAS_OGG
FLAC__bool is_ogg;
-#endif
FLAC__StreamDecoderReadCallback read_callback;
FLAC__StreamDecoderSeekCallback seek_callback;
FLAC__StreamDecoderTellCallback tell_callback;
@@ -137,11 +129,11 @@
FLAC__StreamDecoderMetadataCallback metadata_callback;
FLAC__StreamDecoderErrorCallback error_callback;
/* generic 32-bit datapath: */
- void (*local_lpc_restore_signal)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+ void (*local_lpc_restore_signal)(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
/* generic 64-bit datapath: */
- void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+ void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
/* for use when the signal is <= 16 bits-per-sample, or <= 15 bits-per-sample on a side channel (which requires 1 extra bit): */
- void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
+ void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]);
void *client_data;
FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
FLAC__BitReader *input;
@@ -148,7 +140,7 @@
FLAC__int32 *output[FLAC__MAX_CHANNELS];
FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
- unsigned output_capacity, output_channels;
+ uint32_t output_capacity, output_channels;
FLAC__uint32 fixed_block_size, next_fixed_block_size;
FLAC__uint64 samples_decoded;
FLAC__bool has_stream_info, has_seek_table;
@@ -173,10 +165,8 @@
FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
FLAC__uint64 target_sample;
- unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
-#if FLAC__HAS_OGG
+ uint32_t unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
-#endif
} FLAC__StreamDecoderPrivate;
/***********************************************************************
@@ -251,7 +241,7 @@
FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
{
FLAC__StreamDecoder *decoder;
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
@@ -313,7 +303,7 @@
FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
{
- unsigned i;
+ uint32_t i;
if (decoder == NULL)
return ;
@@ -362,10 +352,8 @@
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
-#if !FLAC__HAS_OGG
- if(is_ogg)
+ if(FLAC__HAS_OGG == 0 && is_ogg)
return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
-#endif
if(
0 == read_callback ||
@@ -396,7 +384,7 @@
FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
#ifdef FLAC__HAS_NASM
decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide_asm_ia32; /* OPT_IA32: was really necessary for GCC < 4.9 */
- if(decoder->private_->cpuinfo.ia32.mmx) {
+ if (decoder->private_->cpuinfo.x86.mmx) {
decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
}
@@ -405,14 +393,13 @@
decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
}
#endif
-#ifdef FLAC__HAS_X86INTRIN
-# if defined FLAC__SSE2_SUPPORTED && !defined FLAC__HAS_NASM /* OPT_SSE: not better than MMX asm */
- if(decoder->private_->cpuinfo.ia32.sse2) {
- decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_16_intrin_sse2;
- }
-# endif
+#if FLAC__HAS_X86INTRIN && ! defined FLAC__INTEGER_ONLY_LIBRARY
# if defined FLAC__SSE4_1_SUPPORTED
- if(decoder->private_->cpuinfo.ia32.sse41) {
+ if (decoder->private_->cpuinfo.x86.sse41) {
+# if !defined FLAC__HAS_NASM /* these are not undoubtedly faster than their MMX ASM counterparts */
+ decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_intrin_sse41;
+ decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_16_intrin_sse41;
+# endif
decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide_intrin_sse41;
}
# endif
@@ -641,7 +628,7 @@
FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
{
FLAC__bool md5_failed = false;
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
@@ -655,18 +642,17 @@
*/
FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
- if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
- free(decoder->private_->seek_table.data.seek_table.points);
- decoder->private_->seek_table.data.seek_table.points = 0;
- decoder->private_->has_seek_table = false;
- }
+ free(decoder->private_->seek_table.data.seek_table.points);
+ decoder->private_->seek_table.data.seek_table.points = 0;
+ decoder->private_->has_seek_table = false;
+
FLAC__bitreader_free(decoder->private_->input);
for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
/* WATCHOUT:
- * FLAC__lpc_restore_signal_asm_ia32_mmx() requires that the
- * output arrays have a buffer of up to 3 zeroes in front
- * (at negative indices) for alignment purposes; we use 4
- * to keep the data well-aligned.
+ * FLAC__lpc_restore_signal_asm_ia32_mmx() and ..._intrin_sseN()
+ * require that the output arrays have a buffer of up to 3 zeroes
+ * in front (at negative indices) for alignment purposes;
+ * we use 4 to keep the data well-aligned.
*/
if(0 != decoder->private_->output[i]) {
free(decoder->private_->output[i]-4);
@@ -736,9 +722,9 @@
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_);
- FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
+ FLAC__ASSERT((uint32_t)type <= FLAC__MAX_METADATA_TYPE_CODE);
/* double protection */
- if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
+ if((uint32_t)type > FLAC__MAX_METADATA_TYPE_CODE)
return false;
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return false;
@@ -778,7 +764,7 @@
FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
{
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_);
@@ -795,9 +781,9 @@
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_);
- FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
+ FLAC__ASSERT((uint32_t)type <= FLAC__MAX_METADATA_TYPE_CODE);
/* double protection */
- if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
+ if((uint32_t)type > FLAC__MAX_METADATA_TYPE_CODE)
return false;
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return false;
@@ -873,7 +859,7 @@
return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
}
-FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
+FLAC_API uint32_t FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->protected_);
@@ -887,7 +873,7 @@
return decoder->protected_->channel_assignment;
}
-FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
+FLAC_API uint32_t FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->protected_);
@@ -894,7 +880,7 @@
return decoder->protected_->bits_per_sample;
}
-FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
+FLAC_API uint32_t FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->protected_);
@@ -901,7 +887,7 @@
return decoder->protected_->sample_rate;
}
-FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
+FLAC_API uint32_t FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->protected_);
@@ -914,10 +900,9 @@
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != position);
-#if FLAC__HAS_OGG
- if(decoder->private_->is_ogg)
+ if(FLAC__HAS_OGG && decoder->private_->is_ogg)
return false;
-#endif
+
if(0 == decoder->private_->tell_callback)
return false;
if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
@@ -936,6 +921,9 @@
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_);
+ if(!decoder->private_->internal_reset_hack && decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
+ return false;
+
decoder->private_->samples_decoded = 0;
decoder->private_->do_md5_checking = false;
@@ -987,11 +975,11 @@
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
decoder->private_->has_stream_info = false;
- if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
- free(decoder->private_->seek_table.data.seek_table.points);
- decoder->private_->seek_table.data.seek_table.points = 0;
- decoder->private_->has_seek_table = false;
- }
+
+ free(decoder->private_->seek_table.data.seek_table.points);
+ decoder->private_->seek_table.data.seek_table.points = 0;
+ decoder->private_->has_seek_table = false;
+
decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
/*
* This goes in reset() and not flush() because according to the spec, a
@@ -1215,7 +1203,7 @@
*
***********************************************************************/
-unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
+uint32_t FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
@@ -1231,9 +1219,7 @@
void set_defaults_(FLAC__StreamDecoder *decoder)
{
-#if FLAC__HAS_OGG
decoder->private_->is_ogg = false;
-#endif
decoder->private_->read_callback = 0;
decoder->private_->seek_callback = 0;
decoder->private_->tell_callback = 0;
@@ -1266,9 +1252,6 @@
*/
#if defined _MSC_VER || defined __MINGW32__
_setmode(_fileno(stdin), _O_BINARY);
-#elif defined __CYGWIN__
- /* almost certainly not needed for any modern Cygwin, but let's be safe... */
- setmode(_fileno(stdin), _O_BINARY);
#elif defined __EMX__
setmode(fileno(stdin), O_BINARY);
#endif
@@ -1276,9 +1259,9 @@
return stdin;
}
-FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
+FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_t channels)
{
- unsigned i;
+ uint32_t i;
FLAC__int32 *tmp;
if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
@@ -1299,10 +1282,10 @@
for(i = 0; i < channels; i++) {
/* WATCHOUT:
- * FLAC__lpc_restore_signal_asm_ia32_mmx() requires that the
- * output arrays have a buffer of up to 3 zeroes in front
- * (at negative indices) for alignment purposes; we use 4
- * to keep the data well-aligned.
+ * FLAC__lpc_restore_signal_asm_ia32_mmx() and ..._intrin_sseN()
+ * require that the output arrays have a buffer of up to 3 zeroes
+ * 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/*)*/);
if(tmp == 0) {
@@ -1341,7 +1324,7 @@
FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
{
FLAC__uint32 x;
- unsigned i, id;
+ uint32_t i, id;
FLAC__bool first = true;
FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
@@ -1431,6 +1414,9 @@
decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
}
else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
+ /* just in case we already have a seek table, and reading the next one fails: */
+ decoder->private_->has_seek_table = false;
+
if(!read_metadata_seektable_(decoder, is_last, length))
return false;
@@ -1440,7 +1426,7 @@
}
else {
FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
- unsigned real_length = length;
+ uint32_t real_length = length;
FLAC__StreamMetadata block;
memset(&block, 0, sizeof(block));
@@ -1578,10 +1564,10 @@
return true;
}
-FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
+FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length)
{
FLAC__uint32 x;
- unsigned bits, used_bits = 0;
+ uint32_t bits, used_bits = 0;
FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
@@ -1649,7 +1635,7 @@
return true;
}
-FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
+FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length)
{
FLAC__uint32 i, x;
FLAC__uint64 xx;
@@ -1691,7 +1677,7 @@
return true;
}
-FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj, unsigned length)
+FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj, uint32_t length)
{
FLAC__uint32 i;
@@ -1728,12 +1714,22 @@
return false; /* read_callback_ sets the state for us */
/* read comments */
+ if (obj->num_comments > 100000) {
+ /* Possibly malicious file. */
+ obj->num_comments = 0;
+ 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)))) {
+ obj->num_comments = 0;
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
return false;
}
for (i = 0; i < obj->num_comments; i++) {
+ /* Initialize here just to make sure. */
+ obj->comments[i].length = 0;
+ obj->comments[i].entry = 0;
+
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
if (length < 4) {
obj->num_comments = i;
@@ -1741,12 +1737,12 @@
}
else
length -= 4;
- if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
+ if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length)) {
+ obj->num_comments = i;
return false; /* read_callback_ sets the state for us */
+ }
if (obj->comments[i].length > 0) {
if (length < obj->comments[i].length) {
- obj->comments[i].length = 0;
- obj->comments[i].entry = 0;
obj->num_comments = i;
goto skip;
}
@@ -1754,10 +1750,17 @@
length -= obj->comments[i].length;
if (0 == (obj->comments[i].entry = safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
+ obj->num_comments = i;
return false;
}
- if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
- return false; /* read_callback_ sets the state for us */
+ memset (obj->comments[i].entry, 0, obj->comments[i].length) ;
+ if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length)) {
+ /* Current i-th entry is bad, so we delete it. */
+ free (obj->comments[i].entry) ;
+ obj->comments[i].entry = NULL ;
+ obj->num_comments = i;
+ goto skip;
+ }
obj->comments[i].entry[obj->comments[i].length] = '\0';
}
else
@@ -1764,13 +1767,15 @@
obj->comments[i].entry = 0;
}
}
- else
- obj->comments = 0;
}
skip:
if (length > 0) {
- /* This will only happen on files with invalid data in comments */
+ /* length > 0 can only happen on files with invalid data in comments */
+ if(obj->num_comments < 1) {
+ free(obj->comments);
+ obj->comments = NULL;
+ }
if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
return false; /* read_callback_ sets the state for us */
}
@@ -1932,7 +1937,7 @@
FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
{
FLAC__uint32 x;
- unsigned i, skip;
+ uint32_t i, skip;
/* skip the version and flags bytes */
if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
@@ -2008,10 +2013,10 @@
FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
{
- unsigned channel;
- unsigned i;
+ uint32_t channel;
+ uint32_t i;
FLAC__int32 mid, side;
- unsigned frame_crc; /* the one we calculate from the input stream */
+ uint32_t frame_crc; /* the one we calculate from the input stream */
FLAC__uint32 x;
*got_a_frame = false;
@@ -2032,7 +2037,7 @@
/*
* first figure the correct bits-per-sample of the subframe
*/
- unsigned bps = decoder->private_->frame.header.bits_per_sample;
+ uint32_t bps = decoder->private_->frame.header.bits_per_sample;
switch(decoder->private_->frame.header.channel_assignment) {
case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
/* no adjustment needed */
@@ -2097,7 +2102,7 @@
#if 1
mid = decoder->private_->output[0][i];
side = decoder->private_->output[1][i];
- mid <<= 1;
+ mid = ((uint32_t) mid) << 1;
mid |= (side & 1); /* i.e. if 'side' is odd... */
decoder->private_->output[0][i] = (mid + side) >> 1;
decoder->private_->output[1][i] = (mid - side) >> 1;
@@ -2143,8 +2148,10 @@
/* write it */
if(do_full_decode) {
- if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
+ if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE) {
+ decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
return false;
+ }
}
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
@@ -2155,9 +2162,9 @@
{
FLAC__uint32 x;
FLAC__uint64 xx;
- unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
+ uint32_t i, blocksize_hint = 0, sample_rate_hint = 0;
FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
- unsigned raw_header_len;
+ uint32_t raw_header_len;
FLAC__bool is_unparseable = false;
FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
@@ -2292,7 +2299,7 @@
FLAC__ASSERT(0);
}
- x = (unsigned)(raw_header[3] >> 4);
+ x = (uint32_t)(raw_header[3] >> 4);
if(x & 8) {
decoder->private_->frame.header.channels = 2;
switch(x & 7) {
@@ -2311,11 +2318,11 @@
}
}
else {
- decoder->private_->frame.header.channels = (unsigned)x + 1;
+ decoder->private_->frame.header.channels = (uint32_t)x + 1;
decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
}
- switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
+ switch(x = (uint32_t)(raw_header[3] & 0x0e) >> 1) {
case 0:
if(decoder->private_->has_stream_info)
decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
@@ -2460,11 +2467,11 @@
return true;
}
-FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
+FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode)
{
FLAC__uint32 x;
FLAC__bool wasted_bits;
- unsigned i;
+ uint32_t i;
if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
return false; /* read_callback_ sets the state for us */
@@ -2473,10 +2480,12 @@
x &= 0xfe;
if(wasted_bits) {
- unsigned u;
+ uint32_t u;
if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
return false; /* read_callback_ sets the state for us */
decoder->private_->frame.subframes[channel].wasted_bits = u+1;
+ if (decoder->private_->frame.subframes[channel].wasted_bits >= bps)
+ return false;
bps -= decoder->private_->frame.subframes[channel].wasted_bits;
}
else
@@ -2523,18 +2532,20 @@
if(wasted_bits && do_full_decode) {
x = decoder->private_->frame.subframes[channel].wasted_bits;
- for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
- decoder->private_->output[channel][i] <<= x;
+ for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
+ uint32_t val = decoder->private_->output[channel][i];
+ decoder->private_->output[channel][i] = (val << x);
+ }
}
return true;
}
-FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
+FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode)
{
FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
FLAC__int32 x;
- unsigned i;
+ uint32_t i;
FLAC__int32 *output = decoder->private_->output[channel];
decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
@@ -2553,12 +2564,12 @@
return true;
}
-FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
+FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode)
{
FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
FLAC__int32 i32;
FLAC__uint32 u32;
- unsigned u;
+ uint32_t u;
decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
@@ -2581,6 +2592,11 @@
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
return false; /* read_callback_ sets the state for us */
+ if(decoder->private_->frame.header.blocksize >> u32 < order) {
+ send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
+ decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
+ return true;
+ }
subframe->entropy_coding_method.data.partitioned_rice.order = u32;
subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
break;
@@ -2610,12 +2626,12 @@
return true;
}
-FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
+FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode)
{
FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
FLAC__int32 i32;
FLAC__uint32 u32;
- unsigned u;
+ uint32_t u;
decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
@@ -2642,6 +2658,11 @@
/* read qlp shift */
if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
return false; /* read_callback_ sets the state for us */
+ if(i32 < 0) {
+ send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
+ decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
+ return true;
+ }
subframe->quantization_level = i32;
/* read quantized lp coefficiencts */
@@ -2660,6 +2681,11 @@
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
return false; /* read_callback_ sets the state for us */
+ if(decoder->private_->frame.header.blocksize >> u32 < order) {
+ send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
+ decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
+ return true;
+ }
subframe->entropy_coding_method.data.partitioned_rice.order = u32;
subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
break;
@@ -2683,9 +2709,6 @@
/* decode the subframe */
if(do_full_decode) {
memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
- /*@@@@@@ technically not pessimistic enough, should be more like
- if( (FLAC__uint64)order * ((((FLAC__uint64)1)<<bps)-1) * ((1<<subframe->qlp_coeff_precision)-1) < (((FLAC__uint64)-1) << 32) )
- */
if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
if(bps <= 16 && subframe->qlp_coeff_precision <= 16)
decoder->private_->local_lpc_restore_signal_16bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
@@ -2698,11 +2721,11 @@
return true;
}
-FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
+FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode)
{
FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
FLAC__int32 x, *residual = decoder->private_->residual[channel];
- unsigned i;
+ uint32_t i;
decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
@@ -2721,33 +2744,18 @@
return true;
}
-FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended)
+FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_t predictor_order, uint32_t partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended)
{
FLAC__uint32 rice_parameter;
int i;
- unsigned partition, sample, u;
- const unsigned partitions = 1u << partition_order;
- const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
- const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
- const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
+ uint32_t partition, sample, u;
+ const uint32_t partitions = 1u << partition_order;
+ const uint32_t partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
+ const uint32_t plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
+ const uint32_t pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
- /* sanity checks */
- if(partition_order == 0) {
- if(decoder->private_->frame.header.blocksize < predictor_order) {
- send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
- decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
- /* We have received a potentially malicious bit stream. All we can do is error out to avoid a heap overflow. */
- return false;
- }
- }
- else {
- if(partition_samples < predictor_order) {
- send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
- decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
- /* We have received a potentially malicious bit stream. All we can do is error out to avoid a heap overflow. */
- return false;
- }
- }
+ /* invalid predictor and partition orders mush be handled in the callers */
+ FLAC__ASSERT(partition_order > 0? partition_samples >= predictor_order : decoder->private_->frame.header.blocksize >= predictor_order);
if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, flac_max(6u, partition_order))) {
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
@@ -2935,12 +2943,12 @@
#endif
decoder->private_->last_frame = *frame; /* save the frame */
if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
- unsigned delta = (unsigned)(target_sample - this_frame_sample);
+ uint32_t delta = (uint32_t)(target_sample - this_frame_sample);
/* kick out of seek mode */
decoder->private_->is_seeking = false;
/* shift out the samples before target_sample */
if(delta > 0) {
- unsigned channel;
+ uint32_t channel;
const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
for(channel = 0; channel < frame->header.channels; channel++)
newbuffer[channel] = buffer[channel] + delta;
@@ -2986,16 +2994,16 @@
FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
FLAC__int64 pos = -1;
int i;
- unsigned approx_bytes_per_frame;
+ uint32_t approx_bytes_per_frame;
FLAC__bool first_seek = true;
const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
- const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
- const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
- const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
- const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
+ const uint32_t min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
+ const uint32_t max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
+ const uint32_t max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
+ const uint32_t min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
/* take these from the current frame in case they've changed mid-stream */
- unsigned channels = FLAC__stream_decoder_get_channels(decoder);
- unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
+ uint32_t channels = FLAC__stream_decoder_get_channels(decoder);
+ uint32_t bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
/* use values from stream info if we didn't decode a frame */
@@ -3014,7 +3022,7 @@
* min_blocksize might be zero.
*/
else if(min_blocksize == max_blocksize && min_blocksize > 0) {
- /* note there are no () around 'bps/8' to keep precision up since it's an integer calulation */
+ /* note there are no () around 'bps/8' to keep precision up since it's an integer calculation */
approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
}
else
@@ -3104,7 +3112,7 @@
return false;
}
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(target_sample - lower_bound_sample) / (FLAC__double)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(upper_bound - lower_bound)) - approx_bytes_per_frame;
+ pos = (FLAC__int64)lower_bound + (FLAC__int64)((double)(target_sample - lower_bound_sample) / (double)(upper_bound_sample - lower_bound_sample) * (double)(upper_bound - lower_bound)) - approx_bytes_per_frame;
#else
/* a little less accurate: */
if(upper_bound - lower_bound < 0xffffffff)
@@ -3131,7 +3139,8 @@
* FLAC__stream_decoder_process_single() to return false.
*/
decoder->private_->unparseable_frame_count = 0;
- if(!FLAC__stream_decoder_process_single(decoder)) {
+ if(!FLAC__stream_decoder_process_single(decoder) ||
+ decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) {
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
@@ -3175,7 +3184,7 @@
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
- approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
+ approx_bytes_per_frame = (uint32_t)(2 * (upper_bound - pos) / 3 + 16);
}
else { /* target_sample >= this_frame_sample + this frame's blocksize */
lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
@@ -3183,7 +3192,7 @@
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
- approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
+ approx_bytes_per_frame = (uint32_t)(2 * (lower_bound - pos) / 3 + 16);
}
}
@@ -3198,7 +3207,7 @@
FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
FLAC__bool did_a_seek;
- unsigned iteration = 0;
+ uint32_t iteration = 0;
/* In the first iterations, we will calculate the target byte position
* by the distance from the target sample to left_sample and
@@ -3205,7 +3214,7 @@
* right_sample (let's call it "proportional search"). After that, we
* will switch to binary search.
*/
- unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
+ uint32_t BINARY_SEARCH_AFTER_ITERATION = 2;
/* We will switch to a linear search once our current sample is less
* than this number of samples ahead of the target sample
@@ -3228,7 +3237,7 @@
}
else {
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
+ pos = (FLAC__uint64)((double)(target_sample - left_sample) / (double)(right_sample - left_sample) * (double)(right_pos - left_pos));
#else
/* a little less accurate: */
if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
@@ -3258,7 +3267,8 @@
did_a_seek = false;
decoder->private_->got_a_frame = false;
- if(!FLAC__stream_decoder_process_single(decoder)) {
+ if(!FLAC__stream_decoder_process_single(decoder) ||
+ decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) {
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
@@ -3386,4 +3396,9 @@
(void)client_data;
return feof(decoder->private_->file)? true : false;
+}
+
+void *get_client_data_from_decoder(FLAC__StreamDecoder *decoder)
+{
+ return decoder->private_->client_data;
}
--- a/sys/src/cmd/audio/libFLAC/stream_encoder.c
+++ b/sys/src/cmd/audio/libFLAC/stream_encoder.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -39,6 +39,10 @@
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcpy() */
#include <sys/types.h> /* for off_t */
+#ifdef _WIN32
+#include <windows.h> /* for GetFileType() */
+#include <io.h> /* for _get_osfhandle() */
+#endif
#include "share/compat.h"
#include "FLAC/assert.h"
#include "FLAC/stream_decoder.h"
@@ -79,14 +83,14 @@
typedef struct {
FLAC__int32 *data[FLAC__MAX_CHANNELS];
- unsigned size; /* of each data[] in samples */
- unsigned tail;
+ uint32_t size; /* of each data[] in samples */
+ uint32_t tail;
} verify_input_fifo;
typedef struct {
const FLAC__byte *data;
- unsigned capacity;
- unsigned bytes;
+ uint32_t capacity;
+ uint32_t bytes;
} verify_output;
typedef enum {
@@ -95,17 +99,17 @@
ENCODER_IN_AUDIO = 2
} EncoderStateHint;
-static struct CompressionLevels {
+static const struct CompressionLevels {
FLAC__bool do_mid_side_stereo;
FLAC__bool loose_mid_side_stereo;
- unsigned max_lpc_order;
- unsigned qlp_coeff_precision;
+ uint32_t max_lpc_order;
+ uint32_t qlp_coeff_precision;
FLAC__bool do_qlp_coeff_prec_search;
FLAC__bool do_escape_coding;
FLAC__bool do_exhaustive_model_search;
- unsigned min_residual_partition_order;
- unsigned max_residual_partition_order;
- unsigned rice_parameter_search_dist;
+ uint32_t min_residual_partition_order;
+ uint32_t max_residual_partition_order;
+ uint32_t rice_parameter_search_dist;
const char *apodization;
} compression_levels_[] = {
{ false, false, 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" },
@@ -129,9 +133,9 @@
static void set_defaults_(FLAC__StreamEncoder *encoder);
static void free_(FLAC__StreamEncoder *encoder);
-static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
-static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
-static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
+static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, uint32_t new_blocksize);
+static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, uint32_t samples, FLAC__bool is_last_block);
+static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, FLAC__bool is_last_block);
static void update_metadata_(const FLAC__StreamEncoder *encoder);
#if FLAC__HAS_OGG
static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
@@ -141,98 +145,98 @@
static FLAC__bool process_subframe_(
FLAC__StreamEncoder *encoder,
- unsigned min_partition_order,
- unsigned max_partition_order,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
const FLAC__FrameHeader *frame_header,
- unsigned subframe_bps,
+ uint32_t subframe_bps,
const FLAC__int32 integer_signal[],
FLAC__Subframe *subframe[2],
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
FLAC__int32 *residual[2],
- unsigned *best_subframe,
- unsigned *best_bits
+ uint32_t *best_subframe,
+ uint32_t *best_bits
);
static FLAC__bool add_subframe_(
FLAC__StreamEncoder *encoder,
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
const FLAC__Subframe *subframe,
FLAC__BitWriter *frame
);
-static unsigned evaluate_constant_subframe_(
+static uint32_t evaluate_constant_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal,
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
FLAC__Subframe *subframe
);
-static unsigned evaluate_fixed_subframe_(
+static uint32_t evaluate_fixed_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal[],
FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned raw_bits_per_partition[],
- unsigned blocksize,
- unsigned subframe_bps,
- unsigned order,
- unsigned rice_parameter,
- unsigned rice_parameter_limit,
- unsigned min_partition_order,
- unsigned max_partition_order,
+ uint32_t raw_bits_per_partition[],
+ uint32_t blocksize,
+ uint32_t subframe_bps,
+ uint32_t order,
+ uint32_t rice_parameter,
+ uint32_t rice_parameter_limit,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
FLAC__bool do_escape_coding,
- unsigned rice_parameter_search_dist,
+ uint32_t rice_parameter_search_dist,
FLAC__Subframe *subframe,
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
);
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-static unsigned evaluate_lpc_subframe_(
+static uint32_t evaluate_lpc_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal[],
FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned raw_bits_per_partition[],
+ uint32_t raw_bits_per_partition[],
const FLAC__real lp_coeff[],
- unsigned blocksize,
- unsigned subframe_bps,
- unsigned order,
- unsigned qlp_coeff_precision,
- unsigned rice_parameter,
- unsigned rice_parameter_limit,
- unsigned min_partition_order,
- unsigned max_partition_order,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
+ uint32_t order,
+ uint32_t qlp_coeff_precision,
+ uint32_t rice_parameter,
+ uint32_t rice_parameter_limit,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
FLAC__bool do_escape_coding,
- unsigned rice_parameter_search_dist,
+ uint32_t rice_parameter_search_dist,
FLAC__Subframe *subframe,
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
);
#endif
-static unsigned evaluate_verbatim_subframe_(
+static uint32_t evaluate_verbatim_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal[],
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
FLAC__Subframe *subframe
);
-static unsigned find_best_partition_order_(
+static uint32_t find_best_partition_order_(
struct FLAC__StreamEncoderPrivate *private_,
const FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned raw_bits_per_partition[],
- unsigned residual_samples,
- unsigned predictor_order,
- unsigned rice_parameter,
- unsigned rice_parameter_limit,
- unsigned min_partition_order,
- unsigned max_partition_order,
- unsigned bps,
+ uint32_t raw_bits_per_partition[],
+ uint32_t residual_samples,
+ uint32_t predictor_order,
+ uint32_t rice_parameter,
+ uint32_t rice_parameter_limit,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
+ uint32_t bps,
FLAC__bool do_escape_coding,
- unsigned rice_parameter_search_dist,
+ uint32_t rice_parameter_search_dist,
FLAC__EntropyCodingMethod *best_ecm
);
@@ -239,20 +243,20 @@
static void precompute_partition_info_sums_(
const FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned residual_samples,
- unsigned predictor_order,
- unsigned min_partition_order,
- unsigned max_partition_order,
- unsigned bps
+ uint32_t residual_samples,
+ uint32_t predictor_order,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
+ uint32_t bps
);
static void precompute_partition_info_escapes_(
const FLAC__int32 residual[],
- unsigned raw_bits_per_partition[],
- unsigned residual_samples,
- unsigned predictor_order,
- unsigned min_partition_order,
- unsigned max_partition_order
+ uint32_t raw_bits_per_partition[],
+ uint32_t residual_samples,
+ uint32_t predictor_order,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order
);
static FLAC__bool set_partitioned_rice_(
@@ -260,35 +264,35 @@
const FLAC__int32 residual[],
#endif
const FLAC__uint64 abs_residual_partition_sums[],
- const unsigned raw_bits_per_partition[],
- const unsigned residual_samples,
- const unsigned predictor_order,
- const unsigned suggested_rice_parameter,
- const unsigned rice_parameter_limit,
- const unsigned rice_parameter_search_dist,
- const unsigned partition_order,
+ const uint32_t raw_bits_per_partition[],
+ const uint32_t residual_samples,
+ const uint32_t predictor_order,
+ const uint32_t suggested_rice_parameter,
+ const uint32_t rice_parameter_limit,
+ const uint32_t rice_parameter_search_dist,
+ const uint32_t partition_order,
const FLAC__bool search_for_escapes,
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
- unsigned *bits
+ uint32_t *bits
);
-static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
+static uint32_t get_wasted_bits_(FLAC__int32 signal[], uint32_t samples);
/* verify-related routines: */
static void append_to_verify_fifo_(
verify_input_fifo *fifo,
const FLAC__int32 * const input[],
- unsigned input_offset,
- unsigned channels,
- unsigned wide_samples
+ uint32_t input_offset,
+ uint32_t channels,
+ uint32_t wide_samples
);
static void append_to_verify_fifo_interleaved_(
verify_input_fifo *fifo,
const FLAC__int32 input[],
- unsigned input_offset,
- unsigned channels,
- unsigned wide_samples
+ uint32_t input_offset,
+ uint32_t channels,
+ uint32_t wide_samples
);
static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
@@ -299,7 +303,7 @@
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, unsigned samples, unsigned current_frame, 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);
@@ -310,7 +314,7 @@
***********************************************************************/
typedef struct FLAC__StreamEncoderPrivate {
- unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
+ uint32_t input_capacity; /* current size (in samples) of the signal and residual buffers */
FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
#ifndef FLAC__INTEGER_ONLY_LIBRARY
@@ -319,8 +323,8 @@
FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
#endif
- unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
- unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
+ uint32_t subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
+ uint32_t subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
FLAC__int32 *residual_workspace_mid_side[2][2];
FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
@@ -331,45 +335,40 @@
FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
- unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
- unsigned best_subframe_mid_side[2];
- unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
- unsigned best_subframe_bits_mid_side[2];
+ uint32_t best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
+ uint32_t best_subframe_mid_side[2];
+ uint32_t best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
+ uint32_t best_subframe_bits_mid_side[2];
FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
- unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
+ uint32_t *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
FLAC__BitWriter *frame; /* the current frame being worked on */
- unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
- unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
+ uint32_t loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
+ uint32_t loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
FLAC__ChannelAssignment last_channel_assignment;
FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
- unsigned current_sample_number;
- unsigned current_frame_number;
+ uint32_t current_sample_number;
+ uint32_t current_frame_number;
FLAC__MD5Context md5context;
FLAC__CPUInfo cpuinfo;
- void (*local_precompute_partition_info_sums)(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps);
+ void (*local_precompute_partition_info_sums)(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);
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
- unsigned (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+ uint32_t (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+ uint32_t (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
#else
- unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
- unsigned (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+ uint32_t (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
+ uint32_t (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
- void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
- void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
- void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+ void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], uint32_t data_len, uint32_t lag, FLAC__real autoc[]);
+ void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
+ void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
+ void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]);
#endif
- FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
- FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
- FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
FLAC__bool disable_constant_subframes;
FLAC__bool disable_fixed_subframes;
FLAC__bool disable_verbatim_subframes;
-#if FLAC__HAS_OGG
FLAC__bool is_ogg;
-#endif
FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
FLAC__StreamEncoderSeekCallback seek_callback;
FLAC__StreamEncoderTellCallback tell_callback;
@@ -377,12 +376,12 @@
FLAC__StreamEncoderMetadataCallback metadata_callback;
FLAC__StreamEncoderProgressCallback progress_callback;
void *client_data;
- unsigned first_seekpoint_to_check;
+ uint32_t first_seekpoint_to_check;
FILE *file; /* only used when encoding to a file */
FLAC__uint64 bytes_written;
FLAC__uint64 samples_written;
- unsigned frames_written;
- unsigned total_frames_estimate;
+ uint32_t frames_written;
+ uint32_t total_frames_estimate;
/* unaligned (original) pointers to allocated data */
FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
FLAC__int32 *integer_signal_mid_side_unaligned[2];
@@ -395,7 +394,7 @@
FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
FLAC__uint64 *abs_residual_partition_sums_unaligned;
- unsigned *raw_bits_per_partition_unaligned;
+ uint32_t *raw_bits_per_partition_unaligned;
/*
* These fields have been moved here from private function local
* declarations merely to save stack space during encoding.
@@ -415,9 +414,9 @@
verify_output output;
struct {
FLAC__uint64 absolute_sample;
- unsigned frame_number;
- unsigned channel;
- unsigned sample;
+ uint32_t frame_number;
+ uint32_t channel;
+ uint32_t sample;
FLAC__int32 expected;
FLAC__int32 got;
} error_stats;
@@ -495,7 +494,7 @@
* WATCHOUT: some parts of the code assert that OVERREAD_ == 1 and there's
* not really any reason to change it.
*/
-static const unsigned OVERREAD_ = 1;
+static const uint32_t OVERREAD_ = 1;
/***********************************************************************
*
@@ -505,7 +504,7 @@
FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
{
FLAC__StreamEncoder *encoder;
- unsigned i;
+ uint32_t i;
FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
@@ -576,7 +575,7 @@
FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
{
- unsigned i;
+ uint32_t i;
if (encoder == NULL)
return ;
@@ -626,7 +625,7 @@
FLAC__bool is_ogg
)
{
- unsigned i;
+ uint32_t i;
FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
FLAC__ASSERT(0 != encoder);
@@ -634,10 +633,8 @@
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
-#if !FLAC__HAS_OGG
- if(is_ogg)
+ if(FLAC__HAS_OGG == 0 && 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;
@@ -653,7 +650,7 @@
encoder->protected_->loose_mid_side_stereo = false;
if(encoder->protected_->bits_per_sample >= 32)
- encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
+ encoder->protected_->do_mid_side_stereo = false; /* since we currently do 32-bit math, the side channel would have 33 bps and overflow */
if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
@@ -746,7 +743,7 @@
#if FLAC__HAS_OGG
/* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */
if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
- unsigned i1;
+ uint32_t i1;
for(i1 = 1; i1 < encoder->protected_->num_metadata_blocks; i1++) {
if(0 != encoder->protected_->metadata[i1] && encoder->protected_->metadata[i1]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
FLAC__StreamMetadata *vc = encoder->protected_->metadata[i1];
@@ -760,7 +757,7 @@
#endif
/* keep track of any SEEKTABLE block */
if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
- unsigned i2;
+ uint32_t i2;
for(i2 = 0; i2 < encoder->protected_->num_metadata_blocks; i2++) {
if(0 != encoder->protected_->metadata[i2] && encoder->protected_->metadata[i2]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
encoder->private_->seek_table = &encoder->protected_->metadata[i2]->data.seek_table;
@@ -853,7 +850,7 @@
encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
+ encoder->private_->loose_mid_side_stereo_frames = (uint32_t)((double)encoder->protected_->sample_rate * 0.4 / (double)encoder->protected_->blocksize + 0.5);
#else
/* 26214 is the approximate fixed-point equivalent to 0.4 (0.4 * 2^16) */
/* sample rate can be up to 655350 Hz, and thus use 20 bits, so we do the multiply÷ by hand */
@@ -861,7 +858,7 @@
FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
- encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
+ encoder->private_->loose_mid_side_stereo_frames = (uint32_t)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
#endif
if(encoder->private_->loose_mid_side_stereo_frames == 0)
encoder->private_->loose_mid_side_stereo_frames = 1;
@@ -869,10 +866,6 @@
encoder->private_->current_sample_number = 0;
encoder->private_->current_frame_number = 0;
- encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
- encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(flac_max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
- encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
-
/*
* get the CPU info and set the function pointers
*/
@@ -892,19 +885,49 @@
/* now override with asm where appropriate */
#ifndef FLAC__INTEGER_ONLY_LIBRARY
# ifndef FLAC__NO_ASM
+#if defined(FLAC__CPU_PPC64) && defined(FLAC__USE_VSX)
+#ifdef FLAC__HAS_TARGET_POWER8
+#ifdef FLAC__HAS_TARGET_POWER9
+ if (encoder->private_->cpuinfo.ppc.arch_3_00) {
+ if(encoder->protected_->max_lpc_order < 4)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_4;
+ else if(encoder->protected_->max_lpc_order < 8)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_8;
+ else if(encoder->protected_->max_lpc_order < 12)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_12;
+ else if(encoder->protected_->max_lpc_order < 16)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power9_vsx_lag_16;
+ else
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
+ } else
+#endif
+ if (encoder->private_->cpuinfo.ppc.arch_2_07) {
+ if(encoder->protected_->max_lpc_order < 4)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_4;
+ else if(encoder->protected_->max_lpc_order < 8)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_8;
+ else if(encoder->protected_->max_lpc_order < 12)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_12;
+ else if(encoder->protected_->max_lpc_order < 16)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_power8_vsx_lag_16;
+ else
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
+ }
+#endif
+#endif
if(encoder->private_->cpuinfo.use_asm) {
# ifdef FLAC__CPU_IA32
FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
# ifdef FLAC__HAS_NASM
- if(encoder->private_->cpuinfo.ia32.sse) {
+ if (encoder->private_->cpuinfo.x86.sse) {
if(encoder->protected_->max_lpc_order < 4)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4_old;
else if(encoder->protected_->max_lpc_order < 8)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8_old;
else if(encoder->protected_->max_lpc_order < 12)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12_old;
else if(encoder->protected_->max_lpc_order < 16)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_16;
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_16_old;
else
encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
}
@@ -912,7 +935,7 @@
encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
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.ia32.mmx) {
+ 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;
}
@@ -921,39 +944,53 @@
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
}
- if(encoder->private_->cpuinfo.ia32.mmx && encoder->private_->cpuinfo.ia32.cmov)
+ 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 */
-# ifdef FLAC__HAS_X86INTRIN
+# if FLAC__HAS_X86INTRIN
# if defined FLAC__SSE_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.sse) {
- if(encoder->protected_->max_lpc_order < 4)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4;
- else if(encoder->protected_->max_lpc_order < 8)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8;
- else if(encoder->protected_->max_lpc_order < 12)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12;
- else if(encoder->protected_->max_lpc_order < 16)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16;
- else
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
+ if (encoder->private_->cpuinfo.x86.sse) {
+ if (encoder->private_->cpuinfo.x86.sse42 || !encoder->private_->cpuinfo.x86.intel) { /* use new autocorrelation functions */
+ if(encoder->protected_->max_lpc_order < 4)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_new;
+ else if(encoder->protected_->max_lpc_order < 8)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_new;
+ else if(encoder->protected_->max_lpc_order < 12)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_new;
+ else if(encoder->protected_->max_lpc_order < 16)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_new;
+ else
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
+ }
+ else { /* use old autocorrelation functions */
+ if(encoder->protected_->max_lpc_order < 4)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_old;
+ else if(encoder->protected_->max_lpc_order < 8)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_old;
+ else if(encoder->protected_->max_lpc_order < 12)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_old;
+ else if(encoder->protected_->max_lpc_order < 16)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_old;
+ else
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
+ }
}
# endif
# ifdef FLAC__SSE2_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.sse2) {
+ if (encoder->private_->cpuinfo.x86.sse2) {
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2;
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2;
}
# endif
# ifdef FLAC__SSE4_1_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.sse41) {
+ if (encoder->private_->cpuinfo.x86.sse41) {
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41;
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41;
}
# endif
# ifdef FLAC__AVX2_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.avx2) {
+ if (encoder->private_->cpuinfo.x86.avx2) {
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2;
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2;
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2;
@@ -961,13 +998,13 @@
# endif
# ifdef FLAC__SSE2_SUPPORTED
- if (encoder->private_->cpuinfo.ia32.sse2) {
+ if (encoder->private_->cpuinfo.x86.sse2) {
encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_sse2;
encoder->private_->local_fixed_compute_best_predictor_wide = FLAC__fixed_compute_best_predictor_wide_intrin_sse2;
}
# endif
# ifdef FLAC__SSSE3_SUPPORTED
- if (encoder->private_->cpuinfo.ia32.ssse3) {
+ if (encoder->private_->cpuinfo.x86.ssse3) {
encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_ssse3;
encoder->private_->local_fixed_compute_best_predictor_wide = FLAC__fixed_compute_best_predictor_wide_intrin_ssse3;
}
@@ -975,16 +1012,28 @@
# endif /* FLAC__HAS_X86INTRIN */
# elif defined FLAC__CPU_X86_64
FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_X86_64);
-# ifdef FLAC__HAS_X86INTRIN
+# if FLAC__HAS_X86INTRIN
# ifdef FLAC__SSE_SUPPORTED
- if(encoder->protected_->max_lpc_order < 4)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4;
- else if(encoder->protected_->max_lpc_order < 8)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8;
- else if(encoder->protected_->max_lpc_order < 12)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12;
- else if(encoder->protected_->max_lpc_order < 16)
- encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16;
+ if(encoder->private_->cpuinfo.x86.sse42 || !encoder->private_->cpuinfo.x86.intel) { /* use new autocorrelation functions */
+ if(encoder->protected_->max_lpc_order < 4)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_new;
+ else if(encoder->protected_->max_lpc_order < 8)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_new;
+ else if(encoder->protected_->max_lpc_order < 12)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_new;
+ else if(encoder->protected_->max_lpc_order < 16)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_new;
+ }
+ else {
+ if(encoder->protected_->max_lpc_order < 4)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4_old;
+ else if(encoder->protected_->max_lpc_order < 8)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8_old;
+ else if(encoder->protected_->max_lpc_order < 12)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12_old;
+ else if(encoder->protected_->max_lpc_order < 16)
+ encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16_old;
+ }
# endif
# ifdef FLAC__SSE2_SUPPORTED
@@ -1018,19 +1067,19 @@
}
# endif /* !FLAC__NO_ASM */
#endif /* !FLAC__INTEGER_ONLY_LIBRARY */
-#if !defined FLAC__NO_ASM && defined FLAC__HAS_X86INTRIN
+#if !defined FLAC__NO_ASM && FLAC__HAS_X86INTRIN
if(encoder->private_->cpuinfo.use_asm) {
# if defined FLAC__CPU_IA32
# ifdef FLAC__SSE2_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.sse2)
+ if (encoder->private_->cpuinfo.x86.sse2)
encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_sse2;
# endif
# ifdef FLAC__SSSE3_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.ssse3)
+ if (encoder->private_->cpuinfo.x86.ssse3)
encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_ssse3;
# endif
# ifdef FLAC__AVX2_SUPPORTED
- if(encoder->private_->cpuinfo.ia32.avx2)
+ if (encoder->private_->cpuinfo.x86.avx2)
encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_avx2;
# endif
# elif defined FLAC__CPU_X86_64
@@ -1048,10 +1097,6 @@
# endif /* FLAC__CPU_... */
}
#endif /* !FLAC__NO_ASM && FLAC__HAS_X86INTRIN */
- /* finally override based on wide-ness if necessary */
- if(encoder->private_->use_wide_by_block) {
- encoder->private_->local_fixed_compute_best_predictor = encoder->private_->local_fixed_compute_best_predictor_wide;
- }
/* set state to OK; from here on, errors are fatal and we'll override the state then */
encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
@@ -1315,7 +1360,8 @@
* Windows can suffer quite badly from disk fragmentation. This can be
* reduced significantly by setting the output buffer size to be 10MB.
*/
- setvbuf(file, NULL, _IOFBF, 10*1024*1024);
+ if(GetFileType((HANDLE)_get_osfhandle(_fileno(file))) == FILE_TYPE_DISK)
+ setvbuf(file, NULL, _IOFBF, 10*1024*1024);
#endif
encoder->private_->file = file;
@@ -1340,10 +1386,10 @@
}
{
- unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
+ uint32_t blocksize = FLAC__stream_encoder_get_blocksize(encoder);
FLAC__ASSERT(blocksize != 0);
- encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
+ encoder->private_->total_frames_estimate = (uint32_t)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
}
return init_status;
@@ -1423,7 +1469,9 @@
{
FLAC__bool error = false;
- FLAC__ASSERT(0 != encoder);
+ if (encoder == NULL)
+ return false;
+
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
@@ -1539,7 +1587,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1550,7 +1598,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1561,7 +1609,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1572,7 +1620,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__bool ok = true;
FLAC__ASSERT(0 != encoder);
@@ -1605,7 +1653,7 @@
return ok;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1752,7 +1800,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1763,7 +1811,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1812,7 +1860,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1823,7 +1871,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1834,7 +1882,7 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, uint32_t value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1857,11 +1905,12 @@
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);
encoder->protected_->total_samples_estimate = value;
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
+FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, uint32_t num_blocks)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -1894,7 +1943,7 @@
}
/*
- * These three functions are not static, but not publically exposed in
+ * 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)
@@ -1960,7 +2009,7 @@
return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
}
-FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
+FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2003,7 +2052,7 @@
return encoder->protected_->do_md5;
}
-FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2011,7 +2060,7 @@
return encoder->protected_->channels;
}
-FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2019,7 +2068,7 @@
return encoder->protected_->bits_per_sample;
}
-FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2027,7 +2076,7 @@
return encoder->protected_->sample_rate;
}
-FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2051,7 +2100,7 @@
return encoder->protected_->loose_mid_side_stereo;
}
-FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2059,7 +2108,7 @@
return encoder->protected_->max_lpc_order;
}
-FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2091,7 +2140,7 @@
return encoder->protected_->do_exhaustive_model_search;
}
-FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2099,7 +2148,7 @@
return encoder->protected_->min_residual_partition_order;
}
-FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2107,7 +2156,7 @@
return encoder->protected_->max_residual_partition_order;
}
-FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
+FLAC_API uint32_t FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2123,10 +2172,10 @@
return encoder->protected_->total_samples_estimate;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
+FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], uint32_t samples)
{
- unsigned i, j = 0, channel;
- const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
+ uint32_t i, j = 0, channel;
+ const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2134,13 +2183,17 @@
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
do {
- const unsigned n = flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
+ const uint32_t n = flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
if(encoder->protected_->verify)
append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
- for(channel = 0; channel < channels; channel++)
+ for(channel = 0; channel < channels; channel++) {
+ if (buffer[channel] == NULL) {
+ return false;
+ }
memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
+ }
if(encoder->protected_->do_mid_side_stereo) {
FLAC__ASSERT(channels == 2);
@@ -2175,11 +2228,11 @@
return true;
}
-FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
+FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], uint32_t samples)
{
- unsigned i, j, k, channel;
+ uint32_t i, j, k, channel;
FLAC__int32 x, mid, side;
- const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
+ const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
@@ -2301,9 +2354,7 @@
encoder->private_->disable_constant_subframes = false;
encoder->private_->disable_fixed_subframes = false;
encoder->private_->disable_verbatim_subframes = false;
-#if FLAC__HAS_OGG
encoder->private_->is_ogg = false;
-#endif
encoder->private_->read_callback = 0;
encoder->private_->write_callback = 0;
encoder->private_->seek_callback = 0;
@@ -2321,7 +2372,7 @@
void free_(FLAC__StreamEncoder *encoder)
{
- unsigned i, channel;
+ uint32_t i, channel;
FLAC__ASSERT(0 != encoder);
if(encoder->protected_->metadata) {
@@ -2400,10 +2451,10 @@
FLAC__bitwriter_free(encoder->private_->frame);
}
-FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
+FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, uint32_t new_blocksize)
{
FLAC__bool ok;
- unsigned i, channel;
+ uint32_t i, channel;
FLAC__ASSERT(new_blocksize > 0);
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
@@ -2540,7 +2591,7 @@
return ok;
}
-FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
+FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, uint32_t samples, FLAC__bool is_last_block)
{
const FLAC__byte *buffer;
size_t bytes;
@@ -2587,7 +2638,7 @@
return true;
}
-FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
+FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, FLAC__bool is_last_block)
{
FLAC__StreamEncoderWriteStatus status;
FLAC__uint64 output_position = 0;
@@ -2619,11 +2670,11 @@
* frame yet)
*/
if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
- const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
+ const uint32_t blocksize = FLAC__stream_encoder_get_blocksize(encoder);
const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
FLAC__uint64 test_sample;
- unsigned i;
+ uint32_t i;
for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
test_sample = encoder->private_->seek_table->points[i].sample_number;
if(test_sample > frame_last_sample) {
@@ -2686,9 +2737,9 @@
FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
- const unsigned min_framesize = metadata->data.stream_info.min_framesize;
- const unsigned max_framesize = metadata->data.stream_info.max_framesize;
- const unsigned bps = metadata->data.stream_info.bits_per_sample;
+ const uint32_t min_framesize = metadata->data.stream_info.min_framesize;
+ const uint32_t max_framesize = metadata->data.stream_info.max_framesize;
+ const uint32_t bps = metadata->data.stream_info.bits_per_sample;
FLAC__StreamEncoderSeekStatus seek_status;
FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
@@ -2702,7 +2753,7 @@
* Write MD5 signature
*/
{
- const unsigned md5_offset =
+ const uint32_t md5_offset =
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
@@ -2730,7 +2781,7 @@
* Write total samples
*/
{
- const unsigned total_samples_byte_offset =
+ const uint32_t total_samples_byte_offset =
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
@@ -2763,7 +2814,7 @@
* Write min/max framesize
*/
{
- const unsigned min_framesize_offset =
+ const uint32_t min_framesize_offset =
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
@@ -2791,7 +2842,7 @@
* Write seektable
*/
if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
- unsigned i;
+ uint32_t i;
FLAC__format_seektable_sort(encoder->private_->seek_table);
@@ -2805,7 +2856,7 @@
for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
FLAC__uint64 xx;
- unsigned x;
+ uint32_t x;
xx = encoder->private_->seek_table->points[i].sample_number;
b[7] = (FLAC__byte)xx; xx >>= 8;
b[6] = (FLAC__byte)xx; xx >>= 8;
@@ -2840,7 +2891,7 @@
void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
{
/* the # of bytes in the 1st packet that precede the STREAMINFO */
- static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
+ static const uint32_t FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
FLAC__OGG_MAPPING_MAGIC_LENGTH +
FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
@@ -2851,8 +2902,8 @@
FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
- const unsigned min_framesize = metadata->data.stream_info.min_framesize;
- const unsigned max_framesize = metadata->data.stream_info.max_framesize;
+ const uint32_t min_framesize = metadata->data.stream_info.min_framesize;
+ const uint32_t max_framesize = metadata->data.stream_info.max_framesize;
ogg_page page;
FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
@@ -2882,7 +2933,7 @@
* Write MD5 signature
*/
{
- const unsigned md5_offset =
+ const uint32_t md5_offset =
FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
@@ -2896,7 +2947,7 @@
FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
) / 8;
- if(md5_offset + 16 > (unsigned)page.body_len) {
+ if(md5_offset + 16 > (uint32_t)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
@@ -2908,7 +2959,7 @@
* Write total samples
*/
{
- const unsigned total_samples_byte_offset =
+ const uint32_t total_samples_byte_offset =
FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
@@ -2922,7 +2973,7 @@
- 4
) / 8;
- if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
+ if(total_samples_byte_offset + 5 > (uint32_t)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
@@ -2940,7 +2991,7 @@
* Write min/max framesize
*/
{
- const unsigned min_framesize_offset =
+ const uint32_t min_framesize_offset =
FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
@@ -2948,7 +2999,7 @@
FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
) / 8;
- if(min_framesize_offset + 6 > (unsigned)page.body_len) {
+ if(min_framesize_offset + 6 > (uint32_t)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
@@ -2971,7 +3022,7 @@
* Write seektable
*/
if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
- unsigned i;
+ uint32_t i;
FLAC__byte *p;
FLAC__format_seektable_sort(encoder->private_->seek_table);
@@ -2984,7 +3035,7 @@
return; /* state already set */
}
- if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
+ if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (uint32_t)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
@@ -2992,7 +3043,7 @@
for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
FLAC__uint64 xx;
- unsigned x;
+ uint32_t x;
xx = encoder->private_->seek_table->points[i].sample_number;
b[7] = (FLAC__byte)xx; xx >>= 8;
b[6] = (FLAC__byte)xx; xx >>= 8;
@@ -3088,7 +3139,7 @@
FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
{
FLAC__FrameHeader frame_header;
- unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
+ uint32_t channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
FLAC__bool do_independent, do_mid_side;
/*
@@ -3145,7 +3196,10 @@
*/
if(do_independent) {
for(channel = 0; channel < encoder->protected_->channels; channel++) {
- const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
+ uint32_t w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
+ if (w > encoder->protected_->bits_per_sample) {
+ w = encoder->protected_->bits_per_sample;
+ }
encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
}
@@ -3153,7 +3207,10 @@
if(do_mid_side) {
FLAC__ASSERT(encoder->protected_->channels == 2);
for(channel = 0; channel < 2; channel++) {
- const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
+ uint32_t w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
+ if (w > encoder->protected_->bits_per_sample) {
+ w = encoder->protected_->bits_per_sample;
+ }
encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
}
@@ -3213,7 +3270,7 @@
* Compose the frame bitbuffer
*/
if(do_mid_side) {
- unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
+ uint32_t left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
FLAC__ChannelAssignment channel_assignment;
@@ -3223,8 +3280,8 @@
channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
}
else {
- unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
- unsigned min_bits;
+ uint32_t bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
+ uint32_t min_bits;
int ca;
FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
@@ -3331,36 +3388,36 @@
FLAC__bool process_subframe_(
FLAC__StreamEncoder *encoder,
- unsigned min_partition_order,
- unsigned max_partition_order,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
const FLAC__FrameHeader *frame_header,
- unsigned subframe_bps,
+ uint32_t subframe_bps,
const FLAC__int32 integer_signal[],
FLAC__Subframe *subframe[2],
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
FLAC__int32 *residual[2],
- unsigned *best_subframe,
- unsigned *best_bits
+ uint32_t *best_subframe,
+ uint32_t *best_bits
)
{
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
+ float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
#else
FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- FLAC__double lpc_residual_bits_per_sample;
+ double lpc_residual_bits_per_sample;
FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is important even though encoder->protected_->max_lpc_order might be less; some asm and x86 intrinsic routines need all the space */
- FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
- unsigned min_lpc_order, max_lpc_order, lpc_order;
- unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
+ double lpc_error[FLAC__MAX_LPC_ORDER];
+ uint32_t min_lpc_order, max_lpc_order, lpc_order;
+ uint32_t min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
#endif
- unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
- unsigned rice_parameter;
- unsigned _candidate_bits, _best_bits;
- unsigned _best_subframe;
+ uint32_t min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
+ uint32_t rice_parameter;
+ uint32_t _candidate_bits, _best_bits;
+ uint32_t _best_subframe;
/* only use RICE2 partitions if stream bps > 16 */
- const unsigned rice_parameter_limit = FLAC__stream_encoder_get_bits_per_sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
+ const uint32_t rice_parameter_limit = FLAC__stream_encoder_get_bits_per_sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
FLAC__ASSERT(frame_header->blocksize > 0);
@@ -3372,8 +3429,11 @@
_best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
- unsigned signal_is_constant = false;
- guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
+ uint32_t signal_is_constant = false;
+ if(subframe_bps + 4 + FLAC__bitmath_ilog2((frame_header->blocksize-FLAC__MAX_FIXED_ORDER)|1) <= 32)
+ guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
+ else
+ guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor_wide(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
/* check for constant subframe */
if(
!encoder->private_->disable_constant_subframes &&
@@ -3384,7 +3444,7 @@
#endif
) {
/* the above means it's possible all samples are the same value; now double-check it: */
- unsigned i;
+ uint32_t i;
signal_is_constant = true;
for(i = 1; i < frame_header->blocksize; i++) {
if(integer_signal[0] != integer_signal[i]) {
@@ -3414,17 +3474,17 @@
max_fixed_order = frame_header->blocksize - 1;
for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
#ifndef FLAC__INTEGER_ONLY_LIBRARY
- if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
+ if(fixed_residual_bits_per_sample[fixed_order] >= (float)subframe_bps)
continue; /* don't even try */
- rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
+ rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (uint32_t)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
#else
if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
continue; /* don't even try */
- rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (unsigned)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
+ rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (uint32_t)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
#endif
- rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
+ rice_parameter++; /* to account for the signed->uint32_t conversion during rice coding */
if(rice_parameter >= rice_parameter_limit) {
-#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
#endif
rice_parameter = rice_parameter_limit - 1;
@@ -3463,7 +3523,7 @@
else
max_lpc_order = encoder->protected_->max_lpc_order;
if(max_lpc_order > 0) {
- unsigned a;
+ uint32_t a;
for (a = 0; a < encoder->protected_->num_apodizations; a++) {
FLAC__lpc_window_data(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+1, autoc);
@@ -3474,7 +3534,7 @@
min_lpc_order = 1;
}
else {
- const unsigned guess_lpc_order =
+ const uint32_t guess_lpc_order =
FLAC__lpc_compute_best_order(
lpc_error,
max_lpc_order,
@@ -3491,12 +3551,12 @@
max_lpc_order = frame_header->blocksize - 1;
for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
- if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
+ if(lpc_residual_bits_per_sample >= (double)subframe_bps)
continue; /* don't even try */
- rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
- rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
+ rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (uint32_t)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
+ rice_parameter++; /* to account for the signed->uint32_t conversion during rice coding */
if(rice_parameter >= rice_parameter_limit) {
-#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
#endif
rice_parameter = rice_parameter_limit - 1;
@@ -3503,8 +3563,8 @@
}
if(encoder->protected_->do_qlp_coeff_prec_search) {
min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
- /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps streams */
- if(subframe_bps <= 16) {
+ /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps(+1bps for side channel) streams */
+ if(subframe_bps <= 17) {
max_qlp_coeff_precision = flac_min(32 - subframe_bps - FLAC__bitmath_ilog2(lpc_order), FLAC__MAX_QLP_COEFF_PRECISION);
max_qlp_coeff_precision = flac_max(max_qlp_coeff_precision, min_qlp_coeff_precision);
}
@@ -3566,8 +3626,8 @@
FLAC__bool add_subframe_(
FLAC__StreamEncoder *encoder,
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
const FLAC__Subframe *subframe,
FLAC__BitWriter *frame
)
@@ -3608,10 +3668,10 @@
#if SPOTCHECK_ESTIMATE
static void spotcheck_subframe_estimate_(
FLAC__StreamEncoder *encoder,
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
const FLAC__Subframe *subframe,
- unsigned estimate
+ uint32_t estimate
)
{
FLAC__bool ret;
@@ -3627,7 +3687,7 @@
ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
FLAC__ASSERT(ret);
{
- const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
+ const uint32_t actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
if(estimate != actual)
fprintf(stderr, "EST: bad, frame#%u sub#%%d type=%8s est=%u, actual=%u, delta=%d\n", encoder->private_->current_frame_number, FLAC__SubframeTypeString[subframe->type], estimate, actual, (int)actual-(int)estimate);
}
@@ -3635,15 +3695,15 @@
}
#endif
-unsigned evaluate_constant_subframe_(
+uint32_t evaluate_constant_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal,
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
FLAC__Subframe *subframe
)
{
- unsigned estimate;
+ uint32_t estimate;
subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
subframe->data.constant.value = signal;
@@ -3658,27 +3718,27 @@
return estimate;
}
-unsigned evaluate_fixed_subframe_(
+uint32_t evaluate_fixed_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal[],
FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned raw_bits_per_partition[],
- unsigned blocksize,
- unsigned subframe_bps,
- unsigned order,
- unsigned rice_parameter,
- unsigned rice_parameter_limit,
- unsigned min_partition_order,
- unsigned max_partition_order,
+ uint32_t raw_bits_per_partition[],
+ uint32_t blocksize,
+ uint32_t subframe_bps,
+ uint32_t order,
+ uint32_t rice_parameter,
+ uint32_t rice_parameter_limit,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
FLAC__bool do_escape_coding,
- unsigned rice_parameter_search_dist,
+ uint32_t rice_parameter_search_dist,
FLAC__Subframe *subframe,
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
)
{
- unsigned i, residual_bits, estimate;
- const unsigned residual_samples = blocksize - order;
+ uint32_t i, residual_bits, estimate;
+ const uint32_t residual_samples = blocksize - order;
FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
@@ -3720,34 +3780,34 @@
}
#ifndef FLAC__INTEGER_ONLY_LIBRARY
-unsigned evaluate_lpc_subframe_(
+uint32_t evaluate_lpc_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal[],
FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned raw_bits_per_partition[],
+ uint32_t raw_bits_per_partition[],
const FLAC__real lp_coeff[],
- unsigned blocksize,
- unsigned subframe_bps,
- unsigned order,
- unsigned qlp_coeff_precision,
- unsigned rice_parameter,
- unsigned rice_parameter_limit,
- unsigned min_partition_order,
- unsigned max_partition_order,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
+ uint32_t order,
+ uint32_t qlp_coeff_precision,
+ uint32_t rice_parameter,
+ uint32_t rice_parameter_limit,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
FLAC__bool do_escape_coding,
- unsigned rice_parameter_search_dist,
+ uint32_t rice_parameter_search_dist,
FLAC__Subframe *subframe,
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
)
{
FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER]; /* WATCHOUT: the size is important; some x86 intrinsic routines need more than lpc order elements */
- unsigned i, residual_bits, estimate;
+ uint32_t i, residual_bits, estimate;
int quantization, ret;
- const unsigned residual_samples = blocksize - order;
+ const uint32_t residual_samples = blocksize - order;
- /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps streams */
- if(subframe_bps <= 16) {
+ /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps(+1bps for side channel) streams */
+ if(subframe_bps <= 17) {
FLAC__ASSERT(order > 0);
FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
qlp_coeff_precision = flac_min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
@@ -3806,15 +3866,15 @@
}
#endif
-unsigned evaluate_verbatim_subframe_(
+uint32_t evaluate_verbatim_subframe_(
FLAC__StreamEncoder *encoder,
const FLAC__int32 signal[],
- unsigned blocksize,
- unsigned subframe_bps,
+ uint32_t blocksize,
+ uint32_t subframe_bps,
FLAC__Subframe *subframe
)
{
- unsigned estimate;
+ uint32_t estimate;
subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
@@ -3831,27 +3891,27 @@
return estimate;
}
-unsigned find_best_partition_order_(
+uint32_t find_best_partition_order_(
FLAC__StreamEncoderPrivate *private_,
const FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned raw_bits_per_partition[],
- unsigned residual_samples,
- unsigned predictor_order,
- unsigned rice_parameter,
- unsigned rice_parameter_limit,
- unsigned min_partition_order,
- unsigned max_partition_order,
- unsigned bps,
+ uint32_t raw_bits_per_partition[],
+ uint32_t residual_samples,
+ uint32_t predictor_order,
+ uint32_t rice_parameter,
+ uint32_t rice_parameter_limit,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
+ uint32_t bps,
FLAC__bool do_escape_coding,
- unsigned rice_parameter_search_dist,
+ uint32_t rice_parameter_search_dist,
FLAC__EntropyCodingMethod *best_ecm
)
{
- unsigned residual_bits, best_residual_bits = 0;
- unsigned best_parameters_index = 0;
- unsigned best_partition_order = 0;
- const unsigned blocksize = residual_samples + predictor_order;
+ uint32_t residual_bits, best_residual_bits = 0;
+ uint32_t best_parameters_index = 0;
+ uint32_t best_partition_order = 0;
+ const uint32_t blocksize = residual_samples + predictor_order;
max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
min_partition_order = flac_min(min_partition_order, max_partition_order);
@@ -3863,7 +3923,7 @@
{
int partition_order;
- unsigned sum;
+ uint32_t sum;
for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
if(!
@@ -3878,7 +3938,7 @@
rice_parameter,
rice_parameter_limit,
rice_parameter_search_dist,
- (unsigned)partition_order,
+ (uint32_t)partition_order,
do_escape_coding,
&private_->partitioned_rice_contents_extra[!best_parameters_index],
&residual_bits
@@ -3905,13 +3965,13 @@
* knowledge; it is const to the outside world.
*/
FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
- unsigned partition;
+ uint32_t partition;
/* save best parameters and raw_bits */
FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, flac_max(6u, best_partition_order));
- memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
+ memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(uint32_t)*(1<<(best_partition_order)));
if(do_escape_coding)
- memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
+ memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(uint32_t)*(1<<(best_partition_order)));
/*
* Now need to check if the type should be changed to
* FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 based on the
@@ -3931,29 +3991,27 @@
void precompute_partition_info_sums_(
const FLAC__int32 residual[],
FLAC__uint64 abs_residual_partition_sums[],
- unsigned residual_samples,
- unsigned predictor_order,
- unsigned min_partition_order,
- unsigned max_partition_order,
- unsigned bps
+ uint32_t residual_samples,
+ uint32_t predictor_order,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order,
+ uint32_t bps
)
{
- const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
- unsigned partitions = 1u << max_partition_order;
+ 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 */
{
- unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
- /* WATCHOUT: "+ bps + FLAC__MAX_EXTRA_RESIDUAL_BPS" is the maximum
- * assumed size of the average residual magnitude */
- if(FLAC__bitmath_ilog2(default_partition_samples) + bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < 32) {
- FLAC__uint32 abs_residual_partition_sum;
-
+ const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples);
+ uint32_t partition, residual_sample, end = (uint32_t)(-(int)predictor_order);
+ /* WATCHOUT: "bps + FLAC__MAX_EXTRA_RESIDUAL_BPS" is the maximum assumed size of the average residual magnitude */
+ if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) {
for(partition = residual_sample = 0; partition < partitions; partition++) {
+ FLAC__uint32 abs_residual_partition_sum = 0;
end += default_partition_samples;
- abs_residual_partition_sum = 0;
for( ; residual_sample < end; residual_sample++)
abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
abs_residual_partition_sums[partition] = abs_residual_partition_sum;
@@ -3960,14 +4018,12 @@
}
}
else { /* have to pessimistically use 64 bits for accumulator */
- FLAC__uint64 abs_residual_partition_sum;
-
for(partition = residual_sample = 0; partition < partitions; partition++) {
+ FLAC__uint64 abs_residual_partition_sum64 = 0;
end += default_partition_samples;
- abs_residual_partition_sum = 0;
for( ; residual_sample < end; residual_sample++)
- abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
- abs_residual_partition_sums[partition] = abs_residual_partition_sum;
+ abs_residual_partition_sum64 += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
+ abs_residual_partition_sums[partition] = abs_residual_partition_sum64;
}
}
}
@@ -3974,10 +4030,10 @@
/* now merge partitions for lower orders */
{
- unsigned from_partition = 0, to_partition = partitions;
+ 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--) {
- unsigned i;
+ uint32_t i;
partitions >>= 1;
for(i = 0; i < partitions; i++) {
abs_residual_partition_sums[to_partition++] =
@@ -3991,24 +4047,24 @@
void precompute_partition_info_escapes_(
const FLAC__int32 residual[],
- unsigned raw_bits_per_partition[],
- unsigned residual_samples,
- unsigned predictor_order,
- unsigned min_partition_order,
- unsigned max_partition_order
+ uint32_t raw_bits_per_partition[],
+ uint32_t residual_samples,
+ uint32_t predictor_order,
+ uint32_t min_partition_order,
+ uint32_t max_partition_order
)
{
int partition_order;
- unsigned from_partition, to_partition = 0;
- const unsigned blocksize = residual_samples + predictor_order;
+ uint32_t from_partition, to_partition = 0;
+ const uint32_t blocksize = residual_samples + predictor_order;
/* first do max_partition_order */
for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
FLAC__int32 r;
FLAC__uint32 rmax;
- unsigned partition, partition_sample, partition_samples, residual_sample;
- const unsigned partitions = 1u << partition_order;
- const unsigned default_partition_samples = blocksize >> partition_order;
+ uint32_t partition, partition_sample, partition_samples, residual_sample;
+ const uint32_t partitions = 1u << partition_order;
+ const uint32_t default_partition_samples = blocksize >> partition_order;
FLAC__ASSERT(default_partition_samples > predictor_order);
@@ -4034,9 +4090,9 @@
/* now merge partitions for lower orders */
for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
- unsigned m;
- unsigned i;
- const unsigned partitions = 1u << partition_order;
+ uint32_t m;
+ uint32_t i;
+ const uint32_t partitions = 1u << partition_order;
for(i = 0; i < partitions; i++) {
m = raw_bits_per_partition[from_partition];
from_partition++;
@@ -4048,13 +4104,13 @@
}
#ifdef EXACT_RICE_BITS_CALCULATION
-static inline unsigned count_rice_bits_in_partition_(
- const unsigned rice_parameter,
- const unsigned partition_samples,
+static inline uint32_t count_rice_bits_in_partition_(
+ const uint32_t rice_parameter,
+ const uint32_t partition_samples,
const FLAC__int32 *residual
)
{
- unsigned i, partition_bits =
+ uint32_t i, partition_bits =
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 */
;
@@ -4063,9 +4119,9 @@
return partition_bits;
}
#else
-static inline unsigned count_rice_bits_in_partition_(
- const unsigned rice_parameter,
- const unsigned partition_samples,
+static inline uint32_t count_rice_bits_in_partition_(
+ const uint32_t rice_parameter,
+ const uint32_t partition_samples,
const FLAC__uint64 abs_residual_partition_sum
)
{
@@ -4074,8 +4130,8 @@
(1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
(
rice_parameter?
- (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
- : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
+ (uint32_t)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
+ : (uint32_t)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
)
- (partition_samples >> 1)
/* -(partition_samples>>1) to subtract out extra contributions to the abs_residual_partition_sum.
@@ -4093,24 +4149,24 @@
const FLAC__int32 residual[],
#endif
const FLAC__uint64 abs_residual_partition_sums[],
- const unsigned raw_bits_per_partition[],
- const unsigned residual_samples,
- const unsigned predictor_order,
- const unsigned suggested_rice_parameter,
- const unsigned rice_parameter_limit,
- const unsigned rice_parameter_search_dist,
- const unsigned partition_order,
+ const uint32_t raw_bits_per_partition[],
+ const uint32_t residual_samples,
+ const uint32_t predictor_order,
+ const uint32_t suggested_rice_parameter,
+ const uint32_t rice_parameter_limit,
+ const uint32_t rice_parameter_search_dist,
+ const uint32_t partition_order,
const FLAC__bool search_for_escapes,
FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
- unsigned *bits
+ uint32_t *bits
)
{
- unsigned rice_parameter, partition_bits;
- unsigned best_partition_bits, best_rice_parameter = 0;
- unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
- unsigned *parameters, *raw_bits;
+ uint32_t rice_parameter, partition_bits;
+ uint32_t best_partition_bits, best_rice_parameter = 0;
+ uint32_t bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
+ uint32_t *parameters, *raw_bits;
#ifdef ENABLE_RICE_PARAMETER_SEARCH
- unsigned min_rice_parameter, max_rice_parameter;
+ uint32_t min_rice_parameter, max_rice_parameter;
#else
(void)rice_parameter_search_dist;
#endif
@@ -4123,7 +4179,7 @@
raw_bits = partitioned_rice_contents->raw_bits;
if(partition_order == 0) {
- best_partition_bits = (unsigned)(-1);
+ best_partition_bits = (uint32_t)(-1);
#ifdef ENABLE_RICE_PARAMETER_SEARCH
if(rice_parameter_search_dist) {
if(suggested_rice_parameter < rice_parameter_search_dist)
@@ -4132,7 +4188,7 @@
min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
if(max_rice_parameter >= rice_parameter_limit) {
-#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
#endif
max_rice_parameter = rice_parameter_limit - 1;
@@ -4171,10 +4227,10 @@
bits_ += best_partition_bits;
}
else {
- unsigned partition, residual_sample;
- unsigned partition_samples;
+ uint32_t partition, residual_sample;
+ uint32_t partition_samples;
FLAC__uint64 mean, k;
- const unsigned partitions = 1u << partition_order;
+ const uint32_t partitions = 1u << partition_order;
for(partition = residual_sample = 0; partition < partitions; partition++) {
partition_samples = (residual_samples+predictor_order) >> partition_order;
if(partition == 0) {
@@ -4222,13 +4278,13 @@
}
#endif
if(rice_parameter >= rice_parameter_limit) {
-#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
#endif
rice_parameter = rice_parameter_limit - 1;
}
- best_partition_bits = (unsigned)(-1);
+ best_partition_bits = (uint32_t)(-1);
#ifdef ENABLE_RICE_PARAMETER_SEARCH
if(rice_parameter_search_dist) {
if(rice_parameter < rice_parameter_search_dist)
@@ -4237,7 +4293,7 @@
min_rice_parameter = rice_parameter - rice_parameter_search_dist;
max_rice_parameter = rice_parameter + rice_parameter_search_dist;
if(max_rice_parameter >= rice_parameter_limit) {
-#ifdef DEBUG_VERBOSE
+#ifndef NDEBUG
fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
#endif
max_rice_parameter = rice_parameter_limit - 1;
@@ -4280,9 +4336,9 @@
return true;
}
-unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
+uint32_t get_wasted_bits_(FLAC__int32 signal[], uint32_t samples)
{
- unsigned i, shift;
+ uint32_t i, shift;
FLAC__int32 x = 0;
for(i = 0; i < samples && !(x&1); i++)
@@ -4304,9 +4360,9 @@
return shift;
}
-void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
+void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], uint32_t input_offset, uint32_t channels, uint32_t wide_samples)
{
- unsigned channel;
+ uint32_t channel;
for(channel = 0; channel < channels; channel++)
memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
@@ -4316,11 +4372,11 @@
FLAC__ASSERT(fifo->tail <= fifo->size);
}
-void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
+void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], uint32_t input_offset, uint32_t channels, uint32_t wide_samples)
{
- unsigned channel;
- unsigned sample, wide_sample;
- unsigned tail = fifo->tail;
+ uint32_t channel;
+ uint32_t sample, wide_sample;
+ uint32_t tail = fifo->tail;
sample = input_offset * channels;
for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
@@ -4367,16 +4423,16 @@
FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
- unsigned channel;
- const unsigned channels = frame->header.channels;
- const unsigned blocksize = frame->header.blocksize;
- const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
+ uint32_t channel;
+ const uint32_t channels = frame->header.channels;
+ const uint32_t blocksize = frame->header.blocksize;
+ const uint32_t bytes_per_block = sizeof(FLAC__int32) * blocksize;
(void)decoder;
for(channel = 0; channel < channels; channel++) {
if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
- unsigned i, sample = 0;
+ uint32_t i, sample = 0;
FLAC__int32 expect = 0, got = 0;
for(i = 0; i < blocksize; i++) {
@@ -4390,7 +4446,7 @@
FLAC__ASSERT(i < blocksize);
FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
- encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
+ encoder->private_->verify.error_stats.frame_number = (uint32_t)(frame->header.number.sample_number / blocksize);
encoder->private_->verify.error_stats.channel = channel;
encoder->private_->verify.error_stats.sample = sample;
encoder->private_->verify.error_stats.expected = expect;
@@ -4472,7 +4528,7 @@
#define local__fwrite fwrite
#endif
-FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
+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)
{
(void)client_data, (void)current_frame;
@@ -4514,9 +4570,6 @@
*/
#if defined _MSC_VER || defined __MINGW32__
_setmode(_fileno(stdout), _O_BINARY);
-#elif defined __CYGWIN__
- /* almost certainly not needed for any modern Cygwin, but let's be safe... */
- setmode(_fileno(stdout), _O_BINARY);
#elif defined __EMX__
setmode(fileno(stdout), O_BINARY);
#endif
--- a/sys/src/cmd/audio/libFLAC/stream_encoder_framing.c
+++ b/sys/src/cmd/audio/libFLAC/stream_encoder_framing.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -39,14 +39,15 @@
#include "private/stream_encoder_framing.h"
#include "private/crc.h"
#include "FLAC/assert.h"
+#include "share/compat.h"
static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
-static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended);
+static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const uint32_t residual_samples, const uint32_t predictor_order, const uint32_t rice_parameters[], const uint32_t raw_bits[], const uint32_t partition_order, const FLAC__bool is_extended);
FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
{
- unsigned i, j;
- const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
+ uint32_t i, j;
+ const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING);
if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
return false;
@@ -64,6 +65,9 @@
i += vendor_string_length;
}
FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
+ /* double protection */
+ if(i >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
+ return false;
if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
return false;
@@ -92,6 +96,7 @@
FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
return false;
+ FLAC__ASSERT(metadata->data.stream_info.total_samples < (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN));
if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
return false;
if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
@@ -214,7 +219,7 @@
FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
{
- unsigned u, blocksize_hint, sample_rate_hint;
+ uint32_t u, blocksize_hint, sample_rate_hint;
FLAC__byte crc;
FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
@@ -359,7 +364,7 @@
return true;
}
-FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
+FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw)
{
FLAC__bool ok;
@@ -372,9 +377,9 @@
return ok;
}
-FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
+FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw)
{
- unsigned i;
+ uint32_t i;
if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK | (subframe->order<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
return false;
@@ -410,9 +415,9 @@
return true;
}
-FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
+FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw)
{
- unsigned i;
+ uint32_t i;
if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK | ((subframe->order-1)<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
return false;
@@ -456,9 +461,9 @@
return true;
}
-FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
+FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, uint32_t samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw)
{
- unsigned i;
+ uint32_t i;
const FLAC__int32 *signal = subframe->data;
if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
@@ -490,13 +495,13 @@
return true;
}
-FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended)
+FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const uint32_t residual_samples, const uint32_t predictor_order, const uint32_t rice_parameters[], const uint32_t raw_bits[], const uint32_t partition_order, const FLAC__bool is_extended)
{
- const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
- const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
+ const uint32_t plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
+ const uint32_t pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
if(partition_order == 0) {
- unsigned i;
+ uint32_t i;
if(raw_bits[0] == 0) {
if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
@@ -518,9 +523,9 @@
return true;
}
else {
- unsigned i, j, k = 0, k_last = 0;
- unsigned partition_samples;
- const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
+ uint32_t i, j, k = 0, k_last = 0;
+ uint32_t partition_samples;
+ const uint32_t default_partition_samples = (residual_samples+predictor_order) >> partition_order;
for(i = 0; i < (1u<<partition_order); i++) {
partition_samples = default_partition_samples;
if(i == 0)
--- a/sys/src/cmd/audio/libFLAC/window.c
+++ b/sys/src/cmd/audio/libFLAC/window.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2006-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * 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
@@ -109,7 +109,7 @@
FLAC__int32 n;
for (n = 0; n < L; n++)
- window[n] = (FLAC__real)(1.0f - 1.93f * cos(2.0f * M_PI * n / N) + 1.29f * cos(4.0f * M_PI * n / N) - 0.388f * cos(6.0f * M_PI * n / N) + 0.0322f * cos(8.0f * M_PI * n / N));
+ window[n] = (FLAC__real)(0.21557895f - 0.41663158f * cos(2.0f * M_PI * n / N) + 0.277263158f * cos(4.0f * M_PI * n / N) - 0.083578947f * cos(6.0f * M_PI * n / N) + 0.006947368f * cos(8.0f * M_PI * n / N));
}
void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)