17#include <FLAC/stream_encoder.h>
18#include <FLAC/assert.h>
22 :
Encoder(outfile, qualitylevel, metadata),
23 m_encoder(FLAC__stream_encoder_new())
25 bool streamable_subset =
true;
26 bool do_mid_side =
true;
27 bool loose_mid_side =
false;
28 int bits_per_sample = 16;
29 int sample_rate = 44100;
31 int max_lpc_order = 8;
32 int qlp_coeff_precision = 0;
33 bool qlp_coeff_prec_search =
false;
34 bool do_escape_coding =
false;
35 bool do_exhaustive_model_search =
false;
36 int min_residual_partition_order = 3;
37 int max_residual_partition_order = 3;
38 int rice_parameter_search_dist = 0;
40 FLAC__stream_encoder_set_streamable_subset(
m_encoder, streamable_subset);
41 FLAC__stream_encoder_set_do_mid_side_stereo(
m_encoder, do_mid_side);
42 FLAC__stream_encoder_set_loose_mid_side_stereo(
m_encoder, loose_mid_side);
44 FLAC__stream_encoder_set_bits_per_sample(
m_encoder, bits_per_sample);
45 FLAC__stream_encoder_set_sample_rate(
m_encoder, sample_rate);
46 FLAC__stream_encoder_set_blocksize(
m_encoder, blocksize);
47 FLAC__stream_encoder_set_max_lpc_order(
m_encoder, max_lpc_order);
48 FLAC__stream_encoder_set_qlp_coeff_precision(
m_encoder, qlp_coeff_precision);
49 FLAC__stream_encoder_set_do_qlp_coeff_prec_search(
m_encoder, qlp_coeff_prec_search);
50 FLAC__stream_encoder_set_do_escape_coding(
m_encoder, do_escape_coding);
51 FLAC__stream_encoder_set_do_exhaustive_model_search(
m_encoder, do_exhaustive_model_search);
52 FLAC__stream_encoder_set_min_residual_partition_order(
m_encoder, min_residual_partition_order);
53 FLAC__stream_encoder_set_max_residual_partition_order(
m_encoder, max_residual_partition_order);
54 FLAC__stream_encoder_set_rice_parameter_search_dist(
m_encoder, rice_parameter_search_dist);
56 QByteArray ofile = outfile.toLocal8Bit();
57 int ret = FLAC__stream_encoder_init_file(
58 m_encoder, ofile.constData(),
nullptr,
nullptr);
59 if (ret != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
61 LOG(VB_GENERAL, LOG_ERR,
62 QString(
"Error initializing FLAC encoder. Got return code: %1")
99 unsigned int index = 0;
101 length /=
sizeof(int16_t);
103 while (index < length)
122 if (!FLAC__stream_encoder_process(
m_encoder,
123 (
const FLAC__int32 *
const *)
m_input.data(),
126 LOG(VB_GENERAL, LOG_ERR,
127 QString(
"Failed to write flac data. Aborting."));
MusicMetadata * m_metadata
unsigned int m_sampleIndex
FlacEncoder(const QString &outfile, int qualitylevel, MusicMetadata *metadata)
std::array< std::array< FLAC__int32, MAX_SAMPLES >, NUM_CHANNELS > m_inputIn
std::array< FLAC__int32 *, NUM_CHANNELS > m_input
int addSamples(int16_t *bytes, unsigned int len) override
FLAC__StreamEncoder * m_encoder
static constexpr size_t MAX_SAMPLES
static constexpr int8_t NUM_CHANNELS
#define LOG(_MASK_, _LEVEL_, _QSTRING_)