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