speex_resampler.h

00001 /* Copyright (C) 2007 Jean-Marc Valin
00002       
00003    File: speex_resampler.h
00004    Resampling code
00005       
00006    The design goals of this code are:
00007       - Very fast algorithm
00008       - Low memory requirement
00009       - Good *perceptual* quality (and not best SNR)
00010 
00011    Redistribution and use in source and binary forms, with or without
00012    modification, are permitted provided that the following conditions are
00013    met:
00014 
00015    1. Redistributions of source code must retain the above copyright notice,
00016    this list of conditions and the following disclaimer.
00017 
00018    2. Redistributions in binary form must reproduce the above copyright
00019    notice, this list of conditions and the following disclaimer in the
00020    documentation and/or other materials provided with the distribution.
00021 
00022    3. The name of the author may not be used to endorse or promote products
00023    derived from this software without specific prior written permission.
00024 
00025    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00026    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00027    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028    DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
00029    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00030    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00032    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00033    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035    POSSIBILITY OF SUCH DAMAGE.
00036 */
00037 
00038 
00039 #ifndef SPEEX_RESAMPLER_H
00040 #define SPEEX_RESAMPLER_H
00041 
00042 #ifdef OUTSIDE_SPEEX
00043 
00044 /********* WARNING: MENTAL SANITY ENDS HERE *************/
00045 
00046 /* If the resampler is defined outside of Speex, we change the symbol names so that 
00047    there won't be any clash if linking with Speex later on. */
00048 
00049 /* #define RANDOM_PREFIX your software name here */
00050 #ifndef RANDOM_PREFIX
00051 #error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes"
00052 #endif
00053 
00054 #define CAT_PREFIX2(a,b) a ## b
00055 #define CAT_PREFIX(a,b) CAT_PREFIX2(a, b)
00056       
00057 #define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
00058 #define speex_resampler_init_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)
00059 #define speex_resampler_destroy CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)
00060 #define speex_resampler_process_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)
00061 #define speex_resampler_process_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)
00062 #define speex_resampler_process_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)
00063 #define speex_resampler_process_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)
00064 #define speex_resampler_set_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)
00065 #define speex_resampler_get_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate)
00066 #define speex_resampler_set_rate_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac)
00067 #define speex_resampler_get_ratio CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio)
00068 #define speex_resampler_set_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality)
00069 #define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
00070 #define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)
00071 #define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
00072 #define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
00073 #define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
00074 #define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
00075 #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
00076 #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
00077 
00078 #define spx_int16_t short
00079 #define spx_int32_t int
00080 #define spx_uint16_t unsigned short
00081 #define spx_uint32_t unsigned int
00082       
00083 #else /* OUTSIDE_SPEEX */
00084 
00085 #include "speex/speex_types.h"
00086 
00087 #endif /* OUTSIDE_SPEEX */
00088 
00089 #ifdef __cplusplus
00090 extern "C" {
00091 #endif
00092 
00093 #define SPEEX_RESAMPLER_QUALITY_MAX 10
00094 #define SPEEX_RESAMPLER_QUALITY_MIN 0
00095 #define SPEEX_RESAMPLER_QUALITY_DEFAULT 4
00096 #define SPEEX_RESAMPLER_QUALITY_VOIP 3
00097 #define SPEEX_RESAMPLER_QUALITY_DESKTOP 5
00098 
00099 enum {
00100    RESAMPLER_ERR_SUCCESS         = 0,
00101    RESAMPLER_ERR_ALLOC_FAILED    = 1,
00102    RESAMPLER_ERR_BAD_STATE       = 2,
00103    RESAMPLER_ERR_INVALID_ARG     = 3,
00104    RESAMPLER_ERR_PTR_OVERLAP     = 4,
00105    
00106    RESAMPLER_ERR_MAX_ERROR
00107 };
00108 
00109 struct SpeexResamplerState_;
00110 typedef struct SpeexResamplerState_ SpeexResamplerState;
00111 
00121 SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, 
00122                                           spx_uint32_t in_rate, 
00123                                           spx_uint32_t out_rate, 
00124                                           int quality,
00125                                           int *err);
00126 
00140 SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, 
00141                                                spx_uint32_t ratio_num, 
00142                                                spx_uint32_t ratio_den, 
00143                                                spx_uint32_t in_rate, 
00144                                                spx_uint32_t out_rate, 
00145                                                int quality,
00146                                                int *err);
00147 
00151 void speex_resampler_destroy(SpeexResamplerState *st);
00152 
00163 int speex_resampler_process_float(SpeexResamplerState *st, 
00164                                    spx_uint32_t channel_index, 
00165                                    const float *in, 
00166                                    spx_uint32_t *in_len, 
00167                                    float *out, 
00168                                    spx_uint32_t *out_len);
00169 
00180 int speex_resampler_process_int(SpeexResamplerState *st, 
00181                                  spx_uint32_t channel_index, 
00182                                  const spx_int16_t *in, 
00183                                  spx_uint32_t *in_len, 
00184                                  spx_int16_t *out, 
00185                                  spx_uint32_t *out_len);
00186 
00196 int speex_resampler_process_interleaved_float(SpeexResamplerState *st, 
00197                                                const float *in, 
00198                                                spx_uint32_t *in_len, 
00199                                                float *out, 
00200                                                spx_uint32_t *out_len);
00201 
00211 int speex_resampler_process_interleaved_int(SpeexResamplerState *st, 
00212                                              const spx_int16_t *in, 
00213                                              spx_uint32_t *in_len, 
00214                                              spx_int16_t *out, 
00215                                              spx_uint32_t *out_len);
00216 
00222 int speex_resampler_set_rate(SpeexResamplerState *st, 
00223                               spx_uint32_t in_rate, 
00224                               spx_uint32_t out_rate);
00225 
00231 void speex_resampler_get_rate(SpeexResamplerState *st, 
00232                               spx_uint32_t *in_rate, 
00233                               spx_uint32_t *out_rate);
00234 
00243 int speex_resampler_set_rate_frac(SpeexResamplerState *st, 
00244                                    spx_uint32_t ratio_num, 
00245                                    spx_uint32_t ratio_den, 
00246                                    spx_uint32_t in_rate, 
00247                                    spx_uint32_t out_rate);
00248 
00255 void speex_resampler_get_ratio(SpeexResamplerState *st, 
00256                                spx_uint32_t *ratio_num, 
00257                                spx_uint32_t *ratio_den);
00258 
00264 int speex_resampler_set_quality(SpeexResamplerState *st, 
00265                                  int quality);
00266 
00272 void speex_resampler_get_quality(SpeexResamplerState *st, 
00273                                  int *quality);
00274 
00279 void speex_resampler_set_input_stride(SpeexResamplerState *st, 
00280                                       spx_uint32_t stride);
00281 
00286 void speex_resampler_get_input_stride(SpeexResamplerState *st, 
00287                                       spx_uint32_t *stride);
00288 
00293 void speex_resampler_set_output_stride(SpeexResamplerState *st, 
00294                                       spx_uint32_t stride);
00295 
00300 void speex_resampler_get_output_stride(SpeexResamplerState *st, 
00301                                       spx_uint32_t *stride);
00302 
00311 int speex_resampler_skip_zeros(SpeexResamplerState *st);
00312 
00316 int speex_resampler_reset_mem(SpeexResamplerState *st);
00317 
00322 const char *speex_resampler_strerror(int err);
00323 
00324 #ifdef __cplusplus
00325 }
00326 #endif
00327 
00328 #endif

Generated on Wed May 23 00:53:16 2007 for Speex by  doxygen 1.5.1