jamulus/libs/celt/cc6_celt.h

275 lines
11 KiB
C
Executable file

/* (C) 2007-2008 Jean-Marc Valin, CSIRO
(C) 2008 Gregory Maxwell */
/**
@file celt.h
@brief Contains all the functions for encoding and decoding audio
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef cc6_CELT_H
#define cc6_CELT_H
#include "cc6_celt_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__GNUC__) && defined(CELT_BUILD)
#define cc6_EXPORT __attribute__ ((visibility ("default")))
#elif defined(WIN32)
#define cc6_EXPORT __declspec(dllexport)
#else
#define cc6_EXPORT
#endif
#define cc6__celt_check_int(x) (((void)((x) == (cc6_celt_int32_t)0)), (cc6_celt_int32_t)(x))
#define cc6__celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (cc6_CELTMode**)(ptr)))
/* Error codes */
/** No error */
#define cc6_CELT_OK 0
/** An (or more) invalid argument (e.g. out of range) */
#define cc6_CELT_BAD_ARG -1
/** The mode struct passed is invalid */
#define cc6_CELT_INVALID_MODE -2
/** An internal error was detected */
#define cc6_CELT_INTERNAL_ERROR -3
/** The data passed (e.g. compressed data to decoder) is corrupted */
#define cc6_CELT_CORRUPTED_DATA -4
/** Invalid/unsupported request number */
#define cc6_CELT_UNIMPLEMENTED -5
/** An encoder or decoder structure is invalid or already freed */
#define cc6_CELT_INVALID_STATE -6
/* Requests */
#define cc6_CELT_GET_MODE_REQUEST 1
/** Get the cc6_CELTMode used by an encoder or decoder */
#define cc6_CELT_GET_MODE(x) cc6_CELT_GET_MODE_REQUEST, cc6__celt_check_mode_ptr_ptr(x)
#define cc6_CELT_SET_COMPLEXITY_REQUEST 2
/** Controls the complexity from 0-10 (int) */
#define cc6_CELT_SET_COMPLEXITY(x) cc6_CELT_SET_COMPLEXITY_REQUEST, cc6__celt_check_int(x)
#define cc6_CELT_SET_PREDICTION_REQUEST 4
/** Controls the use of interframe prediction.
0=Independent frames
1=Short term interframe prediction allowed
2=Long term prediction allowed
*/
#define cc6_CELT_SET_PREDICTION(x) cc6_CELT_SET_PREDICTION_REQUEST, cc6__celt_check_int(x)
#define cc6_CELT_SET_VBR_RATE_REQUEST 6
/** Set the target VBR rate in bits per second(int); 0=CBR (default) */
#define cc6_CELT_SET_VBR_RATE(x) cc6_CELT_SET_VBR_RATE_REQUEST, cc6__celt_check_int(x)
/** Reset the encoder/decoder memories to zero*/
#define cc6_CELT_RESET_STATE_REQUEST 8
#define cc6_CELT_RESET_STATE cc6_CELT_RESET_STATE_REQUEST
/** GET the frame size used in the current mode */
#define cc6_CELT_GET_FRAME_SIZE 1000
/** GET the lookahead used in the current mode */
#define cc6_CELT_GET_LOOKAHEAD 1001
/** GET the number of channels used in the current mode */
#define cc6_CELT_GET_NB_CHANNELS 1002
/** GET the sample rate used in the current mode */
#define cc6_CELT_GET_SAMPLE_RATE 1003
/** GET the bit-stream version for compatibility check */
#define cc6_CELT_GET_BITSTREAM_VERSION 2000
/** Contains the state of an encoder. One encoder state is needed
for each stream. It is initialised once at the beginning of the
stream. Do *not* re-initialise the state for every frame.
@brief Encoder state
*/
typedef struct cc6_CELTEncoder cc6_CELTEncoder;
/** State of the decoder. One decoder state is needed for each stream.
It is initialised once at the beginning of the stream. Do *not*
re-initialise the state for every frame */
typedef struct cc6_CELTDecoder cc6_CELTDecoder;
/** The mode contains all the information necessary to create an
encoder. Both the encoder and decoder need to be initialised
with exactly the same mode, otherwise the quality will be very
bad */
typedef struct cc6_CELTMode cc6_CELTMode;
/** \defgroup codec Encoding and decoding */
/* @{ */
/* Mode calls */
/** Creates a new mode struct. This will be passed to an encoder or
decoder. The mode MUST NOT BE DESTROYED until the encoders and
decoders that use it are destroyed as well.
@param Fs Sampling rate (32000 to 96000 Hz)
@param channels Number of channels
@param frame_size Number of samples (per channel) to encode in each
packet (even values; 64 - 512)
@param error Returned error code (if NULL, no error will be returned)
@return A newly created mode
*/
cc6_EXPORT cc6_CELTMode *cc6_celt_mode_create(cc6_celt_int32_t Fs, int channels, int frame_size, int *error);
/** Destroys a mode struct. Only call this after all encoders and
decoders using this mode are destroyed as well.
@param mode Mode to be destroyed
*/
cc6_EXPORT void cc6_celt_mode_destroy(cc6_CELTMode *mode);
/** Query information from a mode */
cc6_EXPORT int cc6_celt_mode_info(const cc6_CELTMode *mode, int request, cc6_celt_int32_t *value);
/* Encoder stuff */
/** Creates a new encoder state. Each stream needs its own encoder
state (can't be shared across simultaneous streams).
@param mode Contains all the information about the characteristics of
* the stream (must be the same characteristics as used for the
* decoder)
@return Newly created encoder state.
*/
cc6_EXPORT cc6_CELTEncoder *cc6_celt_encoder_create(const cc6_CELTMode *mode);
/** Destroys a an encoder state.
@param st Encoder state to be destroyed
*/
cc6_EXPORT void cc6_celt_encoder_destroy(cc6_CELTEncoder *st);
/** Encodes a frame of audio.
@param st Encoder state
@param pcm PCM audio in float format, with a normal range of ±1.0.
* Samples with a range beyond ±1.0 are supported but will
* be clipped by decoders using the integer API and should
* only be used if it is known that the far end supports
* extended dynmaic range. There must be exactly
* frame_size samples per channel.
@param optional_synthesis If not NULL, the encoder copies the audio signal that
* the decoder would decode. It is the same as calling the
* decoder on the compressed data, just faster.
* This may alias pcm.
@param compressed The compressed data is written here. This may not alias pcm or
* optional_synthesis.
@param nbCompressedBytes Maximum number of bytes to use for compressing the frame
* (can change from one frame to another)
@return Number of bytes written to "compressed". Will be the same as
* "nbCompressedBytes" unless the stream is VBR and will never be larger.
* If negative, an error has occurred (see error codes). It is IMPORTANT that
* the length returned be somehow transmitted to the decoder. Otherwise, no
* decoding is possible.
*/
cc6_EXPORT int cc6_celt_encode_float(cc6_CELTEncoder *st, const float *pcm, float *optional_synthesis, unsigned char *compressed, int nbCompressedBytes);
/** Encodes a frame of audio.
@param st Encoder state
@param pcm PCM audio in signed 16-bit format (native endian). There must be
* exactly frame_size samples per channel.
@param optional_synthesis If not NULL, the encoder copies the audio signal that
* the decoder would decode. It is the same as calling the
* decoder on the compressed data, just faster.
* This may alias pcm.
@param compressed The compressed data is written here. This may not alias pcm or
* optional_synthesis.
@param nbCompressedBytes Maximum number of bytes to use for compressing the frame
* (can change from one frame to another)
@return Number of bytes written to "compressed". Will be the same as
* "nbCompressedBytes" unless the stream is VBR and will never be larger.
* If negative, an error has occurred (see error codes). It is IMPORTANT that
* the length returned be somehow transmitted to the decoder. Otherwise, no
* decoding is possible.
*/
cc6_EXPORT int cc6_celt_encode(cc6_CELTEncoder *st, const cc6_celt_int16_t *pcm, cc6_celt_int16_t *optional_synthesis, unsigned char *compressed, int nbCompressedBytes);
/** Query and set encoder parameters
@param st Encoder state
@param request Parameter to change or query
@param value Pointer to a 32-bit int value
@return Error code
*/
cc6_EXPORT int cc6_celt_encoder_ctl(cc6_CELTEncoder * st, int request, ...);
/* Decoder stuff */
/** Creates a new decoder state. Each stream needs its own decoder state (can't
be shared across simultaneous streams).
@param mode Contains all the information about the characteristics of the
stream (must be the same characteristics as used for the encoder)
@return Newly created decoder state.
*/
cc6_EXPORT cc6_CELTDecoder *cc6_celt_decoder_create(const cc6_CELTMode *mode);
/** Destroys a a decoder state.
@param st Decoder state to be destroyed
*/
cc6_EXPORT void cc6_celt_decoder_destroy(cc6_CELTDecoder *st);
/** Decodes a frame of audio.
@param st Decoder state
@param data Compressed data produced by an encoder
@param len Number of bytes to read from "data". This MUST be exactly the number
of bytes returned by the encoder. Using a larger value WILL NOT WORK.
@param pcm One frame (frame_size samples per channel) of decoded PCM will be
returned here in float format.
@return Error code.
*/
cc6_EXPORT int cc6_celt_decode_float(cc6_CELTDecoder *st, const unsigned char *data, int len, float *pcm);
/** Decodes a frame of audio.
@param st Decoder state
@param data Compressed data produced by an encoder
@param len Number of bytes to read from "data". This MUST be exactly the number
of bytes returned by the encoder. Using a larger value WILL NOT WORK.
@param pcm One frame (frame_size samples per channel) of decoded PCM will be
returned here in 16-bit PCM format (native endian).
@return Error code.
*/
cc6_EXPORT int cc6_celt_decode(cc6_CELTDecoder *st, const unsigned char *data, int len, cc6_celt_int16_t *pcm);
/** Query and set decoder parameters
@param st Decoder state
@param request Parameter to change or query
@param value Pointer to a 32-bit int value
@return Error code
*/
cc6_EXPORT int cc6_celt_decoder_ctl(cc6_CELTDecoder * st, int request, ...);
/* @} */
#ifdef __cplusplus
}
#endif
#endif /*cc6_CELT_H */