Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | /* libFLAC - Free Lossless Audio Codec library |
2 | * Copyright (C) 2000,2001 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 FLAC__STREAM_ENCODER_H |
||
21 | #define FLAC__STREAM_ENCODER_H |
||
22 | |||
23 | #include "format.h" |
||
24 | |||
25 | typedef enum { |
||
26 | FLAC__STREAM_ENCODER_OK = 0, |
||
27 | FLAC__STREAM_ENCODER_INVALID_CALLBACK, |
||
28 | FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS, |
||
29 | FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE, |
||
30 | FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE, |
||
31 | FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE, |
||
32 | FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION, |
||
33 | FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH, |
||
34 | FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH, |
||
35 | FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE, |
||
36 | FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER, |
||
37 | FLAC__STREAM_ENCODER_NOT_STREAMABLE, |
||
38 | FLAC__STREAM_ENCODER_FRAMING_ERROR, |
||
39 | FLAC__STREAM_ENCODER_INVALID_SEEK_TABLE, |
||
40 | FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING, |
||
41 | FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING, /* that is, the write_callback returned an error */ |
||
42 | FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR, |
||
43 | FLAC__STREAM_ENCODER_ALREADY_INITIALIZED, |
||
44 | FLAC__STREAM_ENCODER_UNINITIALIZED |
||
45 | } FLAC__StreamEncoderState; |
||
46 | extern const char *FLAC__StreamEncoderStateString[]; |
||
47 | |||
48 | typedef enum { |
||
49 | FLAC__STREAM_ENCODER_WRITE_OK = 0, |
||
50 | FLAC__STREAM_ENCODER_WRITE_FATAL_ERROR |
||
51 | } FLAC__StreamEncoderWriteStatus; |
||
52 | extern const char *FLAC__StreamEncoderWriteStatusString[]; |
||
53 | |||
54 | /*********************************************************************** |
||
55 | * |
||
56 | * class FLAC__StreamEncoder |
||
57 | * |
||
58 | ***********************************************************************/ |
||
59 | |||
60 | struct FLAC__StreamEncoderProtected; |
||
61 | struct FLAC__StreamEncoderPrivate; |
||
62 | typedef struct { |
||
63 | struct FLAC__StreamEncoderProtected *protected; |
||
64 | struct FLAC__StreamEncoderPrivate *private; |
||
65 | } FLAC__StreamEncoder; |
||
66 | |||
67 | /*********************************************************************** |
||
68 | * |
||
69 | * Class constructor/destructor |
||
70 | * |
||
71 | ***********************************************************************/ |
||
72 | |||
73 | /* |
||
74 | * Any parameters that are not set before FLAC__stream_encoder_init() |
||
75 | * will take on the defaults from the constructor, shown below. |
||
76 | * For more on what the parameters mean, see the documentation. |
||
77 | * |
||
78 | * FLAC__bool streamable_subset (DEFAULT: true ) true to limit encoder to generating a Subset stream, else false |
||
79 | * FLAC__bool do_mid_side_stereo (DEFAULT: false) if true then channels must be 2 |
||
80 | * FLAC__bool loose_mid_side_stereo (DEFAULT: false) if true then do_mid_side_stereo must be true |
||
81 | * unsigned channels (DEFAULT: 2 ) must be <= FLAC__MAX_CHANNELS |
||
82 | * unsigned bits_per_sample (DEFAULT: 16 ) do not give the encoder wider data than what you specify here or bad things will happen! |
||
83 | * unsigned sample_rate (DEFAULT: 44100) |
||
84 | * unsigned blocksize (DEFAULT: 1152 ) |
||
85 | * unsigned max_lpc_order (DEFAULT: 0 ) 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER |
||
86 | * unsigned qlp_coeff_precision (DEFAULT: 0 ) >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize; |
||
87 | * qlp_coeff_precision+bits_per_sample must be < 32 |
||
88 | * FLAC__bool do_qlp_coeff_prec_search (DEFAULT: false) false => use qlp_coeff_precision, true => search around qlp_coeff_precision, take best |
||
89 | * FLAC__bool do_escape_coding (DEFAULT: false) true => search for escape codes in the entropy coding stage for slightly better compression |
||
90 | * FLAC__bool do_exhaustive_model_search (DEFAULT: false) false => use estimated bits per residual for scoring, true => generate all, take shortest |
||
91 | * unsigned min_residual_partition_order (DEFAULT: 0 ) 0 => estimate Rice parameter based on residual variance; >0 => partition residual, use parameter |
||
92 | * unsigned max_residual_partition_order (DEFAULT: 0 ) for each based on mean; min_ and max_ specify the min and max Rice partition order |
||
93 | * unsigned rice_parameter_search_dist (DEFAULT: 0 ) 0 => try only calc'd parameter k; else try all [k-dist..k+dist] parameters, use best |
||
94 | * FLAC__uint64 total_samples_estimate (DEFAULT: 0 ) may be 0 if unknown. acts as a placeholder in the STREAMINFO until the actual total is calculated |
||
95 | * const FLAC__StreamMetaData_SeekTable *seek_table (DEFAULT: NULL) optional seek_table to prepend, NULL => no seek table |
||
96 | * unsigned padding (DEFAULT: 0 ) size of PADDING block to add (goes after seek table); 0 => do not add a PADDING block |
||
97 | * FLAC__bool last_metadata_is_last (DEFAULT: true ) the value the encoder will use for the 'is_last' flag of the last metadata block it writes; set |
||
98 | * this to false if you will be adding more metadata blocks before the audio frames, else true |
||
99 | * (*write_callback)() (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__stream_encoder_init() |
||
100 | * (*metadata_callback)() (DEFAULT: NULL ) |
||
101 | * void* client_data (DEFAULT: NULL ) passed back through the callbacks |
||
102 | */ |
||
103 | FLAC__StreamEncoder *FLAC__stream_encoder_new(); |
||
104 | void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder); |
||
105 | |||
106 | /*********************************************************************** |
||
107 | * |
||
108 | * Public class method prototypes |
||
109 | * |
||
110 | ***********************************************************************/ |
||
111 | |||
112 | /* |
||
113 | * Various "set" methods. These may only be called when the encoder |
||
114 | * is in the state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after |
||
115 | * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but |
||
116 | * before FLAC__stream_encoder_init(). If this is the case they will |
||
117 | * return true, otherwise false. |
||
118 | * |
||
119 | * NOTE that these functions do not validate the values as many are |
||
120 | * interdependent. The FLAC__stream_encoder_init() function will do |
||
121 | * this, so make sure to pay attention to the state returned by |
||
122 | * FLAC__stream_encoder_init(). |
||
123 | * |
||
124 | * Any parameters that are not set before FLAC__stream_encoder_init() |
||
125 | * will take on the defaults from the constructor. NOTE that |
||
126 | * FLAC__stream_encoder_finish() does NOT reset the values to the |
||
127 | * constructor defaults. |
||
128 | */ |
||
129 | FLAC__bool FLAC__stream_encoder_set_streamable_subset(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
130 | FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
131 | FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
132 | FLAC__bool FLAC__stream_encoder_set_channels(const FLAC__StreamEncoder *encoder, unsigned value); |
||
133 | FLAC__bool FLAC__stream_encoder_set_bits_per_sample(const FLAC__StreamEncoder *encoder, unsigned value); |
||
134 | FLAC__bool FLAC__stream_encoder_set_sample_rate(const FLAC__StreamEncoder *encoder, unsigned value); |
||
135 | FLAC__bool FLAC__stream_encoder_set_blocksize(const FLAC__StreamEncoder *encoder, unsigned value); |
||
136 | FLAC__bool FLAC__stream_encoder_set_max_lpc_order(const FLAC__StreamEncoder *encoder, unsigned value); |
||
137 | FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(const FLAC__StreamEncoder *encoder, unsigned value); |
||
138 | FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
139 | FLAC__bool FLAC__stream_encoder_set_do_escape_coding(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
140 | FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
141 | FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value); |
||
142 | FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value); |
||
143 | FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder, unsigned value); |
||
144 | FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(const FLAC__StreamEncoder *encoder, FLAC__uint64 value); |
||
145 | FLAC__bool FLAC__stream_encoder_set_seek_table(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData_SeekTable *value); |
||
146 | FLAC__bool FLAC__stream_encoder_set_padding(const FLAC__StreamEncoder *encoder, unsigned value); |
||
147 | FLAC__bool FLAC__stream_encoder_set_last_metadata_is_last(const FLAC__StreamEncoder *encoder, FLAC__bool value); |
||
148 | FLAC__bool FLAC__stream_encoder_set_write_callback(const FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteStatus (*value)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)); |
||
149 | FLAC__bool FLAC__stream_encoder_set_metadata_callback(const FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data)); |
||
150 | FLAC__bool FLAC__stream_encoder_set_client_data(const FLAC__StreamEncoder *encoder, void *value); |
||
151 | |||
152 | /* |
||
153 | * Various "get" methods |
||
154 | */ |
||
155 | FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder); |
||
156 | FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder); |
||
157 | FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder); |
||
158 | FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder); |
||
159 | unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder); |
||
160 | unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder); |
||
161 | unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder); |
||
162 | unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder); |
||
163 | unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder); |
||
164 | unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder); |
||
165 | FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder); |
||
166 | FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder); |
||
167 | FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder); |
||
168 | unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder); |
||
169 | unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder); |
||
170 | unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder); |
||
171 | |||
172 | /* |
||
173 | * Initialize the instance; should be called after construction and |
||
174 | * 'set' calls but before any of the 'process' calls. Will set and |
||
175 | * return the encoder state, which will be FLAC__STREAM_ENCODER_OK |
||
176 | * if initialization succeeded. |
||
177 | */ |
||
178 | FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder); |
||
179 | |||
180 | /* |
||
181 | * Flush the encoding buffer, release resources, and return the encoder |
||
182 | * state to FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can |
||
183 | * generate one or more write_callback()s before returning. |
||
184 | */ |
||
185 | void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder); |
||
186 | |||
187 | /* |
||
188 | * Methods for encoding the data |
||
189 | */ |
||
190 | FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 *buf[], unsigned samples); |
||
191 | FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buf[], unsigned samples); |
||
192 | |||
193 | #endif>=>=> |