| OLD | NEW |
| 1 /* libFLAC - Free Lossless Audio Codec library | 1 /* libFLAC - Free Lossless Audio Codec library |
| 2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson | 2 * Copyright (C) 2000-2009 Josh Coalson |
| 3 * Copyright (C) 2011-2014 Xiph.Org Foundation |
| 3 * | 4 * |
| 4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 6 * are met: | 7 * are met: |
| 7 * | 8 * |
| 8 * - Redistributions of source code must retain the above copyright | 9 * - Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 10 * | 11 * |
| 11 * - Redistributions in binary form must reproduce the above copyright | 12 * - Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 13 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 14 * documentation and/or other materials provided with the distribution. |
| 14 * | 15 * |
| 15 * - Neither the name of the Xiph.org Foundation nor the names of its | 16 * - Neither the name of the Xiph.org Foundation nor the names of its |
| 16 * contributors may be used to endorse or promote products derived from | 17 * contributors may be used to endorse or promote products derived from |
| 17 * this software without specific prior written permission. | 18 * this software without specific prior written permission. |
| 18 * | 19 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR | 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 31 */ |
| 31 | 32 |
| 32 #if HAVE_CONFIG_H | 33 #ifdef HAVE_CONFIG_H |
| 33 # include <config.h> | 34 # include <config.h> |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 #if defined _MSC_VER || defined __MINGW32__ | |
| 37 #include <io.h> /* for _setmode() */ | |
| 38 #include <fcntl.h> /* for _O_BINARY */ | |
| 39 #endif | |
| 40 #if defined __CYGWIN__ || defined __EMX__ | |
| 41 #include <io.h> /* for setmode(), O_BINARY */ | |
| 42 #include <fcntl.h> /* for _O_BINARY */ | |
| 43 #endif | |
| 44 #include <limits.h> | 37 #include <limits.h> |
| 45 #include <stdio.h> | 38 #include <stdio.h> |
| 46 #include <stdlib.h> /* for malloc() */ | 39 #include <stdlib.h> /* for malloc() */ |
| 47 #include <string.h> /* for memcpy() */ | 40 #include <string.h> /* for memcpy() */ |
| 48 #include <sys/types.h> /* for off_t */ | 41 #include <sys/types.h> /* for off_t */ |
| 49 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ | 42 #include "share/compat.h" |
| 50 #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */ | |
| 51 #define fseeko fseek | |
| 52 #define ftello ftell | |
| 53 #else | |
| 54 #define fseeko _fseeki64 | |
| 55 #define ftello _ftelli64 | |
| 56 #endif | |
| 57 #endif | |
| 58 #include "FLAC/assert.h" | 43 #include "FLAC/assert.h" |
| 59 #include "FLAC/stream_decoder.h" | 44 #include "FLAC/stream_decoder.h" |
| 60 #include "share/alloc.h" | |
| 61 #include "protected/stream_encoder.h" | 45 #include "protected/stream_encoder.h" |
| 62 #include "private/bitwriter.h" | 46 #include "private/bitwriter.h" |
| 63 #include "private/bitmath.h" | 47 #include "private/bitmath.h" |
| 64 #include "private/crc.h" | 48 #include "private/crc.h" |
| 65 #include "private/cpu.h" | 49 #include "private/cpu.h" |
| 66 #include "private/fixed.h" | 50 #include "private/fixed.h" |
| 67 #include "private/format.h" | 51 #include "private/format.h" |
| 68 #include "private/lpc.h" | 52 #include "private/lpc.h" |
| 69 #include "private/md5.h" | 53 #include "private/md5.h" |
| 70 #include "private/memory.h" | 54 #include "private/memory.h" |
| 55 #include "private/macros.h" |
| 71 #if FLAC__HAS_OGG | 56 #if FLAC__HAS_OGG |
| 72 #include "private/ogg_helper.h" | 57 #include "private/ogg_helper.h" |
| 73 #include "private/ogg_mapping.h" | 58 #include "private/ogg_mapping.h" |
| 74 #endif | 59 #endif |
| 60 #include "private/stream_encoder.h" |
| 75 #include "private/stream_encoder_framing.h" | 61 #include "private/stream_encoder_framing.h" |
| 76 #include "private/window.h" | 62 #include "private/window.h" |
| 63 #include "share/alloc.h" |
| 64 #include "share/private.h" |
| 77 | 65 |
| 78 #ifndef FLaC__INLINE | |
| 79 #define FLaC__INLINE | |
| 80 #endif | |
| 81 | |
| 82 #ifdef min | |
| 83 #undef min | |
| 84 #endif | |
| 85 #define min(x,y) ((x)<(y)?(x):(y)) | |
| 86 | |
| 87 #ifdef max | |
| 88 #undef max | |
| 89 #endif | |
| 90 #define max(x,y) ((x)>(y)?(x):(y)) | |
| 91 | 66 |
| 92 /* Exact Rice codeword length calculation is off by default. The simple | 67 /* Exact Rice codeword length calculation is off by default. The simple |
| 93 * (and fast) estimation (of how many bits a residual value will be | 68 * (and fast) estimation (of how many bits a residual value will be |
| 94 * encoded with) in this encoder is very good, almost always yielding | 69 * encoded with) in this encoder is very good, almost always yielding |
| 95 * compression within 0.1% of exact calculation. | 70 * compression within 0.1% of exact calculation. |
| 96 */ | 71 */ |
| 97 #undef EXACT_RICE_BITS_CALCULATION | 72 #undef EXACT_RICE_BITS_CALCULATION |
| 98 /* Rice parameter searching is off by default. The simple (and fast) | 73 /* Rice parameter searching is off by default. The simple (and fast) |
| 99 * parameter estimation in this encoder is very good, almost always | 74 * parameter estimation in this encoder is very good, almost always |
| 100 * yielding compression within 0.1% of the optimal parameters. | 75 * yielding compression within 0.1% of the optimal parameters. |
| 101 */ | 76 */ |
| 102 #undef ENABLE_RICE_PARAMETER_SEARCH | 77 #undef ENABLE_RICE_PARAMETER_SEARCH |
| 103 | 78 |
| 104 | 79 |
| 105 typedef struct { | 80 typedef struct { |
| 106 FLAC__int32 *data[FLAC__MAX_CHANNELS]; | 81 FLAC__int32 *data[FLAC__MAX_CHANNELS]; |
| 107 unsigned size; /* of each data[] in samples */ | 82 unsigned size; /* of each data[] in samples */ |
| 108 unsigned tail; | 83 unsigned tail; |
| 109 } verify_input_fifo; | 84 } verify_input_fifo; |
| 110 | 85 |
| 111 typedef struct { | 86 typedef struct { |
| 112 const FLAC__byte *data; | 87 const FLAC__byte *data; |
| 113 unsigned capacity; | 88 unsigned capacity; |
| 114 » size_t bytes; | 89 » unsigned bytes; |
| 115 } verify_output; | 90 } verify_output; |
| 116 | 91 |
| 117 typedef enum { | 92 typedef enum { |
| 118 ENCODER_IN_MAGIC = 0, | 93 ENCODER_IN_MAGIC = 0, |
| 119 ENCODER_IN_METADATA = 1, | 94 ENCODER_IN_METADATA = 1, |
| 120 ENCODER_IN_AUDIO = 2 | 95 ENCODER_IN_AUDIO = 2 |
| 121 } EncoderStateHint; | 96 } EncoderStateHint; |
| 122 | 97 |
| 123 static struct CompressionLevels { | 98 static struct CompressionLevels { |
| 124 FLAC__bool do_mid_side_stereo; | 99 FLAC__bool do_mid_side_stereo; |
| 125 FLAC__bool loose_mid_side_stereo; | 100 FLAC__bool loose_mid_side_stereo; |
| 126 unsigned max_lpc_order; | 101 unsigned max_lpc_order; |
| 127 unsigned qlp_coeff_precision; | 102 unsigned qlp_coeff_precision; |
| 128 FLAC__bool do_qlp_coeff_prec_search; | 103 FLAC__bool do_qlp_coeff_prec_search; |
| 129 FLAC__bool do_escape_coding; | 104 FLAC__bool do_escape_coding; |
| 130 FLAC__bool do_exhaustive_model_search; | 105 FLAC__bool do_exhaustive_model_search; |
| 131 unsigned min_residual_partition_order; | 106 unsigned min_residual_partition_order; |
| 132 unsigned max_residual_partition_order; | 107 unsigned max_residual_partition_order; |
| 133 unsigned rice_parameter_search_dist; | 108 unsigned rice_parameter_search_dist; |
| 109 const char *apodization; |
| 134 } compression_levels_[] = { | 110 } compression_levels_[] = { |
| 135 » { false, false, 0, 0, false, false, false, 0, 3, 0 }, | 111 » { false, false, 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" }, |
| 136 » { true , true , 0, 0, false, false, false, 0, 3, 0 }, | 112 » { true , true , 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" }, |
| 137 » { true , false, 0, 0, false, false, false, 0, 3, 0 }, | 113 » { true , false, 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" }, |
| 138 » { false, false, 6, 0, false, false, false, 0, 4, 0 }, | 114 » { false, false, 6, 0, false, false, false, 0, 4, 0, "tukey(5e-1)" }, |
| 139 » { true , true , 8, 0, false, false, false, 0, 4, 0 }, | 115 » { true , true , 8, 0, false, false, false, 0, 4, 0, "tukey(5e-1)" }, |
| 140 » { true , false, 8, 0, false, false, false, 0, 5, 0 }, | 116 » { true , false, 8, 0, false, false, false, 0, 5, 0, "tukey(5e-1)" }, |
| 141 » { true , false, 8, 0, false, false, false, 0, 6, 0 }, | 117 » { true , false, 8, 0, false, false, false, 0, 6, 0, "tukey(5e-1);partia
l_tukey(2)" }, |
| 142 » { true , false, 8, 0, false, false, true , 0, 6, 0 }, | 118 » { true , false, 12, 0, false, false, false, 0, 6, 0, "tukey(5e-1);partia
l_tukey(2)" }, |
| 143 » { true , false, 12, 0, false, false, true , 0, 6, 0 } | 119 » { true , false, 12, 0, false, false, false, 0, 6, 0, "tukey(5e-1);partia
l_tukey(2);punchout_tukey(3)" } |
| 120 » /* here we use locale-independent 5e-1 instead of 0.5 or 0,5 */ |
| 144 }; | 121 }; |
| 145 | 122 |
| 146 | 123 |
| 147 /*********************************************************************** | 124 /*********************************************************************** |
| 148 * | 125 * |
| 149 * Private class method prototypes | 126 * Private class method prototypes |
| 150 * | 127 * |
| 151 ***********************************************************************/ | 128 ***********************************************************************/ |
| 152 | 129 |
| 153 static void set_defaults_(FLAC__StreamEncoder *encoder); | 130 static void set_defaults_(FLAC__StreamEncoder *encoder); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 unsigned min_partition_order, | 205 unsigned min_partition_order, |
| 229 unsigned max_partition_order, | 206 unsigned max_partition_order, |
| 230 FLAC__bool do_escape_coding, | 207 FLAC__bool do_escape_coding, |
| 231 unsigned rice_parameter_search_dist, | 208 unsigned rice_parameter_search_dist, |
| 232 FLAC__Subframe *subframe, | 209 FLAC__Subframe *subframe, |
| 233 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_cont
ents | 210 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_cont
ents |
| 234 ); | 211 ); |
| 235 #endif | 212 #endif |
| 236 | 213 |
| 237 static unsigned evaluate_verbatim_subframe_( | 214 static unsigned evaluate_verbatim_subframe_( |
| 238 » FLAC__StreamEncoder *encoder, | 215 » FLAC__StreamEncoder *encoder, |
| 239 const FLAC__int32 signal[], | 216 const FLAC__int32 signal[], |
| 240 unsigned blocksize, | 217 unsigned blocksize, |
| 241 unsigned subframe_bps, | 218 unsigned subframe_bps, |
| 242 FLAC__Subframe *subframe | 219 FLAC__Subframe *subframe |
| 243 ); | 220 ); |
| 244 | 221 |
| 245 static unsigned find_best_partition_order_( | 222 static unsigned find_best_partition_order_( |
| 246 struct FLAC__StreamEncoderPrivate *private_, | 223 struct FLAC__StreamEncoderPrivate *private_, |
| 247 const FLAC__int32 residual[], | 224 const FLAC__int32 residual[], |
| 248 FLAC__uint64 abs_residual_partition_sums[], | 225 FLAC__uint64 abs_residual_partition_sums[], |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 FLAC__BitWriter *frame; /* the current frame b
eing worked on */ | 340 FLAC__BitWriter *frame; /* the current frame b
eing worked on */ |
| 364 unsigned loose_mid_side_stereo_frames; /* rounded number of f
rames the encoder will use before trying both independent and mid/side frames ag
ain */ | 341 unsigned loose_mid_side_stereo_frames; /* rounded number of f
rames the encoder will use before trying both independent and mid/side frames ag
ain */ |
| 365 unsigned loose_mid_side_stereo_frame_count; /* number of frames us
ing the current channel assignment */ | 342 unsigned loose_mid_side_stereo_frame_count; /* number of frames us
ing the current channel assignment */ |
| 366 FLAC__ChannelAssignment last_channel_assignment; | 343 FLAC__ChannelAssignment last_channel_assignment; |
| 367 FLAC__StreamMetadata streaminfo; /* scratchpad for STRE
AMINFO as it is built */ | 344 FLAC__StreamMetadata streaminfo; /* scratchpad for STRE
AMINFO as it is built */ |
| 368 FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encode
r->protected_->metadata_ where the seek table is */ | 345 FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encode
r->protected_->metadata_ where the seek table is */ |
| 369 unsigned current_sample_number; | 346 unsigned current_sample_number; |
| 370 unsigned current_frame_number; | 347 unsigned current_frame_number; |
| 371 FLAC__MD5Context md5context; | 348 FLAC__MD5Context md5context; |
| 372 FLAC__CPUInfo cpuinfo; | 349 FLAC__CPUInfo cpuinfo; |
| 350 void (*local_precompute_partition_info_sums)(const FLAC__int32 residual[
], FLAC__uint64 abs_residual_partition_sums[], unsigned residual_samples, unsign
ed predictor_order, unsigned min_partition_order, unsigned max_partition_order,
unsigned bps); |
| 373 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 351 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 374 unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[],
unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1
]); | 352 unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[],
unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1
]); |
| 353 unsigned (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 da
ta[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_OR
DER+1]); |
| 375 #else | 354 #else |
| 376 unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[],
unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_OR
DER+1]); | 355 unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[],
unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_OR
DER+1]); |
| 356 unsigned (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 da
ta[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIX
ED_ORDER+1]); |
| 377 #endif | 357 #endif |
| 378 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 358 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 379 void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsig
ned data_len, unsigned lag, FLAC__real autoc[]); | 359 void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsig
ned data_len, unsigned lag, FLAC__real autoc[]); |
| 380 void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int
32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int
lp_quantization, FLAC__int32 residual[]); | 360 void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int
32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int
lp_quantization, FLAC__int32 residual[]); |
| 381 void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLA
C__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order
, int lp_quantization, FLAC__int32 residual[]); | 361 void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLA
C__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order
, int lp_quantization, FLAC__int32 residual[]); |
| 382 void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLA
C__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order
, int lp_quantization, FLAC__int32 residual[]); | 362 void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLA
C__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order
, int lp_quantization, FLAC__int32 residual[]); |
| 383 #endif | 363 #endif |
| 384 FLAC__bool use_wide_by_block; /* use slow 64-bit versions of so
me functions because of the block size */ | 364 FLAC__bool use_wide_by_block; /* use slow 64-bit versions of so
me functions because of the block size */ |
| 385 FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of so
me functions because of the min partition order and blocksize */ | 365 FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of so
me functions because of the min partition order and blocksize */ |
| 386 FLAC__bool use_wide_by_order; /* use slow 64-bit versions of so
me functions because of the lpc order */ | 366 FLAC__bool use_wide_by_order; /* use slow 64-bit versions of so
me functions because of the lpc order */ |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE", | 453 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE", |
| 474 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE", | 454 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE", |
| 475 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER", | 455 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER", |
| 476 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION", | 456 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION", |
| 477 "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER", | 457 "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER", |
| 478 "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE", | 458 "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE", |
| 479 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA", | 459 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA", |
| 480 "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED" | 460 "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED" |
| 481 }; | 461 }; |
| 482 | 462 |
| 483 FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = { | 463 FLAC_API const char * const FLAC__StreamEncoderReadStatusString[] = { |
| 484 "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE", | 464 "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE", |
| 485 "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM", | 465 "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM", |
| 486 "FLAC__STREAM_ENCODER_READ_STATUS_ABORT", | 466 "FLAC__STREAM_ENCODER_READ_STATUS_ABORT", |
| 487 "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED" | 467 "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED" |
| 488 }; | 468 }; |
| 489 | 469 |
| 490 FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = { | 470 FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = { |
| 491 "FLAC__STREAM_ENCODER_WRITE_STATUS_OK", | 471 "FLAC__STREAM_ENCODER_WRITE_STATUS_OK", |
| 492 "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR" | 472 "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR" |
| 493 }; | 473 }; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 522 * Class constructor/destructor | 502 * Class constructor/destructor |
| 523 * | 503 * |
| 524 */ | 504 */ |
| 525 FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void) | 505 FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void) |
| 526 { | 506 { |
| 527 FLAC__StreamEncoder *encoder; | 507 FLAC__StreamEncoder *encoder; |
| 528 unsigned i; | 508 unsigned i; |
| 529 | 509 |
| 530 FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is
not true */ | 510 FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is
not true */ |
| 531 | 511 |
| 532 » encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder)); | 512 » encoder = calloc(1, sizeof(FLAC__StreamEncoder)); |
| 533 if(encoder == 0) { | 513 if(encoder == 0) { |
| 534 return 0; | 514 return 0; |
| 535 } | 515 } |
| 536 | 516 |
| 537 » encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FL
AC__StreamEncoderProtected)); | 517 » encoder->protected_ = calloc(1, sizeof(FLAC__StreamEncoderProtected)); |
| 538 if(encoder->protected_ == 0) { | 518 if(encoder->protected_ == 0) { |
| 539 free(encoder); | 519 free(encoder); |
| 540 return 0; | 520 return 0; |
| 541 } | 521 } |
| 542 | 522 |
| 543 » encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__
StreamEncoderPrivate)); | 523 » encoder->private_ = calloc(1, sizeof(FLAC__StreamEncoderPrivate)); |
| 544 if(encoder->private_ == 0) { | 524 if(encoder->private_ == 0) { |
| 545 free(encoder->protected_); | 525 free(encoder->protected_); |
| 546 free(encoder); | 526 free(encoder); |
| 547 return 0; | 527 return 0; |
| 548 } | 528 } |
| 549 | 529 |
| 550 encoder->private_->frame = FLAC__bitwriter_new(); | 530 encoder->private_->frame = FLAC__bitwriter_new(); |
| 551 if(encoder->private_->frame == 0) { | 531 if(encoder->private_->frame == 0) { |
| 552 free(encoder->private_); | 532 free(encoder->private_); |
| 553 free(encoder->protected_); | 533 free(encoder->protected_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 571 |
| 592 encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED; | 572 encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED; |
| 593 | 573 |
| 594 return encoder; | 574 return encoder; |
| 595 } | 575 } |
| 596 | 576 |
| 597 FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder) | 577 FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder) |
| 598 { | 578 { |
| 599 unsigned i; | 579 unsigned i; |
| 600 | 580 |
| 601 » FLAC__ASSERT(0 != encoder); | 581 » if (encoder == NULL) |
| 582 » » return ; |
| 583 |
| 602 FLAC__ASSERT(0 != encoder->protected_); | 584 FLAC__ASSERT(0 != encoder->protected_); |
| 603 FLAC__ASSERT(0 != encoder->private_); | 585 FLAC__ASSERT(0 != encoder->private_); |
| 604 FLAC__ASSERT(0 != encoder->private_->frame); | 586 FLAC__ASSERT(0 != encoder->private_->frame); |
| 605 | 587 |
| 606 encoder->private_->is_being_deleted = true; | 588 encoder->private_->is_being_deleted = true; |
| 607 | 589 |
| 608 (void)FLAC__stream_encoder_finish(encoder); | 590 (void)FLAC__stream_encoder_finish(encoder); |
| 609 | 591 |
| 610 if(0 != encoder->private_->verify.decoder) | 592 if(0 != encoder->private_->verify.decoder) |
| 611 FLAC__stream_decoder_delete(encoder->private_->verify.decoder); | 593 FLAC__stream_decoder_delete(encoder->private_->verify.decoder); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER) | 674 if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER) |
| 693 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER; | 675 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER; |
| 694 | 676 |
| 695 if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order) | 677 if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order) |
| 696 return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR
_LPC_ORDER; | 678 return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR
_LPC_ORDER; |
| 697 | 679 |
| 698 if(encoder->protected_->qlp_coeff_precision == 0) { | 680 if(encoder->protected_->qlp_coeff_precision == 0) { |
| 699 if(encoder->protected_->bits_per_sample < 16) { | 681 if(encoder->protected_->bits_per_sample < 16) { |
| 700 /* @@@ need some data about how to set this here w.r.t.
blocksize and sample rate */ | 682 /* @@@ need some data about how to set this here w.r.t.
blocksize and sample rate */ |
| 701 /* @@@ until then we'll make a guess */ | 683 /* @@@ until then we'll make a guess */ |
| 702 » » » encoder->protected_->qlp_coeff_precision = max(FLAC__MIN
_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2); | 684 » » » encoder->protected_->qlp_coeff_precision = flac_max(FLAC
__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2); |
| 703 } | 685 } |
| 704 else if(encoder->protected_->bits_per_sample == 16) { | 686 else if(encoder->protected_->bits_per_sample == 16) { |
| 705 if(encoder->protected_->blocksize <= 192) | 687 if(encoder->protected_->blocksize <= 192) |
| 706 encoder->protected_->qlp_coeff_precision = 7; | 688 encoder->protected_->qlp_coeff_precision = 7; |
| 707 else if(encoder->protected_->blocksize <= 384) | 689 else if(encoder->protected_->blocksize <= 384) |
| 708 encoder->protected_->qlp_coeff_precision = 8; | 690 encoder->protected_->qlp_coeff_precision = 8; |
| 709 else if(encoder->protected_->blocksize <= 576) | 691 else if(encoder->protected_->blocksize <= 576) |
| 710 encoder->protected_->qlp_coeff_precision = 9; | 692 encoder->protected_->qlp_coeff_precision = 9; |
| 711 else if(encoder->protected_->blocksize <= 1152) | 693 else if(encoder->protected_->blocksize <= 1152) |
| 712 encoder->protected_->qlp_coeff_precision = 10; | 694 encoder->protected_->qlp_coeff_precision = 10; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 724 encoder->protected_->qlp_coeff_precision = FLAC_
_MAX_QLP_COEFF_PRECISION-1; | 706 encoder->protected_->qlp_coeff_precision = FLAC_
_MAX_QLP_COEFF_PRECISION-1; |
| 725 else | 707 else |
| 726 encoder->protected_->qlp_coeff_precision = FLAC_
_MAX_QLP_COEFF_PRECISION; | 708 encoder->protected_->qlp_coeff_precision = FLAC_
_MAX_QLP_COEFF_PRECISION; |
| 727 } | 709 } |
| 728 FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__M
AX_QLP_COEFF_PRECISION); | 710 FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__M
AX_QLP_COEFF_PRECISION); |
| 729 } | 711 } |
| 730 else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_P
RECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECI
SION) | 712 else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_P
RECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECI
SION) |
| 731 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECIS
ION; | 713 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECIS
ION; |
| 732 | 714 |
| 733 if(encoder->protected_->streamable_subset) { | 715 if(encoder->protected_->streamable_subset) { |
| 734 » » if( | 716 » » if(!FLAC__format_blocksize_is_subset(encoder->protected_->blocks
ize, encoder->protected_->sample_rate)) |
| 735 » » » encoder->protected_->blocksize != 192 && | |
| 736 » » » encoder->protected_->blocksize != 576 && | |
| 737 » » » encoder->protected_->blocksize != 1152 && | |
| 738 » » » encoder->protected_->blocksize != 2304 && | |
| 739 » » » encoder->protected_->blocksize != 4608 && | |
| 740 » » » encoder->protected_->blocksize != 256 && | |
| 741 » » » encoder->protected_->blocksize != 512 && | |
| 742 » » » encoder->protected_->blocksize != 1024 && | |
| 743 » » » encoder->protected_->blocksize != 2048 && | |
| 744 » » » encoder->protected_->blocksize != 4096 && | |
| 745 » » » encoder->protected_->blocksize != 8192 && | |
| 746 » » » encoder->protected_->blocksize != 16384 | |
| 747 » » ) | |
| 748 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; | 717 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; |
| 749 if(!FLAC__format_sample_rate_is_subset(encoder->protected_->samp
le_rate)) | 718 if(!FLAC__format_sample_rate_is_subset(encoder->protected_->samp
le_rate)) |
| 750 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; | 719 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; |
| 751 if( | 720 if( |
| 752 encoder->protected_->bits_per_sample != 8 && | 721 encoder->protected_->bits_per_sample != 8 && |
| 753 encoder->protected_->bits_per_sample != 12 && | 722 encoder->protected_->bits_per_sample != 12 && |
| 754 encoder->protected_->bits_per_sample != 16 && | 723 encoder->protected_->bits_per_sample != 16 && |
| 755 encoder->protected_->bits_per_sample != 20 && | 724 encoder->protected_->bits_per_sample != 20 && |
| 756 encoder->protected_->bits_per_sample != 24 | 725 encoder->protected_->bits_per_sample != 24 |
| 757 ) | 726 ) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 770 } | 739 } |
| 771 | 740 |
| 772 if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENT
ROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN)) | 741 if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENT
ROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN)) |
| 773 encoder->protected_->max_residual_partition_order = (1u << FLAC_
_ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1; | 742 encoder->protected_->max_residual_partition_order = (1u << FLAC_
_ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1; |
| 774 if(encoder->protected_->min_residual_partition_order >= encoder->protect
ed_->max_residual_partition_order) | 743 if(encoder->protected_->min_residual_partition_order >= encoder->protect
ed_->max_residual_partition_order) |
| 775 encoder->protected_->min_residual_partition_order = encoder->pro
tected_->max_residual_partition_order; | 744 encoder->protected_->min_residual_partition_order = encoder->pro
tected_->max_residual_partition_order; |
| 776 | 745 |
| 777 #if FLAC__HAS_OGG | 746 #if FLAC__HAS_OGG |
| 778 /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is th
e first, according to the mapping spec */ | 747 /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is th
e first, according to the mapping spec */ |
| 779 if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->
num_metadata_blocks > 1) { | 748 if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->
num_metadata_blocks > 1) { |
| 780 » » unsigned i; | 749 » » unsigned i1; |
| 781 » » for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) { | 750 » » for(i1 = 1; i1 < encoder->protected_->num_metadata_blocks; i1++)
{ |
| 782 » » » if(0 != encoder->protected_->metadata[i] && encoder->pro
tected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { | 751 » » » if(0 != encoder->protected_->metadata[i1] && encoder->pr
otected_->metadata[i1]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { |
| 783 » » » » FLAC__StreamMetadata *vc = encoder->protected_->
metadata[i]; | 752 » » » » FLAC__StreamMetadata *vc = encoder->protected_->
metadata[i1]; |
| 784 » » » » for( ; i > 0; i--) | 753 » » » » for( ; i1 > 0; i1--) |
| 785 » » » » » encoder->protected_->metadata[i] = encod
er->protected_->metadata[i-1]; | 754 » » » » » encoder->protected_->metadata[i1] = enco
der->protected_->metadata[i1-1]; |
| 786 encoder->protected_->metadata[0] = vc; | 755 encoder->protected_->metadata[0] = vc; |
| 787 break; | 756 break; |
| 788 } | 757 } |
| 789 } | 758 } |
| 790 } | 759 } |
| 791 #endif | 760 #endif |
| 792 /* keep track of any SEEKTABLE block */ | 761 /* keep track of any SEEKTABLE block */ |
| 793 if(0 != encoder->protected_->metadata && encoder->protected_->num_metada
ta_blocks > 0) { | 762 if(0 != encoder->protected_->metadata && encoder->protected_->num_metada
ta_blocks > 0) { |
| 794 » » unsigned i; | 763 » » unsigned i2; |
| 795 » » for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) { | 764 » » for(i2 = 0; i2 < encoder->protected_->num_metadata_blocks; i2++)
{ |
| 796 » » » if(0 != encoder->protected_->metadata[i] && encoder->pro
tected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) { | 765 » » » if(0 != encoder->protected_->metadata[i2] && encoder->pr
otected_->metadata[i2]->type == FLAC__METADATA_TYPE_SEEKTABLE) { |
| 797 » » » » encoder->private_->seek_table = &encoder->protec
ted_->metadata[i]->data.seek_table; | 766 » » » » encoder->private_->seek_table = &encoder->protec
ted_->metadata[i2]->data.seek_table; |
| 798 break; /* take only the first one */ | 767 break; /* take only the first one */ |
| 799 } | 768 } |
| 800 } | 769 } |
| 801 } | 770 } |
| 802 | 771 |
| 803 /* validate metadata */ | 772 /* validate metadata */ |
| 804 if(0 == encoder->protected_->metadata && encoder->protected_->num_metada
ta_blocks > 0) | 773 if(0 == encoder->protected_->metadata && encoder->protected_->num_metada
ta_blocks > 0) |
| 805 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; | 774 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; |
| 806 metadata_has_seektable = false; | 775 metadata_has_seektable = false; |
| 807 metadata_has_vorbis_comment = false; | 776 metadata_has_vorbis_comment = false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 829 } | 798 } |
| 830 else if(m->type == FLAC__METADATA_TYPE_PICTURE) { | 799 else if(m->type == FLAC__METADATA_TYPE_PICTURE) { |
| 831 if(!FLAC__format_picture_is_legal(&m->data.picture, /*vi
olation=*/0)) | 800 if(!FLAC__format_picture_is_legal(&m->data.picture, /*vi
olation=*/0)) |
| 832 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_
METADATA; | 801 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_
METADATA; |
| 833 if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE
_TYPE_FILE_ICON_STANDARD) { | 802 if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE
_TYPE_FILE_ICON_STANDARD) { |
| 834 if(metadata_picture_has_type1) /* there should o
nly be 1 per stream */ | 803 if(metadata_picture_has_type1) /* there should o
nly be 1 per stream */ |
| 835 return FLAC__STREAM_ENCODER_INIT_STATUS_
INVALID_METADATA; | 804 return FLAC__STREAM_ENCODER_INIT_STATUS_
INVALID_METADATA; |
| 836 metadata_picture_has_type1 = true; | 805 metadata_picture_has_type1 = true; |
| 837 /* standard icon must be 32x32 pixel PNG */ | 806 /* standard icon must be 32x32 pixel PNG */ |
| 838 if( | 807 if( |
| 839 » » » » » m->data.picture.type == FLAC__STREAM_MET
ADATA_PICTURE_TYPE_FILE_ICON_STANDARD && | 808 » » » » » m->data.picture.type == FLAC__STREAM_MET
ADATA_PICTURE_TYPE_FILE_ICON_STANDARD && |
| 840 ( | 809 ( |
| 841 (strcmp(m->data.picture.mime_typ
e, "image/png") && strcmp(m->data.picture.mime_type, "-->")) || | 810 (strcmp(m->data.picture.mime_typ
e, "image/png") && strcmp(m->data.picture.mime_type, "-->")) || |
| 842 m->data.picture.width != 32 || | 811 m->data.picture.width != 32 || |
| 843 m->data.picture.height != 32 | 812 m->data.picture.height != 32 |
| 844 ) | 813 ) |
| 845 ) | 814 ) |
| 846 return FLAC__STREAM_ENCODER_INIT_STATUS_
INVALID_METADATA; | 815 return FLAC__STREAM_ENCODER_INIT_STATUS_
INVALID_METADATA; |
| 847 } | 816 } |
| 848 else if(m->data.picture.type == FLAC__STREAM_METADATA_PI
CTURE_TYPE_FILE_ICON) { | 817 else if(m->data.picture.type == FLAC__STREAM_METADATA_PI
CTURE_TYPE_FILE_ICON) { |
| 849 if(metadata_picture_has_type2) /* there should o
nly be 1 per stream */ | 818 if(metadata_picture_has_type2) /* there should o
nly be 1 per stream */ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 FLAC__ASSERT(encoder->protected_->blocksize <= 65535); | 863 FLAC__ASSERT(encoder->protected_->blocksize <= 65535); |
| 895 encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedp
oint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(2
6214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF); | 864 encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedp
oint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(2
6214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF); |
| 896 #endif | 865 #endif |
| 897 if(encoder->private_->loose_mid_side_stereo_frames == 0) | 866 if(encoder->private_->loose_mid_side_stereo_frames == 0) |
| 898 encoder->private_->loose_mid_side_stereo_frames = 1; | 867 encoder->private_->loose_mid_side_stereo_frames = 1; |
| 899 encoder->private_->loose_mid_side_stereo_frame_count = 0; | 868 encoder->private_->loose_mid_side_stereo_frame_count = 0; |
| 900 encoder->private_->current_sample_number = 0; | 869 encoder->private_->current_sample_number = 0; |
| 901 encoder->private_->current_frame_number = 0; | 870 encoder->private_->current_frame_number = 0; |
| 902 | 871 |
| 903 encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sa
mple + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30); | 872 encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sa
mple + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30); |
| 904 » encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sa
mple + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIX
ED_ORDER))+1 > 30); /*@@@ need to use this? */ | 873 » encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sa
mple + FLAC__bitmath_ilog2(flac_max(encoder->protected_->max_lpc_order, FLAC__MA
X_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */ |
| 905 encoder->private_->use_wide_by_partition = (false); /*@@@ need to set th
is */ | 874 encoder->private_->use_wide_by_partition = (false); /*@@@ need to set th
is */ |
| 906 | 875 |
| 907 /* | 876 /* |
| 908 * get the CPU info and set the function pointers | 877 * get the CPU info and set the function pointers |
| 909 */ | 878 */ |
| 910 FLAC__cpu_info(&encoder->private_->cpuinfo); | 879 FLAC__cpu_info(&encoder->private_->cpuinfo); |
| 911 /* first default to the non-asm routines */ | 880 /* first default to the non-asm routines */ |
| 912 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 881 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 913 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute
_autocorrelation; | 882 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute
_autocorrelation; |
| 914 #endif | 883 #endif |
| 884 encoder->private_->local_precompute_partition_info_sums = precompute_par
tition_info_sums_; |
| 915 encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_comp
ute_best_predictor; | 885 encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_comp
ute_best_predictor; |
| 886 encoder->private_->local_fixed_compute_best_predictor_wide = FLAC__fixed
_compute_best_predictor_wide; |
| 916 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 887 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 917 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FL
AC__lpc_compute_residual_from_qlp_coefficients; | 888 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FL
AC__lpc_compute_residual_from_qlp_coefficients; |
| 918 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bi
t = FLAC__lpc_compute_residual_from_qlp_coefficients_wide; | 889 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bi
t = FLAC__lpc_compute_residual_from_qlp_coefficients_wide; |
| 919 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bi
t = FLAC__lpc_compute_residual_from_qlp_coefficients; | 890 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bi
t = FLAC__lpc_compute_residual_from_qlp_coefficients; |
| 920 #endif | 891 #endif |
| 921 /* now override with asm where appropriate */ | 892 /* now override with asm where appropriate */ |
| 922 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 893 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 923 # ifndef FLAC__NO_ASM | 894 # ifndef FLAC__NO_ASM |
| 924 if(encoder->private_->cpuinfo.use_asm) { | 895 if(encoder->private_->cpuinfo.use_asm) { |
| 925 # ifdef FLAC__CPU_IA32 | 896 # ifdef FLAC__CPU_IA32 |
| 926 FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TY
PE_IA32); | 897 FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TY
PE_IA32); |
| 927 # ifdef FLAC__HAS_NASM | 898 # ifdef FLAC__HAS_NASM |
| 928 » » if(encoder->private_->cpuinfo.data.ia32.sse) { | 899 » » if(encoder->private_->cpuinfo.ia32.sse) { |
| 929 if(encoder->protected_->max_lpc_order < 4) | 900 if(encoder->protected_->max_lpc_order < 4) |
| 930 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4; | 901 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4; |
| 931 else if(encoder->protected_->max_lpc_order < 8) | 902 else if(encoder->protected_->max_lpc_order < 8) |
| 932 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8; | 903 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8; |
| 933 else if(encoder->protected_->max_lpc_order < 12) | 904 else if(encoder->protected_->max_lpc_order < 12) |
| 934 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12; | 905 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12; |
| 906 else if(encoder->protected_->max_lpc_order < 16) |
| 907 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_16; |
| 935 else | 908 else |
| 936 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32; | 909 encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_asm_ia32; |
| 937 } | 910 } |
| 938 else if(encoder->private_->cpuinfo.data.ia32._3dnow) | |
| 939 encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_asm_ia32_3dnow; | |
| 940 else | 911 else |
| 941 encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_asm_ia32; | 912 encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_asm_ia32; |
| 942 » » if(encoder->private_->cpuinfo.data.ia32.mmx) { | 913 |
| 914 » » encoder->private_->local_lpc_compute_residual_from_qlp_coefficie
nts_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_asm_ia32; /* O
PT_IA32: was really necessary for GCC < 4.9 */ |
| 915 » » if(encoder->private_->cpuinfo.ia32.mmx) { |
| 943 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32; | 916 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32; |
| 944 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mm
x; | 917 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mm
x; |
| 945 } | 918 } |
| 946 else { | 919 else { |
| 947 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32; | 920 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32; |
| 948 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32; | 921 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32; |
| 949 } | 922 } |
| 950 » » if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_
->cpuinfo.data.ia32.cmov) | 923 |
| 924 » » if(encoder->private_->cpuinfo.ia32.mmx && encoder->private_->cpu
info.ia32.cmov) |
| 951 encoder->private_->local_fixed_compute_best_predictor =
FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov; | 925 encoder->private_->local_fixed_compute_best_predictor =
FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov; |
| 952 # endif /* FLAC__HAS_NASM */ | 926 # endif /* FLAC__HAS_NASM */ |
| 953 # endif /* FLAC__CPU_IA32 */ | 927 # ifdef FLAC__HAS_X86INTRIN |
| 928 # if defined FLAC__SSE_SUPPORTED |
| 929 » » if(encoder->private_->cpuinfo.ia32.sse) { |
| 930 » » » if(encoder->protected_->max_lpc_order < 4) |
| 931 » » » » encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_4; |
| 932 » » » else if(encoder->protected_->max_lpc_order < 8) |
| 933 » » » » encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_8; |
| 934 » » » else if(encoder->protected_->max_lpc_order < 12) |
| 935 » » » » encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_12; |
| 936 » » » else if(encoder->protected_->max_lpc_order < 16) |
| 937 » » » » encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16; |
| 938 » » » else |
| 939 » » » » encoder->private_->local_lpc_compute_autocorrela
tion = FLAC__lpc_compute_autocorrelation; |
| 940 » » } |
| 941 # endif |
| 942 |
| 943 # ifdef FLAC__SSE2_SUPPORTED |
| 944 » » if(encoder->private_->cpuinfo.ia32.sse2) { |
| 945 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2
; |
| 946 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_s
se2; |
| 947 » » } |
| 948 # endif |
| 949 # ifdef FLAC__SSE4_1_SUPPORTED |
| 950 » » if(encoder->private_->cpuinfo.ia32.sse41) { |
| 951 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse4
1; |
| 952 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin
_sse41; |
| 953 » » } |
| 954 # endif |
| 955 # ifdef FLAC__AVX2_SUPPORTED |
| 956 » » if(encoder->private_->cpuinfo.ia32.avx2) { |
| 957 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_a
vx2; |
| 958 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2
; |
| 959 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin
_avx2; |
| 960 » » } |
| 961 # endif |
| 962 |
| 963 # ifdef FLAC__SSE2_SUPPORTED |
| 964 » » if (encoder->private_->cpuinfo.ia32.sse2) { |
| 965 » » » encoder->private_->local_fixed_compute_best_predictor
= FLAC__fixed_compute_best_predictor_intrin_sse2; |
| 966 » » » encoder->private_->local_fixed_compute_best_predictor_wi
de = FLAC__fixed_compute_best_predictor_wide_intrin_sse2; |
| 967 » » } |
| 968 # endif |
| 969 # ifdef FLAC__SSSE3_SUPPORTED |
| 970 » » if (encoder->private_->cpuinfo.ia32.ssse3) { |
| 971 » » » encoder->private_->local_fixed_compute_best_predictor
= FLAC__fixed_compute_best_predictor_intrin_ssse3; |
| 972 » » » encoder->private_->local_fixed_compute_best_predictor_wi
de = FLAC__fixed_compute_best_predictor_wide_intrin_ssse3; |
| 973 » » } |
| 974 # endif |
| 975 # endif /* FLAC__HAS_X86INTRIN */ |
| 976 # elif defined FLAC__CPU_X86_64 |
| 977 » » FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TY
PE_X86_64); |
| 978 # ifdef FLAC__HAS_X86INTRIN |
| 979 # ifdef FLAC__SSE_SUPPORTED |
| 980 » » if(encoder->protected_->max_lpc_order < 4) |
| 981 » » » encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_intrin_sse_lag_4; |
| 982 » » else if(encoder->protected_->max_lpc_order < 8) |
| 983 » » » encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_intrin_sse_lag_8; |
| 984 » » else if(encoder->protected_->max_lpc_order < 12) |
| 985 » » » encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_intrin_sse_lag_12; |
| 986 » » else if(encoder->protected_->max_lpc_order < 16) |
| 987 » » » encoder->private_->local_lpc_compute_autocorrelation = F
LAC__lpc_compute_autocorrelation_intrin_sse_lag_16; |
| 988 # endif |
| 989 |
| 990 # ifdef FLAC__SSE2_SUPPORTED |
| 991 » » encoder->private_->local_lpc_compute_residual_from_qlp_coefficie
nts_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2; |
| 992 # endif |
| 993 # ifdef FLAC__SSE4_1_SUPPORTED |
| 994 » » if(encoder->private_->cpuinfo.x86.sse41) { |
| 995 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41; |
| 996 » » } |
| 997 # endif |
| 998 # ifdef FLAC__AVX2_SUPPORTED |
| 999 » » if(encoder->private_->cpuinfo.x86.avx2) { |
| 1000 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_a
vx2; |
| 1001 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2
; |
| 1002 » » » encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin
_avx2; |
| 1003 » » } |
| 1004 # endif |
| 1005 |
| 1006 # ifdef FLAC__SSE2_SUPPORTED |
| 1007 » » encoder->private_->local_fixed_compute_best_predictor = FLA
C__fixed_compute_best_predictor_intrin_sse2; |
| 1008 » » encoder->private_->local_fixed_compute_best_predictor_wide = FLA
C__fixed_compute_best_predictor_wide_intrin_sse2; |
| 1009 # endif |
| 1010 # ifdef FLAC__SSSE3_SUPPORTED |
| 1011 » » if (encoder->private_->cpuinfo.x86.ssse3) { |
| 1012 » » » encoder->private_->local_fixed_compute_best_predictor
= FLAC__fixed_compute_best_predictor_intrin_ssse3; |
| 1013 » » » encoder->private_->local_fixed_compute_best_predictor_wi
de = FLAC__fixed_compute_best_predictor_wide_intrin_ssse3; |
| 1014 » » } |
| 1015 # endif |
| 1016 # endif /* FLAC__HAS_X86INTRIN */ |
| 1017 # endif /* FLAC__CPU_... */ |
| 954 } | 1018 } |
| 955 # endif /* !FLAC__NO_ASM */ | 1019 # endif /* !FLAC__NO_ASM */ |
| 956 #endif /* !FLAC__INTEGER_ONLY_LIBRARY */ | 1020 #endif /* !FLAC__INTEGER_ONLY_LIBRARY */ |
| 1021 #if !defined FLAC__NO_ASM && defined FLAC__HAS_X86INTRIN |
| 1022 if(encoder->private_->cpuinfo.use_asm) { |
| 1023 # if defined FLAC__CPU_IA32 |
| 1024 # ifdef FLAC__SSE2_SUPPORTED |
| 1025 if(encoder->private_->cpuinfo.ia32.sse2) |
| 1026 encoder->private_->local_precompute_partition_info_sums
= FLAC__precompute_partition_info_sums_intrin_sse2; |
| 1027 # endif |
| 1028 # ifdef FLAC__SSSE3_SUPPORTED |
| 1029 if(encoder->private_->cpuinfo.ia32.ssse3) |
| 1030 encoder->private_->local_precompute_partition_info_sums
= FLAC__precompute_partition_info_sums_intrin_ssse3; |
| 1031 # endif |
| 1032 # ifdef FLAC__AVX2_SUPPORTED |
| 1033 if(encoder->private_->cpuinfo.ia32.avx2) |
| 1034 encoder->private_->local_precompute_partition_info_sums
= FLAC__precompute_partition_info_sums_intrin_avx2; |
| 1035 # endif |
| 1036 # elif defined FLAC__CPU_X86_64 |
| 1037 # ifdef FLAC__SSE2_SUPPORTED |
| 1038 encoder->private_->local_precompute_partition_info_sums = FLAC__
precompute_partition_info_sums_intrin_sse2; |
| 1039 # endif |
| 1040 # ifdef FLAC__SSSE3_SUPPORTED |
| 1041 if(encoder->private_->cpuinfo.x86.ssse3) |
| 1042 encoder->private_->local_precompute_partition_info_sums
= FLAC__precompute_partition_info_sums_intrin_ssse3; |
| 1043 # endif |
| 1044 # ifdef FLAC__AVX2_SUPPORTED |
| 1045 if(encoder->private_->cpuinfo.x86.avx2) |
| 1046 encoder->private_->local_precompute_partition_info_sums
= FLAC__precompute_partition_info_sums_intrin_avx2; |
| 1047 # endif |
| 1048 # endif /* FLAC__CPU_... */ |
| 1049 } |
| 1050 #endif /* !FLAC__NO_ASM && FLAC__HAS_X86INTRIN */ |
| 957 /* finally override based on wide-ness if necessary */ | 1051 /* finally override based on wide-ness if necessary */ |
| 958 if(encoder->private_->use_wide_by_block) { | 1052 if(encoder->private_->use_wide_by_block) { |
| 959 » » encoder->private_->local_fixed_compute_best_predictor = FLAC__fi
xed_compute_best_predictor_wide; | 1053 » » encoder->private_->local_fixed_compute_best_predictor = encoder-
>private_->local_fixed_compute_best_predictor_wide; |
| 960 } | 1054 } |
| 961 | 1055 |
| 962 /* set state to OK; from here on, errors are fatal and we'll override th
e state then */ | 1056 /* set state to OK; from here on, errors are fatal and we'll override th
e state then */ |
| 963 encoder->protected_->state = FLAC__STREAM_ENCODER_OK; | 1057 encoder->protected_->state = FLAC__STREAM_ENCODER_OK; |
| 964 | 1058 |
| 965 #if FLAC__HAS_OGG | 1059 #if FLAC__HAS_OGG |
| 966 encoder->private_->is_ogg = is_ogg; | 1060 encoder->private_->is_ogg = is_ogg; |
| 967 if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_en
coder_aspect)) { | 1061 if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_en
coder_aspect)) { |
| 968 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; | 1062 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; |
| 969 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; | 1063 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 990 /* | 1084 /* |
| 991 * Set up the verify stuff if necessary | 1085 * Set up the verify stuff if necessary |
| 992 */ | 1086 */ |
| 993 if(encoder->protected_->verify) { | 1087 if(encoder->protected_->verify) { |
| 994 /* | 1088 /* |
| 995 * First, set up the fifo which will hold the | 1089 * First, set up the fifo which will hold the |
| 996 * original signal to compare against | 1090 * original signal to compare against |
| 997 */ | 1091 */ |
| 998 encoder->private_->verify.input_fifo.size = encoder->protected_-
>blocksize+OVERREAD_; | 1092 encoder->private_->verify.input_fifo.size = encoder->protected_-
>blocksize+OVERREAD_; |
| 999 for(i = 0; i < encoder->protected_->channels; i++) { | 1093 for(i = 0; i < encoder->protected_->channels; i++) { |
| 1000 » » » if(0 == (encoder->private_->verify.input_fifo.data[i] =
(FLAC__int32*)safe_malloc_mul_2op_(sizeof(FLAC__int32), /*times*/encoder->privat
e_->verify.input_fifo.size))) { | 1094 » » » if(0 == (encoder->private_->verify.input_fifo.data[i] =
safe_malloc_mul_2op_p(sizeof(FLAC__int32), /*times*/encoder->private_->verify.in
put_fifo.size))) { |
| 1001 encoder->protected_->state = FLAC__STREAM_ENCODE
R_MEMORY_ALLOCATION_ERROR; | 1095 encoder->protected_->state = FLAC__STREAM_ENCODE
R_MEMORY_ALLOCATION_ERROR; |
| 1002 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_
ERROR; | 1096 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_
ERROR; |
| 1003 } | 1097 } |
| 1004 } | 1098 } |
| 1005 encoder->private_->verify.input_fifo.tail = 0; | 1099 encoder->private_->verify.input_fifo.tail = 0; |
| 1006 | 1100 |
| 1007 /* | 1101 /* |
| 1008 * Now set up a stream decoder for verification | 1102 * Now set up a stream decoder for verification |
| 1009 */ | 1103 */ |
| 1010 encoder->private_->verify.decoder = FLAC__stream_decoder_new(); | |
| 1011 if(0 == encoder->private_->verify.decoder) { | 1104 if(0 == encoder->private_->verify.decoder) { |
| 1012 » » » encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY
_DECODER_ERROR; | 1105 » » » encoder->private_->verify.decoder = FLAC__stream_decoder
_new(); |
| 1013 » » » return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; | 1106 » » » if(0 == encoder->private_->verify.decoder) { |
| 1107 » » » » encoder->protected_->state = FLAC__STREAM_ENCODE
R_VERIFY_DECODER_ERROR; |
| 1108 » » » » return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_
ERROR; |
| 1109 » » » } |
| 1014 } | 1110 } |
| 1015 | 1111 |
| 1016 if(FLAC__stream_decoder_init_stream(encoder->private_->verify.de
coder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length
_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callb
ack_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_I
NIT_STATUS_OK) { | 1112 if(FLAC__stream_decoder_init_stream(encoder->private_->verify.de
coder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length
_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callb
ack_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_I
NIT_STATUS_OK) { |
| 1017 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY
_DECODER_ERROR; | 1113 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY
_DECODER_ERROR; |
| 1018 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; | 1114 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; |
| 1019 } | 1115 } |
| 1020 } | 1116 } |
| 1021 encoder->private_->verify.error_stats.absolute_sample = 0; | 1117 encoder->private_->verify.error_stats.absolute_sample = 0; |
| 1022 encoder->private_->verify.error_stats.frame_number = 0; | 1118 encoder->private_->verify.error_stats.frame_number = 0; |
| 1023 encoder->private_->verify.error_stats.channel = 0; | 1119 encoder->private_->verify.error_stats.channel = 0; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 encoder, | 1272 encoder, |
| 1177 read_callback, | 1273 read_callback, |
| 1178 write_callback, | 1274 write_callback, |
| 1179 seek_callback, | 1275 seek_callback, |
| 1180 tell_callback, | 1276 tell_callback, |
| 1181 metadata_callback, | 1277 metadata_callback, |
| 1182 client_data, | 1278 client_data, |
| 1183 /*is_ogg=*/true | 1279 /*is_ogg=*/true |
| 1184 ); | 1280 ); |
| 1185 } | 1281 } |
| 1186 | 1282 |
| 1187 static FLAC__StreamEncoderInitStatus init_FILE_internal_( | 1283 static FLAC__StreamEncoderInitStatus init_FILE_internal_( |
| 1188 FLAC__StreamEncoder *encoder, | 1284 FLAC__StreamEncoder *encoder, |
| 1189 FILE *file, | 1285 FILE *file, |
| 1190 FLAC__StreamEncoderProgressCallback progress_callback, | 1286 FLAC__StreamEncoderProgressCallback progress_callback, |
| 1191 void *client_data, | 1287 void *client_data, |
| 1192 FLAC__bool is_ogg | 1288 FLAC__bool is_ogg |
| 1193 ) | 1289 ) |
| 1194 { | 1290 { |
| 1195 FLAC__StreamEncoderInitStatus init_status; | 1291 FLAC__StreamEncoderInitStatus init_status; |
| 1196 | 1292 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1207 } | 1303 } |
| 1208 | 1304 |
| 1209 /* | 1305 /* |
| 1210 * To make sure that our file does not go unclosed after an error, we | 1306 * To make sure that our file does not go unclosed after an error, we |
| 1211 * must assign the FILE pointer before any further error can occur in | 1307 * must assign the FILE pointer before any further error can occur in |
| 1212 * this routine. | 1308 * this routine. |
| 1213 */ | 1309 */ |
| 1214 if(file == stdout) | 1310 if(file == stdout) |
| 1215 file = get_binary_stdout_(); /* just to be safe */ | 1311 file = get_binary_stdout_(); /* just to be safe */ |
| 1216 | 1312 |
| 1313 #ifdef _WIN32 |
| 1314 /* |
| 1315 * Windows can suffer quite badly from disk fragmentation. This can be |
| 1316 * reduced significantly by setting the output buffer size to be 10MB. |
| 1317 */ |
| 1318 setvbuf(file, NULL, _IOFBF, 10*1024*1024); |
| 1319 #endif |
| 1217 encoder->private_->file = file; | 1320 encoder->private_->file = file; |
| 1218 | 1321 |
| 1219 encoder->private_->progress_callback = progress_callback; | 1322 encoder->private_->progress_callback = progress_callback; |
| 1220 encoder->private_->bytes_written = 0; | 1323 encoder->private_->bytes_written = 0; |
| 1221 encoder->private_->samples_written = 0; | 1324 encoder->private_->samples_written = 0; |
| 1222 encoder->private_->frames_written = 0; | 1325 encoder->private_->frames_written = 0; |
| 1223 | 1326 |
| 1224 init_status = init_stream_internal_( | 1327 init_status = init_stream_internal_( |
| 1225 encoder, | 1328 encoder, |
| 1226 encoder->private_->file == stdout? 0 : is_ogg? file_read_callbac
k_ : 0, | 1329 encoder->private_->file == stdout? 0 : is_ogg? file_read_callbac
k_ : 0, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1238 | 1341 |
| 1239 { | 1342 { |
| 1240 unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder)
; | 1343 unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder)
; |
| 1241 | 1344 |
| 1242 FLAC__ASSERT(blocksize != 0); | 1345 FLAC__ASSERT(blocksize != 0); |
| 1243 encoder->private_->total_frames_estimate = (unsigned)((FLAC__str
eam_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize); | 1346 encoder->private_->total_frames_estimate = (unsigned)((FLAC__str
eam_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize); |
| 1244 } | 1347 } |
| 1245 | 1348 |
| 1246 return init_status; | 1349 return init_status; |
| 1247 } | 1350 } |
| 1248 | 1351 |
| 1249 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE( | 1352 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE( |
| 1250 FLAC__StreamEncoder *encoder, | 1353 FLAC__StreamEncoder *encoder, |
| 1251 FILE *file, | 1354 FILE *file, |
| 1252 FLAC__StreamEncoderProgressCallback progress_callback, | 1355 FLAC__StreamEncoderProgressCallback progress_callback, |
| 1253 void *client_data | 1356 void *client_data |
| 1254 ) | 1357 ) |
| 1255 { | 1358 { |
| 1256 return init_FILE_internal_(encoder, file, progress_callback, client_data
, /*is_ogg=*/false); | 1359 return init_FILE_internal_(encoder, file, progress_callback, client_data
, /*is_ogg=*/false); |
| 1257 } | 1360 } |
| 1258 | 1361 |
| 1259 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE( | 1362 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE( |
| 1260 FLAC__StreamEncoder *encoder, | 1363 FLAC__StreamEncoder *encoder, |
| 1261 FILE *file, | 1364 FILE *file, |
| 1262 FLAC__StreamEncoderProgressCallback progress_callback, | 1365 FLAC__StreamEncoderProgressCallback progress_callback, |
| 1263 void *client_data | 1366 void *client_data |
| 1264 ) | 1367 ) |
| 1265 { | 1368 { |
| 1266 return init_FILE_internal_(encoder, file, progress_callback, client_data
, /*is_ogg=*/true); | 1369 return init_FILE_internal_(encoder, file, progress_callback, client_data
, /*is_ogg=*/true); |
| 1267 } | 1370 } |
| 1268 | 1371 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1279 FLAC__ASSERT(0 != encoder); | 1382 FLAC__ASSERT(0 != encoder); |
| 1280 | 1383 |
| 1281 /* | 1384 /* |
| 1282 * To make sure that our file does not go unclosed after an error, we | 1385 * To make sure that our file does not go unclosed after an error, we |
| 1283 * have to do the same entrance checks here that are later performed | 1386 * have to do the same entrance checks here that are later performed |
| 1284 * in FLAC__stream_encoder_init_FILE() before the FILE* is assigned. | 1387 * in FLAC__stream_encoder_init_FILE() before the FILE* is assigned. |
| 1285 */ | 1388 */ |
| 1286 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) | 1389 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) |
| 1287 return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; | 1390 return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; |
| 1288 | 1391 |
| 1289 » file = filename? fopen(filename, "w+b") : stdout; | 1392 » file = filename? flac_fopen(filename, "w+b") : stdout; |
| 1290 | 1393 |
| 1291 if(file == 0) { | 1394 if(file == 0) { |
| 1292 encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR; | 1395 encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR; |
| 1293 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; | 1396 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; |
| 1294 } | 1397 } |
| 1295 | 1398 |
| 1296 return init_FILE_internal_(encoder, file, progress_callback, client_data
, is_ogg); | 1399 return init_FILE_internal_(encoder, file, progress_callback, client_data
, is_ogg); |
| 1297 } | 1400 } |
| 1298 | 1401 |
| 1299 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file( | 1402 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file( |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 FLAC__ASSERT(0 != encoder); | 1578 FLAC__ASSERT(0 != encoder); |
| 1476 FLAC__ASSERT(0 != encoder->private_); | 1579 FLAC__ASSERT(0 != encoder->private_); |
| 1477 FLAC__ASSERT(0 != encoder->protected_); | 1580 FLAC__ASSERT(0 != encoder->protected_); |
| 1478 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) | 1581 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) |
| 1479 return false; | 1582 return false; |
| 1480 if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0])) | 1583 if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0])) |
| 1481 value = sizeof(compression_levels_)/sizeof(compression_levels_[0
]) - 1; | 1584 value = sizeof(compression_levels_)/sizeof(compression_levels_[0
]) - 1; |
| 1482 ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, com
pression_levels_[value].do_mid_side_stereo); | 1585 ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, com
pression_levels_[value].do_mid_side_stereo); |
| 1483 ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, com
pression_levels_[value].loose_mid_side_stereo); | 1586 ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, com
pression_levels_[value].loose_mid_side_stereo); |
| 1484 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 1587 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 1485 #if 0 | 1588 #if 1 |
| 1486 » /* was: */ | |
| 1487 ok &= FLAC__stream_encoder_set_apodization (encoder, com
pression_levels_[value].apodization); | 1589 ok &= FLAC__stream_encoder_set_apodization (encoder, com
pression_levels_[value].apodization); |
| 1488 /* but it's too hard to specify the string in a locale-specific way */ | |
| 1489 #else | 1590 #else |
| 1591 /* equivalent to -A tukey(0.5) */ |
| 1490 encoder->protected_->num_apodizations = 1; | 1592 encoder->protected_->num_apodizations = 1; |
| 1491 encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY; | 1593 encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY; |
| 1492 encoder->protected_->apodizations[0].parameters.tukey.p = 0.5; | 1594 encoder->protected_->apodizations[0].parameters.tukey.p = 0.5; |
| 1493 #endif | 1595 #endif |
| 1494 #endif | 1596 #endif |
| 1495 ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, com
pression_levels_[value].max_lpc_order); | 1597 ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, com
pression_levels_[value].max_lpc_order); |
| 1496 ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, com
pression_levels_[value].qlp_coeff_precision); | 1598 ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, com
pression_levels_[value].qlp_coeff_precision); |
| 1497 ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, com
pression_levels_[value].do_qlp_coeff_prec_search); | 1599 ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, com
pression_levels_[value].do_qlp_coeff_prec_search); |
| 1498 ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, com
pression_levels_[value].do_escape_coding); | 1600 ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, com
pression_levels_[value].do_escape_coding); |
| 1499 ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, com
pression_levels_[value].do_exhaustive_model_search); | 1601 ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, com
pression_levels_[value].do_exhaustive_model_search); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 encoder->protected_->apodizations[encoder->protected_->n
um_apodizations++].type = FLAC__APODIZATION_RECTANGLE; | 1685 encoder->protected_->apodizations[encoder->protected_->n
um_apodizations++].type = FLAC__APODIZATION_RECTANGLE; |
| 1584 else if(n==8 && 0 == strncmp("triangle" , specification, n)
) | 1686 else if(n==8 && 0 == strncmp("triangle" , specification, n)
) |
| 1585 encoder->protected_->apodizations[encoder->protected_->n
um_apodizations++].type = FLAC__APODIZATION_TRIANGLE; | 1687 encoder->protected_->apodizations[encoder->protected_->n
um_apodizations++].type = FLAC__APODIZATION_TRIANGLE; |
| 1586 else if(n>7 && 0 == strncmp("tukey(" , specification, 6)
) { | 1688 else if(n>7 && 0 == strncmp("tukey(" , specification, 6)
) { |
| 1587 FLAC__real p = (FLAC__real)strtod(specification+6, 0); | 1689 FLAC__real p = (FLAC__real)strtod(specification+6, 0); |
| 1588 if (p >= 0.0 && p <= 1.0) { | 1690 if (p >= 0.0 && p <= 1.0) { |
| 1589 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations].parameters.tukey.p = p; | 1691 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations].parameters.tukey.p = p; |
| 1590 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; | 1692 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; |
| 1591 } | 1693 } |
| 1592 } | 1694 } |
| 1695 else if(n>15 && 0 == strncmp("partial_tukey(" , specific
ation, 14)) { |
| 1696 FLAC__int32 tukey_parts = (FLAC__int32)strtod(specificat
ion+14, 0); |
| 1697 const char *si_1 = strchr(specification, '/'); |
| 1698 FLAC__real overlap = si_1?flac_min((FLAC__real)strtod(si
_1+1, 0),0.99f):0.1f; |
| 1699 FLAC__real overlap_units = 1.0f/(1.0f - overlap) - 1.0f; |
| 1700 const char *si_2 = strchr((si_1?(si_1+1):specification),
'/'); |
| 1701 FLAC__real tukey_p = si_2?(FLAC__real)strtod(si_2+1, 0):
0.2f; |
| 1702 |
| 1703 if (tukey_parts <= 1) { |
| 1704 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations].parameters.tukey.p = tukey_p; |
| 1705 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; |
| 1706 }else if (encoder->protected_->num_apodizations + tukey_
parts < 32){ |
| 1707 FLAC__int32 m; |
| 1708 for(m = 0; m < tukey_parts; m++){ |
| 1709 encoder->protected_->apodizations[encode
r->protected_->num_apodizations].parameters.multiple_tukey.p = tukey_p; |
| 1710 encoder->protected_->apodizations[encode
r->protected_->num_apodizations].parameters.multiple_tukey.start = m/(tukey_part
s+overlap_units); |
| 1711 encoder->protected_->apodizations[encode
r->protected_->num_apodizations].parameters.multiple_tukey.end = (m+1+overlap_un
its)/(tukey_parts+overlap_units); |
| 1712 encoder->protected_->apodizations[encode
r->protected_->num_apodizations++].type = FLAC__APODIZATION_PARTIAL_TUKEY; |
| 1713 } |
| 1714 } |
| 1715 } |
| 1716 else if(n>16 && 0 == strncmp("punchout_tukey(" , specifi
cation, 15)) { |
| 1717 FLAC__int32 tukey_parts = (FLAC__int32)strtod(specificat
ion+15, 0); |
| 1718 const char *si_1 = strchr(specification, '/'); |
| 1719 FLAC__real overlap = si_1?flac_min((FLAC__real)strtod(si
_1+1, 0),0.99f):0.2f; |
| 1720 FLAC__real overlap_units = 1.0f/(1.0f - overlap) - 1.0f; |
| 1721 const char *si_2 = strchr((si_1?(si_1+1):specification),
'/'); |
| 1722 FLAC__real tukey_p = si_2?(FLAC__real)strtod(si_2+1, 0):
0.2f; |
| 1723 |
| 1724 if (tukey_parts <= 1) { |
| 1725 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations].parameters.tukey.p = tukey_p; |
| 1726 encoder->protected_->apodizations[encoder->prote
cted_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; |
| 1727 }else if (encoder->protected_->num_apodizations + tukey_
parts < 32){ |
| 1728 FLAC__int32 m; |
| 1729 for(m = 0; m < tukey_parts; m++){ |
| 1730 encoder->protected_->apodizations[encode
r->protected_->num_apodizations].parameters.multiple_tukey.p = tukey_p; |
| 1731 encoder->protected_->apodizations[encode
r->protected_->num_apodizations].parameters.multiple_tukey.start = m/(tukey_part
s+overlap_units); |
| 1732 encoder->protected_->apodizations[encode
r->protected_->num_apodizations].parameters.multiple_tukey.end = (m+1+overlap_un
its)/(tukey_parts+overlap_units); |
| 1733 encoder->protected_->apodizations[encode
r->protected_->num_apodizations++].type = FLAC__APODIZATION_PUNCHOUT_TUKEY; |
| 1734 } |
| 1735 } |
| 1736 } |
| 1593 else if(n==5 && 0 == strncmp("welch" , specification, n)
) | 1737 else if(n==5 && 0 == strncmp("welch" , specification, n)
) |
| 1594 encoder->protected_->apodizations[encoder->protected_->n
um_apodizations++].type = FLAC__APODIZATION_WELCH; | 1738 encoder->protected_->apodizations[encoder->protected_->n
um_apodizations++].type = FLAC__APODIZATION_WELCH; |
| 1595 if (encoder->protected_->num_apodizations == 32) | 1739 if (encoder->protected_->num_apodizations == 32) |
| 1596 break; | 1740 break; |
| 1597 if (s) | 1741 if (s) |
| 1598 specification = s+1; | 1742 specification = s+1; |
| 1599 else | 1743 else |
| 1600 break; | 1744 break; |
| 1601 } | 1745 } |
| 1602 if(encoder->protected_->num_apodizations == 0) { | 1746 if(encoder->protected_->num_apodizations == 0) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 if(0 == num_blocks) | 1873 if(0 == num_blocks) |
| 1730 metadata = 0; | 1874 metadata = 0; |
| 1731 /* realloc() does not do exactly what we want so... */ | 1875 /* realloc() does not do exactly what we want so... */ |
| 1732 if(encoder->protected_->metadata) { | 1876 if(encoder->protected_->metadata) { |
| 1733 free(encoder->protected_->metadata); | 1877 free(encoder->protected_->metadata); |
| 1734 encoder->protected_->metadata = 0; | 1878 encoder->protected_->metadata = 0; |
| 1735 encoder->protected_->num_metadata_blocks = 0; | 1879 encoder->protected_->num_metadata_blocks = 0; |
| 1736 } | 1880 } |
| 1737 if(num_blocks) { | 1881 if(num_blocks) { |
| 1738 FLAC__StreamMetadata **m; | 1882 FLAC__StreamMetadata **m; |
| 1739 » » if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof
(m[0]), /*times*/num_blocks))) | 1883 » » if(0 == (m = safe_malloc_mul_2op_p(sizeof(m[0]), /*times*/num_bl
ocks))) |
| 1740 return false; | 1884 return false; |
| 1741 memcpy(m, metadata, sizeof(m[0]) * num_blocks); | 1885 memcpy(m, metadata, sizeof(m[0]) * num_blocks); |
| 1742 encoder->protected_->metadata = m; | 1886 encoder->protected_->metadata = m; |
| 1743 encoder->protected_->num_metadata_blocks = num_blocks; | 1887 encoder->protected_->num_metadata_blocks = num_blocks; |
| 1744 } | 1888 } |
| 1745 #if FLAC__HAS_OGG | 1889 #if FLAC__HAS_OGG |
| 1746 if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_
encoder_aspect, num_blocks)) | 1890 if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_
encoder_aspect, num_blocks)) |
| 1747 return false; | 1891 return false; |
| 1748 #endif | 1892 #endif |
| 1749 return true; | 1893 return true; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 { | 2127 { |
| 1984 unsigned i, j = 0, channel; | 2128 unsigned i, j = 0, channel; |
| 1985 const unsigned channels = encoder->protected_->channels, blocksize = enc
oder->protected_->blocksize; | 2129 const unsigned channels = encoder->protected_->channels, blocksize = enc
oder->protected_->blocksize; |
| 1986 | 2130 |
| 1987 FLAC__ASSERT(0 != encoder); | 2131 FLAC__ASSERT(0 != encoder); |
| 1988 FLAC__ASSERT(0 != encoder->private_); | 2132 FLAC__ASSERT(0 != encoder->private_); |
| 1989 FLAC__ASSERT(0 != encoder->protected_); | 2133 FLAC__ASSERT(0 != encoder->protected_); |
| 1990 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); | 2134 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); |
| 1991 | 2135 |
| 1992 do { | 2136 do { |
| 1993 » » const unsigned n = min(blocksize+OVERREAD_-encoder->private_->cu
rrent_sample_number, samples-j); | 2137 » » const unsigned n = flac_min(blocksize+OVERREAD_-encoder->private
_->current_sample_number, samples-j); |
| 1994 | 2138 |
| 1995 if(encoder->protected_->verify) | 2139 if(encoder->protected_->verify) |
| 1996 append_to_verify_fifo_(&encoder->private_->verify.input_
fifo, buffer, j, channels, n); | 2140 append_to_verify_fifo_(&encoder->private_->verify.input_
fifo, buffer, j, channels, n); |
| 1997 | 2141 |
| 1998 for(channel = 0; channel < channels; channel++) | 2142 for(channel = 0; channel < channels; channel++) |
| 1999 memcpy(&encoder->private_->integer_signal[channel][encod
er->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel
][0]) * n); | 2143 memcpy(&encoder->private_->integer_signal[channel][encod
er->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel
][0]) * n); |
| 2000 | 2144 |
| 2001 if(encoder->protected_->do_mid_side_stereo) { | 2145 if(encoder->protected_->do_mid_side_stereo) { |
| 2002 FLAC__ASSERT(channels == 2); | 2146 FLAC__ASSERT(channels == 2); |
| 2003 /* "i <= blocksize" to overread 1 sample; see comment in
OVERREAD_ decl */ | 2147 /* "i <= blocksize" to overread 1 sample; see comment in
OVERREAD_ decl */ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 /* | 2190 /* |
| 2047 * we have several flavors of the same basic loop, optimized for | 2191 * we have several flavors of the same basic loop, optimized for |
| 2048 * different conditions: | 2192 * different conditions: |
| 2049 */ | 2193 */ |
| 2050 if(encoder->protected_->do_mid_side_stereo && channels == 2) { | 2194 if(encoder->protected_->do_mid_side_stereo && channels == 2) { |
| 2051 /* | 2195 /* |
| 2052 * stereo coding: unroll channel loop | 2196 * stereo coding: unroll channel loop |
| 2053 */ | 2197 */ |
| 2054 do { | 2198 do { |
| 2055 if(encoder->protected_->verify) | 2199 if(encoder->protected_->verify) |
| 2056 » » » » append_to_verify_fifo_interleaved_(&encoder->pri
vate_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->
private_->current_sample_number, samples-j)); | 2200 » » » » append_to_verify_fifo_interleaved_(&encoder->pri
vate_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-enco
der->private_->current_sample_number, samples-j)); |
| 2057 | 2201 |
| 2058 /* "i <= blocksize" to overread 1 sample; see comment in
OVERREAD_ decl */ | 2202 /* "i <= blocksize" to overread 1 sample; see comment in
OVERREAD_ decl */ |
| 2059 for(i = encoder->private_->current_sample_number; i <= b
locksize && j < samples; i++, j++) { | 2203 for(i = encoder->private_->current_sample_number; i <= b
locksize && j < samples; i++, j++) { |
| 2060 encoder->private_->integer_signal[0][i] = mid =
side = buffer[k++]; | 2204 encoder->private_->integer_signal[0][i] = mid =
side = buffer[k++]; |
| 2061 x = buffer[k++]; | 2205 x = buffer[k++]; |
| 2062 encoder->private_->integer_signal[1][i] = x; | 2206 encoder->private_->integer_signal[1][i] = x; |
| 2063 mid += x; | 2207 mid += x; |
| 2064 side -= x; | 2208 side -= x; |
| 2065 mid >>= 1; /* NOTE: not the same as 'mid = (left
+ right) / 2' ! */ | 2209 mid >>= 1; /* NOTE: not the same as 'mid = (left
+ right) / 2' ! */ |
| 2066 encoder->private_->integer_signal_mid_side[1][i]
= side; | 2210 encoder->private_->integer_signal_mid_side[1][i]
= side; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2081 encoder->private_->current_sample_number = 1; | 2225 encoder->private_->current_sample_number = 1; |
| 2082 } | 2226 } |
| 2083 } while(j < samples); | 2227 } while(j < samples); |
| 2084 } | 2228 } |
| 2085 else { | 2229 else { |
| 2086 /* | 2230 /* |
| 2087 * independent channel coding: buffer each channel in inner loop | 2231 * independent channel coding: buffer each channel in inner loop |
| 2088 */ | 2232 */ |
| 2089 do { | 2233 do { |
| 2090 if(encoder->protected_->verify) | 2234 if(encoder->protected_->verify) |
| 2091 » » » » append_to_verify_fifo_interleaved_(&encoder->pri
vate_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->
private_->current_sample_number, samples-j)); | 2235 » » » » append_to_verify_fifo_interleaved_(&encoder->pri
vate_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-enco
der->private_->current_sample_number, samples-j)); |
| 2092 | 2236 |
| 2093 /* "i <= blocksize" to overread 1 sample; see comment in
OVERREAD_ decl */ | 2237 /* "i <= blocksize" to overread 1 sample; see comment in
OVERREAD_ decl */ |
| 2094 for(i = encoder->private_->current_sample_number; i <= b
locksize && j < samples; i++, j++) { | 2238 for(i = encoder->private_->current_sample_number; i <= b
locksize && j < samples; i++, j++) { |
| 2095 for(channel = 0; channel < channels; channel++) | 2239 for(channel = 0; channel < channels; channel++) |
| 2096 encoder->private_->integer_signal[channe
l][i] = buffer[k++]; | 2240 encoder->private_->integer_signal[channe
l][i] = buffer[k++]; |
| 2097 } | 2241 } |
| 2098 encoder->private_->current_sample_number = i; | 2242 encoder->private_->current_sample_number = i; |
| 2099 /* we only process if we have a full block + 1 extra sam
ple; final block is always handled by FLAC__stream_encoder_finish() */ | 2243 /* we only process if we have a full block + 1 extra sam
ple; final block is always handled by FLAC__stream_encoder_finish() */ |
| 2100 if(i > blocksize) { | 2244 if(i > blocksize) { |
| 2101 if(!process_frame_(encoder, /*is_fractional_bloc
k=*/false, /*is_last_block=*/false)) | 2245 if(!process_frame_(encoder, /*is_fractional_bloc
k=*/false, /*is_last_block=*/false)) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 encoder->private_->write_callback = 0; | 2308 encoder->private_->write_callback = 0; |
| 2165 encoder->private_->seek_callback = 0; | 2309 encoder->private_->seek_callback = 0; |
| 2166 encoder->private_->tell_callback = 0; | 2310 encoder->private_->tell_callback = 0; |
| 2167 encoder->private_->metadata_callback = 0; | 2311 encoder->private_->metadata_callback = 0; |
| 2168 encoder->private_->progress_callback = 0; | 2312 encoder->private_->progress_callback = 0; |
| 2169 encoder->private_->client_data = 0; | 2313 encoder->private_->client_data = 0; |
| 2170 | 2314 |
| 2171 #if FLAC__HAS_OGG | 2315 #if FLAC__HAS_OGG |
| 2172 FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_
aspect); | 2316 FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_
aspect); |
| 2173 #endif | 2317 #endif |
| 2318 |
| 2319 FLAC__stream_encoder_set_compression_level(encoder, 5); |
| 2174 } | 2320 } |
| 2175 | 2321 |
| 2176 void free_(FLAC__StreamEncoder *encoder) | 2322 void free_(FLAC__StreamEncoder *encoder) |
| 2177 { | 2323 { |
| 2178 unsigned i, channel; | 2324 unsigned i, channel; |
| 2179 | 2325 |
| 2180 FLAC__ASSERT(0 != encoder); | 2326 FLAC__ASSERT(0 != encoder); |
| 2181 if(encoder->protected_->metadata) { | 2327 if(encoder->protected_->metadata) { |
| 2182 free(encoder->protected_->metadata); | 2328 free(encoder->protected_->metadata); |
| 2183 encoder->protected_->metadata = 0; | 2329 encoder->protected_->metadata = 0; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2262 FLAC__ASSERT(new_blocksize > 0); | 2408 FLAC__ASSERT(new_blocksize > 0); |
| 2263 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); | 2409 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); |
| 2264 FLAC__ASSERT(encoder->private_->current_sample_number == 0); | 2410 FLAC__ASSERT(encoder->private_->current_sample_number == 0); |
| 2265 | 2411 |
| 2266 /* To avoid excessive malloc'ing, we only grow the buffer; no shrinking.
*/ | 2412 /* To avoid excessive malloc'ing, we only grow the buffer; no shrinking.
*/ |
| 2267 if(new_blocksize <= encoder->private_->input_capacity) | 2413 if(new_blocksize <= encoder->private_->input_capacity) |
| 2268 return true; | 2414 return true; |
| 2269 | 2415 |
| 2270 ok = true; | 2416 ok = true; |
| 2271 | 2417 |
| 2272 » /* WATCHOUT: FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_m
mx() | 2418 » /* WATCHOUT: FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_m
mx() and ..._intrin_sse2() |
| 2273 » * requires that the input arrays (in our case the integer signals) | 2419 » * require that the input arrays (in our case the integer signals) |
| 2274 * have a buffer of up to 3 zeroes in front (at negative indices) for | 2420 * have a buffer of up to 3 zeroes in front (at negative indices) for |
| 2275 * alignment purposes; we use 4 in front to keep the data well-aligned. | 2421 * alignment purposes; we use 4 in front to keep the data well-aligned. |
| 2276 */ | 2422 */ |
| 2277 | 2423 |
| 2278 for(i = 0; ok && i < encoder->protected_->channels; i++) { | 2424 for(i = 0; ok && i < encoder->protected_->channels; i++) { |
| 2279 ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+
4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_
->integer_signal[i]); | 2425 ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+
4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_
->integer_signal[i]); |
| 2280 memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int
32)*4); | 2426 memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int
32)*4); |
| 2281 encoder->private_->integer_signal[i] += 4; | 2427 encoder->private_->integer_signal[i] += 4; |
| 2282 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 2428 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 2283 #if 0 /* @@@ currently unused */ | 2429 #if 0 /* @@@ currently unused */ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 break; | 2506 break; |
| 2361 case FLAC__APODIZATION_RECTANGLE: | 2507 case FLAC__APODIZATION_RECTANGLE: |
| 2362 FLAC__window_rectangle(encoder->private_
->window[i], new_blocksize); | 2508 FLAC__window_rectangle(encoder->private_
->window[i], new_blocksize); |
| 2363 break; | 2509 break; |
| 2364 case FLAC__APODIZATION_TRIANGLE: | 2510 case FLAC__APODIZATION_TRIANGLE: |
| 2365 FLAC__window_triangle(encoder->private_-
>window[i], new_blocksize); | 2511 FLAC__window_triangle(encoder->private_-
>window[i], new_blocksize); |
| 2366 break; | 2512 break; |
| 2367 case FLAC__APODIZATION_TUKEY: | 2513 case FLAC__APODIZATION_TUKEY: |
| 2368 FLAC__window_tukey(encoder->private_->wi
ndow[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p)
; | 2514 FLAC__window_tukey(encoder->private_->wi
ndow[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p)
; |
| 2369 break; | 2515 break; |
| 2516 case FLAC__APODIZATION_PARTIAL_TUKEY: |
| 2517 FLAC__window_partial_tukey(encoder->priv
ate_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.
multiple_tukey.p, encoder->protected_->apodizations[i].parameters.multiple_tukey
.start, encoder->protected_->apodizations[i].parameters.multiple_tukey.end); |
| 2518 break; |
| 2519 case FLAC__APODIZATION_PUNCHOUT_TUKEY: |
| 2520 FLAC__window_punchout_tukey(encoder->pri
vate_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters
.multiple_tukey.p, encoder->protected_->apodizations[i].parameters.multiple_tuke
y.start, encoder->protected_->apodizations[i].parameters.multiple_tukey.end); |
| 2521 break; |
| 2370 case FLAC__APODIZATION_WELCH: | 2522 case FLAC__APODIZATION_WELCH: |
| 2371 FLAC__window_welch(encoder->private_->wi
ndow[i], new_blocksize); | 2523 FLAC__window_welch(encoder->private_->wi
ndow[i], new_blocksize); |
| 2372 break; | 2524 break; |
| 2373 default: | 2525 default: |
| 2374 FLAC__ASSERT(0); | 2526 FLAC__ASSERT(0); |
| 2375 /* double protection */ | 2527 /* double protection */ |
| 2376 FLAC__window_hann(encoder->private_->win
dow[i], new_blocksize); | 2528 FLAC__window_hann(encoder->private_->win
dow[i], new_blocksize); |
| 2377 break; | 2529 break; |
| 2378 } | 2530 } |
| 2379 } | 2531 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 FLAC__bitwriter_release_buffer(encoder->private_->frame); | 2573 FLAC__bitwriter_release_buffer(encoder->private_->frame); |
| 2422 FLAC__bitwriter_clear(encoder->private_->frame); | 2574 FLAC__bitwriter_clear(encoder->private_->frame); |
| 2423 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; | 2575 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; |
| 2424 return false; | 2576 return false; |
| 2425 } | 2577 } |
| 2426 | 2578 |
| 2427 FLAC__bitwriter_release_buffer(encoder->private_->frame); | 2579 FLAC__bitwriter_release_buffer(encoder->private_->frame); |
| 2428 FLAC__bitwriter_clear(encoder->private_->frame); | 2580 FLAC__bitwriter_clear(encoder->private_->frame); |
| 2429 | 2581 |
| 2430 if(samples > 0) { | 2582 if(samples > 0) { |
| 2431 » » encoder->private_->streaminfo.data.stream_info.min_framesize = (
unsigned)min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize
); | 2583 » » encoder->private_->streaminfo.data.stream_info.min_framesize = f
lac_min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize); |
| 2432 » » encoder->private_->streaminfo.data.stream_info.max_framesize = (
unsigned)max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize
); | 2584 » » encoder->private_->streaminfo.data.stream_info.max_framesize = f
lac_max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize); |
| 2433 } | 2585 } |
| 2434 | 2586 |
| 2435 return true; | 2587 return true; |
| 2436 } | 2588 } |
| 2437 | 2589 |
| 2438 FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const
FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block) | 2590 FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const
FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block) |
| 2439 { | 2591 { |
| 2440 FLAC__StreamEncoderWriteStatus status; | 2592 FLAC__StreamEncoderWriteStatus status; |
| 2441 FLAC__uint64 output_position = 0; | 2593 FLAC__uint64 output_position = 0; |
| 2442 | 2594 |
| 2595 #if FLAC__HAS_OGG == 0 |
| 2596 (void)is_last_block; |
| 2597 #endif |
| 2598 |
| 2443 /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get
the offset; no error */ | 2599 /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get
the offset; no error */ |
| 2444 if(encoder->private_->tell_callback && encoder->private_->tell_callback(
encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCOD
ER_TELL_STATUS_ERROR) { | 2600 if(encoder->private_->tell_callback && encoder->private_->tell_callback(
encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCOD
ER_TELL_STATUS_ERROR) { |
| 2445 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; | 2601 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; |
| 2446 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; | 2602 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; |
| 2447 } | 2603 } |
| 2448 | 2604 |
| 2449 /* | 2605 /* |
| 2450 * Watch for the STREAMINFO block and first SEEKTABLE block to go by and
store their offsets. | 2606 * Watch for the STREAMINFO block and first SEEKTABLE block to go by and
store their offsets. |
| 2451 */ | 2607 */ |
| 2452 if(samples == 0) { | 2608 if(samples == 0) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 #endif | 2665 #endif |
| 2510 status = encoder->private_->write_callback(encoder, buffer, bytes, sampl
es, encoder->private_->current_frame_number, encoder->private_->client_data); | 2666 status = encoder->private_->write_callback(encoder, buffer, bytes, sampl
es, encoder->private_->current_frame_number, encoder->private_->client_data); |
| 2511 | 2667 |
| 2512 if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { | 2668 if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { |
| 2513 encoder->private_->bytes_written += bytes; | 2669 encoder->private_->bytes_written += bytes; |
| 2514 encoder->private_->samples_written += samples; | 2670 encoder->private_->samples_written += samples; |
| 2515 /* we keep a high watermark on the number of frames written beca
use | 2671 /* we keep a high watermark on the number of frames written beca
use |
| 2516 * when the encoder goes back to write metadata, 'current_frame' | 2672 * when the encoder goes back to write metadata, 'current_frame' |
| 2517 * will drop back to 0. | 2673 * will drop back to 0. |
| 2518 */ | 2674 */ |
| 2519 » » encoder->private_->frames_written = max(encoder->private_->frame
s_written, encoder->private_->current_frame_number+1); | 2675 » » encoder->private_->frames_written = flac_max(encoder->private_->
frames_written, encoder->private_->current_frame_number+1); |
| 2520 } | 2676 } |
| 2521 else | 2677 else |
| 2522 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; | 2678 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; |
| 2523 | 2679 |
| 2524 return status; | 2680 return status; |
| 2525 } | 2681 } |
| 2526 | 2682 |
| 2527 /* Gets called when the encoding process has finished so that we can update the
STREAMINFO and SEEKTABLE blocks. */ | 2683 /* Gets called when the encoding process has finished so that we can update the
STREAMINFO and SEEKTABLE blocks. */ |
| 2528 void update_metadata_(const FLAC__StreamEncoder *encoder) | 2684 void update_metadata_(const FLAC__StreamEncoder *encoder) |
| 2529 { | 2685 { |
| 2530 » FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; | 2686 » FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; |
| 2531 const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; | 2687 const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; |
| 2532 const FLAC__uint64 samples = metadata->data.stream_info.total_samples; | 2688 const FLAC__uint64 samples = metadata->data.stream_info.total_samples; |
| 2533 const unsigned min_framesize = metadata->data.stream_info.min_framesize; | 2689 const unsigned min_framesize = metadata->data.stream_info.min_framesize; |
| 2534 const unsigned max_framesize = metadata->data.stream_info.max_framesize; | 2690 const unsigned max_framesize = metadata->data.stream_info.max_framesize; |
| 2535 const unsigned bps = metadata->data.stream_info.bits_per_sample; | 2691 const unsigned bps = metadata->data.stream_info.bits_per_sample; |
| 2536 FLAC__StreamEncoderSeekStatus seek_status; | 2692 FLAC__StreamEncoderSeekStatus seek_status; |
| 2537 | 2693 |
| 2538 FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); | 2694 FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); |
| 2539 | 2695 |
| 2540 /* All this is based on intimate knowledge of the stream header | 2696 /* All this is based on intimate knowledge of the stream header |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2685 { | 2841 { |
| 2686 /* the # of bytes in the 1st packet that precede the STREAMINFO */ | 2842 /* the # of bytes in the 1st packet that precede the STREAMINFO */ |
| 2687 static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH = | 2843 static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH = |
| 2688 FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + | 2844 FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + |
| 2689 FLAC__OGG_MAPPING_MAGIC_LENGTH + | 2845 FLAC__OGG_MAPPING_MAGIC_LENGTH + |
| 2690 FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + | 2846 FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + |
| 2691 FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + | 2847 FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + |
| 2692 FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH + | 2848 FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH + |
| 2693 FLAC__STREAM_SYNC_LENGTH | 2849 FLAC__STREAM_SYNC_LENGTH |
| 2694 ; | 2850 ; |
| 2695 » FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; | 2851 » FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; |
| 2696 const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; | 2852 const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; |
| 2697 const FLAC__uint64 samples = metadata->data.stream_info.total_samples; | 2853 const FLAC__uint64 samples = metadata->data.stream_info.total_samples; |
| 2698 const unsigned min_framesize = metadata->data.stream_info.min_framesize; | 2854 const unsigned min_framesize = metadata->data.stream_info.min_framesize; |
| 2699 const unsigned max_framesize = metadata->data.stream_info.max_framesize; | 2855 const unsigned max_framesize = metadata->data.stream_info.max_framesize; |
| 2700 ogg_page page; | 2856 ogg_page page; |
| 2701 | 2857 |
| 2702 FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); | 2858 FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); |
| 2703 FLAC__ASSERT(0 != encoder->private_->seek_callback); | 2859 FLAC__ASSERT(0 != encoder->private_->seek_callback); |
| 2704 | 2860 |
| 2705 /* Pre-check that client supports seeking, since we don't want the | 2861 /* Pre-check that client supports seeking, since we don't want the |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2936 FLAC__bool do_independent, do_mid_side; | 3092 FLAC__bool do_independent, do_mid_side; |
| 2937 | 3093 |
| 2938 /* | 3094 /* |
| 2939 * Calculate the min,max Rice partition orders | 3095 * Calculate the min,max Rice partition orders |
| 2940 */ | 3096 */ |
| 2941 if(is_fractional_block) { | 3097 if(is_fractional_block) { |
| 2942 max_partition_order = 0; | 3098 max_partition_order = 0; |
| 2943 } | 3099 } |
| 2944 else { | 3100 else { |
| 2945 max_partition_order = FLAC__format_get_max_rice_partition_order_
from_blocksize(encoder->protected_->blocksize); | 3101 max_partition_order = FLAC__format_get_max_rice_partition_order_
from_blocksize(encoder->protected_->blocksize); |
| 2946 » » max_partition_order = min(max_partition_order, encoder->protecte
d_->max_residual_partition_order); | 3102 » » max_partition_order = flac_min(max_partition_order, encoder->pro
tected_->max_residual_partition_order); |
| 2947 } | 3103 } |
| 2948 » min_partition_order = min(min_partition_order, max_partition_order); | 3104 » min_partition_order = flac_min(min_partition_order, max_partition_order)
; |
| 2949 | 3105 |
| 2950 /* | 3106 /* |
| 2951 * Setup the frame | 3107 * Setup the frame |
| 2952 */ | 3108 */ |
| 2953 frame_header.blocksize = encoder->protected_->blocksize; | 3109 frame_header.blocksize = encoder->protected_->blocksize; |
| 2954 frame_header.sample_rate = encoder->protected_->sample_rate; | 3110 frame_header.sample_rate = encoder->protected_->sample_rate; |
| 2955 frame_header.channels = encoder->protected_->channels; | 3111 frame_header.channels = encoder->protected_->channels; |
| 2956 frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
/* the default unless the encoder determines otherwise */ | 3112 frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
/* the default unless the encoder determines otherwise */ |
| 2957 frame_header.bits_per_sample = encoder->protected_->bits_per_sample; | 3113 frame_header.bits_per_sample = encoder->protected_->bits_per_sample; |
| 2958 frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER; | 3114 frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3187 unsigned *best_bits | 3343 unsigned *best_bits |
| 3188 ) | 3344 ) |
| 3189 { | 3345 { |
| 3190 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 3346 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 3191 FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]; | 3347 FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]; |
| 3192 #else | 3348 #else |
| 3193 FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]
; | 3349 FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]
; |
| 3194 #endif | 3350 #endif |
| 3195 #ifndef FLAC__INTEGER_ONLY_LIBRARY | 3351 #ifndef FLAC__INTEGER_ONLY_LIBRARY |
| 3196 FLAC__double lpc_residual_bits_per_sample; | 3352 FLAC__double lpc_residual_bits_per_sample; |
| 3197 » FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is import
ant even though encoder->protected_->max_lpc_order might be less; some asm routi
nes need all the space */ | 3353 » FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is import
ant even though encoder->protected_->max_lpc_order might be less; some asm and x
86 intrinsic routines need all the space */ |
| 3198 FLAC__double lpc_error[FLAC__MAX_LPC_ORDER]; | 3354 FLAC__double lpc_error[FLAC__MAX_LPC_ORDER]; |
| 3199 unsigned min_lpc_order, max_lpc_order, lpc_order; | 3355 unsigned min_lpc_order, max_lpc_order, lpc_order; |
| 3200 unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_pre
cision; | 3356 unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_pre
cision; |
| 3201 #endif | 3357 #endif |
| 3202 unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_orde
r; | 3358 unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_orde
r; |
| 3203 unsigned rice_parameter; | 3359 unsigned rice_parameter; |
| 3204 unsigned _candidate_bits, _best_bits; | 3360 unsigned _candidate_bits, _best_bits; |
| 3205 unsigned _best_subframe; | 3361 unsigned _best_subframe; |
| 3206 /* only use RICE2 partitions if stream bps > 16 */ | 3362 /* only use RICE2 partitions if stream bps > 16 */ |
| 3207 const unsigned rice_parameter_limit = FLAC__stream_encoder_get_bits_per_
sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAM
ETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; | 3363 const unsigned rice_parameter_limit = FLAC__stream_encoder_get_bits_per_
sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAM
ETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3340 rice_parameter =
(lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0
.5) : 0; /* 0.5 is for rounding */ | 3496 rice_parameter =
(lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0
.5) : 0; /* 0.5 is for rounding */ |
| 3341 rice_parameter++
; /* to account for the signed->unsigned conversion during rice coding */ | 3497 rice_parameter++
; /* to account for the signed->unsigned conversion during rice coding */ |
| 3342 if(rice_paramete
r >= rice_parameter_limit) { | 3498 if(rice_paramete
r >= rice_parameter_limit) { |
| 3343 #ifdef DEBUG_VERBOSE | 3499 #ifdef DEBUG_VERBOSE |
| 3344 fprintf(
stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_paramete
r_limit - 1); | 3500 fprintf(
stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_paramete
r_limit - 1); |
| 3345 #endif | 3501 #endif |
| 3346 rice_par
ameter = rice_parameter_limit - 1; | 3502 rice_par
ameter = rice_parameter_limit - 1; |
| 3347 } | 3503 } |
| 3348 if(encoder->prot
ected_->do_qlp_coeff_prec_search) { | 3504 if(encoder->prot
ected_->do_qlp_coeff_prec_search) { |
| 3349 min_qlp_
coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION; | 3505 min_qlp_
coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION; |
| 3350 » » » » » » » » » /* try t
o ensure a 32-bit datapath throughout for 16bps(+1bps for side channel) or less
*/ | 3506 » » » » » » » » » /* try t
o keep qlp coeff precision such that only 32-bit math is required for decode of
<=16bps streams */ |
| 3351 » » » » » » » » » if(subfr
ame_bps <= 17) { | 3507 » » » » » » » » » if(subfr
ame_bps <= 16) { |
| 3352 » » » » » » » » » »
max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF
_PRECISION); | 3508 » » » » » » » » » »
max_qlp_coeff_precision = flac_min(32 - subframe_bps - FLAC__bitmath_ilog2(lpc_o
rder), FLAC__MAX_QLP_COEFF_PRECISION); |
| 3353 » » » » » » » » » »
max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision); | 3509 » » » » » » » » » »
max_qlp_coeff_precision = flac_max(max_qlp_coeff_precision, min_qlp_coeff_precis
ion); |
| 3354 } | 3510 } |
| 3355 else | 3511 else |
| 3356
max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION; | 3512
max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION; |
| 3357 } | 3513 } |
| 3358 else { | 3514 else { |
| 3359 min_qlp_
coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_preci
sion; | 3515 min_qlp_
coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_preci
sion; |
| 3360 } | 3516 } |
| 3361 for(qlp_coeff_pr
ecision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precisio
n; qlp_coeff_precision++) { | 3517 for(qlp_coeff_pr
ecision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precisio
n; qlp_coeff_precision++) { |
| 3362 _candida
te_bits = | 3518 _candida
te_bits = |
| 3363
evaluate_lpc_subframe_( | 3519
evaluate_lpc_subframe_( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3578 unsigned rice_parameter, | 3734 unsigned rice_parameter, |
| 3579 unsigned rice_parameter_limit, | 3735 unsigned rice_parameter_limit, |
| 3580 unsigned min_partition_order, | 3736 unsigned min_partition_order, |
| 3581 unsigned max_partition_order, | 3737 unsigned max_partition_order, |
| 3582 FLAC__bool do_escape_coding, | 3738 FLAC__bool do_escape_coding, |
| 3583 unsigned rice_parameter_search_dist, | 3739 unsigned rice_parameter_search_dist, |
| 3584 FLAC__Subframe *subframe, | 3740 FLAC__Subframe *subframe, |
| 3585 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_cont
ents | 3741 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_cont
ents |
| 3586 ) | 3742 ) |
| 3587 { | 3743 { |
| 3588 » FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER]; | 3744 » FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER]; /* WATCHOUT: the size is imp
ortant; some x86 intrinsic routines need more than lpc order elements */ |
| 3589 unsigned i, residual_bits, estimate; | 3745 unsigned i, residual_bits, estimate; |
| 3590 int quantization, ret; | 3746 int quantization, ret; |
| 3591 const unsigned residual_samples = blocksize - order; | 3747 const unsigned residual_samples = blocksize - order; |
| 3592 | 3748 |
| 3593 /* try to keep qlp coeff precision such that only 32-bit math is require
d for decode of <=16bps streams */ | 3749 /* try to keep qlp coeff precision such that only 32-bit math is require
d for decode of <=16bps streams */ |
| 3594 if(subframe_bps <= 16) { | 3750 if(subframe_bps <= 16) { |
| 3595 FLAC__ASSERT(order > 0); | 3751 FLAC__ASSERT(order > 0); |
| 3596 FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER); | 3752 FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER); |
| 3597 » » qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps
- FLAC__bitmath_ilog2(order)); | 3753 » » qlp_coeff_precision = flac_min(qlp_coeff_precision, 32 - subfram
e_bps - FLAC__bitmath_ilog2(order)); |
| 3598 } | 3754 } |
| 3599 | 3755 |
| 3600 ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precisi
on, qlp_coeff, &quantization); | 3756 ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precisi
on, qlp_coeff, &quantization); |
| 3601 if(ret != 0) | 3757 if(ret != 0) |
| 3602 return 0; /* this is a hack to indicate to the caller that we ca
n't do lp at this order on this subframe */ | 3758 return 0; /* this is a hack to indicate to the caller that we ca
n't do lp at this order on this subframe */ |
| 3603 | 3759 |
| 3604 if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32
) | 3760 if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32
) |
| 3605 if(subframe_bps <= 16 && qlp_coeff_precision <= 16) | 3761 if(subframe_bps <= 16 && qlp_coeff_precision <= 16) |
| 3606 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization
, residual); | 3762 encoder->private_->local_lpc_compute_residual_from_qlp_c
oefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization
, residual); |
| 3607 else | 3763 else |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3691 unsigned rice_parameter_search_dist, | 3847 unsigned rice_parameter_search_dist, |
| 3692 FLAC__EntropyCodingMethod *best_ecm | 3848 FLAC__EntropyCodingMethod *best_ecm |
| 3693 ) | 3849 ) |
| 3694 { | 3850 { |
| 3695 unsigned residual_bits, best_residual_bits = 0; | 3851 unsigned residual_bits, best_residual_bits = 0; |
| 3696 unsigned best_parameters_index = 0; | 3852 unsigned best_parameters_index = 0; |
| 3697 unsigned best_partition_order = 0; | 3853 unsigned best_partition_order = 0; |
| 3698 const unsigned blocksize = residual_samples + predictor_order; | 3854 const unsigned blocksize = residual_samples + predictor_order; |
| 3699 | 3855 |
| 3700 max_partition_order = FLAC__format_get_max_rice_partition_order_from_blo
cksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor
_order); | 3856 max_partition_order = FLAC__format_get_max_rice_partition_order_from_blo
cksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor
_order); |
| 3701 » min_partition_order = min(min_partition_order, max_partition_order); | 3857 » min_partition_order = flac_min(min_partition_order, max_partition_order)
; |
| 3702 | 3858 |
| 3703 » precompute_partition_info_sums_(residual, abs_residual_partition_sums, r
esidual_samples, predictor_order, min_partition_order, max_partition_order, bps)
; | 3859 » private_->local_precompute_partition_info_sums(residual, abs_residual_pa
rtition_sums, residual_samples, predictor_order, min_partition_order, max_partit
ion_order, bps); |
| 3704 | 3860 |
| 3705 if(do_escape_coding) | 3861 if(do_escape_coding) |
| 3706 precompute_partition_info_escapes_(residual, raw_bits_per_partit
ion, residual_samples, predictor_order, min_partition_order, max_partition_order
); | 3862 precompute_partition_info_escapes_(residual, raw_bits_per_partit
ion, residual_samples, predictor_order, min_partition_order, max_partition_order
); |
| 3707 | 3863 |
| 3708 { | 3864 { |
| 3709 int partition_order; | 3865 int partition_order; |
| 3710 unsigned sum; | 3866 unsigned sum; |
| 3711 | 3867 |
| 3712 for(partition_order = (int)max_partition_order, sum = 0; partiti
on_order >= (int)min_partition_order; partition_order--) { | 3868 for(partition_order = (int)max_partition_order, sum = 0; partiti
on_order >= (int)min_partition_order; partition_order--) { |
| 3713 if(! | 3869 if(! |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3745 | 3901 |
| 3746 { | 3902 { |
| 3747 /* | 3903 /* |
| 3748 * We are allowed to de-const the pointer based on our special | 3904 * We are allowed to de-const the pointer based on our special |
| 3749 * knowledge; it is const to the outside world. | 3905 * knowledge; it is const to the outside world. |
| 3750 */ | 3906 */ |
| 3751 FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__
EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.con
tents; | 3907 FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__
EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.con
tents; |
| 3752 unsigned partition; | 3908 unsigned partition; |
| 3753 | 3909 |
| 3754 /* save best parameters and raw_bits */ | 3910 /* save best parameters and raw_bits */ |
| 3755 » » FLAC__format_entropy_coding_method_partitioned_rice_contents_ens
ure_size(prc, max(6, best_partition_order)); | 3911 » » FLAC__format_entropy_coding_method_partitioned_rice_contents_ens
ure_size(prc, flac_max(6u, best_partition_order)); |
| 3756 » » memcpy(prc->parameters, private_->partitioned_rice_contents_extr
a[best_parameters_index].parameters, sizeof(unsigned)*((size_t)1<<(best_partitio
n_order))); | 3912 » » memcpy(prc->parameters, private_->partitioned_rice_contents_extr
a[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)
)); |
| 3757 if(do_escape_coding) | 3913 if(do_escape_coding) |
| 3758 » » » memcpy(prc->raw_bits, private_->partitioned_rice_content
s_extra[best_parameters_index].raw_bits, sizeof(unsigned)*((size_t)1<<(best_part
ition_order))); | 3914 » » » memcpy(prc->raw_bits, private_->partitioned_rice_content
s_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_or
der))); |
| 3759 /* | 3915 /* |
| 3760 * Now need to check if the type should be changed to | 3916 * Now need to check if the type should be changed to |
| 3761 * FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 based on the | 3917 * FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 based on the |
| 3762 * size of the rice parameters. | 3918 * size of the rice parameters. |
| 3763 */ | 3919 */ |
| 3764 for(partition = 0; partition < (1u<<best_partition_order); parti
tion++) { | 3920 for(partition = 0; partition < (1u<<best_partition_order); parti
tion++) { |
| 3765 if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_ME
THOD_PARTITIONED_RICE_ESCAPE_PARAMETER) { | 3921 if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_ME
THOD_PARTITIONED_RICE_ESCAPE_PARAMETER) { |
| 3766 best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PAR
TITIONED_RICE2; | 3922 best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PAR
TITIONED_RICE2; |
| 3767 break; | 3923 break; |
| 3768 } | 3924 } |
| 3769 } | 3925 } |
| 3770 } | 3926 } |
| 3771 | 3927 |
| 3772 return best_residual_bits; | 3928 return best_residual_bits; |
| 3773 } | 3929 } |
| 3774 | 3930 |
| 3775 #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM | |
| 3776 extern void precompute_partition_info_sums_32bit_asm_ia32_( | |
| 3777 const FLAC__int32 residual[], | |
| 3778 FLAC__uint64 abs_residual_partition_sums[], | |
| 3779 unsigned blocksize, | |
| 3780 unsigned predictor_order, | |
| 3781 unsigned min_partition_order, | |
| 3782 unsigned max_partition_order | |
| 3783 ); | |
| 3784 #endif | |
| 3785 | |
| 3786 void precompute_partition_info_sums_( | 3931 void precompute_partition_info_sums_( |
| 3787 const FLAC__int32 residual[], | 3932 const FLAC__int32 residual[], |
| 3788 FLAC__uint64 abs_residual_partition_sums[], | 3933 FLAC__uint64 abs_residual_partition_sums[], |
| 3789 unsigned residual_samples, | 3934 unsigned residual_samples, |
| 3790 unsigned predictor_order, | 3935 unsigned predictor_order, |
| 3791 unsigned min_partition_order, | 3936 unsigned min_partition_order, |
| 3792 unsigned max_partition_order, | 3937 unsigned max_partition_order, |
| 3793 unsigned bps | 3938 unsigned bps |
| 3794 ) | 3939 ) |
| 3795 { | 3940 { |
| 3796 const unsigned default_partition_samples = (residual_samples + predictor
_order) >> max_partition_order; | 3941 const unsigned default_partition_samples = (residual_samples + predictor
_order) >> max_partition_order; |
| 3797 unsigned partitions = 1u << max_partition_order; | 3942 unsigned partitions = 1u << max_partition_order; |
| 3798 | 3943 |
| 3799 FLAC__ASSERT(default_partition_samples > predictor_order); | 3944 FLAC__ASSERT(default_partition_samples > predictor_order); |
| 3800 | 3945 |
| 3801 #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM | |
| 3802 /* slightly pessimistic but still catches all common cases */ | |
| 3803 /* WATCHOUT: "+ bps" is an assumption that the average residual magnitud
e will not be more than "bps" bits */ | |
| 3804 if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) { | |
| 3805 precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_res
idual_partition_sums, residual_samples + predictor_order, predictor_order, min_p
artition_order, max_partition_order); | |
| 3806 return; | |
| 3807 } | |
| 3808 #endif | |
| 3809 | |
| 3810 /* first do max_partition_order */ | 3946 /* first do max_partition_order */ |
| 3811 { | 3947 { |
| 3812 unsigned partition, residual_sample, end = (unsigned)(-(int)pred
ictor_order); | 3948 unsigned partition, residual_sample, end = (unsigned)(-(int)pred
ictor_order); |
| 3813 » » /* slightly pessimistic but still catches all common cases */ | 3949 » » /* WATCHOUT: "+ bps + FLAC__MAX_EXTRA_RESIDUAL_BPS" is the maxim
um |
| 3814 » » /* WATCHOUT: "+ bps" is an assumption that the average residual
magnitude will not be more than "bps" bits */ | 3950 » » * assumed size of the average residual magnitude */ |
| 3815 » » if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) { | 3951 » » if(FLAC__bitmath_ilog2(default_partition_samples) + bps + FLAC__
MAX_EXTRA_RESIDUAL_BPS < 32) { |
| 3816 FLAC__uint32 abs_residual_partition_sum; | 3952 FLAC__uint32 abs_residual_partition_sum; |
| 3817 | 3953 |
| 3818 for(partition = residual_sample = 0; partition < partiti
ons; partition++) { | 3954 for(partition = residual_sample = 0; partition < partiti
ons; partition++) { |
| 3819 end += default_partition_samples; | 3955 end += default_partition_samples; |
| 3820 abs_residual_partition_sum = 0; | 3956 abs_residual_partition_sum = 0; |
| 3821 for( ; residual_sample < end; residual_sample++) | 3957 for( ; residual_sample < end; residual_sample++) |
| 3822 abs_residual_partition_sum += abs(residu
al[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_M
IN we have bigger problems */ | 3958 abs_residual_partition_sum += abs(residu
al[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_M
IN we have bigger problems */ |
| 3823 abs_residual_partition_sums[partition] = abs_res
idual_partition_sum; | 3959 abs_residual_partition_sums[partition] = abs_res
idual_partition_sum; |
| 3824 } | 3960 } |
| 3825 } | 3961 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3897 } | 4033 } |
| 3898 | 4034 |
| 3899 /* now merge partitions for lower orders */ | 4035 /* now merge partitions for lower orders */ |
| 3900 for(from_partition = 0, --partition_order; partition_order >= (int)min_p
artition_order; partition_order--) { | 4036 for(from_partition = 0, --partition_order; partition_order >= (int)min_p
artition_order; partition_order--) { |
| 3901 unsigned m; | 4037 unsigned m; |
| 3902 unsigned i; | 4038 unsigned i; |
| 3903 const unsigned partitions = 1u << partition_order; | 4039 const unsigned partitions = 1u << partition_order; |
| 3904 for(i = 0; i < partitions; i++) { | 4040 for(i = 0; i < partitions; i++) { |
| 3905 m = raw_bits_per_partition[from_partition]; | 4041 m = raw_bits_per_partition[from_partition]; |
| 3906 from_partition++; | 4042 from_partition++; |
| 3907 » » » raw_bits_per_partition[to_partition] = max(m, raw_bits_p
er_partition[from_partition]); | 4043 » » » raw_bits_per_partition[to_partition] = flac_max(m, raw_b
its_per_partition[from_partition]); |
| 3908 from_partition++; | 4044 from_partition++; |
| 3909 to_partition++; | 4045 to_partition++; |
| 3910 } | 4046 } |
| 3911 } | 4047 } |
| 3912 } | 4048 } |
| 3913 | 4049 |
| 3914 #ifdef EXACT_RICE_BITS_CALCULATION | 4050 #ifdef EXACT_RICE_BITS_CALCULATION |
| 3915 static FLaC__INLINE unsigned count_rice_bits_in_partition_( | 4051 static inline unsigned count_rice_bits_in_partition_( |
| 3916 const unsigned rice_parameter, | 4052 const unsigned rice_parameter, |
| 3917 const unsigned partition_samples, | 4053 const unsigned partition_samples, |
| 3918 const FLAC__int32 *residual | 4054 const FLAC__int32 *residual |
| 3919 ) | 4055 ) |
| 3920 { | 4056 { |
| 3921 unsigned i, partition_bits = | 4057 unsigned i, partition_bits = |
| 3922 FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /*
actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAME
TER_LEN but err on side of 16bps */ | 4058 FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /*
actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAME
TER_LEN but err on side of 16bps */ |
| 3923 (1+rice_parameter) * partition_samples /* 1 for unary stop bit +
rice_parameter for the binary portion */ | 4059 (1+rice_parameter) * partition_samples /* 1 for unary stop bit +
rice_parameter for the binary portion */ |
| 3924 ; | 4060 ; |
| 3925 for(i = 0; i < partition_samples; i++) | 4061 for(i = 0; i < partition_samples; i++) |
| 3926 partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]
>>31)) >> rice_parameter ); | 4062 partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]
>>31)) >> rice_parameter ); |
| 3927 return partition_bits; | 4063 return partition_bits; |
| 3928 } | 4064 } |
| 3929 #else | 4065 #else |
| 3930 static FLaC__INLINE unsigned count_rice_bits_in_partition_( | 4066 static inline unsigned count_rice_bits_in_partition_( |
| 3931 const unsigned rice_parameter, | 4067 const unsigned rice_parameter, |
| 3932 const unsigned partition_samples, | 4068 const unsigned partition_samples, |
| 3933 const FLAC__uint64 abs_residual_partition_sum | 4069 const FLAC__uint64 abs_residual_partition_sum |
| 3934 ) | 4070 ) |
| 3935 { | 4071 { |
| 3936 return | 4072 return |
| 3937 FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /*
actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAME
TER_LEN but err on side of 16bps */ | 4073 FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /*
actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAME
TER_LEN but err on side of 16bps */ |
| 3938 (1+rice_parameter) * partition_samples + /* 1 for unary stop bit
+ rice_parameter for the binary portion */ | 4074 (1+rice_parameter) * partition_samples + /* 1 for unary stop bit
+ rice_parameter for the binary portion */ |
| 3939 ( | 4075 ( |
| 3940 rice_parameter? | 4076 rice_parameter? |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3975 unsigned *parameters, *raw_bits; | 4111 unsigned *parameters, *raw_bits; |
| 3976 #ifdef ENABLE_RICE_PARAMETER_SEARCH | 4112 #ifdef ENABLE_RICE_PARAMETER_SEARCH |
| 3977 unsigned min_rice_parameter, max_rice_parameter; | 4113 unsigned min_rice_parameter, max_rice_parameter; |
| 3978 #else | 4114 #else |
| 3979 (void)rice_parameter_search_dist; | 4115 (void)rice_parameter_search_dist; |
| 3980 #endif | 4116 #endif |
| 3981 | 4117 |
| 3982 FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PART
ITIONED_RICE2_ESCAPE_PARAMETER); | 4118 FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PART
ITIONED_RICE2_ESCAPE_PARAMETER); |
| 3983 FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITI
ONED_RICE2_ESCAPE_PARAMETER); | 4119 FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITI
ONED_RICE2_ESCAPE_PARAMETER); |
| 3984 | 4120 |
| 3985 » FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size
(partitioned_rice_contents, max(6, partition_order)); | 4121 » FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size
(partitioned_rice_contents, flac_max(6u, partition_order)); |
| 3986 parameters = partitioned_rice_contents->parameters; | 4122 parameters = partitioned_rice_contents->parameters; |
| 3987 raw_bits = partitioned_rice_contents->raw_bits; | 4123 raw_bits = partitioned_rice_contents->raw_bits; |
| 3988 | 4124 |
| 3989 if(partition_order == 0) { | 4125 if(partition_order == 0) { |
| 3990 best_partition_bits = (unsigned)(-1); | 4126 best_partition_bits = (unsigned)(-1); |
| 3991 #ifdef ENABLE_RICE_PARAMETER_SEARCH | 4127 #ifdef ENABLE_RICE_PARAMETER_SEARCH |
| 3992 if(rice_parameter_search_dist) { | 4128 if(rice_parameter_search_dist) { |
| 3993 if(suggested_rice_parameter < rice_parameter_search_dist
) | 4129 if(suggested_rice_parameter < rice_parameter_search_dist
) |
| 3994 min_rice_parameter = 0; | 4130 min_rice_parameter = 0; |
| 3995 else | 4131 else |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4049 } | 4185 } |
| 4050 mean = abs_residual_partition_sums[partition]; | 4186 mean = abs_residual_partition_sums[partition]; |
| 4051 /* we are basically calculating the size in bits of the | 4187 /* we are basically calculating the size in bits of the |
| 4052 * average residual magnitude in the partition: | 4188 * average residual magnitude in the partition: |
| 4053 * rice_parameter = floor(log2(mean/partition_samples)
) | 4189 * rice_parameter = floor(log2(mean/partition_samples)
) |
| 4054 * 'mean' is not a good name for the variable, it is | 4190 * 'mean' is not a good name for the variable, it is |
| 4055 * actually the sum of magnitudes of all residual values | 4191 * actually the sum of magnitudes of all residual values |
| 4056 * in the partition, so the actual mean is | 4192 * in the partition, so the actual mean is |
| 4057 * mean/partition_samples | 4193 * mean/partition_samples |
| 4058 */ | 4194 */ |
| 4195 #if 0 /* old simple code */ |
| 4059 for(rice_parameter = 0, k = partition_samples; k < mean;
rice_parameter++, k <<= 1) | 4196 for(rice_parameter = 0, k = partition_samples; k < mean;
rice_parameter++, k <<= 1) |
| 4060 ; | 4197 ; |
| 4198 #else |
| 4199 #if defined FLAC__CPU_X86_64 /* and other 64-bit arch, too */ |
| 4200 if(mean <= 0x80000000/512) { /* 512: more or less optima
l for both 16- and 24-bit input */ |
| 4201 #else |
| 4202 if(mean <= 0x80000000/8) { /* 32-bit arch: use 32-bit ma
th if possible */ |
| 4203 #endif |
| 4204 FLAC__uint32 k2, mean2 = (FLAC__uint32) mean; |
| 4205 rice_parameter = 0; k2 = partition_samples; |
| 4206 while(k2*8 < mean2) { /* requires: mean <= (2^31
)/8 */ |
| 4207 rice_parameter += 4; k2 <<= 4; /* tuned
for 16-bit input */ |
| 4208 } |
| 4209 while(k2 < mean2) { /* requires: mean <= 2^31 */ |
| 4210 rice_parameter++; k2 <<= 1; |
| 4211 } |
| 4212 } |
| 4213 else { |
| 4214 rice_parameter = 0; k = partition_samples; |
| 4215 if(mean <= FLAC__U64L(0x8000000000000000)/128) /
* usually mean is _much_ smaller than this value */ |
| 4216 while(k*128 < mean) { /* requires: mean
<= (2^63)/128 */ |
| 4217 rice_parameter += 8; k <<= 8; /*
tuned for 24-bit input */ |
| 4218 } |
| 4219 while(k < mean) { /* requires: mean <= 2^63 */ |
| 4220 rice_parameter++; k <<= 1; |
| 4221 } |
| 4222 } |
| 4223 #endif |
| 4061 if(rice_parameter >= rice_parameter_limit) { | 4224 if(rice_parameter >= rice_parameter_limit) { |
| 4062 #ifdef DEBUG_VERBOSE | 4225 #ifdef DEBUG_VERBOSE |
| 4063 fprintf(stderr, "clipping rice_parameter (%u ->
%u) @6\n", rice_parameter, rice_parameter_limit - 1); | 4226 fprintf(stderr, "clipping rice_parameter (%u ->
%u) @6\n", rice_parameter, rice_parameter_limit - 1); |
| 4064 #endif | 4227 #endif |
| 4065 rice_parameter = rice_parameter_limit - 1; | 4228 rice_parameter = rice_parameter_limit - 1; |
| 4066 } | 4229 } |
| 4067 | 4230 |
| 4068 best_partition_bits = (unsigned)(-1); | 4231 best_partition_bits = (unsigned)(-1); |
| 4069 #ifdef ENABLE_RICE_PARAMETER_SEARCH | 4232 #ifdef ENABLE_RICE_PARAMETER_SEARCH |
| 4070 if(rice_parameter_search_dist) { | 4233 if(rice_parameter_search_dist) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4267 else if (ferror(encoder->private_->file)) | 4430 else if (ferror(encoder->private_->file)) |
| 4268 return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; | 4431 return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; |
| 4269 } | 4432 } |
| 4270 return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; | 4433 return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; |
| 4271 } | 4434 } |
| 4272 | 4435 |
| 4273 FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *enc
oder, FLAC__uint64 absolute_byte_offset, void *client_data) | 4436 FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *enc
oder, FLAC__uint64 absolute_byte_offset, void *client_data) |
| 4274 { | 4437 { |
| 4275 (void)client_data; | 4438 (void)client_data; |
| 4276 | 4439 |
| 4277 » if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET
) < 0) | 4440 » if(fseeko(encoder->private_->file, (FLAC__off_t)absolute_byte_offset, SE
EK_SET) < 0) |
| 4278 return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; | 4441 return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; |
| 4279 else | 4442 else |
| 4280 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; | 4443 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; |
| 4281 } | 4444 } |
| 4282 | 4445 |
| 4283 FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *enc
oder, FLAC__uint64 *absolute_byte_offset, void *client_data) | 4446 FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *enc
oder, FLAC__uint64 *absolute_byte_offset, void *client_data) |
| 4284 { | 4447 { |
| 4285 » off_t offset; | 4448 » FLAC__off_t offset; |
| 4286 | 4449 |
| 4287 (void)client_data; | 4450 (void)client_data; |
| 4288 | 4451 |
| 4289 offset = ftello(encoder->private_->file); | 4452 offset = ftello(encoder->private_->file); |
| 4290 | 4453 |
| 4291 if(offset < 0) { | 4454 if(offset < 0) { |
| 4292 return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; | 4455 return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; |
| 4293 } | 4456 } |
| 4294 else { | 4457 else { |
| 4295 *absolute_byte_offset = (FLAC__uint64)offset; | 4458 *absolute_byte_offset = (FLAC__uint64)offset; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4353 _setmode(_fileno(stdout), _O_BINARY); | 4516 _setmode(_fileno(stdout), _O_BINARY); |
| 4354 #elif defined __CYGWIN__ | 4517 #elif defined __CYGWIN__ |
| 4355 /* almost certainly not needed for any modern Cygwin, but let's be safe.
.. */ | 4518 /* almost certainly not needed for any modern Cygwin, but let's be safe.
.. */ |
| 4356 setmode(_fileno(stdout), _O_BINARY); | 4519 setmode(_fileno(stdout), _O_BINARY); |
| 4357 #elif defined __EMX__ | 4520 #elif defined __EMX__ |
| 4358 setmode(fileno(stdout), O_BINARY); | 4521 setmode(fileno(stdout), O_BINARY); |
| 4359 #endif | 4522 #endif |
| 4360 | 4523 |
| 4361 return stdout; | 4524 return stdout; |
| 4362 } | 4525 } |
| OLD | NEW |