CELT  0.8.1
libcelt/celt.h
Go to the documentation of this file.
00001 /* Copyright (c) 2007-2008 CSIRO
00002    Copyright (c) 2007-2009 Xiph.Org Foundation
00003    Copyright (c) 2008 Gregory Maxwell 
00004    Written by Jean-Marc Valin and Gregory Maxwell */
00010 /*
00011    Redistribution and use in source and binary forms, with or without
00012    modification, are permitted provided that the following conditions
00013    are met:
00014    
00015    - Redistributions of source code must retain the above copyright
00016    notice, this list of conditions and the following disclaimer.
00017    
00018    - Redistributions in binary form must reproduce the above copyright
00019    notice, this list of conditions and the following disclaimer in the
00020    documentation and/or other materials provided with the distribution.
00021    
00022    - Neither the name of the Xiph.org Foundation nor the names of its
00023    contributors may be used to endorse or promote products derived from
00024    this software without specific prior written permission.
00025    
00026    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
00030    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 */
00038 
00039 #ifndef CELT_H
00040 #define CELT_H
00041 
00042 #include "celt_types.h"
00043 
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 #if defined(__GNUC__) && defined(CELT_BUILD)
00049 #define EXPORT __attribute__ ((visibility ("default")))
00050 #elif defined(WIN32)
00051 #define EXPORT __declspec(dllexport)
00052 #else
00053 #define EXPORT
00054 #endif
00055 
00056 #define _celt_check_int(x) (((void)((x) == (celt_int32)0)), (celt_int32)(x))
00057 #define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr)))
00058 
00059 /* Error codes */
00061 #define CELT_OK                0
00062 
00063 #define CELT_BAD_ARG          -1
00064 
00065 #define CELT_INVALID_MODE     -2
00066 
00067 #define CELT_INTERNAL_ERROR   -3
00068 
00069 #define CELT_CORRUPTED_DATA   -4
00070 
00071 #define CELT_UNIMPLEMENTED    -5
00072 
00073 #define CELT_INVALID_STATE    -6
00074 
00075 #define CELT_ALLOC_FAIL       -7
00076 
00077 /* Requests */
00078 #define CELT_GET_MODE_REQUEST    1
00079 
00080 #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x)
00081 #define CELT_SET_COMPLEXITY_REQUEST    2
00082 
00083 #define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)
00084 #define CELT_SET_PREDICTION_REQUEST    4
00085 
00090 #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, _celt_check_int(x)
00091 #define CELT_SET_VBR_RATE_REQUEST    6
00092 
00093 #define CELT_SET_VBR_RATE(x) CELT_SET_VBR_RATE_REQUEST, _celt_check_int(x)
00094 
00095 #define CELT_RESET_STATE_REQUEST        8
00096 #define CELT_RESET_STATE       CELT_RESET_STATE_REQUEST
00097 
00098 #define CELT_SET_START_BAND_REQUEST    10000
00099 
00100 #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)
00101 
00103 #define CELT_GET_LOOKAHEAD    1001
00104 
00105 #define CELT_GET_SAMPLE_RATE  1003
00106 
00108 #define CELT_GET_BITSTREAM_VERSION 2000
00109 
00110 
00116 typedef struct CELTEncoder CELTEncoder;
00117 
00121 typedef struct CELTDecoder CELTDecoder;
00122 
00127 typedef struct CELTMode CELTMode;
00128 
00129 
00131 /*  @{ */
00132 
00133 /* Mode calls */
00134 
00144 EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error);
00145 
00150 EXPORT void celt_mode_destroy(CELTMode *mode);
00151 
00153 EXPORT int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value);
00154 
00155 /* Encoder stuff */
00156 
00157 
00167 EXPORT CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error);
00168 
00172 EXPORT void celt_encoder_destroy(CELTEncoder *st);
00173 
00196 EXPORT int celt_encode_resynthesis_float(CELTEncoder *st, const float *pcm, float *optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
00197 
00216 EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
00217 
00236 EXPORT int celt_encode_resynthesis(CELTEncoder *st, const celt_int16 *pcm, celt_int16 *optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
00237 
00252 EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
00253 
00260 EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, ...);
00261 
00262 /* Decoder stuff */
00263 
00264 
00273 EXPORT CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error);
00274 
00278 EXPORT void celt_decoder_destroy(CELTDecoder *st);
00279 
00289 EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, int len, float *pcm, int frame_size);
00290 
00300 EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt_int16 *pcm, int frame_size);
00301 
00308 EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...);
00309 
00310 
00315 EXPORT const char *celt_strerror(int error);
00316 
00317 /*  @} */
00318 
00319 
00320 #ifdef __cplusplus
00321 }
00322 #endif
00323 
00324 #endif /*CELT_H */