mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
src/FLAC : Update from upstream CVS.
This commit is contained in:
parent
43d11aa41d
commit
d6bb65d967
@ -1,3 +1,8 @@
|
||||
2007-06-16 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/FLAC/*
|
||||
Update from upstream CVS.
|
||||
|
||||
2007-06-14 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* tests/cpp_test.cc
|
||||
|
@ -191,9 +191,13 @@ extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
|
||||
|
||||
/** An enumeration of the available entropy coding methods. */
|
||||
typedef enum {
|
||||
FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
|
||||
FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
|
||||
/**< Residual is coded by partitioning into contexts, each with it's own
|
||||
* Rice parameter. */
|
||||
* 4-bit Rice parameter. */
|
||||
|
||||
FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
|
||||
/**< Residual is coded by partitioning into contexts, each with it's own
|
||||
* 5-bit Rice parameter. */
|
||||
} FLAC__EntropyCodingMethodType;
|
||||
|
||||
/** Maps a FLAC__EntropyCodingMethodType to a C string.
|
||||
@ -212,7 +216,9 @@ typedef struct {
|
||||
/**< The Rice parameters for each context. */
|
||||
|
||||
unsigned *raw_bits;
|
||||
/**< Widths for escape-coded partitions. */
|
||||
/**< Widths for escape-coded partitions. Will be non-zero for escaped
|
||||
* partitions and zero for unescaped partitions.
|
||||
*/
|
||||
|
||||
unsigned capacity_by_order;
|
||||
/**< The capacity of the \a parameters and \a raw_bits arrays
|
||||
@ -235,10 +241,13 @@ typedef struct {
|
||||
|
||||
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 unsigned 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;
|
||||
/**< == (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>)
|
||||
*/
|
||||
@ -342,7 +351,14 @@ typedef struct {
|
||||
unsigned wasted_bits;
|
||||
} FLAC__Subframe;
|
||||
|
||||
extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN; /**< == 1 (bit) */
|
||||
/** == 1 (bit)
|
||||
*
|
||||
* This used to be a zero-padding bit (hence the name
|
||||
* FLAC__SUBFRAME_ZERO_PAD_LEN) but is now a reserved bit. It still has a
|
||||
* 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) */
|
||||
|
||||
@ -408,7 +424,9 @@ typedef struct {
|
||||
/**< The sample resolution. */
|
||||
|
||||
FLAC__FrameNumberType number_type;
|
||||
/**< The numbering scheme used for the frame. */
|
||||
/**< The numbering scheme used for the frame. As a convenience, the
|
||||
* decoder will always convert a frame number to a sample number because
|
||||
* the rules are complex. */
|
||||
|
||||
union {
|
||||
FLAC__uint32 frame_number;
|
||||
@ -426,7 +444,8 @@ typedef struct {
|
||||
|
||||
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; /**< == 2 (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) */
|
||||
|
@ -16,8 +16,8 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef FLAC__TEST_LIBFLAC_METADATA_UTILS_H
|
||||
#define FLAC__TEST_LIBFLAC_METADATA_UTILS_H
|
||||
#ifndef FLAC__TEST_LIBS_COMMON_METADATA_UTILS_H
|
||||
#define FLAC__TEST_LIBS_COMMON_METADATA_UTILS_H
|
||||
|
||||
/*
|
||||
* These are not tests, just utility functions used by the metadata tests
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for qsort() */
|
||||
#include <string.h> /* for memset() */
|
||||
#include "FLAC/assert.h"
|
||||
#include "FLAC/format.h"
|
||||
#include "private/format.h"
|
||||
@ -123,7 +124,8 @@ FLAC_API const unsigned 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 = 2; /* 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 */
|
||||
@ -136,12 +138,15 @@ FLAC_API const unsigned 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 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 char * const FLAC__EntropyCodingMethodTypeString[] = {
|
||||
"PARTITIONED_RICE"
|
||||
"PARTITIONED_RICE",
|
||||
"PARTITIONED_RICE2"
|
||||
};
|
||||
|
||||
FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
|
||||
@ -576,6 +581,7 @@ FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_s
|
||||
return false;
|
||||
if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
|
||||
return false;
|
||||
memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
|
||||
object->capacity_by_order = max_partition_order;
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,7 @@ typedef struct FLAC__StreamEncoderProtected {
|
||||
FLAC__StreamEncoderState state;
|
||||
FLAC__bool verify;
|
||||
FLAC__bool streamable_subset;
|
||||
FLAC__bool do_md5;
|
||||
FLAC__bool do_mid_side_stereo;
|
||||
FLAC__bool loose_mid_side_stereo;
|
||||
unsigned channels;
|
||||
|
@ -303,7 +303,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
#else /* fully unrolled version for normal use */
|
||||
{
|
||||
unsigned i;
|
||||
int i;
|
||||
FLAC__int32 sum;
|
||||
|
||||
FLAC__ASSERT(order > 0);
|
||||
@ -318,7 +318,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
if(order > 8) {
|
||||
if(order > 10) {
|
||||
if(order == 12) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[11] * data[i-12];
|
||||
sum += qlp_coeff[10] * data[i-11];
|
||||
@ -336,7 +336,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
}
|
||||
else { /* order == 11 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[10] * data[i-11];
|
||||
sum += qlp_coeff[9] * data[i-10];
|
||||
@ -355,7 +355,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
else {
|
||||
if(order == 10) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[9] * data[i-10];
|
||||
sum += qlp_coeff[8] * data[i-9];
|
||||
@ -371,7 +371,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
}
|
||||
else { /* order == 9 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[8] * data[i-9];
|
||||
sum += qlp_coeff[7] * data[i-8];
|
||||
@ -390,7 +390,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
else if(order > 4) {
|
||||
if(order > 6) {
|
||||
if(order == 8) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[7] * data[i-8];
|
||||
sum += qlp_coeff[6] * data[i-7];
|
||||
@ -404,7 +404,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
}
|
||||
else { /* order == 7 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[6] * data[i-7];
|
||||
sum += qlp_coeff[5] * data[i-6];
|
||||
@ -419,7 +419,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
else {
|
||||
if(order == 6) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[5] * data[i-6];
|
||||
sum += qlp_coeff[4] * data[i-5];
|
||||
@ -431,7 +431,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
}
|
||||
else { /* order == 5 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[4] * data[i-5];
|
||||
sum += qlp_coeff[3] * data[i-4];
|
||||
@ -446,7 +446,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
else {
|
||||
if(order > 2) {
|
||||
if(order == 4) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[3] * data[i-4];
|
||||
sum += qlp_coeff[2] * data[i-3];
|
||||
@ -456,7 +456,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
}
|
||||
else { /* order == 3 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[2] * data[i-3];
|
||||
sum += qlp_coeff[1] * data[i-2];
|
||||
@ -467,7 +467,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
else {
|
||||
if(order == 2) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[1] * data[i-2];
|
||||
sum += qlp_coeff[0] * data[i-1];
|
||||
@ -475,14 +475,14 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, u
|
||||
}
|
||||
}
|
||||
else { /* order == 1 */
|
||||
for(i = 0; i < data_len; i++)
|
||||
for(i = 0; i < (int)data_len; i++)
|
||||
residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* order > 12 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
switch(order) {
|
||||
case 32: sum += qlp_coeff[31] * data[i-32];
|
||||
@ -833,7 +833,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
#else /* fully unrolled version for normal use */
|
||||
{
|
||||
unsigned i;
|
||||
int i;
|
||||
FLAC__int32 sum;
|
||||
|
||||
FLAC__ASSERT(order > 0);
|
||||
@ -848,7 +848,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
if(order > 8) {
|
||||
if(order > 10) {
|
||||
if(order == 12) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[11] * data[i-12];
|
||||
sum += qlp_coeff[10] * data[i-11];
|
||||
@ -866,7 +866,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
}
|
||||
else { /* order == 11 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[10] * data[i-11];
|
||||
sum += qlp_coeff[9] * data[i-10];
|
||||
@ -885,7 +885,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
else {
|
||||
if(order == 10) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[9] * data[i-10];
|
||||
sum += qlp_coeff[8] * data[i-9];
|
||||
@ -901,7 +901,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
}
|
||||
else { /* order == 9 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[8] * data[i-9];
|
||||
sum += qlp_coeff[7] * data[i-8];
|
||||
@ -920,7 +920,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
else if(order > 4) {
|
||||
if(order > 6) {
|
||||
if(order == 8) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[7] * data[i-8];
|
||||
sum += qlp_coeff[6] * data[i-7];
|
||||
@ -934,7 +934,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
}
|
||||
else { /* order == 7 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[6] * data[i-7];
|
||||
sum += qlp_coeff[5] * data[i-6];
|
||||
@ -949,7 +949,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
else {
|
||||
if(order == 6) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[5] * data[i-6];
|
||||
sum += qlp_coeff[4] * data[i-5];
|
||||
@ -961,7 +961,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
}
|
||||
else { /* order == 5 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[4] * data[i-5];
|
||||
sum += qlp_coeff[3] * data[i-4];
|
||||
@ -976,7 +976,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
else {
|
||||
if(order > 2) {
|
||||
if(order == 4) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[3] * data[i-4];
|
||||
sum += qlp_coeff[2] * data[i-3];
|
||||
@ -986,7 +986,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
}
|
||||
else { /* order == 3 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[2] * data[i-3];
|
||||
sum += qlp_coeff[1] * data[i-2];
|
||||
@ -997,7 +997,7 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
else {
|
||||
if(order == 2) {
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
sum += qlp_coeff[1] * data[i-2];
|
||||
sum += qlp_coeff[0] * data[i-1];
|
||||
@ -1005,14 +1005,14 @@ void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, c
|
||||
}
|
||||
}
|
||||
else { /* order == 1 */
|
||||
for(i = 0; i < data_len; i++)
|
||||
for(i = 0; i < (int)data_len; i++)
|
||||
data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* order > 12 */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
for(i = 0; i < (int)data_len; i++) {
|
||||
sum = 0;
|
||||
switch(order) {
|
||||
case 32: sum += qlp_coeff[31] * data[i-32];
|
||||
|
@ -45,6 +45,16 @@ void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
|
||||
#ifdef FLAC__ALIGN_MALLOC_DATA
|
||||
/* align on 32-byte (256-bit) boundary */
|
||||
x = malloc(bytes+31);
|
||||
#ifdef SIZEOF_VOIDP
|
||||
#if SIZEOF_VOIDP == 4
|
||||
/* could do *aligned_address = x + ((unsigned) (32 - (((unsigned)x) & 31))) & 31; */
|
||||
*aligned_address = (void*)(((unsigned)x + 31) & -32);
|
||||
#elif SIZEOF_VOIDP == 8
|
||||
*aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
|
||||
#else
|
||||
# error Unsupported sizeof(void*)
|
||||
#endif
|
||||
#else
|
||||
/* there's got to be a better way to do this right for all archs */
|
||||
if(sizeof(void*) == sizeof(unsigned))
|
||||
*aligned_address = (void*)(((unsigned)x + 31) & -32);
|
||||
@ -52,6 +62,7 @@ void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
|
||||
*aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
#else
|
||||
x = malloc(bytes);
|
||||
*aligned_address = x;
|
||||
|
@ -121,7 +121,7 @@ static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned
|
||||
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);
|
||||
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_zero_padding_(FLAC__StreamDecoder *decoder);
|
||||
static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
|
||||
#if FLAC__HAS_OGG
|
||||
@ -174,8 +174,7 @@ typedef struct FLAC__StreamDecoderPrivate {
|
||||
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;
|
||||
FLAC__uint32 last_frame_number;
|
||||
FLAC__uint32 last_block_size;
|
||||
FLAC__uint32 fixed_block_size, next_fixed_block_size;
|
||||
FLAC__uint64 samples_decoded;
|
||||
FLAC__bool has_stream_info, has_seek_table;
|
||||
FLAC__StreamMetadata stream_info;
|
||||
@ -460,8 +459,7 @@ static FLAC__StreamDecoderInitStatus init_stream_internal_(
|
||||
decoder->private_->metadata_callback = metadata_callback;
|
||||
decoder->private_->error_callback = error_callback;
|
||||
decoder->private_->client_data = client_data;
|
||||
decoder->private_->last_frame_number = 0;
|
||||
decoder->private_->last_block_size = 0;
|
||||
decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
|
||||
decoder->private_->samples_decoded = 0;
|
||||
decoder->private_->has_stream_info = false;
|
||||
decoder->private_->cached = false;
|
||||
@ -969,8 +967,6 @@ FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
decoder->private_->last_frame_number = 0;
|
||||
decoder->private_->last_block_size = 0;
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||
|
||||
return true;
|
||||
@ -1016,6 +1012,11 @@ FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
|
||||
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
|
||||
* fixed-blocksize stream must stay that way through the whole stream.
|
||||
*/
|
||||
decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
|
||||
|
||||
/* We initialize the FLAC__MD5Context even though we may never use it. This
|
||||
* is because md5 checking may be turned on to start and then turned off if
|
||||
@ -2100,6 +2101,10 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
|
||||
|
||||
*got_a_frame = true;
|
||||
|
||||
/* we wait to update fixed_block_size until here, when we're sure we've got a proper frame and hence a correct blocksize */
|
||||
if(decoder->private_->next_fixed_block_size)
|
||||
decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
|
||||
|
||||
/* put the latest values into the public section of the decoder instance */
|
||||
decoder->protected_->channels = decoder->private_->frame.header.channels;
|
||||
decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
|
||||
@ -2128,8 +2133,6 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
|
||||
unsigned raw_header_len;
|
||||
FLAC__bool is_unparseable = false;
|
||||
const FLAC__bool is_known_variable_blocksize_stream = (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize);
|
||||
const FLAC__bool is_known_fixed_blocksize_stream = (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize);
|
||||
|
||||
FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
|
||||
|
||||
@ -2138,12 +2141,9 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
raw_header[1] = decoder->private_->header_warmup[1];
|
||||
raw_header_len = 2;
|
||||
|
||||
/*
|
||||
* check to make sure that the reserved bits are 0
|
||||
*/
|
||||
if(raw_header[1] & 0x03) { /* MAGIC NUMBER */
|
||||
/* check to make sure that reserved bit is 0 */
|
||||
if(raw_header[1] & 0x02) /* MAGIC NUMBER */
|
||||
is_unparseable = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that along the way as we read the header, we look for a sync
|
||||
@ -2183,10 +2183,7 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
|
||||
switch(x = raw_header[2] >> 4) {
|
||||
case 0:
|
||||
if(is_known_fixed_blocksize_stream)
|
||||
decoder->private_->frame.header.blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
|
||||
else
|
||||
is_unparseable = true;
|
||||
is_unparseable = true;
|
||||
break;
|
||||
case 1:
|
||||
decoder->private_->frame.header.blocksize = 192;
|
||||
@ -2224,9 +2221,13 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
is_unparseable = true;
|
||||
break;
|
||||
case 1:
|
||||
decoder->private_->frame.header.sample_rate = 88200;
|
||||
break;
|
||||
case 2:
|
||||
decoder->private_->frame.header.sample_rate = 176400;
|
||||
break;
|
||||
case 3:
|
||||
is_unparseable = true;
|
||||
decoder->private_->frame.header.sample_rate = 192000;
|
||||
break;
|
||||
case 4:
|
||||
decoder->private_->frame.header.sample_rate = 8000;
|
||||
@ -2319,42 +2320,29 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
break;
|
||||
}
|
||||
|
||||
if(raw_header[3] & 0x01) { /* this should be a zero padding bit */
|
||||
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||
return true;
|
||||
}
|
||||
/* check to make sure that reserved bit is 0 */
|
||||
if(raw_header[3] & 0x01) /* MAGIC NUMBER */
|
||||
is_unparseable = true;
|
||||
|
||||
/*
|
||||
* Now we get to the regrettable consequences of not knowing for sure
|
||||
* whether we got a frame number or a sample number. There are no
|
||||
* encoders that do variable-blocksize encoding so unless we know from
|
||||
* the STREAMINFO that it is variable-blocksize we will assume it is
|
||||
* fixed-blocksize. The trouble comes when we have no STREAMINFO; again
|
||||
* we will guess that is fixed-blocksize. Where this can go wrong: 1) a
|
||||
* variable-blocksize stream with no STREAMINFO; 2) a fixed-blocksize
|
||||
* stream that was edited such that one or more frames before or
|
||||
* including this one do not have the same number of samples as the
|
||||
* STREAMINFO's min and max blocksize.
|
||||
*/
|
||||
if(is_known_variable_blocksize_stream) {
|
||||
if(blocksize_hint) {
|
||||
if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
|
||||
return false; /* read_callback_ sets the state for us */
|
||||
if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
|
||||
decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
|
||||
decoder->private_->cached = true;
|
||||
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||
return true;
|
||||
}
|
||||
decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
|
||||
decoder->private_->frame.header.number.sample_number = xx;
|
||||
/* read the frame's starting sample number (or frame number as the case may be) */
|
||||
if(
|
||||
raw_header[1] & 0x01 ||
|
||||
/*@@@ this clause is a concession to the old way of doing variable blocksize; the only known implementation is flake and can probably be removed without inconveniencing anyone */
|
||||
(decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
|
||||
) { /* variable blocksize */
|
||||
if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
|
||||
return false; /* read_callback_ sets the state for us */
|
||||
if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
|
||||
decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
|
||||
decoder->private_->cached = true;
|
||||
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
is_unparseable = true;
|
||||
decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
|
||||
decoder->private_->frame.header.number.sample_number = xx;
|
||||
}
|
||||
else {
|
||||
else { /* fixed blocksize */
|
||||
if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
|
||||
return false; /* read_callback_ sets the state for us */
|
||||
if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
|
||||
@ -2364,23 +2352,8 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||
return true;
|
||||
}
|
||||
decoder->private_->last_frame_number = x;
|
||||
decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
|
||||
if(decoder->private_->has_stream_info) {
|
||||
FLAC__ASSERT(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize);
|
||||
decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
|
||||
decoder->private_->last_block_size = decoder->private_->frame.header.blocksize;
|
||||
}
|
||||
else if(blocksize_hint) {
|
||||
if(decoder->private_->last_block_size)
|
||||
decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->last_block_size * (FLAC__uint64)x;
|
||||
else
|
||||
is_unparseable = true;
|
||||
}
|
||||
else {
|
||||
decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
|
||||
decoder->private_->last_block_size = decoder->private_->frame.header.blocksize;
|
||||
}
|
||||
decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
|
||||
decoder->private_->frame.header.number.frame_number = x;
|
||||
}
|
||||
|
||||
if(blocksize_hint) {
|
||||
@ -2427,6 +2400,31 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* calculate the sample number from the frame number if needed */
|
||||
decoder->private_->next_fixed_block_size = 0;
|
||||
if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
|
||||
x = decoder->private_->frame.header.number.frame_number;
|
||||
decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
|
||||
if(decoder->private_->fixed_block_size)
|
||||
decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
|
||||
else if(decoder->private_->has_stream_info) {
|
||||
if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
|
||||
decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
|
||||
decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
|
||||
}
|
||||
else
|
||||
is_unparseable = true;
|
||||
}
|
||||
else if(x == 0) {
|
||||
decoder->private_->frame.header.number.sample_number = 0;
|
||||
decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
|
||||
}
|
||||
else {
|
||||
/* can only get here if the stream has invalid frame numbering and no STREAMINFO, so assume it's not the last (possibly short) frame */
|
||||
decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_unparseable) {
|
||||
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||
@ -2554,6 +2552,7 @@ FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel,
|
||||
subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
|
||||
switch(subframe->entropy_coding_method.type) {
|
||||
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
|
||||
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 */
|
||||
subframe->entropy_coding_method.data.partitioned_rice.order = u32;
|
||||
@ -2568,7 +2567,8 @@ FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel,
|
||||
/* read residual */
|
||||
switch(subframe->entropy_coding_method.type) {
|
||||
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
|
||||
if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel]))
|
||||
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
|
||||
if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
@ -2631,6 +2631,7 @@ FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, un
|
||||
subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
|
||||
switch(subframe->entropy_coding_method.type) {
|
||||
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
|
||||
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 */
|
||||
subframe->entropy_coding_method.data.partitioned_rice.order = u32;
|
||||
@ -2645,7 +2646,8 @@ FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, un
|
||||
/* read residual */
|
||||
switch(subframe->entropy_coding_method.type) {
|
||||
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
|
||||
if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel]))
|
||||
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
|
||||
if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
@ -2697,13 +2699,15 @@ FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channe
|
||||
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 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__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;
|
||||
|
||||
/* sanity checks */
|
||||
if(partition_order == 0) {
|
||||
@ -2728,10 +2732,11 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigne
|
||||
|
||||
sample = 0;
|
||||
for(partition = 0; partition < partitions; partition++) {
|
||||
if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN))
|
||||
if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
|
||||
return false; /* read_callback_ sets the state for us */
|
||||
partitioned_rice_contents->parameters[partition] = rice_parameter;
|
||||
if(rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
|
||||
if(rice_parameter < pesc) {
|
||||
partitioned_rice_contents->raw_bits[partition] = 0;
|
||||
u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
|
||||
if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter))
|
||||
return false; /* read_callback_ sets the state for us */
|
||||
@ -2978,7 +2983,6 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
|
||||
/* we are just guessing here */
|
||||
if(max_framesize > 0)
|
||||
approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
|
||||
|
||||
/*
|
||||
* Check if it's a known fixed-blocksize stream. Note that though
|
||||
* the spec doesn't allow zeroes in the STREAMINFO block, we may
|
||||
@ -3001,9 +3005,9 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
|
||||
lower_bound = first_frame_offset;
|
||||
lower_bound_sample = 0;
|
||||
upper_bound = stream_length;
|
||||
upper_bound_sample = total_samples > 0 ? total_samples : target_sample;
|
||||
if(upper_bound_sample == 0)
|
||||
upper_bound_sample = 1;
|
||||
upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
|
||||
|
||||
/*@@@@@@ add step to validate seek table before using? encoding to pipe leaves some flac files with incomplete seektables which screw us up */
|
||||
|
||||
/*
|
||||
* Now we refine the bounds if we have a seektable with
|
||||
@ -3032,6 +3036,19 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
|
||||
}
|
||||
}
|
||||
|
||||
FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
|
||||
/* there are 2 insidious ways that the following equality occurs, which
|
||||
* we need to fix:
|
||||
* 1) total_samples is 0 (unknown) and target_sample is 0
|
||||
* 2) total_samples is 0 (unknown) and target_sample happens to be
|
||||
* exactly equal to the last seek point in the seek table; this
|
||||
* means there is no seek point above it, and upper_bound_samples
|
||||
* remains equal to the estimate (of target_samples) we made above
|
||||
* in either case it does not hurt to move upper_bound_sample up by 1
|
||||
*/
|
||||
if(upper_bound_sample == lower_bound_sample)
|
||||
upper_bound_sample++;
|
||||
|
||||
decoder->private_->target_sample = target_sample;
|
||||
while(1) {
|
||||
/* check if the bounds are still ok */
|
||||
@ -3083,21 +3100,23 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
|
||||
break;
|
||||
#endif
|
||||
if(!decoder->private_->is_seeking) {
|
||||
if(!decoder->private_->is_seeking)
|
||||
break;
|
||||
}
|
||||
|
||||
FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
|
||||
this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
|
||||
|
||||
if (!decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
|
||||
if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
|
||||
if (pos == (FLAC__int64)lower_bound) {
|
||||
/* can't move back any more than the first frame, something is fatally wrong */
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
|
||||
return false;
|
||||
}
|
||||
/* our last move backwards wasn't big enough, try again */
|
||||
approx_bytes_per_frame *= 2;
|
||||
approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
|
||||
continue;
|
||||
}
|
||||
/* allow one seek over upper bound, required for streams with unknown total_samples */
|
||||
/* allow one seek over upper bound, so we can get a correct upper_bound_sample for streams with unknown total_samples */
|
||||
first_seek = false;
|
||||
|
||||
/* make sure we are not seeking in corrupted stream */
|
||||
@ -3106,20 +3125,17 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
|
||||
return false;
|
||||
}
|
||||
|
||||
FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
|
||||
|
||||
/* we need to narrow the search */
|
||||
if(target_sample < this_frame_sample) {
|
||||
upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
|
||||
/*@@@@@@ what will decode position be if at end of stream? */
|
||||
if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
|
||||
return false;
|
||||
}
|
||||
approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
|
||||
}
|
||||
else {
|
||||
/* target_sample >= this_frame_sample + this frame's blocksize */
|
||||
|
||||
else { /* target_sample >= this_frame_sample + this frame's blocksize */
|
||||
lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
|
||||
if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
|
||||
|
@ -1056,7 +1056,8 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
|
||||
encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
|
||||
encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
|
||||
memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
|
||||
FLAC__MD5Init(&encoder->private_->md5context);
|
||||
if(encoder->protected_->do_md5)
|
||||
FLAC__MD5Init(&encoder->private_->md5context);
|
||||
if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
|
||||
encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
|
||||
return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
|
||||
@ -1325,7 +1326,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
|
||||
}
|
||||
}
|
||||
|
||||
FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
|
||||
if(encoder->protected_->do_md5)
|
||||
FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
|
||||
|
||||
if(!encoder->private_->is_being_deleted) {
|
||||
if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
|
||||
@ -1413,6 +1415,17 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncod
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->protected_->do_md5 = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
@ -1723,6 +1736,43 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encod
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* These three functions are not static, but not publically 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)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->private_->disable_constant_subframes = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->private_->disable_fixed_subframes = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->private_->disable_verbatim_subframes = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
@ -1788,6 +1838,14 @@ FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__Strea
|
||||
return encoder->protected_->streamable_subset;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
return encoder->protected_->do_md5;
|
||||
}
|
||||
|
||||
FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
@ -2058,6 +2116,7 @@ void set_defaults_(FLAC__StreamEncoder *encoder)
|
||||
encoder->protected_->verify = false;
|
||||
#endif
|
||||
encoder->protected_->streamable_subset = true;
|
||||
encoder->protected_->do_md5 = true;
|
||||
encoder->protected_->do_mid_side_stereo = false;
|
||||
encoder->protected_->loose_mid_side_stereo = false;
|
||||
encoder->protected_->channels = 2;
|
||||
@ -2806,7 +2865,7 @@ FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional
|
||||
/*
|
||||
* Accumulate raw signal to the MD5 signature
|
||||
*/
|
||||
if(!FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) {
|
||||
if(encoder->protected_->do_md5 && !FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) {
|
||||
encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
@ -229,6 +229,9 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWrit
|
||||
if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
|
||||
return false;
|
||||
|
||||
if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
|
||||
return false;
|
||||
|
||||
FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
|
||||
/* when this assertion holds true, any legal blocksize can be expressed in the frame header */
|
||||
FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
|
||||
|
@ -122,7 +122,12 @@ typedef signed int Int32_t;
|
||||
* sampleWindow calculation in ResetSampleFrequency(), and was causing
|
||||
* buffer overflows for 48kHz analysis, hence the +1.
|
||||
*/
|
||||
#define MAX_SAMPLES_PER_WINDOW (size_t) (MAX_SAMP_FREQ * RMS_WINDOW_TIME + 1.) /* max. Samples per Time slice */
|
||||
#ifndef __sun
|
||||
#define MAX_SAMPLES_PER_WINDOW (size_t) (MAX_SAMP_FREQ * RMS_WINDOW_TIME + 1.) /* max. Samples per Time slice */
|
||||
#else
|
||||
/* [JEC] Solaris Forte compiler doesn't like float calc in array indices */
|
||||
#define MAX_SAMPLES_PER_WINDOW (size_t) (2401)
|
||||
#endif
|
||||
#define PINK_REF 64.82 /* 298640883795 */ /* calibration value */
|
||||
|
||||
static Float_t linprebuf [MAX_ORDER * 2];
|
||||
@ -142,8 +147,14 @@ static unsigned long totsamp;
|
||||
static double lsum;
|
||||
static double rsum;
|
||||
static int freqindex;
|
||||
#ifndef __sun
|
||||
static Uint32_t A [(size_t)(STEPS_per_dB * MAX_dB)];
|
||||
static Uint32_t B [(size_t)(STEPS_per_dB * MAX_dB)];
|
||||
#else
|
||||
/* [JEC] Solaris Forte compiler doesn't like float calc in array indices */
|
||||
static Uint32_t A [12000];
|
||||
static Uint32_t B [12000];
|
||||
#endif
|
||||
|
||||
/* for each filter:
|
||||
[0] 48 kHz, [1] 44.1 kHz, [2] 32 kHz, [3] 24 kHz, [4] 22050 Hz, [5] 16 kHz, [6] 12 kHz, [7] is 11025 Hz, [8] 8 kHz */
|
||||
|
@ -31,9 +31,11 @@
|
||||
#endif
|
||||
#include <sys/stat.h> /* for stat() */
|
||||
#include "FLAC/assert.h"
|
||||
#include "FLAC/metadata.h"
|
||||
#include "FLAC/stream_decoder.h"
|
||||
|
||||
typedef struct {
|
||||
FLAC__int32 **pcm;
|
||||
FLAC__bool got_data;
|
||||
FLAC__uint64 total_samples;
|
||||
unsigned channels;
|
||||
@ -83,6 +85,89 @@ static off_t get_filesize_(const char *srcpath)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static FLAC__bool read_pcm_(FLAC__int32 *pcm[], const char *rawfilename, const char *flacfilename)
|
||||
{
|
||||
FILE *f;
|
||||
unsigned channels, bps = 0, samples, i, j;
|
||||
|
||||
off_t rawfilesize = get_filesize_(rawfilename);
|
||||
if (rawfilesize < 0) {
|
||||
fprintf(stderr, "ERROR: can't determine filesize for %s\n", rawfilename);
|
||||
return false;
|
||||
}
|
||||
/* get sample format from flac file; would just use FLAC__metadata_get_streaminfo() except it doesn't work for Ogg FLAC yet */
|
||||
{
|
||||
#if 0
|
||||
FLAC__StreamMetadata streaminfo;
|
||||
if(!FLAC__metadata_get_streaminfo(flacfilename, &streaminfo)) {
|
||||
printf("ERROR: getting STREAMINFO from %s\n", flacfilename);
|
||||
return false;
|
||||
}
|
||||
channels = streaminfo.data.stream_info.channels;
|
||||
bps = streaminfo.data.stream_info.bits_per_sample;
|
||||
#else
|
||||
FLAC__bool ok = true;
|
||||
FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
|
||||
FLAC__Metadata_Iterator *it = 0;
|
||||
ok = ok && chain && (FLAC__metadata_chain_read(chain, flacfilename) || FLAC__metadata_chain_read_ogg(chain, flacfilename));
|
||||
ok = ok && (it = FLAC__metadata_iterator_new());
|
||||
if(ok) FLAC__metadata_iterator_init(it, chain);
|
||||
ok = ok && (FLAC__metadata_iterator_get_block(it)->type == FLAC__METADATA_TYPE_STREAMINFO);
|
||||
ok = ok && (channels = FLAC__metadata_iterator_get_block(it)->data.stream_info.channels);
|
||||
ok = ok && (bps = FLAC__metadata_iterator_get_block(it)->data.stream_info.bits_per_sample);
|
||||
if(it) FLAC__metadata_iterator_delete(it);
|
||||
if(chain) FLAC__metadata_chain_delete(chain);
|
||||
if(!ok) {
|
||||
printf("ERROR: getting STREAMINFO from %s\n", flacfilename);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if(channels > 2) {
|
||||
printf("ERROR: PCM verification requires 1 or 2 channels, got %u\n", channels);
|
||||
return false;
|
||||
}
|
||||
if(bps != 8 && bps != 16) {
|
||||
printf("ERROR: PCM verification requires 8 or 16 bps, got %u\n", bps);
|
||||
return false;
|
||||
}
|
||||
samples = rawfilesize / channels / (bps>>3);
|
||||
if (samples > 10000000) {
|
||||
fprintf(stderr, "ERROR: %s is too big\n", rawfilename);
|
||||
return false;
|
||||
}
|
||||
for(i = 0; i < channels; i++) {
|
||||
if(0 == (pcm[i] = (FLAC__int32*)malloc(sizeof(FLAC__int32)*samples))) {
|
||||
printf("ERROR: allocating space for PCM samples\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(0 == (f = fopen(rawfilename, "r"))) {
|
||||
printf("ERROR: opening %s for reading\n", rawfilename);
|
||||
return false;
|
||||
}
|
||||
/* assumes signed big-endian data */
|
||||
if(bps == 8) {
|
||||
signed char c;
|
||||
for(i = 0; i < samples; i++) {
|
||||
for(j = 0; j < channels; j++) {
|
||||
fread(&c, 1, 1, f);
|
||||
pcm[j][i] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* bps == 16 */
|
||||
unsigned char c[2];
|
||||
for(i = 0; i < samples; i++) {
|
||||
for(j = 0; j < channels; j++) {
|
||||
fread(&c, 1, 2, f);
|
||||
pcm[j][i] = ((int)((signed char)c[0])) << 8 | (int)c[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
|
||||
{
|
||||
DecoderClientData *dcd = (DecoderClientData*)client_data;
|
||||
@ -97,25 +182,26 @@ static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder
|
||||
if(dcd->error_occurred)
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||
|
||||
if (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
|
||||
if (!dcd->quiet)
|
||||
printf("frame@%uf(%u)... ", frame->header.number.frame_number, frame->header.blocksize);
|
||||
}
|
||||
else if (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER) {
|
||||
if (!dcd->quiet)
|
||||
FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); /* decoder guarantees this */
|
||||
if (!dcd->quiet)
|
||||
#ifdef _MSC_VER
|
||||
printf("frame@%I64u(%u)... ", frame->header.number.sample_number, frame->header.blocksize);
|
||||
printf("frame@%I64u(%u)... ", frame->header.number.sample_number, frame->header.blocksize);
|
||||
#else
|
||||
printf("frame@%llu(%u)... ", (unsigned long long)frame->header.number.sample_number, frame->header.blocksize);
|
||||
printf("frame@%llu(%u)... ", (unsigned long long)frame->header.number.sample_number, frame->header.blocksize);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
FLAC__ASSERT(0);
|
||||
dcd->error_occurred = true;
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
/* check against PCM data if we have it */
|
||||
if (dcd->pcm) {
|
||||
unsigned c, i, j;
|
||||
for (c = 0; c < frame->header.channels; c++)
|
||||
for (i = (unsigned)frame->header.number.sample_number, j = 0; j < frame->header.blocksize; i++, j++)
|
||||
if (buffer[c][j] != dcd->pcm[c][i]) {
|
||||
printf("ERROR: sample mismatch at sample#%u(%u), channel=%u, expected %d, got %d\n", i, j, c, buffer[c][j], dcd->pcm[c][i]);
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||
}
|
||||
}
|
||||
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
@ -163,13 +249,14 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
|
||||
* 1 - read 2 frames
|
||||
* 2 - read until end
|
||||
*/
|
||||
static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count, FLAC__int64 total_samples, unsigned read_mode)
|
||||
static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count, FLAC__int64 total_samples, unsigned read_mode, FLAC__int32 **pcm)
|
||||
{
|
||||
FLAC__StreamDecoder *decoder;
|
||||
DecoderClientData decoder_client_data;
|
||||
unsigned i;
|
||||
long int n;
|
||||
|
||||
decoder_client_data.pcm = pcm;
|
||||
decoder_client_data.got_data = false;
|
||||
decoder_client_data.total_samples = 0;
|
||||
decoder_client_data.quiet = false;
|
||||
@ -330,28 +417,31 @@ static FLAC__uint64 local__strtoull(const char *src)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *filename;
|
||||
const char *flacfilename, *rawfilename = 0;
|
||||
unsigned count = 0, read_mode;
|
||||
FLAC__int64 samples = -1;
|
||||
off_t filesize;
|
||||
off_t flacfilesize;
|
||||
FLAC__int32 *pcm[2] = { 0, 0 };
|
||||
|
||||
static const char * const usage = "usage: test_seeking file.flac [#seeks] [#samples-in-file.flac]\n";
|
||||
static const char * const usage = "usage: test_seeking file.flac [#seeks] [#samples-in-file.flac] [file.raw]\n";
|
||||
|
||||
if (argc < 2 || argc > 4) {
|
||||
if (argc < 2 || argc > 5) {
|
||||
fprintf(stderr, usage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
filename = argv[1];
|
||||
flacfilename = argv[1];
|
||||
|
||||
if (argc > 2)
|
||||
count = strtoul(argv[2], 0, 10);
|
||||
if (argc > 3)
|
||||
#ifdef _MSC_VER
|
||||
samples = local__strtoull(argv[3]);
|
||||
samples = local__strtoull(argv[4]);
|
||||
#else
|
||||
samples = strtoull(argv[3], 0, 10);
|
||||
#endif
|
||||
if (argc > 4)
|
||||
rawfilename = argv[4];
|
||||
|
||||
if (count < 30)
|
||||
fprintf(stderr, "WARNING: random seeks don't kick in until after 30 preprogrammed ones\n");
|
||||
@ -370,26 +460,32 @@ int main(int argc, char *argv[])
|
||||
srand((unsigned)time(0));
|
||||
#endif
|
||||
|
||||
filesize = get_filesize_(filename);
|
||||
if (filesize < 0) {
|
||||
fprintf(stderr, "ERROR: can't determine filesize for %s\n", filename);
|
||||
flacfilesize = get_filesize_(flacfilename);
|
||||
if (flacfilesize < 0) {
|
||||
fprintf(stderr, "ERROR: can't determine filesize for %s\n", flacfilename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (rawfilename && !read_pcm_(pcm, rawfilename, flacfilename))
|
||||
return 1;
|
||||
|
||||
(void) signal(SIGINT, our_sigint_handler_);
|
||||
|
||||
for (read_mode = 0; read_mode <= 2; read_mode++) {
|
||||
FLAC__bool ok;
|
||||
if (strlen(filename) > 4 && 0 == strcmp(filename+strlen(filename)-4, ".ogg")) {
|
||||
/* no need to do "decode all" read_mode if PCM checking is available */
|
||||
if (rawfilename && read_mode > 1)
|
||||
continue;
|
||||
if (strlen(flacfilename) > 4 && 0 == strcmp(flacfilename+strlen(flacfilename)-4, ".ogg")) {
|
||||
#if FLAC__HAS_OGG
|
||||
ok = seek_barrage(/*is_ogg=*/true, filename, filesize, count, samples, read_mode);
|
||||
ok = seek_barrage(/*is_ogg=*/true, flacfilename, flacfilesize, count, samples, read_mode, rawfilename? pcm : 0);
|
||||
#else
|
||||
fprintf(stderr, "ERROR: Ogg FLAC not supported\n");
|
||||
ok = false;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
ok = seek_barrage(/*is_ogg=*/false, filename, filesize, count, samples, read_mode);
|
||||
ok = seek_barrage(/*is_ogg=*/false, flacfilename, flacfilesize, count, samples, read_mode, rawfilename? pcm : 0);
|
||||
}
|
||||
if (!ok)
|
||||
return 2;
|
||||
|
Loading…
Reference in New Issue
Block a user