| celt.h | | celt.h | |
| /* (C) 2007-2008 Jean-Marc Valin, CSIRO | | /* (C) 2007-2008 Jean-Marc Valin, CSIRO | |
| (C) 2008 Gregory Maxwell */ | | (C) 2008 Gregory Maxwell */ | |
| /** | | /** | |
| @file celt.h | | @file celt.h | |
|
| @brief Contains all the functions for encoding and decoding audio streams | | @brief Contains all the functions for encoding and decoding audio | |
| */ | | */ | |
| | | | |
| /* | | /* | |
| Redistribution and use in source and binary forms, with or without | | Redistribution and use in source and binary forms, with or without | |
| modification, are permitted provided that the following conditions | | modification, are permitted provided that the following conditions | |
| are met: | | are met: | |
| | | | |
| - Redistributions of source code must retain the above copyright | | - Redistributions of source code must retain the above copyright | |
| notice, this list of conditions and the following disclaimer. | | notice, this list of conditions and the following disclaimer. | |
| | | | |
| | | | |
| skipping to change at line 54 | | skipping to change at line 54 | |
| #endif | | #endif | |
| | | | |
| #if defined(__GNUC__) && defined(CELT_BUILD) | | #if defined(__GNUC__) && defined(CELT_BUILD) | |
| #define EXPORT __attribute__ ((visibility ("default"))) | | #define EXPORT __attribute__ ((visibility ("default"))) | |
| #elif defined(WIN32) | | #elif defined(WIN32) | |
| #define EXPORT __declspec(dllexport) | | #define EXPORT __declspec(dllexport) | |
| #else | | #else | |
| #define EXPORT | | #define EXPORT | |
| #endif | | #endif | |
| | | | |
|
| #define _celt_check_int(x) (((void)((x) == (int)0)), (int)(x)) | | #define _celt_check_int(x) (((void)((x) == (celt_int32_t)0)), (celt_int32_t | |
| | | )(x)) | |
| | | #define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr))) | |
| | | | |
| /* Error codes */ | | /* Error codes */ | |
| /** No error */ | | /** No error */ | |
| #define CELT_OK 0 | | #define CELT_OK 0 | |
| /** An (or more) invalid argument (e.g. out of range) */ | | /** An (or more) invalid argument (e.g. out of range) */ | |
| #define CELT_BAD_ARG -1 | | #define CELT_BAD_ARG -1 | |
| /** The mode struct passed is invalid */ | | /** The mode struct passed is invalid */ | |
| #define CELT_INVALID_MODE -2 | | #define CELT_INVALID_MODE -2 | |
| /** An internal error was detected */ | | /** An internal error was detected */ | |
| #define CELT_INTERNAL_ERROR -3 | | #define CELT_INTERNAL_ERROR -3 | |
| /** The data passed (e.g. compressed data to decoder) is corrupted */ | | /** The data passed (e.g. compressed data to decoder) is corrupted */ | |
| #define CELT_CORRUPTED_DATA -4 | | #define CELT_CORRUPTED_DATA -4 | |
| /** Invalid/unsupported request number */ | | /** Invalid/unsupported request number */ | |
| #define CELT_UNIMPLEMENTED -5 | | #define CELT_UNIMPLEMENTED -5 | |
|
| | | /** An encoder or decoder structure is invalid or already freed */ | |
| | | #define CELT_INVALID_STATE -6 | |
| | | | |
| /* Requests */ | | /* Requests */ | |
|
| | | #define CELT_GET_MODE_REQUEST 1 | |
| | | /** Get the CELTMode used by an encoder or decoder */ | |
| | | #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x) | |
| #define CELT_SET_COMPLEXITY_REQUEST 2 | | #define CELT_SET_COMPLEXITY_REQUEST 2 | |
| /** Controls the complexity from 0-10 (int) */ | | /** Controls the complexity from 0-10 (int) */ | |
| #define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int
(x) | | #define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int
(x) | |
|
| #define CELT_SET_LTP_REQUEST 3 | | #define CELT_SET_PREDICTION_REQUEST 4 | |
| /** Activate or deactivate the use of the long term predictor (PITCH) from | | /** Controls the use of interframe prediction. | |
| 0 or 1 (int) */ | | 0=Independent frames | |
| #define CELT_SET_LTP(x) CELT_SET_LTP_REQUEST, _celt_check_int(x) | | 1=Short term interframe prediction allowed | |
| | | 2=Long term prediction allowed | |
| | | */ | |
| | | #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, _celt_check_int | |
| | | (x) | |
| | | #define CELT_SET_VBR_RATE_REQUEST 6 | |
| | | /** Set the target VBR rate in bits per second(int); 0=CBR (default) */ | |
| | | #define CELT_SET_VBR_RATE(x) CELT_SET_VBR_RATE_REQUEST, _celt_check_int(x) | |
| | | /** Reset the encoder/decoder memories to zero*/ | |
| | | #define CELT_RESET_STATE_REQUEST 8 | |
| | | #define CELT_RESET_STATE CELT_RESET_STATE_REQUEST | |
| | | | |
| /** GET the frame size used in the current mode */ | | /** GET the frame size used in the current mode */ | |
| #define CELT_GET_FRAME_SIZE 1000 | | #define CELT_GET_FRAME_SIZE 1000 | |
| /** GET the lookahead used in the current mode */ | | /** GET the lookahead used in the current mode */ | |
| #define CELT_GET_LOOKAHEAD 1001 | | #define CELT_GET_LOOKAHEAD 1001 | |
| /** GET the number of channels used in the current mode */ | | /** GET the number of channels used in the current mode */ | |
| #define CELT_GET_NB_CHANNELS 1002 | | #define CELT_GET_NB_CHANNELS 1002 | |
|
| | | /** GET the sample rate used in the current mode */ | |
| | | #define CELT_GET_SAMPLE_RATE 1003 | |
| | | | |
| /** GET the bit-stream version for compatibility check */ | | /** GET the bit-stream version for compatibility check */ | |
| #define CELT_GET_BITSTREAM_VERSION 2000 | | #define CELT_GET_BITSTREAM_VERSION 2000 | |
| | | | |
|
| /** Contains the state of an encoder. One encoder state is needed for each | | /** Contains the state of an encoder. One encoder state is needed | |
| stream. It is initialised once at the beginning of the stream. Do *not* | | for each stream. It is initialised once at the beginning of the | |
| re-initialise the state for every frame. | | stream. Do *not* re-initialise the state for every frame. | |
| @brief Encoder state | | @brief Encoder state | |
| */ | | */ | |
| typedef struct CELTEncoder CELTEncoder; | | typedef struct CELTEncoder CELTEncoder; | |
| | | | |
|
| /** State of the decoder. One decoder state is needed for each stream. It i | | /** State of the decoder. One decoder state is needed for each stream. | |
| s | | It is initialised once at the beginning of the stream. Do *not* | |
| initialised once at the beginning of the stream. Do *not* re-initialise | | re-initialise the state for every frame */ | |
| the state for every frame */ | | | |
| typedef struct CELTDecoder CELTDecoder; | | typedef struct CELTDecoder CELTDecoder; | |
| | | | |
|
| /** The mode contains all the information necessary to create an encoder. B | | /** The mode contains all the information necessary to create an | |
| oth | | encoder. Both the encoder and decoder need to be initialised | |
| the encoder and decoder need to be initialised with exactly the same mo | | with exactly the same mode, otherwise the quality will be very | |
| de, | | bad */ | |
| otherwise the quality will be very bad */ | | | |
| typedef struct CELTMode CELTMode; | | typedef struct CELTMode CELTMode; | |
| | | | |
| /** \defgroup codec Encoding and decoding */ | | /** \defgroup codec Encoding and decoding */ | |
| /* @{ */ | | /* @{ */ | |
| | | | |
| /* Mode calls */ | | /* Mode calls */ | |
| | | | |
|
| /** Creates a new mode struct. This will be passed to an encoder or decoder | | /** Creates a new mode struct. This will be passed to an encoder or | |
| . | | decoder. The mode MUST NOT BE DESTROYED until the encoders and | |
| The mode MUST NOT BE DESTROYED until the encoders and decoders that use | | decoders that use it are destroyed as well. | |
| it | | | |
| are destroyed as well. | | | |
| @param Fs Sampling rate (32000 to 96000 Hz) | | @param Fs Sampling rate (32000 to 96000 Hz) | |
| @param channels Number of channels | | @param channels Number of channels | |
|
| @param frame_size Number of samples (per channel) to encode in each packet | | @param frame_size Number of samples (per channel) to encode in each | |
| (even values; 64 - 512) | | packet (even values; 64 - 512) | |
| @param lookahead Extra latency (in samples per channel) in addition to the | | | |
| frame size (between 32 and frame_size). | | | |
| @param error Returned error code (if NULL, no error will be returned) | | @param error Returned error code (if NULL, no error will be returned) | |
| @return A newly created mode | | @return A newly created mode | |
| */ | | */ | |
| EXPORT CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_
size, int *error); | | EXPORT CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_
size, int *error); | |
| | | | |
|
| /** Destroys a mode struct. Only call this after all encoders and decoders | | /** Destroys a mode struct. Only call this after all encoders and | |
| using this mode are destroyed as well. | | decoders using this mode are destroyed as well. | |
| @param mode Mode to be destroyed | | @param mode Mode to be destroyed | |
| */ | | */ | |
| EXPORT void celt_mode_destroy(CELTMode *mode); | | EXPORT void celt_mode_destroy(CELTMode *mode); | |
| | | | |
| /** Query information from a mode */ | | /** Query information from a mode */ | |
| EXPORT int celt_mode_info(const CELTMode *mode, int request, celt_int32_t *
value); | | EXPORT int celt_mode_info(const CELTMode *mode, int request, celt_int32_t *
value); | |
| | | | |
| /* Encoder stuff */ | | /* Encoder stuff */ | |
| | | | |
|
| /** Creates a new encoder state. Each stream needs its own encoder state (c | | /** Creates a new encoder state. Each stream needs its own encoder | |
| an't | | state (can't be shared across simultaneous streams). | |
| be shared across simultaneous streams). | | @param mode Contains all the information about the characteristics of | |
| @param mode Contains all the information about the characteristics of the | | * the stream (must be the same characteristics as used for the | |
| stream | | * decoder) | |
| (must be the same characteristics as used for the decoder) | | | |
| @return Newly created encoder state. | | @return Newly created encoder state. | |
| */ | | */ | |
| EXPORT CELTEncoder *celt_encoder_create(const CELTMode *mode); | | EXPORT CELTEncoder *celt_encoder_create(const CELTMode *mode); | |
| | | | |
| /** Destroys a an encoder state. | | /** Destroys a an encoder state. | |
| @param st Encoder state to be destroyed | | @param st Encoder state to be destroyed | |
| */ | | */ | |
| EXPORT void celt_encoder_destroy(CELTEncoder *st); | | EXPORT void celt_encoder_destroy(CELTEncoder *st); | |
| | | | |
| /** Encodes a frame of audio. | | /** Encodes a frame of audio. | |
| @param st Encoder state | | @param st Encoder state | |
| @param pcm PCM audio in float format, with a normal range of ±1.0. | | @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 clip | | * Samples with a range beyond ±1.0 are supported but will | |
| ped by | | * be clipped by decoders using the integer API and should | |
| * decoders using the integer API and should only be used if it is | | * only be used if it is known that the far end supports | |
| known that | | * extended dynmaic range. There must be exactly | |
| * the far end supports extended dynmaic range. There must be exac | | | |
| tly | | | |
| * frame_size samples per channel. | | * frame_size samples per channel. | |
| @param optional_synthesis If not NULL, the encoder copies the audio signal
that | | @param optional_synthesis If not NULL, the encoder copies the audio signal
that | |
|
| * the decoder would decode. It is the same as call | | * the decoder would decode. It is the same as calling the | |
| ing the | | * decoder on the compressed data, just faster. | |
| * decoder on the compressed data, just faster. | | * This may alias pcm. | |
| * This may alias pcm. | | | |
| @param compressed The compressed data is written here. This may not alias
pcm or | | @param compressed The compressed data is written here. This may not alias
pcm or | |
|
| * optional_synthesis. | | * optional_synthesis. | |
| @param nbCompressedBytes Maximum number of bytes to use for compressing th
e frame | | @param nbCompressedBytes Maximum number of bytes to use for compressing th
e frame | |
|
| * (can change from one frame to another) | | * (can change from one frame to another) | |
| @return Number of bytes written to "compressed". Will be the same as | | @return Number of bytes written to "compressed". Will be the same as | |
| * "nbCompressedBytes" unless the stream is VBR and will never be lar
ger. | | * "nbCompressedBytes" unless the stream is VBR and will never be lar
ger. | |
| * If negative, an error has occurred (see error codes). It is IMPORT
ANT that | | * If negative, an error has occurred (see error codes). It is IMPORT
ANT that | |
| * the length returned be somehow transmitted to the decoder. Otherwi
se, no | | * the length returned be somehow transmitted to the decoder. Otherwi
se, no | |
| * decoding is possible. | | * decoding is possible. | |
| */ | | */ | |
| EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, float *opti
onal_synthesis, unsigned char *compressed, int nbCompressedBytes); | | EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, float *opti
onal_synthesis, unsigned char *compressed, int nbCompressedBytes); | |
| | | | |
| /** Encodes a frame of audio. | | /** Encodes a frame of audio. | |
| @param st Encoder state | | @param st Encoder state | |
| | | | |
| skipping to change at line 221 | | skipping to change at line 242 | |
| | | | |
| /** Decodes a frame of audio. | | /** Decodes a frame of audio. | |
| @param st Decoder state | | @param st Decoder state | |
| @param data Compressed data produced by an encoder | | @param data Compressed data produced by an encoder | |
| @param len Number of bytes to read from "data". This MUST be exactly the n
umber | | @param len Number of bytes to read from "data". This MUST be exactly the n
umber | |
| of bytes returned by the encoder. Using a larger value WILL NOT
WORK. | | 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 | | @param pcm One frame (frame_size samples per channel) of decoded PCM will
be | |
| returned here in float format. | | returned here in float format. | |
| @return Error code. | | @return Error code. | |
| */ | | */ | |
|
| EXPORT int celt_decode_float(CELTDecoder *st, unsigned char *data, int len,
float *pcm); | | EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, in
t len, float *pcm); | |
| | | | |
| /** Decodes a frame of audio. | | /** Decodes a frame of audio. | |
| @param st Decoder state | | @param st Decoder state | |
| @param data Compressed data produced by an encoder | | @param data Compressed data produced by an encoder | |
| @param len Number of bytes to read from "data". This MUST be exactly the n
umber | | @param len Number of bytes to read from "data". This MUST be exactly the n
umber | |
| of bytes returned by the encoder. Using a larger value WILL NOT
WORK. | | 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 | | @param pcm One frame (frame_size samples per channel) of decoded PCM will
be | |
| returned here in 16-bit PCM format (native endian). | | returned here in 16-bit PCM format (native endian). | |
| @return Error code. | | @return Error code. | |
| */ | | */ | |
|
| EXPORT int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_ | | EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, | |
| int16_t *pcm); | | 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 | |
| | | */ | |
| | | EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...); | |
| | | | |
| /* @} */ | | /* @} */ | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| #endif /*CELT_H */ | | #endif /*CELT_H */ | |
| | | | |
End of changes. 19 change blocks. |
| 50 lines changed or deleted | | 67 lines changed or added | |
|