MythTV  master
flacencoder.h
Go to the documentation of this file.
1 #ifndef FLACENCODER_H_
2 #define FLACENCODER_H_
3 
4 #include <cstdint>
5 
6 #include <FLAC/export.h>
7 #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
8  /* FLAC 1.0.4 to 1.1.2 */
9  #include <FLAC/file_encoder.h>
10  #define encoder_new() FLAC__file_encoder_new()
11  #define encoder_setup(enc, streamable_subset, do_mid_side_stereo, \
12  loose_mid_side_stereo, channels, bits_per_sample, \
13  sample_rate, blocksize, max_lpc_order, \
14  qlp_coeff_precision, do_qlp_coeff_prec_search, \
15  do_escape_coding, do_exhaustive_model_search, \
16  min_residual_partition_order, max_residual_partition_order, \
17  rice_parameter_search_dist) \
18  { \
19  FLAC__file_encoder_set_streamable_subset(enc, streamable_subset); \
20  FLAC__file_encoder_set_do_mid_side_stereo(enc, do_mid_side_stereo); \
21  FLAC__file_encoder_set_loose_mid_side_stereo(enc, loose_mid_side_stereo); \
22  FLAC__file_encoder_set_channels(enc, channels); \
23  FLAC__file_encoder_set_bits_per_sample(enc, bits_per_sample); \
24  FLAC__file_encoder_set_sample_rate(enc, sample_rate); \
25  FLAC__file_encoder_set_blocksize(enc, blocksize); \
26  FLAC__file_encoder_set_max_lpc_order(enc, max_lpc_order); \
27  FLAC__file_encoder_set_qlp_coeff_precision(enc, qlp_coeff_precision); \
28  FLAC__file_encoder_set_do_qlp_coeff_prec_search(enc, do_qlp_coeff_prec_search); \
29  FLAC__file_encoder_set_do_escape_coding(enc, do_escape_coding); \
30  FLAC__file_encoder_set_do_exhaustive_model_search(enc, do_exhaustive_model_search); \
31  FLAC__file_encoder_set_min_residual_partition_order(enc, min_residual_partition_order); \
32  FLAC__file_encoder_set_max_residual_partition_order(enc, max_residual_partition_order); \
33  FLAC__file_encoder_set_rice_parameter_search_dist(enc, rice_parameter_search_dist); \
34  }
35  #define encoder_finish(enc) FLAC__file_encoder_finish(enc)
36  #define encoder_delete(enc) FLAC__file_encoder_delete(enc)
37  #define encoder_process(enc, data, index) FLAC__file_encoder_process(enc, data, index)
38  #define FLAC_ENCODER FLAC__FileEncoder
39 #else
40  /* FLAC 1.1.3 and up */
41  #define NEWFLAC
42  #include <FLAC/stream_encoder.h>
43  #define encoder_new() FLAC__stream_encoder_new()
44  #define encoder_setup(enc, streamable_subset, do_mid_side_stereo, \
45  loose_mid_side_stereo, channels, bits_per_sample, \
46  sample_rate, blocksize, max_lpc_order, \
47  qlp_coeff_precision, do_qlp_coeff_prec_search, \
48  do_escape_coding, do_exhaustive_model_search, \
49  min_residual_partition_order, max_residual_partition_order, \
50  rice_parameter_search_dist) \
51  { \
52  FLAC__stream_encoder_set_streamable_subset(enc, streamable_subset); \
53  FLAC__stream_encoder_set_do_mid_side_stereo(enc, do_mid_side_stereo); \
54  FLAC__stream_encoder_set_loose_mid_side_stereo(enc, loose_mid_side_stereo); \
55  FLAC__stream_encoder_set_channels(enc, channels); \
56  FLAC__stream_encoder_set_bits_per_sample(enc, bits_per_sample); \
57  FLAC__stream_encoder_set_sample_rate(enc, sample_rate); \
58  FLAC__stream_encoder_set_blocksize(enc, blocksize); \
59  FLAC__stream_encoder_set_max_lpc_order(enc, max_lpc_order); \
60  FLAC__stream_encoder_set_qlp_coeff_precision(enc, qlp_coeff_precision); \
61  FLAC__stream_encoder_set_do_qlp_coeff_prec_search(enc, do_qlp_coeff_prec_search); \
62  FLAC__stream_encoder_set_do_escape_coding(enc, do_escape_coding); \
63  FLAC__stream_encoder_set_do_exhaustive_model_search(enc, do_exhaustive_model_search); \
64  FLAC__stream_encoder_set_min_residual_partition_order(enc, min_residual_partition_order); \
65  FLAC__stream_encoder_set_max_residual_partition_order(enc, max_residual_partition_order); \
66  FLAC__stream_encoder_set_rice_parameter_search_dist(enc, rice_parameter_search_dist); \
67  }
68  #define encoder_finish(enc) FLAC__stream_encoder_finish(enc)
69  #define encoder_delete(enc) FLAC__stream_encoder_delete(enc)
70  #define encoder_process(enc, data, index) FLAC__stream_encoder_process(enc, data, index)
71  #define FLAC_ENCODER FLAC__StreamEncoder
72 #endif
73 
74 #include "encoder.h"
75 
76 #define MAX_SAMPLES (588 * 4)
77 #define NUM_CHANNELS 2
78 
79 class MusicMetadata;
80 class QString;
81 
82 class FlacEncoder : public Encoder
83 {
84  public:
85  FlacEncoder(const QString &outfile, int qualitylevel, MusicMetadata *metadata);
86  ~FlacEncoder() override;
87  int addSamples(int16_t *bytes, unsigned int len) override; // Encoder
88 
89  private:
90  FLAC_ENCODER *m_encoder {nullptr};
91  unsigned int m_sampleIndex {0};
93  FLAC__int32 *m_input[NUM_CHANNELS] {};
94 };
95 
96 #endif
~FlacEncoder() override
Definition: flacencoder.cpp:86
int addSamples(int16_t *bytes, unsigned int len) override
unsigned int m_sampleIndex
Definition: flacencoder.h:91
#define FLAC_ENCODER
Definition: flacencoder.h:38
FLAC__int32 * m_input[NUM_CHANNELS]
Definition: flacencoder.h:93
#define MAX_SAMPLES
Definition: flacencoder.h:76
#define NUM_CHANNELS
Definition: flacencoder.h:77
FLAC_ENCODER * m_encoder
Definition: flacencoder.h:90
FlacEncoder(const QString &outfile, int qualitylevel, MusicMetadata *metadata)
Definition: flacencoder.cpp:28
FLAC__int32 m_inputIn[NUM_CHANNELS][MAX_SAMPLES]
Definition: flacencoder.h:92