~ubuntu-branches/ubuntu/raring/mumble/raring

« back to all changes in this revision

Viewing changes to celt-0.11.0-src/libcelt/celt.h

  • Committer: Bazaar Package Importer
  • Author(s): Thorvald Natvig, Patrick Matthäi, Thorvald Natvig
  • Date: 2011-02-19 22:58:58 UTC
  • mfrom: (9.1.15 sid)
  • Revision ID: james.westby@ubuntu.com-20110219225858-0xlftrf4z1z4jt9e
Tags: 1.2.3-1
[ Patrick Matthäi ]
* Do not build with non existant libpulse-dev on hurd-i386.

[ Thorvald Natvig ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2007-2008 CSIRO
 
2
   Copyright (c) 2007-2009 Xiph.Org Foundation
 
3
   Copyright (c) 2008 Gregory Maxwell 
 
4
   Written by Jean-Marc Valin and Gregory Maxwell */
 
5
/**
 
6
  @file celt.h
 
7
  @brief Contains all the functions for encoding and decoding audio
 
8
 */
 
9
 
 
10
/*
 
11
   Redistribution and use in source and binary forms, with or without
 
12
   modification, are permitted provided that the following conditions
 
13
   are met:
 
14
   
 
15
   - Redistributions of source code must retain the above copyright
 
16
   notice, this list of conditions and the following disclaimer.
 
17
   
 
18
   - Redistributions in binary form must reproduce the above copyright
 
19
   notice, this list of conditions and the following disclaimer in the
 
20
   documentation and/or other materials provided with the distribution.
 
21
   
 
22
   - Neither the name of the Xiph.org Foundation nor the names of its
 
23
   contributors may be used to endorse or promote products derived from
 
24
   this software without specific prior written permission.
 
25
   
 
26
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
27
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
28
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
29
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
 
30
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
31
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
32
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
33
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
34
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
35
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
36
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
37
*/
 
38
 
 
39
#ifndef CELT_H
 
40
#define CELT_H
 
41
 
 
42
#include "celt_types.h"
 
43
 
 
44
#ifdef __cplusplus
 
45
extern "C" {
 
46
#endif
 
47
 
 
48
#if defined(__GNUC__) && defined(CELT_BUILD)
 
49
#define EXPORT __attribute__ ((visibility ("default")))
 
50
#elif defined(WIN32)
 
51
#define EXPORT __declspec(dllexport)
 
52
#else
 
53
#define EXPORT
 
54
#endif
 
55
 
 
56
#define _celt_check_int(x) (((void)((x) == (celt_int32)0)), (celt_int32)(x))
 
57
#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr)))
 
58
 
 
59
/* Error codes */
 
60
/** No error */
 
61
#define CELT_OK                0
 
62
/** An (or more) invalid argument (e.g. out of range) */
 
63
#define CELT_BAD_ARG          -1
 
64
/** The mode struct passed is invalid */
 
65
#define CELT_INVALID_MODE     -2
 
66
/** An internal error was detected */
 
67
#define CELT_INTERNAL_ERROR   -3
 
68
/** The data passed (e.g. compressed data to decoder) is corrupted */
 
69
#define CELT_CORRUPTED_DATA   -4
 
70
/** Invalid/unsupported request number */
 
71
#define CELT_UNIMPLEMENTED    -5
 
72
/** An encoder or decoder structure is invalid or already freed */
 
73
#define CELT_INVALID_STATE    -6
 
74
/** Memory allocation has failed */
 
75
#define CELT_ALLOC_FAIL       -7
 
76
 
 
77
/* Requests */
 
78
#define CELT_GET_MODE_REQUEST    1
 
79
/** Get the CELTMode used by an encoder or decoder */
 
80
#define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x)
 
81
 
 
82
#define CELT_SET_COMPLEXITY_REQUEST    2
 
83
/** Controls the complexity from 0-10 (int) */
 
84
#define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)
 
85
 
 
86
#define CELT_SET_PREDICTION_REQUEST    4
 
87
/** Controls the use of interframe prediction.
 
88
    0=Independent frames
 
89
    1=Short term interframe prediction allowed
 
90
    2=Long term prediction allowed
 
91
 */
 
92
#define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, _celt_check_int(x)
 
93
 
 
94
#define CELT_SET_BITRATE_REQUEST    6
 
95
/** Set the target VBR rate in bits per second(int); 0=CBR (default) */
 
96
#define CELT_SET_BITRATE(x) CELT_SET_BITRATE_REQUEST, _celt_check_int(x)
 
97
 
 
98
/** Reset the encoder/decoder memories to zero*/
 
99
#define CELT_RESET_STATE_REQUEST        8
 
100
#define CELT_RESET_STATE       CELT_RESET_STATE_REQUEST
 
101
 
 
102
#define CELT_SET_VBR_CONSTRAINT_REQUEST 10
 
103
#define CELT_SET_VBR_CONSTRAINT(x)       CELT_SET_VBR_CONSTRAINT_REQUEST, _celt_check_int(x)
 
104
 
 
105
#define CELT_SET_VBR_REQUEST 12
 
106
#define CELT_SET_VBR(x)       CELT_SET_VBR_REQUEST, _celt_check_int(x)
 
107
 
 
108
#define CELT_SET_INPUT_CLIPPING_REQUEST    14
 
109
#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, _celt_check_int(x)
 
110
 
 
111
#define CELT_SET_START_BAND_REQUEST    10000
 
112
#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)
 
113
 
 
114
#define CELT_SET_END_BAND_REQUEST    10001
 
115
#define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, _celt_check_int(x)
 
116
 
 
117
#define CELT_SET_CHANNELS_REQUEST    10002
 
118
#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, _celt_check_int(x)
 
119
 
 
120
/** GET the lookahead used in the current mode */
 
121
#define CELT_GET_LOOKAHEAD    1001
 
122
/** GET the sample rate used in the current mode */
 
123
#define CELT_GET_SAMPLE_RATE  1003
 
124
 
 
125
/** GET the bit-stream version for compatibility check */
 
126
#define CELT_GET_BITSTREAM_VERSION 2000
 
127
 
 
128
 
 
129
/** Contains the state of an encoder. One encoder state is needed 
 
130
    for each stream. It is initialised once at the beginning of the
 
131
    stream. Do *not* re-initialise the state for every frame.
 
132
   @brief Encoder state
 
133
 */
 
134
typedef struct CELTEncoder CELTEncoder;
 
135
 
 
136
/** State of the decoder. One decoder state is needed for each stream.
 
137
    It is initialised once at the beginning of the stream. Do *not*
 
138
    re-initialise the state for every frame */
 
139
typedef struct CELTDecoder CELTDecoder;
 
140
 
 
141
/** The mode contains all the information necessary to create an
 
142
    encoder. Both the encoder and decoder need to be initialised
 
143
    with exactly the same mode, otherwise the quality will be very 
 
144
    bad */
 
145
typedef struct CELTMode CELTMode;
 
146
 
 
147
 
 
148
/** \defgroup codec Encoding and decoding */
 
149
/*  @{ */
 
150
 
 
151
/* Mode calls */
 
152
 
 
153
/** Creates a new mode struct. This will be passed to an encoder or 
 
154
    decoder. The mode MUST NOT BE DESTROYED until the encoders and 
 
155
    decoders that use it are destroyed as well.
 
156
 @param Fs Sampling rate (32000 to 96000 Hz)
 
157
 @param frame_size Number of samples (per channel) to encode in each 
 
158
                   packet (even values; 64 - 512)
 
159
 @param error Returned error code (if NULL, no error will be returned)
 
160
 @return A newly created mode
 
161
*/
 
162
EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error);
 
163
 
 
164
/** Destroys a mode struct. Only call this after all encoders and 
 
165
    decoders using this mode are destroyed as well.
 
166
 @param mode Mode to be destroyed
 
167
*/
 
168
EXPORT void celt_mode_destroy(CELTMode *mode);
 
169
 
 
170
/** Query information from a mode */
 
171
EXPORT int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value);
 
