speex.h | speex.h | |||
---|---|---|---|---|
/* Copyright (C) 2002 Jean-Marc Valin | /* Copyright (C) 2002 Jean-Marc Valin*/ | |||
File: modes.h | /** | |||
@file speex.h | ||||
@brief Describes the different modes of the codec | ||||
*/ | ||||
/* | ||||
Redistribution and use in source and binary forms, with or without | ||||
modification, are permitted provided that the following conditions | ||||
are met: | ||||
Describes the different modes of the codec | - Redistributions of source code must retain the above copyright | |||
notice, this list of conditions and the following disclaimer. | ||||
This library is free software; you can redistribute it and/or | - Redistributions in binary form must reproduce the above copyright | |||
modify it under the terms of the GNU Lesser General Public | notice, this list of conditions and the following disclaimer in the | |||
License as published by the Free Software Foundation; either | documentation and/or other materials provided with the distribution. | |||
version 2.1 of the License, or (at your option) any later version. | ||||
This library is distributed in the hope that it will be useful, | - Neither the name of the Xiph.org Foundation nor the names of its | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | contributors may be used to endorse or promote products derived from | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | this software without specific prior written permission. | |||
Lesser General Public License for more details. | ||||
You should have received a copy of the GNU Lesser General Public | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |||
License along with this library; if not, write to the Free Software | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |||
A | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION O | |||
R | ||||
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 SPEEX_H | #ifndef SPEEX_H | |||
#define SPEEX_H | #define SPEEX_H | |||
#include "speex_bits.h" | #include "speex_bits.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
/* Values allowed for *ctl() requests */ | /* Values allowed for *ctl() requests */ | |||
/** Set enhancement on/off (decoder only) */ | ||||
#define SPEEX_SET_ENH 0 | #define SPEEX_SET_ENH 0 | |||
/** Get enhancement state (decoder only) */ | ||||
#define SPEEX_GET_ENH 1 | #define SPEEX_GET_ENH 1 | |||
/*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/ | /*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/ | |||
/** Obtain frame size used by encoder/decoder */ | ||||
#define SPEEX_GET_FRAME_SIZE 3 | #define SPEEX_GET_FRAME_SIZE 3 | |||
/** Set quality value */ | ||||
#define SPEEX_SET_QUALITY 4 | #define SPEEX_SET_QUALITY 4 | |||
/** Get current quality setting */ | ||||
#define SPEEX_GET_QUALITY 5 | #define SPEEX_GET_QUALITY 5 | |||
/** Set sub-mode to use */ | ||||
#define SPEEX_SET_MODE 6 | #define SPEEX_SET_MODE 6 | |||
/** Get current sub-mode in use */ | ||||
#define SPEEX_GET_MODE 7 | #define SPEEX_GET_MODE 7 | |||
/** Set low-band sub-mode to use (wideband only)*/ | ||||
#define SPEEX_SET_LOW_MODE 8 | #define SPEEX_SET_LOW_MODE 8 | |||
/** Get current low-band mode in use (wideband only)*/ | ||||
#define SPEEX_GET_LOW_MODE 9 | #define SPEEX_GET_LOW_MODE 9 | |||
/** Set high-band sub-mode to use (wideband only)*/ | ||||
#define SPEEX_SET_HIGH_MODE 10 | #define SPEEX_SET_HIGH_MODE 10 | |||
/** Get current high-band mode in use (wideband only)*/ | ||||
#define SPEEX_GET_HIGH_MODE 11 | #define SPEEX_GET_HIGH_MODE 11 | |||
/** Set VBR on (1) or off (0) */ | ||||
#define SPEEX_SET_VBR 12 | #define SPEEX_SET_VBR 12 | |||
/** Get VBR status (1 for on, 0 for off) */ | ||||
#define SPEEX_GET_VBR 13 | #define SPEEX_GET_VBR 13 | |||
/** Set quality value for VBR encoding (0-10) */ | ||||
#define SPEEX_SET_VBR_QUALITY 14 | #define SPEEX_SET_VBR_QUALITY 14 | |||
/** Get current quality value for VBR encoding (0-10) */ | ||||
#define SPEEX_GET_VBR_QUALITY 15 | #define SPEEX_GET_VBR_QUALITY 15 | |||
/** Set complexity of the encoder (0-10) */ | ||||
#define SPEEX_SET_COMPLEXITY 16 | #define SPEEX_SET_COMPLEXITY 16 | |||
/** Get current complexity of the encoder (0-10) */ | ||||
#define SPEEX_GET_COMPLEXITY 17 | #define SPEEX_GET_COMPLEXITY 17 | |||
/*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/ | ||||
/** Set bit-rate used by the encoder (or lower) */ | ||||
#define SPEEX_SET_BITRATE 18 | ||||
/** Get current bit-rate used by the encoder or decoder */ | ||||
#define SPEEX_GET_BITRATE 19 | #define SPEEX_GET_BITRATE 19 | |||
/**Define a handler function for in-band Speex request*/ | ||||
#define SPEEX_SET_HANDLER 20 | ||||
/**Define a handler function for in-band user-defined request*/ | ||||
#define SPEEX_SET_USER_HANDLER 22 | ||||
/** Set sampling rate used in bit-rate computation */ | ||||
#define SPEEX_SET_SAMPLING_RATE 24 | ||||
/** Get sampling rate used in bit-rate computation */ | ||||
#define SPEEX_GET_SAMPLING_RATE 25 | ||||
/** Reset the encoder/decoder memories to zero*/ | ||||
#define SPEEX_RESET_STATE 26 | ||||
/** Get VBR info (mostly used internally) */ | ||||
#define SPEEX_GET_RELATIVE_QUALITY 29 | ||||
/** Set VAD status (1 for on, 0 for off) */ | ||||
#define SPEEX_SET_VAD 30 | ||||
/** Get VAD status (1 for on, 0 for off) */ | ||||
#define SPEEX_GET_VAD 31 | ||||
/** Set Average Bit-Rate (ABR) to n bits per seconds */ | ||||
#define SPEEX_SET_ABR 32 | ||||
/** Get Average Bit-Rate (ABR) setting (in bps) */ | ||||
#define SPEEX_GET_ABR 33 | ||||
/** Set DTX status (1 for on, 0 for off) */ | ||||
#define SPEEX_SET_DTX 34 | ||||
/** Get DTX status (1 for on, 0 for off) */ | ||||
#define SPEEX_GET_DTX 35 | ||||
/* Used internally, not to be used in applications */ | ||||
/** Used internally*/ | ||||
#define SPEEX_GET_PI_GAIN 100 | ||||
/** Used internally*/ | ||||
#define SPEEX_GET_EXC 101 | ||||
/** Used internally*/ | ||||
#define SPEEX_GET_INNOV 102 | ||||
/** Used internally*/ | ||||
#define SPEEX_GET_DTX_STATUS 103 | ||||
/* Preserving compatibility:*/ | /* Preserving compatibility:*/ | |||
/** Equivalent to SPEEX_SET_ENH */ | ||||
#define SPEEX_SET_PF 0 | #define SPEEX_SET_PF 0 | |||
/** Equivalent to SPEEX_GET_ENH */ | ||||
#define SPEEX_GET_PF 1 | #define SPEEX_GET_PF 1 | |||
/* Values allowed for mode queries */ | /* Values allowed for mode queries */ | |||
/** Query the frame size of a mode */ | ||||
#define SPEEX_MODE_FRAME_SIZE 0 | #define SPEEX_MODE_FRAME_SIZE 0 | |||
/** Query the size of an encoded frame for a particular sub-mode */ | ||||
#define SPEEX_SUBMODE_BITS_PER_FRAME 1 | #define SPEEX_SUBMODE_BITS_PER_FRAME 1 | |||
#define SPEEX_NB_MODES 2 | /** Number of defined modes in Speex */ | |||
#define SPEEX_NB_MODES 3 | ||||
struct SpeexMode; | struct SpeexMode; | |||
/* Prototypes for mode function pointers */ | /* Prototypes for mode function pointers */ | |||
/** Encoder state initialization function */ | ||||
typedef void *(*encoder_init_func)(struct SpeexMode *mode); | typedef void *(*encoder_init_func)(struct SpeexMode *mode); | |||
/** Encoder state destruction function */ | ||||
typedef void (*encoder_destroy_func)(void *st); | typedef void (*encoder_destroy_func)(void *st); | |||
typedef void (*encode_func)(void *state, float *in, SpeexBits *bits); | ||||
/** Main encoding function */ | ||||
typedef int (*encode_func)(void *state, float *in, SpeexBits *bits); | ||||
/** Function for controlling the encoder options */ | ||||
typedef int (*encoder_ctl_func)(void *state, int request, void *ptr); | ||||
/** Decoder state initialization function */ | ||||
typedef void *(*decoder_init_func)(struct SpeexMode *mode); | typedef void *(*decoder_init_func)(struct SpeexMode *mode); | |||
/** Decoder state destruction function */ | ||||
typedef void (*decoder_destroy_func)(void *st); | typedef void (*decoder_destroy_func)(void *st); | |||
/** Main decoding function */ | ||||
typedef int (*decode_func)(void *state, SpeexBits *bits, float *out); | typedef int (*decode_func)(void *state, SpeexBits *bits, float *out); | |||
typedef void (*encoder_ctl_func)(void *state, int request, void *ptr); | ||||
typedef void (*decoder_ctl_func)(void *state, int request, void *ptr); | ||||
typedef void (*mode_query_func)(void *mode, int request, void *ptr); | /** Function for controlling the decoder options */ | |||
typedef int (*decoder_ctl_func)(void *state, int request, void *ptr); | ||||
/** Query function for a mode */ | ||||
typedef int (*mode_query_func)(void *mode, int request, void *ptr); | ||||
/** Struct defining a Speex mode */ | /** Struct defining a Speex mode */ | |||
typedef struct SpeexMode { | typedef struct SpeexMode { | |||
/** Pointer to the low-level mode data */ | /** Pointer to the low-level mode data */ | |||
void *mode; | void *mode; | |||
/** Pointer to the mode query function */ | /** Pointer to the mode query function */ | |||
mode_query_func query; | mode_query_func query; | |||
/** The name of the mode (you should not rely on this to identify the mo de)*/ | /** The name of the mode (you should not rely on this to identify the mo de)*/ | |||
skipping to change at line 121 | skipping to change at line 230 | |||
decode_func dec; | decode_func dec; | |||
/** ioctl-like requests for encoder */ | /** ioctl-like requests for encoder */ | |||
encoder_ctl_func enc_ctl; | encoder_ctl_func enc_ctl; | |||
/** ioctl-like requests for decoder */ | /** ioctl-like requests for decoder */ | |||
decoder_ctl_func dec_ctl; | decoder_ctl_func dec_ctl; | |||
} SpeexMode; | } SpeexMode; | |||
/**Returns a handle to a newly created Speex encoder state structure. For n | /** | |||
ow, the | * Returns a handle to a newly created Speex encoder state structure. For n | |||
"mode" arguent can be &nb_mode or &wb_mode . In the future, more modes m | ow, | |||
ay be | * the "mode" argument can be &nb_mode or &wb_mode . In the future, more mo | |||
added. Note that for now if you have more than one channels to encode, y | des | |||
ou need | * may be added. Note that for now if you have more than one channels to | |||
one state per channel.*/ | * encode, you need one state per channel. | |||
* | ||||
* @param mode The mode to use (either speex_nb_mode or speex_wb.mode) | ||||
* @return A newly created encoder | ||||
*/ | ||||
void *speex_encoder_init(SpeexMode *mode); | void *speex_encoder_init(SpeexMode *mode); | |||
/** Frees all resources associated to an existing Speex encoder state. */ | /** Frees all resources associated to an existing Speex encoder state. | |||
* @param state Encoder state to be destroyed */ | ||||
void speex_encoder_destroy(void *state); | void speex_encoder_destroy(void *state); | |||
/** Uses an existing encoder state to encode one frame of speech pointed to by | /** Uses an existing encoder state to encode one frame of speech pointed to by | |||
"in". The encoded bit-stream is saved in "bits".*/ | "in". The encoded bit-stream is saved in "bits". | |||
void speex_encode(void *state, float *in, SpeexBits *bits); | @param state Encoder state | |||
@param in Frame that will be encoded with a +-2^16 range | ||||
@param bits Bit-stream where the data will be written | ||||
*/ | ||||
int speex_encode(void *state, float *in, SpeexBits *bits); | ||||
/** Used like the ioctl function to control the encoder parameters */ | /** Used like the ioctl function to control the encoder parameters | |||
void speex_encoder_ctl(void *state, int request, void *ptr); | * | |||
* @param state Encoder state | ||||
* @param request ioctl-type request (one of the SPEEX_* macros) | ||||
* @param ptr Data exchanged to-from function | ||||
* @return 0 if frame needs not be transmitted (DTX only), 1 otherwise | ||||
*/ | ||||
int speex_encoder_ctl(void *state, int request, void *ptr); | ||||
/** Returns a handle to a newly created decoder state structure. For now, t | /** Returns a handle to a newly created decoder state structure. For now, | |||
he mode | * the mode argument can be &nb_mode or &wb_mode . In the future, more mode | |||
arguent can be &nb_mode or &wb_mode . In the future, more modes may be | s | |||
added. | * may be added. Note that for now if you have more than one channels to | |||
Note that for now if you have more than one channels to decode, you nee | * decode, you need one state per channel. | |||
d one | * | |||
state per channel. */ | * @param mode Speex mode (one of speex_nb_mode or speex_wb_mode) | |||
* @return A newly created decoder state | ||||
*/ | ||||
void *speex_decoder_init(SpeexMode *mode); | void *speex_decoder_init(SpeexMode *mode); | |||
/** Frees all resources associated to an existing decoder state. */ | /** Frees all resources associated to an existing decoder state. | |||
* | ||||
* @param state State to be destroyed | ||||
*/ | ||||
void speex_decoder_destroy(void *state); | void speex_decoder_destroy(void *state); | |||
/** Uses an existing decoder state to decode one frame of speech from bit-s | /** Uses an existing decoder state to decode one frame of speech from | |||
tream | * bit-stream bits. The output speech is saved written to out. | |||
bits. The output speech is saved written to out. */ | * | |||
* @param state Decoder state | ||||
* @param bits Bit-stream from which to decode the frame (NULL if the packe | ||||
t was lost) | ||||
* @param out Where to write the decoded frame | ||||
* @return return status (0 for no error, -1 for end of stream, -2 other) | ||||
*/ | ||||
int speex_decode(void *state, SpeexBits *bits, float *out); | int speex_decode(void *state, SpeexBits *bits, float *out); | |||
/** Used like the ioctl function to control the encoder parameters */ | /** Used like the ioctl function to control the encoder parameters | |||
void speex_decoder_ctl(void *state, int request, void *ptr); | * | |||
* @param state Decoder state | ||||
* @param request ioctl-type request (one of the SPEEX_* macros) | ||||
* @param ptr Data exchanged to-from function | ||||
* @return 0 for no error, 1 if a terminator is reached, 2 for another erro | ||||
r | ||||
*/ | ||||
int speex_decoder_ctl(void *state, int request, void *ptr); | ||||
/** Query function for mode information */ | /** Query function for mode information | |||
void speex_mode_query(SpeexMode *mode, int request, void *ptr); | * | |||
* @param mode Speex mode | ||||
* @param request ioctl-type request (one of the SPEEX_* macros) | ||||
* @param ptr Data exchanged to-from function | ||||
*/ | ||||
int speex_mode_query(SpeexMode *mode, int request, void *ptr); | ||||
/** Default narrowband mode */ | /** Default narrowband mode */ | |||
extern SpeexMode speex_nb_mode; | extern SpeexMode speex_nb_mode; | |||
/** Default wideband mode */ | /** Default wideband mode */ | |||
extern SpeexMode speex_wb_mode; | extern SpeexMode speex_wb_mode; | |||
/** List of all modes availavle */ | /** Default "ultra-wideband" mode */ | |||
extern SpeexMode speex_uwb_mode; | ||||
/** List of all modes available */ | ||||
extern SpeexMode *speex_mode_list[SPEEX_NB_MODES]; | extern SpeexMode *speex_mode_list[SPEEX_NB_MODES]; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 47 change blocks. | ||||
49 lines changed or deleted | 199 lines changed or added | |||
speex_bits.h | speex_bits.h | |||
---|---|---|---|---|
/* Copyright (C) 2002 Jean-Marc Valin | /* Copyright (C) 2002 Jean-Marc Valin */ | |||
File: speex_bits.h | /** | |||
@file speex_bits.h | ||||
@brief Handles bit packing/unpacking | ||||
*/ | ||||
/* | ||||
Redistribution and use in source and binary forms, with or without | ||||
modification, are permitted provided that the following conditions | ||||
are met: | ||||
Handles bit packing/unpacking | - Redistributions of source code must retain the above copyright | |||
notice, this list of conditions and the following disclaimer. | ||||
This library is free software; you can redistribute it and/or | - Redistributions in binary form must reproduce the above copyright | |||
modify it under the terms of the GNU Lesser General Public | notice, this list of conditions and the following disclaimer in the | |||
License as published by the Free Software Foundation; either | documentation and/or other materials provided with the distribution. | |||
version 2.1 of the License, or (at your option) any later version. | ||||
This library is distributed in the hope that it will be useful, | - Neither the name of the Xiph.org Foundation nor the names of its | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | contributors may be used to endorse or promote products derived from | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | this software without specific prior written permission. | |||
Lesser General Public License for more details. | ||||
You should have received a copy of the GNU Lesser General Public | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |||
License along with this library; if not, write to the Free Software | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |||
A | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION O | |||
R | ||||
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 BITS_H | #ifndef BITS_H | |||
#define BITS_H | #define BITS_H | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
#define MAX_BYTES_PER_FRAME 1000 | /** Maximum size of the bit-stream (for fixed-size allocation) */ | |||
#define MAX_BYTES_PER_FRAME 2000 | ||||
/** Bit-packing data structure representing (part of) a bit-stream. */ | /** Bit-packing data structure representing (part of) a bit-stream. */ | |||
typedef struct SpeexBits { | typedef struct SpeexBits { | |||
char *bytes; | char *bytes; /**< "raw" data */ | |||
int nbBits; | int nbBits; /**< Total number of bits stored in the stream*/ | |||
int bytePtr; | int bytePtr; /**< Position of the byte "cursor" */ | |||
int bitPtr; | int bitPtr; /**< Position of the bit "cursor" within the current byte | |||
int owner; | */ | |||
int owner; /**< Does the struct "own" the "raw" buffer (member "byte | ||||
s") */ | ||||
int overflow;/**< Set to one if we try to read past the valid data */ | ||||
int buf_size;/**< Allocated size for buffer */ | ||||
int reserved1; /**< Reserved for future use */ | ||||
void *reserved2; /**< Reserved for future use */ | ||||
} SpeexBits; | } SpeexBits; | |||
/** Initializes and allocates resources for a SpeexBits struct */ | /** Initializes and allocates resources for a SpeexBits struct */ | |||
void speex_bits_init(SpeexBits *bits); | void speex_bits_init(SpeexBits *bits); | |||
/** Initializes SpeexBits struct using a pre-allocated buffer*/ | /** Initializes SpeexBits struct using a pre-allocated buffer*/ | |||
void speex_bits_init_buffer(SpeexBits *bits, void *buff); | void speex_bits_init_buffer(SpeexBits *bits, void *buff, int buf_size); | |||
/** Frees all resources assiociated to a SpeexBits struct. Right now this d oes nothing since no resources are allocated, but this could change in the future.*/ | /** Frees all resources associated to a SpeexBits struct. Right now this do es nothing since no resources are allocated, but this could change in the f uture.*/ | |||
void speex_bits_destroy(SpeexBits *bits); | void speex_bits_destroy(SpeexBits *bits); | |||
/** Resets bits to initial value (just after initialization, erasing conten t)*/ | /** Resets bits to initial value (just after initialization, erasing conten t)*/ | |||
void speex_bits_reset(SpeexBits *bits); | void speex_bits_reset(SpeexBits *bits); | |||
/** Rewind the bit-stream to beginning (ready for read) without erasing con tent*/ | /** Rewind the bit-stream to the beginning (ready for read) without erasing the content */ | |||
void speex_bits_rewind(SpeexBits *bits); | void speex_bits_rewind(SpeexBits *bits); | |||
/** Initializes the bit-stream from the data in an area of memory */ | /** Initializes the bit-stream from the data in an area of memory */ | |||
void speex_bits_read_from(SpeexBits *bits, char *bytes, int len); | void speex_bits_read_from(SpeexBits *bits, char *bytes, int len); | |||
/** Append bytes to the bit-stream | ||||
* @param bits Bit-stream to operate on | ||||
* @param bytes pointer to the bytes what will be appended | ||||
* @param len Number of bytes of append | ||||
*/ | ||||
void speex_bits_read_whole_bytes(SpeexBits *bits, char *bytes, int len); | void speex_bits_read_whole_bytes(SpeexBits *bits, char *bytes, int len); | |||
/** Write the content of a bit-stream to an area of memory */ | /** Write the content of a bit-stream to an area of memory */ | |||
int speex_bits_write(SpeexBits *bits, char *bytes, int max_len); | int speex_bits_write(SpeexBits *bits, char *bytes, int max_len); | |||
/** Like speex_bits_write, but writes only the complete bytes in the stream . Also removes the written bytes from the stream */ | ||||
int speex_bits_write_whole_bytes(SpeexBits *bits, char *bytes, int max_len) ; | int speex_bits_write_whole_bytes(SpeexBits *bits, char *bytes, int max_len) ; | |||
/** Append bits to the bit-stream | ||||
* @param bits Bit-stream to operate on | ||||
* @param data Value to append as integer | ||||
* @param nbBits number of bits to consider in "data" | ||||
*/ | ||||
void speex_bits_pack(SpeexBits *bits, int data, int nbBits); | void speex_bits_pack(SpeexBits *bits, int data, int nbBits); | |||
/** Interpret the next bits in the bit-stream as a signed integer | ||||
* | ||||
* @param bits Bit-stream to operate on | ||||
* @param nbBits Number of bits to interpret | ||||
* @return A signed integer represented by the bits read | ||||
*/ | ||||
int speex_bits_unpack_signed(SpeexBits *bits, int nbBits); | int speex_bits_unpack_signed(SpeexBits *bits, int nbBits); | |||
/** Interpret the next bits in the bit-stream as an unsigned integer | ||||
* | ||||
* @param bits Bit-stream to operate on | ||||
* @param nbBits Number of bits to interpret | ||||
* @return An unsigned integer represented by the bits read | ||||
*/ | ||||
unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits); | unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits); | |||
/** Returns the number of bytes in the bit-stream, including the last one e | ||||
ven if it is not "full" | ||||
* | ||||
* @param bits Bit-stream to operate on | ||||
* @return Number of bytes in the stream | ||||
*/ | ||||
int speex_bits_nbytes(SpeexBits *bits); | int speex_bits_nbytes(SpeexBits *bits); | |||
/** Same as speex_bits_unpack_unsigned, but without modifying the cursor po sition */ | ||||
unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits); | unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits); | |||
/** Get the value of the next bit in the stream, without modifying the | ||||
* "cursor" position | ||||
* | ||||
* @param bits Bit-stream to operate on | ||||
*/ | ||||
int speex_bits_peek(SpeexBits *bits); | int speex_bits_peek(SpeexBits *bits); | |||
/** Advances the position of the "bit cursor" in the stream | ||||
* | ||||
* @param bits Bit-stream to operate on | ||||
* @param n Number of bits to advance | ||||
*/ | ||||
void speex_bits_advance(SpeexBits *bits, int n); | void speex_bits_advance(SpeexBits *bits, int n); | |||
/** Returns the number of bits remaining to be read in a stream | ||||
* | ||||
* @param bits Bit-stream to operate on | ||||
*/ | ||||
int speex_bits_remaining(SpeexBits *bits); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 20 change blocks. | ||||
24 lines changed or deleted | 91 lines changed or added | |||
speex_header.h | speex_header.h | |||
---|---|---|---|---|
/* Copyright (C) 2002 Jean-Marc Valin | /* Copyright (C) 2002 Jean-Marc Valin */ | |||
File: speex_header.h | /** | |||
Describes the Speex header | @file speex_header.h | |||
@brief Describes the Speex header | ||||
*/ | ||||
/* | ||||
Redistribution and use in source and binary forms, with or without | ||||
modification, are permitted provided that the following conditions | ||||
are met: | ||||
This library is free software; you can redistribute it and/or | - Redistributions of source code must retain the above copyright | |||
modify it under the terms of the GNU Lesser General Public | notice, this list of conditions and the following disclaimer. | |||
License as published by the Free Software Foundation; either | ||||
version 2.1 of the License, or (at your option) any later version. | ||||
This library is distributed in the hope that it will be useful, | - Redistributions in binary form must reproduce the above copyright | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | notice, this list of conditions and the following disclaimer in the | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | documentation and/or other materials provided with the distribution. | |||
Lesser General Public License for more details. | ||||
You should have received a copy of the GNU Lesser General Public | - Neither the name of the Xiph.org Foundation nor the names of its | |||
License along with this library; if not, write to the Free Software | contributors may be used to endorse or promote products derived from | |||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US | this software without specific prior written permission. | |||
A | ||||
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 O | ||||
R | ||||
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 SPEEX_HEADER_H | #ifndef SPEEX_HEADER_H | |||
#define SPEEX_HEADER_H | #define SPEEX_HEADER_H | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
struct SpeexMode; | struct SpeexMode; | |||
#define SPEEX_HEADER_VERSION_LENGTH 20 | ||||
#define SPEEX_HEADER_VERSION -1 | /** Maximum number of characters for encoding the Speex version number in t | |||
he header */ | ||||
#define SPEEX_HEADER_VERSION_LENGTH 20 | ||||
/** Speex header info for file-based formats */ | ||||
typedef struct SpeexHeader { | typedef struct SpeexHeader { | |||
char speex_string[8]; | char speex_string[8]; /**< Identifies a Speex bit-stream, always s | |||
char speex_version[SPEEX_HEADER_VERSION_LENGTH]; | et to "Speex " */ | |||
int speex_header_version; | char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */ | |||
int header_size; | int speex_version_id; /**< Version for Speex (for checking compati | |||
int rate; | bility) */ | |||
int mode; | int header_size; /**< Total size of the header ( sizeof(Speex | |||
int mode_bitstream_version; | Header) ) */ | |||
int nb_channels; | int rate; /**< Sampling rate used */ | |||
int bitrate; | int mode; /**< Mode used (0 for narrowband, 1 for wide | |||
int frame_size; | band) */ | |||
int vbr; | int mode_bitstream_version; /**< Version ID of the bit-stream */ | |||
int frames_per_packet; | int nb_channels; /**< Number of channels encoded */ | |||
int reserved1; | int bitrate; /**< Bit-rate used */ | |||
int reserved2; | int frame_size; /**< Size of frames */ | |||
int reserved3; | int vbr; /**< 1 for a VBR encoding, 0 otherwise */ | |||
int frames_per_packet; /**< Number of frames stored per Ogg packet | ||||
*/ | ||||
int extra_headers; /**< Number of additional headers after the | ||||
comments */ | ||||
int reserved1; /**< Reserved for future use, must be zero * | ||||
/ | ||||
int reserved2; /**< Reserved for future use, must be zero * | ||||
/ | ||||
} SpeexHeader; | } SpeexHeader; | |||
/** Initializes a SpeexHeader using basic information */ | ||||
void speex_init_header(SpeexHeader *header, int rate, int nb_channels, stru ct SpeexMode *m); | void speex_init_header(SpeexHeader *header, int rate, int nb_channels, stru ct SpeexMode *m); | |||
/** Creates the header packet from the header itself (mostly involves endia nness conversion) */ | ||||
char *speex_header_to_packet(SpeexHeader *header, int *size); | char *speex_header_to_packet(SpeexHeader *header, int *size); | |||
/** Creates a SpeexHeader from a packet */ | ||||
SpeexHeader *speex_packet_to_header(char *packet, int size); | SpeexHeader *speex_packet_to_header(char *packet, int size); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 11 change blocks. | ||||
32 lines changed or deleted | 60 lines changed or added | |||