change Coder to Codec everywhere
[flac.git] / include / FLAC / encoder.h
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__ENCODER_H
21 #define FLAC__ENCODER_H
22
23 #include "format.h"
24
25 typedef enum {
26         FLAC__ENCODER_WRITE_OK = 0,
27         FLAC__ENCODER_WRITE_FATAL_ERROR
28 } FLAC__EncoderWriteStatus;
29 extern const char *FLAC__EncoderWriteStatusString[];
30
31 typedef enum {
32         FLAC__ENCODER_OK = 0,
33         FLAC__ENCODER_UNINITIALIZED,
34         FLAC__ENCODER_INVALID_NUMBER_OF_CHANNELS,
35         FLAC__ENCODER_INVALID_BITS_PER_SAMPLE,
36         FLAC__ENCODER_INVALID_SAMPLE_RATE,
37         FLAC__ENCODER_INVALID_BLOCK_SIZE,
38         FLAC__ENCODER_INVALID_QLP_COEFF_PRECISION,
39         FLAC__ENCODER_MID_SIDE_CHANNELS_MISMATCH,
40         FLAC__ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
41         FLAC__ENCODER_ILLEGAL_MID_SIDE_FORCE,
42         FLAC__ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
43         FLAC__ENCODER_NOT_STREAMABLE,
44         FLAC__ENCODER_FRAMING_ERROR,
45         FLAC__ENCODER_FATAL_ERROR_WHILE_ENCODING,
46         FLAC__ENCODER_FATAL_ERROR_WHILE_WRITING, /* that is, the write_callback returned an error */
47         FLAC__ENCODER_MEMORY_ALLOCATION_ERROR
48 } FLAC__EncoderState;
49 extern const char *FLAC__EncoderStateString[];
50
51 struct FLAC__EncoderPrivate;
52 typedef struct {
53         /*
54          * none of these fields may change once FLAC__encoder_init() is called
55          */
56         struct FLAC__EncoderPrivate *guts;    /* must be 0 when passed to FLAC__encoder_init() */
57         FLAC__EncoderState state;             /* must be FLAC__ENCODER_UNINITIALIZED when passed to FLAC__encoder_init() */
58         bool     streamable_subset;
59         bool     do_mid_side_stereo;          /* 0 or 1; 1 only if channels==2 */
60         bool     loose_mid_side_stereo;       /* 0 or 1; 1 only if channels==2 and do_mid_side_stereo==true */
61         unsigned channels;                    /* must be <= FLAC__MAX_CHANNELS */
62         unsigned bits_per_sample;             /* do not give the encoder wider data than what you specify here or bad things will happen! */
63         unsigned sample_rate;
64         unsigned blocksize;
65         unsigned max_lpc_order;               /* 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER */
66         unsigned qlp_coeff_precision;         /* >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize; */
67                                               /* qlp_coeff_precision+bits_per_sample must be < 32 */
68         bool     do_qlp_coeff_prec_search;    /* 0 => use qlp_coeff_precision, 1 => search around qlp_coeff_precision, take best */
69         bool     do_exhaustive_model_search;  /* 0 => use estimated bits per residual for scoring, 1 => generate all, take shortest */
70         unsigned rice_optimization_level;     /* 0 => estimate Rice parameter based on residual variance, 1-8 => partition residual, use parameter for each */
71         uint64   total_samples_estimate;      /* may be 0 if unknown.  this will be a placeholder in the metadata block until the actual total is calculated */
72 } FLAC__Encoder;
73
74
75 FLAC__Encoder *FLAC__encoder_get_new_instance();
76 void FLAC__encoder_free_instance(FLAC__Encoder *encoder);
77 FLAC__EncoderState FLAC__encoder_init(FLAC__Encoder *encoder, FLAC__EncoderWriteStatus (*write_callback)(const FLAC__Encoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data), void (*metadata_callback)(const FLAC__Encoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data), void *client_data);
78 void FLAC__encoder_finish(FLAC__Encoder *encoder);
79 bool FLAC__encoder_process(FLAC__Encoder *encoder, const int32 *buf[], unsigned samples);
80 bool FLAC__encoder_process_interleaved(FLAC__Encoder *encoder, const int32 buf[], unsigned samples);
81
82 #endif