172
 
 
173
/* Encoder stuff */
 
174
 
 
175
EXPORT int celt_encoder_get_size(int channels);
 
176
 
 
177
EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels);
 
178
 
 
179
/** Creates a new encoder state. Each stream needs its own encoder 
 
180
    state (can't be shared across simultaneous streams).
 
181
 @param channels Number of channels
 
182
 @param error Returns an error code
 
183
 @return Newly created encoder state.
 
184
*/
 
185
EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error);
 
186
 
 
187
/** Creates a new encoder state. Each stream needs its own encoder
 
188
    state (can't be shared across simultaneous streams).
 
189
 @param mode Contains all the information about the characteristics of
 
190
 *  the stream (must be the same characteristics as used for the 
 
191
 *  decoder)
 
192
 @param channels Number of channels
 
193
 @param error Returns an error code
 
194
 @return Newly created encoder state.
 
195
*/
 
196
EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
 
197
 
 
198
EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error);
 
199
 
 
200
EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
 
201
 
 
202
/** Destroys a an encoder state.
 
203
 @param st Encoder state to be destroyed
 
204
 */
 
205
EXPORT void celt_encoder_destroy(CELTEncoder *st);
 
206
 
 
207
/** Encodes a frame of audio.
 
208
 @param st Encoder state
 
209
 @param pcm PCM audio in float format, with a normal range of ±1.0.
 
210
 *          Samples with a range beyond ±1.0 are supported but will
 
211
 *          be clipped by decoders using the integer API and should
 
212
 *          only be used if it is known that the far end supports
 
213
 *          extended dynmaic range. There must be exactly
 
214
 *          frame_size samples per channel.
 
215
 @param compressed The compressed data is written here. This may not alias pcm or
 
216
 *                 optional_synthesis.
 
217
 @param nbCompressedBytes Maximum number of bytes to use for compressing the frame
 
218
 *          (can change from one frame to another)
 
219
 @return Number of bytes written to "compressed". Will be the same as
 
220
 *       "nbCompressedBytes" unless the stream is VBR and will never be larger.
 
221
 *       If negative, an error has occurred (see error codes). It is IMPORTANT that
 
222
 *       the length returned be somehow transmitted to the decoder. Otherwise, no
 
223
 *       decoding is possible.
 
224
*/
 
