Blame pph/speex_resampler.h

Packit 675970
/* Copyright (C) 2007 Jean-Marc Valin
Packit 675970
      
Packit 675970
   File: speex_resampler.h
Packit 675970
   Resampling code
Packit 675970
      
Packit 675970
   The design goals of this code are:
Packit 675970
      - Very fast algorithm
Packit 675970
      - Low memory requirement
Packit 675970
      - Good *perceptual* quality (and not best SNR)
Packit 675970
Packit 675970
   Redistribution and use in source and binary forms, with or without
Packit 675970
   modification, are permitted provided that the following conditions are
Packit 675970
   met:
Packit 675970
Packit 675970
   1. Redistributions of source code must retain the above copyright notice,
Packit 675970
   this list of conditions and the following disclaimer.
Packit 675970
Packit 675970
   2. Redistributions in binary form must reproduce the above copyright
Packit 675970
   notice, this list of conditions and the following disclaimer in the
Packit 675970
   documentation and/or other materials provided with the distribution.
Packit 675970
Packit 675970
   3. The name of the author may not be used to endorse or promote products
Packit 675970
   derived from this software without specific prior written permission.
Packit 675970
Packit 675970
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit 675970
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit 675970
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 675970
   DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
Packit 675970
   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Packit 675970
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 675970
   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 675970
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Packit 675970
   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
Packit 675970
   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit 675970
   POSSIBILITY OF SUCH DAMAGE.
Packit 675970
*/
Packit 675970
Packit 675970
Packit 675970
#ifndef SPEEX_RESAMPLER_H
Packit 675970
#define SPEEX_RESAMPLER_H
Packit 675970
Packit 675970
#ifdef OUTSIDE_SPEEX
Packit 675970
Packit 675970
/********* WARNING: MENTAL SANITY ENDS HERE *************/
Packit 675970
Packit 675970
/* If the resampler is defined outside of Speex, we change the symbol names so that 
Packit 675970
   there won't be any clash if linking with Speex later on. */
Packit 675970
Packit 675970
/* #define RANDOM_PREFIX your software name here */
Packit 675970
#ifndef RANDOM_PREFIX
Packit 675970
#error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes"
Packit 675970
#endif
Packit 675970
Packit 675970
#define CAT_PREFIX2(a,b) a ## b
Packit 675970
#define CAT_PREFIX(a,b) CAT_PREFIX2(a, b)
Packit 675970
      
Packit 675970
#define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
Packit 675970
#define speex_resampler_init_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)
Packit 675970
#define speex_resampler_destroy CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)
Packit 675970
#define speex_resampler_process_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)
Packit 675970
#define speex_resampler_process_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)
Packit 675970
#define speex_resampler_process_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)
Packit 675970
#define speex_resampler_process_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)
Packit 675970
#define speex_resampler_set_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)
Packit 675970
#define speex_resampler_get_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate)
Packit 675970
#define speex_resampler_set_rate_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac)
Packit 675970
#define speex_resampler_get_ratio CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio)
Packit 675970
#define speex_resampler_set_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality)
Packit 675970
#define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
Packit 675970
#define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)
Packit 675970
#define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
Packit 675970
#define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
Packit 675970
#define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
Packit 675970
#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
Packit 675970
#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
Packit 675970
#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
Packit 675970
Packit 675970
#define spx_int16_t short
Packit 675970
#define spx_int32_t int
Packit 675970
#define spx_uint16_t unsigned short
Packit 675970
#define spx_uint32_t unsigned int
Packit 675970
      
