mirror of https://github.com/xiph/flac
add FLAC__stream_encoder_set_compression_level()
This commit is contained in:
parent
7464fec9fe
commit
425609cb0c
|
@ -127,12 +127,13 @@ namespace FLAC {
|
|||
virtual bool set_ogg_serial_number(long value); ///< See FLAC__stream_encoder_set_ogg_serial_number()
|
||||
virtual bool set_verify(bool value); ///< See FLAC__stream_encoder_set_verify()
|
||||
virtual bool set_streamable_subset(bool value); ///< See FLAC__stream_encoder_set_streamable_subset()
|
||||
virtual bool set_do_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_do_mid_side_stereo()
|
||||
virtual bool set_loose_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_loose_mid_side_stereo()
|
||||
virtual bool set_channels(unsigned value); ///< See FLAC__stream_encoder_set_channels()
|
||||
virtual bool set_bits_per_sample(unsigned value); ///< See FLAC__stream_encoder_set_bits_per_sample()
|
||||
virtual bool set_sample_rate(unsigned value); ///< See FLAC__stream_encoder_set_sample_rate()
|
||||
virtual bool set_compression_level(unsigned value); ///< See FLAC__stream_encoder_set_compression_level()
|
||||
virtual bool set_blocksize(unsigned value); ///< See FLAC__stream_encoder_set_blocksize()
|
||||
virtual bool set_do_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_do_mid_side_stereo()
|
||||
virtual bool set_loose_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_loose_mid_side_stereo()
|
||||
virtual bool set_apodization(const char *specification); ///< See FLAC__stream_encoder_set_apodization()
|
||||
virtual bool set_max_lpc_order(unsigned value); ///< See FLAC__stream_encoder_set_max_lpc_order()
|
||||
virtual bool set_qlp_coeff_precision(unsigned value); ///< See FLAC__stream_encoder_set_qlp_coeff_precision()
|
||||
|
|
|
@ -85,14 +85,27 @@ extern "C" {
|
|||
* - The program creates an instance of an encoder using
|
||||
* FLAC__stream_encoder_new().
|
||||
* - The program overrides the default settings using
|
||||
* FLAC__stream_encoder_set_*() functions.
|
||||
* FLAC__stream_encoder_set_*() functions. At a minimum, the following
|
||||
* functions should be called:
|
||||
* - FLAC__stream_encoder_set_channels()
|
||||
* - FLAC__stream_encoder_set_bits_per_sample()
|
||||
* - FLAC__stream_encoder_set_sample_rate()
|
||||
* - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC)
|
||||
* - FLAC__stream_encoder_set_total_samples_estimate() (if known)
|
||||
* - If the application wants to control the compression level or set its own
|
||||
* metadata, then the following should also be called:
|
||||
* - FLAC__stream_encoder_set_compression_level()
|
||||
* - FLAC__stream_encoder_set_verify()
|
||||
* - FLAC__stream_encoder_set_metadata()
|
||||
* - The rest of the set functions should only be called if the client needs
|
||||
* exact control over how the audio is compressed; thorough understanding
|
||||
* of the FLAC format is necessary to achieve good results.
|
||||
* - The program initializes the instance to validate the settings and
|
||||
* prepare for encoding using FLAC__stream_encoder_init_stream() or
|
||||
* FLAC__stream_encoder_init_FILE() or FLAC__stream_encoder_init_file()
|
||||
* for native FLAC, or FLAC__stream_encoder_init_ogg_stream() or
|
||||
* FLAC__stream_encoder_init_ogg_FILE() or
|
||||
* FLAC__stream_encoder_init_ogg_file() for Ogg FLAC, depending on the
|
||||
* nature of the input.
|
||||
* prepare for encoding using
|
||||
* - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE()
|
||||
* or FLAC__stream_encoder_init_file() for native FLAC
|
||||
* - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE()
|
||||
* or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC
|
||||
* - The program calls FLAC__stream_encoder_process() or
|
||||
* FLAC__stream_encoder_process_interleaved() to encode data, which
|
||||
* subsequently calls the callbacks when there is encoder data ready
|
||||
|
@ -308,12 +321,6 @@ typedef enum {
|
|||
FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
|
||||
/**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
|
||||
|
||||
FLAC__STREAM_ENCODER_INIT_STATUS_MID_SIDE_CHANNELS_MISMATCH,
|
||||
/**< Mid/side coding was specified but the number of channels is not equal to 2. */
|
||||
|
||||
FLAC__STREAM_ENCODER_INIT_STATUS_ILLEGAL_MID_SIDE_FORCE,
|
||||
/**< Loose mid/side coding was specified but mid/side coding was not. */
|
||||
|
||||
FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
|
||||
/**< The specified block size is less than the maximum LPC order. */
|
||||
|
||||
|
@ -698,35 +705,6 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder
|
|||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||
|
||||
/** Set to \c true to enable mid-side encoding on stereo input. The
|
||||
* number of channels must be 2. Set to \c false to use only
|
||||
* independent channel coding.
|
||||
*
|
||||
* \default \c false
|
||||
* \param encoder An encoder instance to set.
|
||||
* \param value Flag value (see above).
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* \c false if the encoder is already initialized, else \c true.
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||
|
||||
/** Set to \c true to enable adaptive switching between mid-side and
|
||||
* left-right encoding on stereo input. The number of channels must
|
||||
* be 2. Set to \c false to use exhaustive searching. In either
|
||||
* case, the mid/side stereo setting must be \c true.
|
||||
*
|
||||
* \default \c false
|
||||
* \param encoder An encoder instance to set.
|
||||
* \param value Flag value (see above).
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* \c false if the encoder is already initialized, else \c true.
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||
|
||||
/** Set the number of channels to be encoded.
|
||||
*
|
||||
* \default \c 2
|
||||
|
@ -767,9 +745,75 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder
|
|||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
|
||||
|
||||
/** Set the compression level
|
||||
*
|
||||
* The compression level is roughly proportional to the amount of effort
|
||||
* the encoder expends to compress the file. A higher level usually
|
||||
* means more computation but higher compression. The default level is
|
||||
* suitable for most applications.
|
||||
*
|
||||
* Currently the levels range from \c 0 (fastest, least compression) to
|
||||
* \c 8 (slowest, most compression). A value larger than \c 8 will be
|
||||
* treated as \c 8.
|
||||
*
|
||||
* This function automatically calls the following other \c _set_
|
||||
* functions with appropriate values, so the client does not need to
|
||||
* unless it specifically wants to override them:
|
||||
* - FLAC__stream_encoder_set_do_mid_side_stereo()
|
||||
* - FLAC__stream_encoder_set_loose_mid_side_stereo()
|
||||
* - FLAC__stream_encoder_set_apodization()
|
||||
* - FLAC__stream_encoder_set_max_lpc_order()
|
||||
* - FLAC__stream_encoder_set_qlp_coeff_precision()
|
||||
* - FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
|
||||
* - FLAC__stream_encoder_set_do_escape_coding()
|
||||
* - FLAC__stream_encoder_set_do_exhaustive_model_search()
|
||||
* - FLAC__stream_encoder_set_min_residual_partition_order()
|
||||
* - FLAC__stream_encoder_set_max_residual_partition_order()
|
||||
* - FLAC__stream_encoder_set_rice_parameter_search_dist()
|
||||
*
|
||||
* The actual values set for each level are:
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td><b>level</b><td>
|
||||
* <td>do mid-side stereo<td>
|
||||
* <td>loose mid-side stereo<td>
|
||||
* <td>apodization<td>
|
||||
* <td>max lpc order<td>
|
||||
* <td>qlp coeff precision<td>
|
||||
* <td>qlp coeff prec search<td>
|
||||
* <td>escape coding<td>
|
||||
* <td>exhaustive model search<td>
|
||||
* <td>min residual partition order<td>
|
||||
* <td>max residual partition order<td>
|
||||
* <td>rice parameter search dist<td>
|
||||
* </tr>
|
||||
* <tr> <td><b>0</b><td> <td>false<td> <td>false<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>2<td> <td>2<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>1</b><td> <td>true<td> <td>true<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>2<td> <td>2<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>2</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>3<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>3</b><td> <td>false<td> <td>false<td> <td>tukey(0.5)<td> <td>6<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>3<td> <td>3<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>4</b><td> <td>true<td> <td>true<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>3<td> <td>3<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>5</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>3<td> <td>3<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>6</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>4<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>7</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>true<td> <td>0<td> <td>6<td> <td>0<td> </tr>
|
||||
* <tr> <td><b>8</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>12<td> <td>0<td> <td>false<td> <td>false<td> <td>true<td> <td>0<td> <td>6<td> <td>0<td> </tr>
|
||||
* </table>
|
||||
*
|
||||
* \default \c 5
|
||||
* \param encoder An encoder instance to set.
|
||||
* \param value See above.
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* \c false if the encoder is already initialized, else \c true.
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
|
||||
|
||||
/** Set the blocksize to use while encoding.
|
||||
*
|
||||
* \default \c 1152
|
||||
* The number of samples to use per frame. Use \c 0 to let the encoder
|
||||
* estimate a blocksize; this is usually best.
|
||||
*
|
||||
* \default \c 0
|
||||
* \param encoder An encoder instance to set.
|
||||
* \param value See above.
|
||||
* \assert
|
||||
|
@ -779,6 +823,36 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *en
|
|||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
|
||||
|
||||
/** Set to \c true to enable mid-side encoding on stereo input. The
|
||||
* number of channels must be 2 for this to have any effect. Set to
|
||||
* \c false to use only independent channel coding.
|
||||
*
|
||||
* \default \c false
|
||||
* \param encoder An encoder instance to set.
|
||||
* \param value Flag value (see above).
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* \c false if the encoder is already initialized, else \c true.
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||
|
||||
/** Set to \c true to enable adaptive switching between mid-side and
|
||||
* left-right encoding on stereo input. Set to \c false to use
|
||||
* exhaustive searching. Setting this to \c true requires
|
||||
* FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to
|
||||
* \c true in order to have any effect.
|
||||
*
|
||||
* \default \c false
|
||||
* \param encoder An encoder instance to set.
|
||||
* \param value Flag value (see above).
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* \c false if the encoder is already initialized, else \c true.
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
|
||||
|
||||
/** Sets the apodization function(s) the encoder will use when windowing
|
||||
* audio data for LPC analysis.
|
||||
*
|
||||
|
@ -1126,26 +1200,6 @@ FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *e
|
|||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
|
||||
|
||||
/** Get the "mid/side stereo coding" flag.
|
||||
*
|
||||
* \param encoder An encoder instance to query.
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* See FLAC__stream_encoder_get_do_mid_side_stereo().
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
|
||||
|
||||
/** Get the "adaptive mid/side switching" flag.
|
||||
*
|
||||
* \param encoder An encoder instance to query.
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* See FLAC__stream_encoder_set_loose_mid_side_stereo().
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
|
||||
|
||||
/** Get the number of input channels being processed.
|
||||
*
|
||||
* \param encoder An encoder instance to query.
|
||||
|
@ -1186,6 +1240,26 @@ FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder
|
|||
*/
|
||||
FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
|
||||
|
||||
/** Get the "mid/side stereo coding" flag.
|
||||
*
|
||||
* \param encoder An encoder instance to query.
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* See FLAC__stream_encoder_get_do_mid_side_stereo().
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
|
||||
|
||||
/** Get the "adaptive mid/side switching" flag.
|
||||
*
|
||||
* \param encoder An encoder instance to query.
|
||||
* \assert
|
||||
* \code encoder != NULL \endcode
|
||||
* \retval FLAC__bool
|
||||
* See FLAC__stream_encoder_set_loose_mid_side_stereo().
|
||||
*/
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
|
||||
|
||||
/** Get the maximum LPC order setting.
|
||||
*
|
||||
* \param encoder An encoder instance to query.
|
||||
|
|
|
@ -82,18 +82,6 @@ namespace FLAC {
|
|||
return (bool)::FLAC__stream_encoder_set_streamable_subset(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_do_mid_side_stereo(bool value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__stream_encoder_set_do_mid_side_stereo(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_loose_mid_side_stereo(bool value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__stream_encoder_set_loose_mid_side_stereo(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_channels(unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
|
@ -112,12 +100,30 @@ namespace FLAC {
|
|||
return (bool)::FLAC__stream_encoder_set_sample_rate(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_compression_level(unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__stream_encoder_set_compression_level(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_blocksize(unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__stream_encoder_set_blocksize(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_do_mid_side_stereo(bool value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__stream_encoder_set_do_mid_side_stereo(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_loose_mid_side_stereo(bool value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__stream_encoder_set_loose_mid_side_stereo(encoder_, value);
|
||||
}
|
||||
|
||||
bool Stream::set_apodization(const char *specification)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
|
|
|
@ -98,6 +98,31 @@ typedef enum {
|
|||
ENCODER_IN_AUDIO = 2
|
||||
} EncoderStateHint;
|
||||
|
||||
static struct CompressionLevels {
|
||||
FLAC__bool do_mid_side_stereo;
|
||||
FLAC__bool loose_mid_side_stereo;
|
||||
const char *apodization;
|
||||
unsigned max_lpc_order;
|
||||
unsigned qlp_coeff_precision;
|
||||
FLAC__bool do_qlp_coeff_prec_search;
|
||||
FLAC__bool do_escape_coding;
|
||||
FLAC__bool do_exhaustive_model_search;
|
||||
unsigned min_residual_partition_order;
|
||||
unsigned max_residual_partition_order;
|
||||
unsigned rice_parameter_search_dist;
|
||||
} compression_levels_[] = {
|
||||
{ false, false, "tukey(0.5)", 0, 0, false, false, false, 2, 2, 0 },
|
||||
{ true , true , "tukey(0.5)", 0, 0, false, false, false, 2, 2, 0 },
|
||||
{ true , false, "tukey(0.5)", 0, 0, false, false, false, 0, 3, 0 },
|
||||
{ false, false, "tukey(0.5)", 6, 0, false, false, false, 3, 3, 0 },
|
||||
{ true , true , "tukey(0.5)", 8, 0, false, false, false, 3, 3, 0 },
|
||||
{ true , false, "tukey(0.5)", 8, 0, false, false, false, 3, 3, 0 },
|
||||
{ true , false, "tukey(0.5)", 8, 0, false, false, false, 0, 4, 0 },
|
||||
{ true , false, "tukey(0.5)", 8, 0, false, false, true , 0, 6, 0 },
|
||||
{ true , false, "tukey(0.5)", 12, 0, false, false, true , 0, 6, 0 }
|
||||
};
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Private class method prototypes
|
||||
|
@ -469,8 +494,6 @@ FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
|
|||
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_MID_SIDE_CHANNELS_MISMATCH",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_ILLEGAL_MID_SIDE_FORCE",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
|
||||
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
|
||||
|
@ -647,11 +670,12 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
|
|||
if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
|
||||
return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
|
||||
|
||||
if(encoder->protected_->do_mid_side_stereo && encoder->protected_->channels != 2)
|
||||
return FLAC__STREAM_ENCODER_INIT_STATUS_MID_SIDE_CHANNELS_MISMATCH;
|
||||
|
||||
if(encoder->protected_->loose_mid_side_stereo && !encoder->protected_->do_mid_side_stereo)
|
||||
return FLAC__STREAM_ENCODER_INIT_STATUS_ILLEGAL_MID_SIDE_FORCE;
|
||||
if(encoder->protected_->channels != 2) {
|
||||
encoder->protected_->do_mid_side_stereo = false;
|
||||
encoder->protected_->loose_mid_side_stereo = false;
|
||||
}
|
||||
else if(!encoder->protected_->do_mid_side_stereo)
|
||||
encoder->protected_->loose_mid_side_stereo = false;
|
||||
|
||||
if(encoder->protected_->bits_per_sample >= 32)
|
||||
encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
|
||||
|
@ -662,6 +686,13 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
|
|||
if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
|
||||
return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
|
||||
|
||||
if(encoder->protected_->blocksize == 0) {
|
||||
if(encoder->protected_->max_lpc_order == 0)
|
||||
encoder->protected_->blocksize = 1152;
|
||||
else
|
||||
encoder->protected_->blocksize = 4608;
|
||||
}
|
||||
|
||||
if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
|
||||
return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
|
||||
|
||||
|
@ -1411,28 +1442,6 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncod
|
|||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->protected_->do_mid_side_stereo = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->protected_->loose_mid_side_stereo = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
|
@ -1466,6 +1475,30 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *en
|
|||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
|
||||
{
|
||||
FLAC__bool ok = true;
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
|
||||
value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
|
||||
ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
|
||||
ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
|
||||
ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
|
||||
ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
|
||||
ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
|
||||
ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
|
||||
ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
|
||||
ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
|
||||
ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
|
||||
ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
|
||||
ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
|
||||
return ok;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
|
@ -1477,6 +1510,28 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *enco
|
|||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->protected_->do_mid_side_stereo = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||
return false;
|
||||
encoder->protected_->loose_mid_side_stereo = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
|
@ -1775,22 +1830,6 @@ FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__Strea
|
|||
return encoder->protected_->streamable_subset;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
return encoder->protected_->do_mid_side_stereo;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
return encoder->protected_->loose_mid_side_stereo;
|
||||
}
|
||||
|
||||
FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
|
@ -1823,6 +1862,22 @@ FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *
|
|||
return encoder->protected_->blocksize;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
return encoder->protected_->do_mid_side_stereo;
|
||||
}
|
||||
|
||||
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
FLAC__ASSERT(0 != encoder->private_);
|
||||
FLAC__ASSERT(0 != encoder->protected_);
|
||||
return encoder->protected_->loose_mid_side_stereo;
|
||||
}
|
||||
|
||||
FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__ASSERT(0 != encoder);
|
||||
|
@ -2180,7 +2235,7 @@ void set_defaults_(FLAC__StreamEncoder *encoder)
|
|||
encoder->protected_->channels = 2;
|
||||
encoder->protected_->bits_per_sample = 16;
|
||||
encoder->protected_->sample_rate = 44100;
|
||||
encoder->protected_->blocksize = 1152;
|
||||
encoder->protected_->blocksize = 0;
|
||||
#ifndef FLAC__INTEGER_ONLY_LIBRARY
|
||||
encoder->protected_->num_apodizations = 1;
|
||||
encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
|
||||
|
|
|
@ -201,16 +201,6 @@ static bool test_stream_encoder(Layer layer, bool is_ogg)
|
|||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_do_mid_side_stereo()... ");
|
||||
if(!encoder->set_do_mid_side_stereo(false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_loose_mid_side_stereo()... ");
|
||||
if(!encoder->set_loose_mid_side_stereo(false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_channels()... ");
|
||||
if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
|
||||
return die_s_("returned false", encoder);
|
||||
|
@ -226,11 +216,26 @@ static bool test_stream_encoder(Layer layer, bool is_ogg)
|
|||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_compression_level()... ");
|
||||
if(!encoder->set_compression_level((unsigned)(-1)))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_blocksize()... ");
|
||||
if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_do_mid_side_stereo()... ");
|
||||
if(!encoder->set_do_mid_side_stereo(false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_loose_mid_side_stereo()... ");
|
||||
if(!encoder->set_loose_mid_side_stereo(false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing set_max_lpc_order()... ");
|
||||
if(!encoder->set_max_lpc_order(0))
|
||||
return die_s_("returned false", encoder);
|
||||
|
|
|
@ -164,16 +164,6 @@ static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg)
|
|||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
|
||||
if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
|
||||
if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_channels()... ");
|
||||
if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
|
||||
return die_s_("returned false", encoder);
|
||||
|
@ -189,11 +179,26 @@ static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg)
|
|||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_compression_level()... ");
|
||||
if(!FLAC__stream_encoder_set_compression_level(encoder, (unsigned)(-1)))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_blocksize()... ");
|
||||
if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
|
||||
if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
|
||||
if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
|
||||
return die_s_("returned false", encoder);
|
||||
printf("OK\n");
|
||||
|
||||
printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
|
||||
if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
|
||||
return die_s_("returned false", encoder);
|
||||
|
|
Loading…
Reference in New Issue