mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
add functions/switches for disabling certain subframe types for use by the test suite
This commit is contained in:
@@ -94,6 +94,19 @@ static FLAC__int32 in_[FLAC__MAX_CHANNELS][CHUNK_OF_SAMPLES];
|
|||||||
static FLAC__int32 *input_[FLAC__MAX_CHANNELS];
|
static FLAC__int32 *input_[FLAC__MAX_CHANNELS];
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unpublished debug routines from the FLAC libs
|
||||||
|
*/
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__file_encoder_disable_constant_subframes(FLAC__FileEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__file_encoder_disable_fixed_subframes(FLAC__FileEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__file_encoder_disable_verbatim_subframes(FLAC__FileEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool OggFLAC__stream_encoder_disable_constant_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool OggFLAC__stream_encoder_disable_fixed_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool OggFLAC__stream_encoder_disable_verbatim_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* local routines
|
* local routines
|
||||||
*/
|
*/
|
||||||
@@ -1205,6 +1218,10 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
|
|||||||
OggFLAC__stream_encoder_set_write_callback(e->encoder.ogg.stream, ogg_stream_encoder_write_callback);
|
OggFLAC__stream_encoder_set_write_callback(e->encoder.ogg.stream, ogg_stream_encoder_write_callback);
|
||||||
OggFLAC__stream_encoder_set_client_data(e->encoder.ogg.stream, e);
|
OggFLAC__stream_encoder_set_client_data(e->encoder.ogg.stream, e);
|
||||||
|
|
||||||
|
OggFLAC__stream_encoder_disable_constant_subframes(e->encoder.ogg.stream, options.debug.disable_constant_subframes);
|
||||||
|
OggFLAC__stream_encoder_disable_fixed_subframes(e->encoder.ogg.stream, options.debug.disable_fixed_subframes);
|
||||||
|
OggFLAC__stream_encoder_disable_verbatim_subframes(e->encoder.ogg.stream, options.debug.disable_verbatim_subframes);
|
||||||
|
|
||||||
if(OggFLAC__stream_encoder_init(e->encoder.ogg.stream) != FLAC__STREAM_ENCODER_OK) {
|
if(OggFLAC__stream_encoder_init(e->encoder.ogg.stream) != FLAC__STREAM_ENCODER_OK) {
|
||||||
print_error_with_state(e, "ERROR initializing encoder");
|
print_error_with_state(e, "ERROR initializing encoder");
|
||||||
return false;
|
return false;
|
||||||
@@ -1235,6 +1252,10 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
|
|||||||
FLAC__stream_encoder_set_metadata_callback(e->encoder.flac.stream, flac_stream_encoder_metadata_callback);
|
FLAC__stream_encoder_set_metadata_callback(e->encoder.flac.stream, flac_stream_encoder_metadata_callback);
|
||||||
FLAC__stream_encoder_set_client_data(e->encoder.flac.stream, e);
|
FLAC__stream_encoder_set_client_data(e->encoder.flac.stream, e);
|
||||||
|
|
||||||
|
FLAC__stream_encoder_disable_constant_subframes(e->encoder.flac.stream, options.debug.disable_constant_subframes);
|
||||||
|
FLAC__stream_encoder_disable_fixed_subframes(e->encoder.flac.stream, options.debug.disable_fixed_subframes);
|
||||||
|
FLAC__stream_encoder_disable_verbatim_subframes(e->encoder.flac.stream, options.debug.disable_verbatim_subframes);
|
||||||
|
|
||||||
if(FLAC__stream_encoder_init(e->encoder.flac.stream) != FLAC__STREAM_ENCODER_OK) {
|
if(FLAC__stream_encoder_init(e->encoder.flac.stream) != FLAC__STREAM_ENCODER_OK) {
|
||||||
print_error_with_state(e, "ERROR initializing encoder");
|
print_error_with_state(e, "ERROR initializing encoder");
|
||||||
return false;
|
return false;
|
||||||
@@ -1263,6 +1284,10 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
|
|||||||
FLAC__file_encoder_set_progress_callback(e->encoder.flac.file, flac_file_encoder_progress_callback);
|
FLAC__file_encoder_set_progress_callback(e->encoder.flac.file, flac_file_encoder_progress_callback);
|
||||||
FLAC__file_encoder_set_client_data(e->encoder.flac.file, e);
|
FLAC__file_encoder_set_client_data(e->encoder.flac.file, e);
|
||||||
|
|
||||||
|
FLAC__file_encoder_disable_constant_subframes(e->encoder.flac.file, options.debug.disable_constant_subframes);
|
||||||
|
FLAC__file_encoder_disable_fixed_subframes(e->encoder.flac.file, options.debug.disable_fixed_subframes);
|
||||||
|
FLAC__file_encoder_disable_verbatim_subframes(e->encoder.flac.file, options.debug.disable_verbatim_subframes);
|
||||||
|
|
||||||
if(FLAC__file_encoder_init(e->encoder.flac.file) != FLAC__FILE_ENCODER_OK) {
|
if(FLAC__file_encoder_init(e->encoder.flac.file) != FLAC__FILE_ENCODER_OK) {
|
||||||
print_error_with_state(e, "ERROR initializing encoder");
|
print_error_with_state(e, "ERROR initializing encoder");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ typedef struct {
|
|||||||
FLAC__bool sector_align;
|
FLAC__bool sector_align;
|
||||||
|
|
||||||
FLAC__StreamMetadata *vorbis_comment;
|
FLAC__StreamMetadata *vorbis_comment;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
FLAC__bool disable_constant_subframes;
|
||||||
|
FLAC__bool disable_fixed_subframes;
|
||||||
|
FLAC__bool disable_verbatim_subframes;
|
||||||
|
} debug;
|
||||||
} encode_options_t;
|
} encode_options_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -171,6 +171,12 @@ static struct FLAC__share__option long_options_[] = {
|
|||||||
{ "no-verify", 0, 0, 0 },
|
{ "no-verify", 0, 0, 0 },
|
||||||
{ "no-residual-gnuplot", 0, 0, 0 },
|
{ "no-residual-gnuplot", 0, 0, 0 },
|
||||||
{ "no-residual-text", 0, 0, 0 },
|
{ "no-residual-text", 0, 0, 0 },
|
||||||
|
/*
|
||||||
|
* undocumented debugging options for the test suite
|
||||||
|
*/
|
||||||
|
{ "disable-constant-subframes", 0, 0, 0 },
|
||||||
|
{ "disable-fixed-subframes", 0, 0, 0 },
|
||||||
|
{ "disable-verbatim-subframes", 0, 0, 0 },
|
||||||
|
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
@@ -226,6 +232,12 @@ static struct {
|
|||||||
char **filenames;
|
char **filenames;
|
||||||
|
|
||||||
FLAC__StreamMetadata *vorbis_comment;
|
FLAC__StreamMetadata *vorbis_comment;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
FLAC__bool disable_constant_subframes;
|
||||||
|
FLAC__bool disable_fixed_subframes;
|
||||||
|
FLAC__bool disable_verbatim_subframes;
|
||||||
|
} debug;
|
||||||
} option_values;
|
} option_values;
|
||||||
|
|
||||||
|
|
||||||
@@ -489,6 +501,10 @@ FLAC__bool init_options()
|
|||||||
if(0 == (option_values.vorbis_comment = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)))
|
if(0 == (option_values.vorbis_comment = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
option_values.debug.disable_constant_subframes = false;
|
||||||
|
option_values.debug.disable_fixed_subframes = false;
|
||||||
|
option_values.debug.disable_verbatim_subframes = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -673,6 +689,15 @@ int parse_option(int short_option, const char *long_option, const char *option_a
|
|||||||
else if(0 == strcmp(long_option, "no-residual-text")) {
|
else if(0 == strcmp(long_option, "no-residual-text")) {
|
||||||
option_values.aopts.do_residual_text = false;
|
option_values.aopts.do_residual_text = false;
|
||||||
}
|
}
|
||||||
|
else if(0 == strcmp(long_option, "disable-constant-subframes")) {
|
||||||
|
option_values.debug.disable_constant_subframes = true;
|
||||||
|
}
|
||||||
|
else if(0 == strcmp(long_option, "disable-fixed-subframes")) {
|
||||||
|
option_values.debug.disable_fixed_subframes = true;
|
||||||
|
}
|
||||||
|
else if(0 == strcmp(long_option, "disable-verbatim-subframes")) {
|
||||||
|
option_values.debug.disable_verbatim_subframes = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const char *violation;
|
const char *violation;
|
||||||
@@ -1359,6 +1384,9 @@ int encode_file(const char *infilename, const char *forced_outfilename, FLAC__bo
|
|||||||
common_options.align_reservoir_samples = &align_reservoir_samples;
|
common_options.align_reservoir_samples = &align_reservoir_samples;
|
||||||
common_options.sector_align = option_values.sector_align;
|
common_options.sector_align = option_values.sector_align;
|
||||||
common_options.vorbis_comment = option_values.vorbis_comment;
|
common_options.vorbis_comment = option_values.vorbis_comment;
|
||||||
|
common_options.debug.disable_constant_subframes = option_values.debug.disable_constant_subframes;
|
||||||
|
common_options.debug.disable_fixed_subframes = option_values.debug.disable_fixed_subframes;
|
||||||
|
common_options.debug.disable_verbatim_subframes = option_values.debug.disable_verbatim_subframes;
|
||||||
|
|
||||||
if(fmt == RAW) {
|
if(fmt == RAW) {
|
||||||
raw_encode_options_t options;
|
raw_encode_options_t options;
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
*
|
*
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
|
/* unpublished debug routines */
|
||||||
|
extern FLAC__bool FLAC__seekable_stream_encoder_disable_constant_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__seekable_stream_encoder_disable_fixed_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__seekable_stream_encoder_disable_verbatim_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
|
||||||
|
|
||||||
static void set_defaults_(FLAC__FileEncoder *encoder);
|
static void set_defaults_(FLAC__FileEncoder *encoder);
|
||||||
static FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
|
static FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
|
||||||
static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
|
static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
|
||||||
@@ -444,6 +449,40 @@ FLAC__bool FLAC__file_encoder_set_client_data(FLAC__FileEncoder *encoder, void *
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These three functions are not static, but not publically exposed in
|
||||||
|
* include/FLAC/ either. They are used by the test suite.
|
||||||
|
*/
|
||||||
|
FLAC__bool FLAC__file_encoder_disable_constant_subframes(FLAC__FileEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != FLAC__FILE_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__seekable_stream_encoder_disable_constant_subframes(encoder->private_->seekable_stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool FLAC__file_encoder_disable_fixed_subframes(FLAC__FileEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != FLAC__FILE_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__seekable_stream_encoder_disable_fixed_subframes(encoder->private_->seekable_stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool FLAC__file_encoder_disable_verbatim_subframes(FLAC__FileEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != FLAC__FILE_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__seekable_stream_encoder_disable_verbatim_subframes(encoder->private_->seekable_stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
FLAC__FileEncoderState FLAC__file_encoder_get_state(const FLAC__FileEncoder *encoder)
|
FLAC__FileEncoderState FLAC__file_encoder_get_state(const FLAC__FileEncoder *encoder)
|
||||||
{
|
{
|
||||||
FLAC__ASSERT(0 != encoder);
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
|||||||
@@ -35,6 +35,11 @@
|
|||||||
*
|
*
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
|
/* unpublished debug routines */
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
|
||||||
static void set_defaults_(FLAC__SeekableStreamEncoder *encoder);
|
static void set_defaults_(FLAC__SeekableStreamEncoder *encoder);
|
||||||
static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
|
static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
|
||||||
static void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
|
static void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
|
||||||
@@ -449,6 +454,40 @@ FLAC__bool FLAC__seekable_stream_encoder_set_client_data(FLAC__SeekableStreamEnc
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These three functions are not static, but not publically exposed in
|
||||||
|
* include/FLAC/ either. They are used by the test suite.
|
||||||
|
*/
|
||||||
|
FLAC__bool FLAC__seekable_stream_encoder_disable_constant_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__stream_encoder_disable_constant_subframes(encoder->private_->stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool FLAC__seekable_stream_encoder_disable_fixed_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__stream_encoder_disable_fixed_subframes(encoder->private_->stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool FLAC__seekable_stream_encoder_disable_verbatim_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__stream_encoder_disable_verbatim_subframes(encoder->private_->stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
FLAC__SeekableStreamEncoderState FLAC__seekable_stream_encoder_get_state(const FLAC__SeekableStreamEncoder *encoder)
|
FLAC__SeekableStreamEncoderState FLAC__seekable_stream_encoder_get_state(const FLAC__SeekableStreamEncoder *encoder)
|
||||||
{
|
{
|
||||||
FLAC__ASSERT(0 != encoder);
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h> /* for malloc() */
|
#include <stdlib.h> /* for malloc() */
|
||||||
#include <string.h> /* for memcpy() */
|
#include <string.h> /* for memcpy() */
|
||||||
@@ -80,7 +81,6 @@ static FLAC__bool process_subframe_(
|
|||||||
unsigned min_partition_order,
|
unsigned min_partition_order,
|
||||||
unsigned max_partition_order,
|
unsigned max_partition_order,
|
||||||
FLAC__bool precompute_partition_sums,
|
FLAC__bool precompute_partition_sums,
|
||||||
FLAC__bool verbatim_only,
|
|
||||||
const FLAC__FrameHeader *frame_header,
|
const FLAC__FrameHeader *frame_header,
|
||||||
unsigned subframe_bps,
|
unsigned subframe_bps,
|
||||||
const FLAC__int32 integer_signal[],
|
const FLAC__int32 integer_signal[],
|
||||||
@@ -339,6 +339,9 @@ typedef struct FLAC__StreamEncoderPrivate {
|
|||||||
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_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 use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
|
||||||
FLAC__bool precompute_partition_sums; /* our initial guess as to whether precomputing the partitions sums will be a speed improvement */
|
FLAC__bool precompute_partition_sums; /* our initial guess as to whether precomputing the partitions sums will be a speed improvement */
|
||||||
|
FLAC__bool disable_constant_subframes;
|
||||||
|
FLAC__bool disable_fixed_subframes;
|
||||||
|
FLAC__bool disable_verbatim_subframes;
|
||||||
FLAC__StreamEncoderWriteCallback write_callback;
|
FLAC__StreamEncoderWriteCallback write_callback;
|
||||||
FLAC__StreamEncoderMetadataCallback metadata_callback;
|
FLAC__StreamEncoderMetadataCallback metadata_callback;
|
||||||
void *client_data;
|
void *client_data;
|
||||||
@@ -1135,6 +1138,37 @@ FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, vo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These three functions are not static, but not publically exposed in
|
||||||
|
* include/FLAC/ either. They are used by the test suite.
|
||||||
|
*/
|
||||||
|
FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
encoder->private_->disable_constant_subframes = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
encoder->private_->disable_fixed_subframes = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
encoder->private_->disable_verbatim_subframes = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
|
FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
|
||||||
{
|
{
|
||||||
FLAC__ASSERT(0 != encoder);
|
FLAC__ASSERT(0 != encoder);
|
||||||
@@ -1419,6 +1453,9 @@ void set_defaults_(FLAC__StreamEncoder *encoder)
|
|||||||
encoder->protected_->metadata = 0;
|
encoder->protected_->metadata = 0;
|
||||||
encoder->protected_->num_metadata_blocks = 0;
|
encoder->protected_->num_metadata_blocks = 0;
|
||||||
|
|
||||||
|
encoder->private_->disable_constant_subframes = false;
|
||||||
|
encoder->private_->disable_fixed_subframes = false;
|
||||||
|
encoder->private_->disable_verbatim_subframes = false;
|
||||||
encoder->private_->write_callback = 0;
|
encoder->private_->write_callback = 0;
|
||||||
encoder->private_->metadata_callback = 0;
|
encoder->private_->metadata_callback = 0;
|
||||||
encoder->private_->client_data = 0;
|
encoder->private_->client_data = 0;
|
||||||
@@ -1728,7 +1765,6 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_f
|
|||||||
min_partition_order,
|
min_partition_order,
|
||||||
max_partition_order,
|
max_partition_order,
|
||||||
precompute_partition_sums,
|
precompute_partition_sums,
|
||||||
false,
|
|
||||||
&frame_header,
|
&frame_header,
|
||||||
encoder->private_->subframe_bps[channel],
|
encoder->private_->subframe_bps[channel],
|
||||||
encoder->private_->integer_signal[channel],
|
encoder->private_->integer_signal[channel],
|
||||||
@@ -1757,7 +1793,6 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_f
|
|||||||
min_partition_order,
|
min_partition_order,
|
||||||
max_partition_order,
|
max_partition_order,
|
||||||
precompute_partition_sums,
|
precompute_partition_sums,
|
||||||
false,
|
|
||||||
&frame_header,
|
&frame_header,
|
||||||
encoder->private_->subframe_bps_mid_side[channel],
|
encoder->private_->subframe_bps_mid_side[channel],
|
||||||
encoder->private_->integer_signal_mid_side[channel],
|
encoder->private_->integer_signal_mid_side[channel],
|
||||||
@@ -1892,7 +1927,6 @@ FLAC__bool process_subframe_(
|
|||||||
unsigned min_partition_order,
|
unsigned min_partition_order,
|
||||||
unsigned max_partition_order,
|
unsigned max_partition_order,
|
||||||
FLAC__bool precompute_partition_sums,
|
FLAC__bool precompute_partition_sums,
|
||||||
FLAC__bool verbatim_only,
|
|
||||||
const FLAC__FrameHeader *frame_header,
|
const FLAC__FrameHeader *frame_header,
|
||||||
unsigned subframe_bps,
|
unsigned subframe_bps,
|
||||||
const FLAC__int32 integer_signal[],
|
const FLAC__int32 integer_signal[],
|
||||||
@@ -1917,73 +1951,80 @@ FLAC__bool process_subframe_(
|
|||||||
|
|
||||||
/* verbatim subframe is the baseline against which we measure other compressed subframes */
|
/* verbatim subframe is the baseline against which we measure other compressed subframes */
|
||||||
_best_subframe = 0;
|
_best_subframe = 0;
|
||||||
_best_bits = evaluate_verbatim_subframe_(integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
|
if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
|
||||||
|
_best_bits = UINT_MAX;
|
||||||
|
else
|
||||||
|
_best_bits = evaluate_verbatim_subframe_(integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
|
||||||
|
|
||||||
if(!verbatim_only && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
|
if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
|
||||||
/* check for constant subframe */
|
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);
|
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);
|
||||||
if(fixed_residual_bits_per_sample[1] == 0.0) {
|
/* check for constant subframe */
|
||||||
|
if(!encoder->private_->disable_constant_subframes && fixed_residual_bits_per_sample[1] == 0.0) {
|
||||||
/* the above means integer_signal+FLAC__MAX_FIXED_ORDER is constant, now we just have to check the warmup samples */
|
/* the above means integer_signal+FLAC__MAX_FIXED_ORDER is constant, now we just have to check the warmup samples */
|
||||||
unsigned i, signal_is_constant = true;
|
unsigned i;
|
||||||
|
signal_is_constant = true;
|
||||||
for(i = 1; i <= FLAC__MAX_FIXED_ORDER; i++) {
|
for(i = 1; i <= FLAC__MAX_FIXED_ORDER; i++) {
|
||||||
if(integer_signal[0] != integer_signal[i]) {
|
if(integer_signal[0] != integer_signal[i]) {
|
||||||
signal_is_constant = false;
|
signal_is_constant = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(signal_is_constant) {
|
}
|
||||||
_candidate_bits = evaluate_constant_subframe_(integer_signal[0], subframe_bps, subframe[!_best_subframe]);
|
if(signal_is_constant) {
|
||||||
if(_candidate_bits < _best_bits) {
|
_candidate_bits = evaluate_constant_subframe_(integer_signal[0], subframe_bps, subframe[!_best_subframe]);
|
||||||
_best_subframe = !_best_subframe;
|
if(_candidate_bits < _best_bits) {
|
||||||
_best_bits = _candidate_bits;
|
_best_subframe = !_best_subframe;
|
||||||
}
|
_best_bits = _candidate_bits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* encode fixed */
|
if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
|
||||||
if(encoder->protected_->do_exhaustive_model_search) {
|
/* encode fixed */
|
||||||
min_fixed_order = 0;
|
if(encoder->protected_->do_exhaustive_model_search) {
|
||||||
max_fixed_order = FLAC__MAX_FIXED_ORDER;
|
min_fixed_order = 0;
|
||||||
}
|
max_fixed_order = FLAC__MAX_FIXED_ORDER;
|
||||||
else {
|
|
||||||
min_fixed_order = max_fixed_order = guess_fixed_order;
|
|
||||||
}
|
|
||||||
for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
|
|
||||||
if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__real)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 */
|
|
||||||
#ifndef FLAC__SYMMETRIC_RICE
|
|
||||||
rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
|
|
||||||
#endif
|
|
||||||
if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
|
|
||||||
#ifdef DEBUG_VERBOSE
|
|
||||||
fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
|
|
||||||
#endif
|
|
||||||
rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
|
|
||||||
}
|
}
|
||||||
_candidate_bits =
|
else {
|
||||||
evaluate_fixed_subframe_(
|
min_fixed_order = max_fixed_order = guess_fixed_order;
|
||||||
encoder,
|
}
|
||||||
integer_signal,
|
for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
|
||||||
residual[!_best_subframe],
|
if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__real)subframe_bps)
|
||||||
encoder->private_->abs_residual,
|
continue; /* don't even try */
|
||||||
encoder->private_->abs_residual_partition_sums,
|
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 */
|
||||||
encoder->private_->raw_bits_per_partition,
|
#ifndef FLAC__SYMMETRIC_RICE
|
||||||
frame_header->blocksize,
|
rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
|
||||||
subframe_bps,
|
#endif
|
||||||
fixed_order,
|
if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
|
||||||
rice_parameter,
|
#ifdef DEBUG_VERBOSE
|
||||||
min_partition_order,
|
fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
|
||||||
max_partition_order,
|
#endif
|
||||||
precompute_partition_sums,
|
rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
|
||||||
encoder->protected_->do_escape_coding,
|
}
|
||||||
encoder->protected_->rice_parameter_search_dist,
|
_candidate_bits =
|
||||||
subframe[!_best_subframe],
|
evaluate_fixed_subframe_(
|
||||||
partitioned_rice_contents[!_best_subframe]
|
encoder,
|
||||||
);
|
integer_signal,
|
||||||
if(_candidate_bits < _best_bits) {
|
residual[!_best_subframe],
|
||||||
_best_subframe = !_best_subframe;
|
encoder->private_->abs_residual,
|
||||||
_best_bits = _candidate_bits;
|
encoder->private_->abs_residual_partition_sums,
|
||||||
|
encoder->private_->raw_bits_per_partition,
|
||||||
|
frame_header->blocksize,
|
||||||
|
subframe_bps,
|
||||||
|
fixed_order,
|
||||||
|
rice_parameter,
|
||||||
|
min_partition_order,
|
||||||
|
max_partition_order,
|
||||||
|
precompute_partition_sums,
|
||||||
|
encoder->protected_->do_escape_coding,
|
||||||
|
encoder->protected_->rice_parameter_search_dist,
|
||||||
|
subframe[!_best_subframe],
|
||||||
|
partitioned_rice_contents[!_best_subframe]
|
||||||
|
);
|
||||||
|
if(_candidate_bits < _best_bits) {
|
||||||
|
_best_subframe = !_best_subframe;
|
||||||
|
_best_bits = _candidate_bits;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2067,6 +2108,8 @@ FLAC__bool process_subframe_(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FLAC__ASSERT(_best_bits < UINT_MAX);
|
||||||
|
|
||||||
*best_subframe = _best_subframe;
|
*best_subframe = _best_subframe;
|
||||||
*best_bits = _best_bits;
|
*best_bits = _best_bits;
|
||||||
|
|
||||||
@@ -2083,24 +2126,28 @@ FLAC__bool add_subframe_(
|
|||||||
{
|
{
|
||||||
switch(subframe->type) {
|
switch(subframe->type) {
|
||||||
case FLAC__SUBFRAME_TYPE_CONSTANT:
|
case FLAC__SUBFRAME_TYPE_CONSTANT:
|
||||||
|
//@@@@fprintf(stderr,"@@@@ add CONSTANT, bps=%u\n",subframe_bps);
|
||||||
if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
|
if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
|
||||||
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FLAC__SUBFRAME_TYPE_FIXED:
|
case FLAC__SUBFRAME_TYPE_FIXED:
|
||||||
|
//@@@@fprintf(stderr,"@@@@ add FIXED, bps=%u, order=%u\n",subframe_bps,subframe->data.fixed.order);
|
||||||
if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), frame_header->blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
|
if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), frame_header->blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
|
||||||
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FLAC__SUBFRAME_TYPE_LPC:
|
case FLAC__SUBFRAME_TYPE_LPC:
|
||||||
|
//@@@@fprintf(stderr,"@@@@ add LPC, bps=%u, order=%u, prec=%u, shift=%d\n",subframe_bps,subframe->data.lpc.order,subframe->data.lpc.qlp_coeff_precision,subframe->data.lpc.quantization_level);
|
||||||
if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), frame_header->blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
|
if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), frame_header->blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
|
||||||
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FLAC__SUBFRAME_TYPE_VERBATIM:
|
case FLAC__SUBFRAME_TYPE_VERBATIM:
|
||||||
|
//@@@@fprintf(stderr,"@@@@ add VERBATIM, bps=%u\n",subframe_bps);
|
||||||
if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), frame_header->blocksize, subframe_bps, subframe->wasted_bits, frame)) {
|
if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), frame_header->blocksize, subframe_bps, subframe->wasted_bits, frame)) {
|
||||||
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
encoder->protected_->state = FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -31,6 +31,11 @@
|
|||||||
*
|
*
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
|
/* unpublished debug routines */
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||||
|
|
||||||
static void set_defaults_(OggFLAC__StreamEncoder *encoder);
|
static void set_defaults_(OggFLAC__StreamEncoder *encoder);
|
||||||
static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
|
static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
|
||||||
static void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
|
static void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
|
||||||
@@ -420,6 +425,40 @@ FLAC__bool OggFLAC__stream_encoder_set_client_data(OggFLAC__StreamEncoder *encod
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These three functions are not static, but not publically exposed in
|
||||||
|
* include/FLAC/ either. They are used by the test suite.
|
||||||
|
*/
|
||||||
|
FLAC__bool OggFLAC__stream_encoder_disable_constant_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__stream_encoder_disable_constant_subframes(encoder->private_->FLAC_stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool OggFLAC__stream_encoder_disable_fixed_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__stream_encoder_disable_fixed_subframes(encoder->private_->FLAC_stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
FLAC__bool OggFLAC__stream_encoder_disable_verbatim_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||||
|
{
|
||||||
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
FLAC__ASSERT(0 != encoder->private_);
|
||||||
|
FLAC__ASSERT(0 != encoder->protected_);
|
||||||
|
if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
|
return false;
|
||||||
|
return FLAC__stream_encoder_disable_verbatim_subframes(encoder->private_->FLAC_stream_encoder, value);
|
||||||
|
}
|
||||||
|
|
||||||
OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder)
|
OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder)
|
||||||
{
|
{
|
||||||
FLAC__ASSERT(0 != encoder);
|
FLAC__ASSERT(0 != encoder);
|
||||||
|
|||||||
Reference in New Issue
Block a user