Packit 675970
#else /* OUTSIDE_SPEEX */
Packit 675970
Packit 675970
#ifdef HAVE_SPEEX_SPEEXDSP_TYPES_H
Packit 675970
#include "speex/speexdsp_types.h"
Packit 675970
#else
Packit 675970
#include "speex/speex_types.h"
Packit 675970
#endif
Packit 675970
Packit 675970
#endif /* OUTSIDE_SPEEX */
Packit 675970
Packit 675970
#ifdef __cplusplus
Packit 675970
extern "C" {
Packit 675970
#endif
Packit 675970
Packit 675970
#define SPEEX_RESAMPLER_QUALITY_MAX 10
Packit 675970
#define SPEEX_RESAMPLER_QUALITY_MIN 0
Packit 675970
#define SPEEX_RESAMPLER_QUALITY_DEFAULT 4
Packit 675970
#define SPEEX_RESAMPLER_QUALITY_VOIP 3
Packit 675970
#define SPEEX_RESAMPLER_QUALITY_DESKTOP 5
Packit 675970
Packit 675970
enum {
Packit 675970
   RESAMPLER_ERR_SUCCESS         = 0,
Packit 675970
   RESAMPLER_ERR_ALLOC_FAILED    = 1,
Packit 675970
   RESAMPLER_ERR_BAD_STATE       = 2,
Packit 675970
   RESAMPLER_ERR_INVALID_ARG     = 3,
Packit 675970
   RESAMPLER_ERR_PTR_OVERLAP     = 4,
Packit 675970
   
Packit 675970
   RESAMPLER_ERR_MAX_ERROR
Packit 675970
};
Packit 675970
Packit 675970
struct SpeexResamplerState_;
Packit 675970
typedef struct SpeexResamplerState_ SpeexResamplerState;
Packit 675970
Packit 675970
/** Create a new resampler with integer input and output rates.
Packit 675970
 * @param nb_channels Number of channels to be processed
Packit 675970
 * @param in_rate Input sampling rate (integer number of Hz).
Packit 675970
 * @param out_rate Output sampling rate (integer number of Hz).
Packit 675970
 * @param quality Resampling quality between 0 and 10, where 0 has poor quality
Packit 675970
 * and 10 has very high quality.
Packit 675970
 * @return Newly created resampler state
Packit 675970
 * @retval NULL Error: not enough memory
Packit 675970
 */
Packit 675970
SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, 
Packit 675970
                                          spx_uint32_t in_rate, 
Packit 675970
                                          spx_uint32_t out_rate, 
Packit 675970
                                          int quality,
Packit 675970
                                          int *err);
Packit 675970
Packit 675970
/** Create a new resampler with fractional input/output rates. The sampling 
Packit 675970
 * rate ratio is an arbitrary rational number with both the numerator and 
Packit 675970
 * denominator being 32-bit integers.
Packit 675970
 * @param nb_channels Number of channels to be processed
Packit 675970
 * @param ratio_num Numerator of the sampling rate ratio
Packit 675970
 * @param ratio_den Denominator of the sampling rate ratio
Packit 675970
 * @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
Packit 675970
 * @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
Packit 675970
 * @param quality Resampling quality between 0 and 10, where 0 has poor quality
Packit 675970
 * and 10 has very high quality.
Packit 675970
 * @return Newly created resampler state
Packit 675970
 * @retval NULL Error: not enough memory
Packit 675970
 */
Packit 675970
SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, 
Packit 675970
                                               spx_uint32_t ratio_num, 
Packit 675970
                                               spx_uint32_t ratio_den, 
Packit 675970
                                               spx_uint32_t in_rate, 
Packit 675970
                                               spx_uint32_t out_rate, 
Packit 675970
                                               int quality,
Packit 675970
                                               int *err);
Packit 675970
Packit 675970
/** Destroy a resampler state.
Packit 675970
 * @param st Resampler state
Packit 675970
 */
Packit 675970
void speex_resampler_destroy(SpeexResamplerState *st);
Packit 675970
Packit 675970
/** Resample a float array. The input and output buffers must *not* overlap.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param channel_index Index of the channel to process for the multi-channel 
Packit 675970
 * base (0 otherwise)
Packit 675970
 * @param in Input buffer
Packit 675970
 * @param in_len Number of input samples in the input buffer. Returns the 
Packit 675970
 * number of samples processed
Packit 675970
 * @param out Output buffer
Packit 675970
 * @param out_len Size of the output buffer. Returns the number of samples written
Packit 675970
 */
