Josh Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 1 | /* 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 Coalson | f6efd9c | 2002-07-27 04:59:54 +0000 | [diff] [blame^] | 33 | /** \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 Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 52 | namespace 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 Coalson | f6efd9c | 2002-07-27 04:59:54 +0000 | [diff] [blame^] | 69 | /** \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 Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 81 | 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 Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 114 | bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks); |
Josh Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 115 | |
| 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 Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 140 | bool process(const FLAC__int32 * const buffer[], unsigned samples); |
| 141 | bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); |
Josh Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 142 | protected: |
| 143 | virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0; |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 144 | virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0; |
Josh Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 145 | |
| 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 Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 149 | static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data); |
Josh Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 150 | |
| 151 | // Private and undefined so you can't use them: |
| 152 | Stream(const Stream &); |
| 153 | void operator=(const Stream &); |
| 154 | }; |
| 155 | |
Josh Coalson | f6efd9c | 2002-07-27 04:59:54 +0000 | [diff] [blame^] | 156 | /* \} */ |
| 157 | |
Josh Coalson | b04a16e | 2002-05-29 05:49:50 +0000 | [diff] [blame] | 158 | }; |
| 159 | }; |
| 160 | |
| 161 | #endif |