225
EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
 
226
 
 
227
/** Encodes a frame of audio.
 
228
 @param st Encoder state
 
229
 @param pcm PCM audio in signed 16-bit format (native endian). There must be
 
230
 *          exactly frame_size samples per channel.
 
231
 @param compressed The compressed data is written here. This may not alias pcm or
 
232
 *                         optional_synthesis.
 
233
 @param nbCompressedBytes Maximum number of bytes to use for compressing the frame
 
234
 *                        (can change from one frame to another)
 
235
 @return Number of bytes written to "compressed". Will be the same as
 
236
 *       "nbCompressedBytes" unless the stream is VBR and will never be larger.
 
237
 *       If negative, an error has occurred (see error codes). It is IMPORTANT that
 
238
 *       the length returned be somehow transmitted to the decoder. Otherwise, no
 
239
 *       decoding is possible.
 
240
 */
 
241
EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
 
242
 
 
243
/** Query and set encoder parameters 
 
244
 @param st Encoder state
 
245
 @param request Parameter to change or query
 
246
 @param value Pointer to a 32-bit int value
 
247
 @return Error code
 
248
*/
 
249
EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, ...);
 
250
 
 
251
/* Decoder stuff */
 
252
 
 
253
EXPORT int celt_decoder_get_size(int channels);
 
254
 
 
255
EXPORT int celt_decoder_get_size_custom(const CELTMode *mode, int channels);
 
256
 
 
257
/** Creates a new decoder state. Each stream needs its own decoder state (can't
 
258
    be shared across simultaneous streams).
 
259
 @param mode Contains all the information about the characteristics of the
 
260
             stream (must be the same characteristics as used for the encoder)
 
261
 @param channels Number of channels
 
262
 @param error Returns an error code
 
263
 @return Newly created decoder state.
 
264
 */
 
265
EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error);
 
266
 
 
267
/** Creates a new decoder state. Each stream needs its own decoder state (can't
 
268
    be shared across simultaneous streams).
 
269
 @param mode Contains all the information about the characteristics of the
 
270
             stream (must be the same characteristics as used for the encoder)
 
271
 @param channels Number of channels
 
272
 @param error Returns an error code
 
273
 @return Newly created decoder state.
 
274
 */
 
275
EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error);
 
276
 
 
277
EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error);
 
278
 
 
279
EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
 
280
 
 
281
/** Destroys a a decoder state.
 
282
 @param st Decoder state to be destroyed
 
283
 */
 
284
EXPORT void celt_decoder_destroy(CELTDecoder *st);
 
285
 
 
286
/** Decodes a frame of audio.
 
287
 @param st Decoder state
 
288
 @param data Compressed data produced by an encoder
 
289
 @param len Number of bytes to read from "data". This MUST be exactly the number
 
290
            of bytes returned by the encoder. Using a larger value WILL NOT WORK.
 
291
 @param pcm One frame (frame_size samples per channel) of decoded PCM will be
 
292
            returned here in float format. 
 
293
 @return Error code.
 
294
   */
 
295
EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, int len, float *pcm, int frame_size);
 
296
 
 
297
/** Decodes a frame of audio.
 
298
 @param st Decoder state
 
299
 @param data Compressed data produced by an encoder
 
300
 @param len Number of bytes to read from "data". This MUST be exactly the number
 
301
            of bytes returned by the encoder. Using a larger value WILL NOT WORK.
 
302
 @param pcm One frame (frame_size samples per channel) of decoded PCM will be
 
303
            returned here in 16-bit PCM format (native endian). 
 
304
 @return Error code.
 
305
 */
 
306
EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt_int16 *pcm, int frame_size);
 
307
 
 
308
/** Query and set decoder parameters
 
309
   @param st Decoder state
 
310
   @param request Parameter to change or query
 
311
   @param value Pointer to a 32-bit int value
 
312
   @return Error code
 
313
 */
 
314
EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...);
 
315
 
 
316
 
 
317
/** Returns the English string that corresponds to an error code
 
318
 * @param error Error code (negative for an error, 0 for success
 
319
 * @return Constant string (must NOT be freed)
 
320
 */
 
321
EXPORT const char *celt_strerror(int error);
 
322
 
 
323
/*  @} */
 
324
 
 
325
 
 
326
#ifdef __cplusplus
 
327
}
 
328
#endif
 
329
 
 
330
#endif /*CELT_H */