Blame libcelt/celt.h

Packit 664db3
/* (C) 2007-2008 Jean-Marc Valin, CSIRO
Packit 664db3
*/
Packit 664db3
/**
Packit 664db3
  @file celt.h
Packit 664db3
  @brief Contains all the functions for encoding and decoding audio streams
Packit 664db3
 */
Packit 664db3
Packit 664db3
/*
Packit 664db3
   Redistribution and use in source and binary forms, with or without
Packit 664db3
   modification, are permitted provided that the following conditions
Packit 664db3
   are met:
Packit 664db3
   
Packit 664db3
   - Redistributions of source code must retain the above copyright
Packit 664db3
   notice, this list of conditions and the following disclaimer.
Packit 664db3
   
Packit 664db3
   - Redistributions in binary form must reproduce the above copyright
Packit 664db3
   notice, this list of conditions and the following disclaimer in the
Packit 664db3
   documentation and/or other materials provided with the distribution.
Packit 664db3
   
Packit 664db3
   - Neither the name of the Xiph.org Foundation nor the names of its
Packit 664db3
   contributors may be used to endorse or promote products derived from
Packit 664db3
   this software without specific prior written permission.
Packit 664db3
   
Packit 664db3
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 664db3
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 664db3
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 664db3
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
Packit 664db3
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit 664db3
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit 664db3
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit 664db3
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit 664db3
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit 664db3
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit 664db3
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 664db3
*/
Packit 664db3
Packit 664db3
#ifndef CELT051_H
Packit 664db3
#define CELT051_H
Packit 664db3
Packit 664db3
#include "celt_types.h"
Packit 664db3
Packit 664db3
#ifdef __cplusplus
Packit 664db3
extern "C" {
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#ifndef CELT_H
Packit 664db3
#define CELT_H
Packit 664db3
Packit 664db3
#if defined(__GNUC__) && defined(CELT_BUILD)
Packit 664db3
#define EXPORT __attribute__ ((visibility ("default")))
Packit 664db3
#elif defined(WIN32)
Packit 664db3
#define EXPORT __declspec(dllexport)
Packit 664db3
#else
Packit 664db3
#define EXPORT
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#define _celt_check_int(x) (((void)((x) == (int)0)), (int)(x))
Packit 664db3
Packit 664db3
/* Error codes */
Packit 664db3
/** No error */
Packit 664db3
#define CELT_OK                0
Packit 664db3
/** An (or more) invalid argument (e.g. out of range) */
Packit 664db3
#define CELT_BAD_ARG          -1
Packit 664db3
/** The mode struct passed is invalid */
Packit 664db3
#define CELT_INVALID_MODE     -2
Packit 664db3
/** An internal error was detected */
Packit 664db3
#define CELT_INTERNAL_ERROR   -3
Packit 664db3
/** The data passed (e.g. compressed data to decoder) is corrupted */
Packit 664db3
#define CELT_CORRUPTED_DATA   -4
Packit 664db3
/** Invalid/unsupported request number */
Packit 664db3
#define CELT_UNIMPLEMENTED    -5
Packit 664db3
Packit 664db3
/* Requests */
Packit 664db3
#define CELT_SET_COMPLEXITY_REQUEST    2
Packit 664db3
/** Controls the complexity from 0-10 (int) */
Packit 664db3
#define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)
Packit 664db3
#define CELT_SET_LTP_REQUEST    3
Packit 664db3
/** Activate or deactivate the use of the long term predictor (PITCH) from 0 or 1 (int) */
Packit 664db3
#define CELT_SET_LTP(x) CELT_SET_LTP_REQUEST, _celt_check_int(x)
Packit 664db3
Packit 664db3
/** GET the frame size used in the current mode */
Packit 664db3
#define CELT_GET_FRAME_SIZE   1000
Packit 664db3
/** GET the lookahead used in the current mode */
Packit 664db3
#define CELT_GET_LOOKAHEAD    1001
Packit 664db3
/** GET the number of channels used in the current mode */
Packit 664db3
#define CELT_GET_NB_CHANNELS  1002
Packit 664db3
Packit 664db3
/** GET the bit-stream version for compatibility check */
Packit 664db3
#define CELT_GET_BITSTREAM_VERSION 2000
Packit 664db3
Packit 664db3
Packit 664db3
/** Contains the state of an encoder. One encoder state is needed for each 
Packit 664db3
    stream. It is initialised once at the beginning of the stream. Do *not*
Packit 664db3
    re-initialise the state for every frame.
Packit 664db3
   @brief Encoder state
Packit 664db3
 */
Packit 664db3
typedef struct CELTEncoder CELTEncoder;
Packit 664db3
Packit 664db3
/** State of the decoder. One decoder state is needed for each stream. It is
Packit 664db3
    initialised once at the beginning of the stream. Do *not* re-initialise
Packit 664db3
    the state for every frame */
Packit 664db3
typedef struct CELTDecoder CELTDecoder;
Packit 664db3
Packit 664db3
/** The mode contains all the information necessary to create an encoder. Both
Packit 664db3
    the encoder and decoder need to be initialised with exactly the same mode,
Packit 664db3
    otherwise the quality will be very bad */
Packit 664db3
typedef struct CELTMode CELTMode;
Packit 664db3
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** \defgroup codec Encoding and decoding */
Packit 664db3
/*  @{ */
Packit 664db3
Packit 664db3
/* Mode calls */
Packit 664db3
Packit 664db3
/** Creates a new mode struct. This will be passed to an encoder or decoder.
Packit 664db3
    The mode MUST NOT BE DESTROYED until the encoders and decoders that use it
Packit 664db3
    are destroyed as well.
Packit 664db3
 @param Fs Sampling rate (32000 to 96000 Hz)
Packit 664db3
 @param channels Number of channels
Packit 664db3
 @param frame_size Number of samples (per channel) to encode in each packet (64 - 256)
Packit 664db3
 @param lookahead Extra latency (in samples per channel) in addition to the frame size (between 32 and frame_size). The larger that value, the better the quality (at the expense of latency)
Packit 664db3
 @param error Returned error code (if NULL, no error will be returned)
Packit 664db3
 @return A newly created mode
Packit 664db3
*/
Packit 664db3
EXPORT CELTMode *celt051_mode_create(celt_int32_t Fs, int channels, int frame_size, int *error);
Packit 664db3
Packit 664db3
/** Destroys a mode struct. Only call this after all encoders and decoders
Packit 664db3
    using this mode are destroyed as well.
Packit 664db3
 @param mode Mode to be destroyed
Packit 664db3
*/
Packit 664db3
EXPORT void celt051_mode_destroy(CELTMode *mode);
Packit 664db3
Packit 664db3
/** Query information from a mode */
Packit 664db3
EXPORT int celt051_mode_info(const CELTMode *mode, int request, celt_int32_t *value);
Packit 664db3
Packit 664db3
/* Encoder stuff */
Packit 664db3
Packit 664db3
Packit 664db3
/** Creates a new encoder state. Each stream needs its own encoder state (can't
Packit 664db3
    be shared across simultaneous streams).
Packit 664db3
 @param mode Contains all the information about the characteristics of the stream
Packit 664db3
             (must be the same characteristics as used for the decoder)
Packit 664db3
 @return Newly created encoder state.
Packit 664db3
*/
Packit 664db3
EXPORT CELTEncoder *celt051_encoder_create(const CELTMode *mode);
Packit 664db3
Packit 664db3
/** Destroys a an encoder state.
Packit 664db3
 @param st Encoder state to be destroyed
Packit 664db3
 */
Packit 664db3
EXPORT void celt051_encoder_destroy(CELTEncoder *st);
Packit 664db3
Packit 664db3
/** Encodes a frame of audio.
Packit 664db3
 @param st Encoder state
Packit 664db3
 @param pcm PCM audio in signed float format. There must be 
Packit 664db3
 *          exactly frame_size samples per channel. The input data is 
Packit 664db3
 *          overwritten by a copy of what the remote decoder would decode.
Packit 664db3
 @param optional_synthesis If not NULL, the encoder copies the audio signal that
Packit 664db3
 *                         the decoder would decode. It is the same as calling the
Packit 664db3
 *                         decoder on the compressed data, just faster.
Packit 664db3
 @param compressed The compressed data is written here
Packit 664db3
 @param nbCompressedBytes Number of bytes to use for compressing the frame
Packit 664db3
 *                        (can change from one frame to another)
Packit 664db3
 @return Number of bytes written to "compressed". Should be the same as 
Packit 664db3
 *       "nbCompressedBytes" unless the stream is VBR. If negative, an error
Packit 664db3
 *       has occured (see error codes). It is IMPORTANT that the length returned
Packit 664db3
 *       be somehow transmitted to the decoder. Otherwise, no decoding is possible.
Packit 664db3
*/
Packit 664db3
EXPORT int celt051_encode_float(CELTEncoder *st, const float *pcm, float *optional_synthesis, unsigned char *compressed, int nbCompressedBytes);
Packit 664db3
/** Encodes a frame of audio.
Packit 664db3
 @param st Encoder state
Packit 664db3
 @param pcm PCM audio in signed 16-bit format (native endian). There must be 
Packit 664db3
 *          exactly frame_size samples per channel. The input data is 
Packit 664db3
 *          overwritten by a copy of what the remote decoder would decode.
Packit 664db3
 @param optional_synthesis If not NULL, the encoder copies the audio signal that
Packit 664db3
 *                         the decoder would decode. It is the same as calling the
Packit 664db3
 *                         decoder on the compressed data, just faster.
Packit 664db3
 @param compressed The compressed data is written here
Packit 664db3
 @param nbCompressedBytes Number of bytes to use for compressing the frame
Packit 664db3
 *                        (can change from one frame to another)
Packit 664db3
 @return Number of bytes written to "compressed". Should be the same as 
Packit 664db3
 *       "nbCompressedBytes" unless the stream is VBR. If negative, an error
Packit 664db3
 *       has occured (see error codes). It is IMPORTANT that the length returned
Packit 664db3
 *       be somehow transmitted to the decoder. Otherwise, no decoding is possible.
Packit 664db3
 */
Packit 664db3
EXPORT int celt051_encode(CELTEncoder *st, const celt_int16_t *pcm, celt_int16_t *optional_synthesis, unsigned char *compressed, int nbCompressedBytes);
Packit 664db3
Packit 664db3
/** Query and set encoder parameters 
Packit 664db3
 @param st Encoder state
Packit 664db3
 @param request Parameter to change or query
Packit 664db3
 @param value Pointer to a 32-bit int value
Packit 664db3
 @return Error code
Packit 664db3
*/
Packit 664db3
EXPORT int celt051_encoder_ctl(CELTEncoder * st, int request, ...);
Packit 664db3
Packit 664db3
/* Decoder stuff */
Packit 664db3
Packit 664db3
Packit 664db3
/** Creates a new decoder state. Each stream needs its own decoder state (can't
Packit 664db3
    be shared across simultaneous streams).
Packit 664db3
 @param mode Contains all the information about the characteristics of the
Packit 664db3
             stream (must be the same characteristics as used for the encoder)
Packit 664db3
 @return Newly created decoder state.
Packit 664db3
 */
Packit 664db3
EXPORT CELTDecoder *celt051_decoder_create(const CELTMode *mode);
Packit 664db3
Packit 664db3
/** Destroys a a decoder state.
Packit 664db3
 @param st Decoder state to be destroyed
Packit 664db3
 */
Packit 664db3
EXPORT void celt051_decoder_destroy(CELTDecoder *st);
Packit 664db3
Packit 664db3
/** Decodes a frame of audio.
Packit 664db3
 @param st Decoder state
Packit 664db3
 @param data Compressed data produced by an encoder
Packit 664db3
 @param len Number of bytes to read from "data". This MUST be exactly the number
Packit 664db3
            of bytes returned by the encoder. Using a larger value WILL NOT WORK.
Packit 664db3
 @param pcm One frame (frame_size samples per channel) of decoded PCM will be
Packit 664db3
            returned here in float format. 
Packit 664db3
 @return Error code.
Packit 664db3
   */
Packit 664db3
EXPORT int celt051_decode_float(CELTDecoder *st, unsigned char *data, int len, float *pcm);
Packit 664db3
/** Decodes a frame of audio.
Packit 664db3
 @param st Decoder state
Packit 664db3
 @param data Compressed data produced by an encoder
Packit 664db3
 @param len Number of bytes to read from "data". This MUST be exactly the number
Packit 664db3
            of bytes returned by the encoder. Using a larger value WILL NOT WORK.
Packit 664db3
 @param pcm One frame (frame_size samples per channel) of decoded PCM will be
Packit 664db3
            returned here in 16-bit PCM format (native endian). 
Packit 664db3
 @return Error code.
Packit 664db3
 */
Packit 664db3
EXPORT int celt051_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm);
Packit 664db3
Packit 664db3
/*  @} */
Packit 664db3
Packit 664db3
Packit 664db3
#ifdef __cplusplus
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#endif /*CELT051_H */