Packit 675970
int speex_resampler_process_float(SpeexResamplerState *st, 
Packit 675970
                                   spx_uint32_t channel_index, 
Packit 675970
                                   const float *in, 
Packit 675970
                                   spx_uint32_t *in_len, 
Packit 675970
                                   float *out, 
Packit 675970
                                   spx_uint32_t *out_len);
Packit 675970
Packit 675970
/** Resample an int array. The input and output buffers must *not* overlap.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param channel_index Index of the channel to process for the multi-channel 
Packit 675970
 * base (0 otherwise)
Packit 675970
 * @param in Input buffer
Packit 675970
 * @param in_len Number of input samples in the input buffer. Returns the number
Packit 675970
 * of samples processed
Packit 675970
 * @param out Output buffer
Packit 675970
 * @param out_len Size of the output buffer. Returns the number of samples written
Packit 675970
 */
Packit 675970
int speex_resampler_process_int(SpeexResamplerState *st, 
Packit 675970
                                 spx_uint32_t channel_index, 
Packit 675970
                                 const spx_int16_t *in, 
Packit 675970
                                 spx_uint32_t *in_len, 
Packit 675970
                                 spx_int16_t *out, 
Packit 675970
                                 spx_uint32_t *out_len);
Packit 675970
Packit 675970
/** Resample an interleaved float array. The input and output buffers must *not* overlap.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param in Input buffer
Packit 675970
 * @param in_len Number of input samples in the input buffer. Returns the number
Packit 675970
 * of samples processed. This is all per-channel.
Packit 675970
 * @param out Output buffer
Packit 675970
 * @param out_len Size of the output buffer. Returns the number of samples written.
Packit 675970
 * This is all per-channel.
Packit 675970
 */
Packit 675970
int speex_resampler_process_interleaved_float(SpeexResamplerState *st, 
Packit 675970
                                               const float *in, 
Packit 675970
                                               spx_uint32_t *in_len, 
Packit 675970
                                               float *out, 
Packit 675970
                                               spx_uint32_t *out_len);
Packit 675970
Packit 675970
/** Resample an interleaved int array. The input and output buffers must *not* overlap.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param in Input buffer
Packit 675970
 * @param in_len Number of input samples in the input buffer. Returns the number
Packit 675970
 * of samples processed. This is all per-channel.
Packit 675970
 * @param out Output buffer
Packit 675970
 * @param out_len Size of the output buffer. Returns the number of samples written.
Packit 675970
 * This is all per-channel.
Packit 675970
 */
Packit 675970
int speex_resampler_process_interleaved_int(SpeexResamplerState *st, 
Packit 675970
                                             const spx_int16_t *in, 
Packit 675970
                                             spx_uint32_t *in_len, 
Packit 675970
                                             spx_int16_t *out, 
Packit 675970
                                             spx_uint32_t *out_len);
Packit 675970
Packit 675970
/** Set (change) the input/output sampling rates (integer value).
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param in_rate Input sampling rate (integer number of Hz).
Packit 675970
 * @param out_rate Output sampling rate (integer number of Hz).
Packit 675970
 */
Packit 675970
int speex_resampler_set_rate(SpeexResamplerState *st, 
Packit 675970
                              spx_uint32_t in_rate, 
Packit 675970
                              spx_uint32_t out_rate);
Packit 675970
Packit 675970
/** Get the current input/output sampling rates (integer value).
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param in_rate Input sampling rate (integer number of Hz) copied.
Packit 675970
 * @param out_rate Output sampling rate (integer number of Hz) copied.
Packit 675970
 */
Packit 675970
void speex_resampler_get_rate(SpeexResamplerState *st, 
Packit 675970
                              spx_uint32_t *in_rate, 
Packit 675970
                              spx_uint32_t *out_rate);
Packit 675970
Packit 675970
/** Set (change) the input/output sampling rates and resampling ratio 
Packit 675970
 * (fractional values in Hz supported).
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param ratio_num Numerator of the sampling rate ratio
Packit 675970
 * @param ratio_den Denominator of the sampling rate ratio
Packit 675970
 * @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
Packit 675970
 * @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
Packit 675970
 */
