00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 #ifndef SPEEX_RESAMPLER_H
00040 #define SPEEX_RESAMPLER_H
00041 
00042 #ifdef OUTSIDE_SPEEX
00043 
00044 
00045 
00046 
00047 
00048 
00049 
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 
00086 
00087 #include "speex/speex_types.h"
00088 
00089 #endif 
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