SAF
Loading...
Searching...
No Matches
speex_resampler.h
Go to the documentation of this file.
1/* Copyright (C) 2007 Jean-Marc Valin */
7/*
8 File: speex_resampler.h
9 Resampling code
10
11 The design goals of this code are:
12 - Very fast algorithm
13 - Low memory requirement
14 - Good *perceptual* quality (and not best SNR)
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are
18 met:
19
20 1. Redistributions of source code must retain the above copyright notice,
21 this list of conditions and the following disclaimer.
22
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
26
27 3. The name of the author may not be used to endorse or promote products
28 derived from this software without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
31 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
34 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 POSSIBILITY OF SUCH DAMAGE.
41*/
42
43
44#ifndef SPEEX_RESAMPLER_H
45#define SPEEX_RESAMPLER_H
46
47#define OUTSIDE_SPEEX
48#define RANDOM_PREFIX speex_
49
50#ifdef OUTSIDE_SPEEX
51
52/********* WARNING: MENTAL SANITY ENDS HERE *************/
53
54/* If the resampler is defined outside of Speex, we change the symbol names so that
55 there won't be any clash if linking with Speex later on. */
56
57/* #define RANDOM_PREFIX your software name here */
58#ifndef RANDOM_PREFIX
59#error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes"
60#endif
61
62#define CAT_PREFIX2(a,b) a ## b
63#define CAT_PREFIX(a,b) CAT_PREFIX2(a, b)
64
65#define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
66#define speex_resampler_init_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)
67#define speex_resampler_destroy CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)
68#define speex_resampler_process_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)
69#define speex_resampler_process_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)
70#define speex_resampler_process_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)
71#define speex_resampler_process_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)
72#define speex_resampler_set_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)
73#define speex_resampler_get_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate)
74#define speex_resampler_set_rate_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac)
75#define speex_resampler_get_ratio CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio)
76#define speex_resampler_set_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality)
77#define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
78#define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)
79#define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
80#define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
81#define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
82#define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)
83#define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)
84#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
85#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
86#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
87
88#define spx_int16_t short
89#define spx_int32_t int
90#define spx_uint16_t unsigned short
91#define spx_uint32_t unsigned int
92
93#define speex_assert(cond)
94
95#else /* OUTSIDE_SPEEX */
96
97#include "speexdsp_types.h"
98
99#endif /* OUTSIDE_SPEEX */
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
105#define SPEEX_RESAMPLER_QUALITY_MAX 10
106#define SPEEX_RESAMPLER_QUALITY_MIN 0
107#define SPEEX_RESAMPLER_QUALITY_DEFAULT 4
108#define SPEEX_RESAMPLER_QUALITY_VOIP 3
109#define SPEEX_RESAMPLER_QUALITY_DESKTOP 5
110
111enum {
112 RESAMPLER_ERR_SUCCESS = 0,
113 RESAMPLER_ERR_ALLOC_FAILED = 1,
114 RESAMPLER_ERR_BAD_STATE = 2,
115 RESAMPLER_ERR_INVALID_ARG = 3,
116 RESAMPLER_ERR_PTR_OVERLAP = 4,
117 RESAMPLER_ERR_OVERFLOW = 5,
118
119 RESAMPLER_ERR_MAX_ERROR
120};
121
123typedef struct SpeexResamplerState_ SpeexResamplerState;
124
134SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels,
135 spx_uint32_t in_rate,
136 spx_uint32_t out_rate,
137 int quality,
138 int *err);
139
153SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
154 spx_uint32_t ratio_num,
155 spx_uint32_t ratio_den,
156 spx_uint32_t in_rate,
157 spx_uint32_t out_rate,
158 int quality,
159 int *err);
160
164void speex_resampler_destroy(SpeexResamplerState *st);
165
176int speex_resampler_process_float(SpeexResamplerState *st,
177 spx_uint32_t channel_index,
178 const float *in,
179 spx_uint32_t *in_len,
180 float *out,
181 spx_uint32_t *out_len);
182
193int speex_resampler_process_int(SpeexResamplerState *st,
194 spx_uint32_t channel_index,
195 const spx_int16_t *in,
196 spx_uint32_t *in_len,
197 spx_int16_t *out,
198 spx_uint32_t *out_len);
199
209int speex_resampler_process_interleaved_float(SpeexResamplerState *st,
210 const float *in,
211 spx_uint32_t *in_len,
212 float *out,
213 spx_uint32_t *out_len);
214
224int speex_resampler_process_interleaved_int(SpeexResamplerState *st,
225 const spx_int16_t *in,
226 spx_uint32_t *in_len,
227 spx_int16_t *out,
228 spx_uint32_t *out_len);
229
235int speex_resampler_set_rate(SpeexResamplerState *st,
236 spx_uint32_t in_rate,
237 spx_uint32_t out_rate);
238
244void speex_resampler_get_rate(SpeexResamplerState *st,
245 spx_uint32_t *in_rate,
246 spx_uint32_t *out_rate);
247
256int speex_resampler_set_rate_frac(SpeexResamplerState *st,
257 spx_uint32_t ratio_num,
258 spx_uint32_t ratio_den,
259 spx_uint32_t in_rate,
260 spx_uint32_t out_rate);
261
268void speex_resampler_get_ratio(SpeexResamplerState *st,
269 spx_uint32_t *ratio_num,
270 spx_uint32_t *ratio_den);
271
277int speex_resampler_set_quality(SpeexResamplerState *st,
278 int quality);
279
285void speex_resampler_get_quality(SpeexResamplerState *st,
286 int *quality);
287
292void speex_resampler_set_input_stride(SpeexResamplerState *st,
293 spx_uint32_t stride);
294
299void speex_resampler_get_input_stride(SpeexResamplerState *st,
300 spx_uint32_t *stride);
301
306void speex_resampler_set_output_stride(SpeexResamplerState *st,
307 spx_uint32_t stride);
308
313void speex_resampler_get_output_stride(SpeexResamplerState *st,
314 spx_uint32_t *stride);
315
319int speex_resampler_get_input_latency(SpeexResamplerState *st);
320
324int speex_resampler_get_output_latency(SpeexResamplerState *st);
325
334int speex_resampler_skip_zeros(SpeexResamplerState *st);
335
339int speex_resampler_reset_mem(SpeexResamplerState *st);
340
345const char *speex_resampler_strerror(int err);
346
347#ifdef __cplusplus
348}
349#endif
350
351#endif
Speex types.