Packit 675970
int speex_resampler_set_rate_frac(SpeexResamplerState *st, 
Packit 675970
                                   spx_uint32_t ratio_num, 
Packit 675970
                                   spx_uint32_t ratio_den, 
Packit 675970
                                   spx_uint32_t in_rate, 
Packit 675970
                                   spx_uint32_t out_rate);
Packit 675970
Packit 675970
/** Get the current resampling ratio. This will be reduced to the least
Packit 675970
 * common denominator.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param ratio_num Numerator of the sampling rate ratio copied
Packit 675970
 * @param ratio_den Denominator of the sampling rate ratio copied
Packit 675970
 */
Packit 675970
void speex_resampler_get_ratio(SpeexResamplerState *st, 
Packit 675970
                               spx_uint32_t *ratio_num, 
Packit 675970
                               spx_uint32_t *ratio_den);
Packit 675970
Packit 675970
/** Set (change) the conversion quality.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param quality Resampling quality between 0 and 10, where 0 has poor 
Packit 675970
 * quality and 10 has very high quality.
Packit 675970
 */
Packit 675970
int speex_resampler_set_quality(SpeexResamplerState *st, 
Packit 675970
                                 int quality);
Packit 675970
Packit 675970
/** Get the conversion quality.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param quality Resampling quality between 0 and 10, where 0 has poor 
Packit 675970
 * quality and 10 has very high quality.
Packit 675970
 */
Packit 675970
void speex_resampler_get_quality(SpeexResamplerState *st, 
Packit 675970
                                 int *quality);
Packit 675970
Packit 675970
/** Set (change) the input stride.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param stride Input stride
Packit 675970
 */
Packit 675970
void speex_resampler_set_input_stride(SpeexResamplerState *st, 
Packit 675970
                                      spx_uint32_t stride);
Packit 675970
Packit 675970
/** Get the input stride.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param stride Input stride copied
Packit 675970
 */
Packit 675970
void speex_resampler_get_input_stride(SpeexResamplerState *st, 
Packit 675970
                                      spx_uint32_t *stride);
Packit 675970
Packit 675970
/** Set (change) the output stride.
Packit 675970
 * @param st Resampler state
Packit 675970
 * @param stride Output stride
Packit 675970
 */
Packit 675970
void speex_resampler_set_output_stride(SpeexResamplerState *st, 
Packit 675970
                                      spx_uint32_t stride);
Packit 675970
Packit 675970
/** Get the output stride.
Packit 675970
 * @param st Resampler state copied
Packit 675970
 * @param stride Output stride
Packit 675970
 */
Packit 675970
void speex_resampler_get_output_stride(SpeexResamplerState *st, 
Packit 675970
                                      spx_uint32_t *stride);
Packit 675970
Packit 675970
/** Make sure that the first samples to go out of the resamplers don't have 
Packit 675970
 * leading zeros. This is only useful before starting to use a newly created 
Packit 675970
 * resampler. It is recommended to use that when resampling an audio file, as
Packit 675970
 * it will generate a file with the same length. For real-time processing,
Packit 675970
 * it is probably easier not to use this call (so that the output duration
Packit 675970
 * is the same for the first frame).
Packit 675970
 * @param st Resampler state
Packit 675970
 */
Packit 675970
int speex_resampler_skip_zeros(SpeexResamplerState *st);
Packit 675970
Packit 675970
/** Reset a resampler so a new (unrelated) stream can be processed.
Packit 675970
 * @param st Resampler state
Packit 675970
 */
Packit 675970
int speex_resampler_reset_mem(SpeexResamplerState *st);
Packit 675970
Packit 675970
/** Returns the English meaning for an error code
Packit 675970
 * @param err Error code
Packit 675970
 * @return English string
Packit 675970
 */
Packit 675970
const char *speex_resampler_strerror(int err);
Packit 675970
Packit 675970
#ifdef __cplusplus
Packit 675970
}
Packit 675970
#endif
Packit 675970
Packit 675970
#endif