blob: 7166e289c340d7ce2b0bf4beb3423b01dc2c0a89 [file] [log] [blame]
Josh Coalsonb04a16e2002-05-29 05:49:50 +00001/* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 Josh Coalson
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#ifndef FLACPP__ENCODER_H
21#define FLACPP__ENCODER_H
22
23#include "FLAC/stream_encoder.h"
24
25// ===============================================================
26//
27// Full documentation for the encoder interface can be found
28// in the C layer in include/FLAC/stream_encoder.h
29//
30// ===============================================================
31
32
Josh Coalsonf6efd9c2002-07-27 04:59:54 +000033/** \file include/FLAC++/encoder.h
34 *
35 * \brief
36 * This module contains the classes which implement the various
37 * encoders.
38 *
39 * See the detailed documentation in the
40 * \link flacpp_encoder encoder \endlink module.
41 */
42
43/** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
44 * \ingroup flacpp
45 *
46 * \brief
47 * Brief XXX.
48 *
49 * Detailed encoder XXX.
50 */
51
Josh Coalsonb04a16e2002-05-29 05:49:50 +000052namespace FLAC {
53 namespace Encoder {
54
55 // ============================================================
56 //
57 // Equivalent: FLAC__StreamEncoder
58 //
59 // ----------------------------------------------------------
60 //
61 // The only real difference here is that instead of passing
62 // in C function pointers for callbacks, you inherit from
63 // stream and provide implementations for the callbacks in
64 // the derived class; because of this there is no need for a
65 // 'client_data' property.
66 //
67 // ============================================================
68
Josh Coalsonf6efd9c2002-07-27 04:59:54 +000069 /** \defgroup flacpp_stream_encoder FLAC++/encoder.h: stream encoder class
70 * \ingroup flacpp_encoder
71 *
72 * \brief
73 * Brief XXX.
74 *
75 * Detailed stream encoder XXX.
76 * \{
77 */
78
79 /** stream encoder XXX.
80 */
Josh Coalsonb04a16e2002-05-29 05:49:50 +000081 class Stream {
82 public:
83 class State {
84 public:
85 inline State(::FLAC__StreamEncoderState state): state_(state) { }
86 inline operator ::FLAC__StreamEncoderState() const { return state_; }
87 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
88 protected:
89 ::FLAC__StreamEncoderState state_;
90 };
91
92 Stream();
93 virtual ~Stream();
94
95 bool is_valid() const;
96 inline operator bool() const { return is_valid(); }
97
98 bool set_streamable_subset(bool value);
99 bool set_do_mid_side_stereo(bool value);
100 bool set_loose_mid_side_stereo(bool value);
101 bool set_channels(unsigned value);
102 bool set_bits_per_sample(unsigned value);
103 bool set_sample_rate(unsigned value);
104 bool set_blocksize(unsigned value);
105 bool set_max_lpc_order(unsigned value);
106 bool set_qlp_coeff_precision(unsigned value);
107 bool set_do_qlp_coeff_prec_search(bool value);
108 bool set_do_escape_coding(bool value);
109 bool set_do_exhaustive_model_search(bool value);
110 bool set_min_residual_partition_order(unsigned value);
111 bool set_max_residual_partition_order(unsigned value);
112 bool set_rice_parameter_search_dist(unsigned value);
113 bool set_total_samples_estimate(FLAC__uint64 value);
Josh Coalsoncc682512002-06-08 04:53:42 +0000114 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
Josh Coalsonb04a16e2002-05-29 05:49:50 +0000115
116 State get_state() const;
117 bool get_streamable_subset() const;
118 bool get_do_mid_side_stereo() const;
119 bool get_loose_mid_side_stereo() const;
120 unsigned get_channels() const;
121 unsigned get_bits_per_sample() const;
122 unsigned get_sample_rate() const;
123 unsigned get_blocksize() const;
124 unsigned get_max_lpc_order() const;
125 unsigned get_qlp_coeff_precision() const;
126 bool get_do_qlp_coeff_prec_search() const;
127 bool get_do_escape_coding() const;
128 bool get_do_exhaustive_model_search() const;
129 unsigned get_min_residual_partition_order() const;
130 unsigned get_max_residual_partition_order() const;
131 unsigned get_rice_parameter_search_dist() const;
132
133 // Initialize the instance; as with the C interface,
134 // init() should be called after construction and 'set'
135 // calls but before any of the 'process' calls.
136 State init();
137
138 void finish();
139
Josh Coalson57ba6f42002-06-07 05:27:37 +0000140 bool process(const FLAC__int32 * const buffer[], unsigned samples);
141 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
Josh Coalsonb04a16e2002-05-29 05:49:50 +0000142 protected:
143 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
Josh Coalsoncc682512002-06-08 04:53:42 +0000144 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
Josh Coalsonb04a16e2002-05-29 05:49:50 +0000145
146 ::FLAC__StreamEncoder *encoder_;
147 private:
148 static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
Josh Coalsoncc682512002-06-08 04:53:42 +0000149 static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
Josh Coalsonb04a16e2002-05-29 05:49:50 +0000150
151 // Private and undefined so you can't use them:
152 Stream(const Stream &);
153 void operator=(const Stream &);
154 };
155
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000156 /* \} */
157
Josh Coalsonb04a16e2002-05-29 05:49:50 +0000158 };
159};
160
161#endif