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_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)
00075 #define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)
00076 #define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
00077 #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
00078 #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
00079 
00080 #define spx_int16_t short
00081 #define spx_int32_t int
00082 #define spx_uint16_t unsigned short
00083 #define spx_uint32_t unsigned int
00084       
00085 #else /* OUTSIDE_SPEEX */
00086 
00087 #include "speex/speex_types.h"
00088 
00089 #endif /* OUTSIDE_SPEEX */
00090 
00091 #ifdef __cplusplus
00092 extern "C" {
00093 #endif
00094 
00095 #define SPEEX_RESAMPLER_QUALITY_MAX 10
00096 #define SPEEX_RESAMPLER_QUALITY_MIN 0
00097 #define SPEEX_RESAMPLER_QUALITY_DEFAULT 4
00098 #define SPEEX_RESAMPLER_QUALITY_VOIP 3
00099 #define SPEEX_RESAMPLER_QUALITY_DESKTOP 5
00100 
00101 enum {
00102    RESAMPLER_ERR_SUCCESS         = 0,
00103    RESAMPLER_ERR_ALLOC_FAILED    = 1,
00104    RESAMPLER_ERR_BAD_STATE       = 2,
00105    RESAMPLER_ERR_INVALID_ARG     = 3,
00106    RESAMPLER_ERR_PTR_OVERLAP     = 4,
00107    
00108    RESAMPLER_ERR_MAX_ERROR
00109 };
00110 
00111 struct SpeexResamplerState_;
00112 typedef struct SpeexResamplerState_ SpeexResamplerState;
00113 
00123 SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, 
00124                                           spx_uint32_t in_rate, 
00125                                           spx_uint32_t out_rate, 
00126                                           int quality,
00127                                           int *err);
00128 
00142 SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, 
00143                                                spx_uint32_t ratio_num, 
00144                                                spx_uint32_t ratio_den, 
00145                                                spx_uint32_t in_rate, 
00146                                                spx_uint32_t out_rate, 
00147                                                int quality,
00148                                                int *err);
00149 
00153 void speex_resampler_destroy(SpeexResamplerState *st);
00154 
00165 int speex_resampler_process_float(SpeexResamplerState *st, 
00166                                    spx_uint32_t channel_index, 
00167                                    const float *in, 
00168                                    spx_uint32_t *in_len, 
00169                                    float *out, 
00170                                    spx_uint32_t *out_len);
00171 
00182 int speex_resampler_process_int(SpeexResamplerState *st, 
00183                                  spx_uint32_t channel_index, 
00184                                  const spx_int16_t *in, 
00185                                  spx_uint32_t *in_len, 
00186                                  spx_int16_t *out, 
00187                                  spx_uint32_t *out_len);
00188 
00198 int speex_resampler_process_interleaved_float(SpeexResamplerState *st, 
00199                                                const float *in, 
00200                                                spx_uint32_t *in_len, 
00201                                                float *out, 
00202                                                spx_uint32_t *out_len);
00203 
00213 int speex_resampler_process_interleaved_int(SpeexResamplerState *st, 
00214                                              const spx_int16_t *in, 
00215                                              spx_uint32_t *in_len, 
00216                                              spx_int16_t *out, 
00217                                              spx_uint32_t *out_len);
00218 
00224 int speex_resampler_set_rate(SpeexResamplerState *st, 
00225                               spx_uint32_t in_rate, 
00226                               spx_uint32_t out_rate);
00227 
00233 void speex_resampler_get_rate(SpeexResamplerState *st, 
00234                               spx_uint32_t *in_rate, 
00235                               spx_uint32_t *out_rate);
00236 
00245 int speex_resampler_set_rate_frac(SpeexResamplerState *st, 
00246                                    spx_uint32_t ratio_num, 
00247                                    spx_uint32_t ratio_den, 
00248                                    spx_uint32_t in_rate, 
00249                                    spx_uint32_t out_rate);
00250 
00257 void speex_resampler_get_ratio(SpeexResamplerState *st, 
00258                                spx_uint32_t *ratio_num, 
00259                                spx_uint32_t *ratio_den);
00260 
00266 int speex_resampler_set_quality(SpeexResamplerState *st, 
00267                                  int quality);
00268 
00274 void speex_resampler_get_quality(SpeexResamplerState *st, 
00275                                  int *quality);
00276 
00281 void speex_resampler_set_input_stride(SpeexResamplerState *st, 
00282                                       spx_uint32_t stride);
00283 
00288 void speex_resampler_get_input_stride(SpeexResamplerState *st, 
00289                                       spx_uint32_t *stride);
00290 
00295 void speex_resampler_set_output_stride(SpeexResamplerState *st, 
00296                                       spx_uint32_t stride);
00297 
00302 void speex_resampler_get_output_stride(SpeexResamplerState *st, 
00303                                       spx_uint32_t *stride);
00304 
00308 int speex_resampler_get_input_latency(SpeexResamplerState *st);
00309 
00313 int speex_resampler_get_output_latency(SpeexResamplerState *st);
00314 
00323 int speex_resampler_skip_zeros(SpeexResamplerState *st);
00324 
00328 int speex_resampler_reset_mem(SpeexResamplerState *st);
00329 
00334 const char *speex_resampler_strerror(int err);
00335 
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339 
00340 #endif

Generated on Tue Apr 7 20:09:08 2009 for Speex by  doxygen 1.5.1