|
1 /* Resampling library |
|
2 * Copyright (C) <2001> David Schleef <ds@schleef.org> |
|
3 * |
|
4 * This library is free software; you can redistribute it and/or |
|
5 * modify it under the terms of the GNU Library General Public |
|
6 * License as published by the Free Software Foundation; either |
|
7 * version 2 of the License, or any later version. |
|
8 * |
|
9 * This library is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * Library General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Library General Public |
|
15 * License along with this library; if not, write to the |
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
17 * Boston, MA 02111-1307, USA. |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef __RESAMPLE_H__ |
|
22 #define __RESAMPLE_H__ |
|
23 |
|
24 #include "functable.h" |
|
25 #include "buffer.h" |
|
26 |
|
27 #ifndef M_PI |
|
28 #define M_PI 3.14159265358979323846 |
|
29 #endif |
|
30 |
|
31 #ifdef WIN32 |
|
32 #define rint(x) (floor((x)+0.5)) |
|
33 #endif |
|
34 |
|
35 typedef enum { |
|
36 RESAMPLE_FORMAT_S16 = 0, |
|
37 RESAMPLE_FORMAT_S32, |
|
38 RESAMPLE_FORMAT_F32, |
|
39 RESAMPLE_FORMAT_F64 |
|
40 } ResampleFormat; |
|
41 |
|
42 typedef void (*ResampleCallback) (void *); |
|
43 |
|
44 typedef struct _ResampleState ResampleState; |
|
45 |
|
46 struct _ResampleState { |
|
47 /* parameters */ |
|
48 |
|
49 int n_channels; |
|
50 ResampleFormat format; |
|
51 |
|
52 int filter_length; |
|
53 |
|
54 double i_rate; |
|
55 double o_rate; |
|
56 |
|
57 int method; |
|
58 |
|
59 /* internal parameters */ |
|
60 |
|
61 int need_reinit; |
|
62 |
|
63 double halftaps; |
|
64 |
|
65 /* filter state */ |
|
66 |
|
67 unsigned char *o_buf; |
|
68 int o_size; |
|
69 |
|
70 AudioresampleBufferQueue *queue; |
|
71 int eos; |
|
72 int started; |
|
73 |
|
74 int sample_size; |
|
75 |
|
76 unsigned char *buffer; |
|
77 int buffer_len; |
|
78 int buffer_filled; |
|
79 |
|
80 double i_start; |
|
81 double o_start; |
|
82 |
|
83 double i_inc; |
|
84 double o_inc; |
|
85 |
|
86 double sinc_scale; |
|
87 |
|
88 double i_end; |
|
89 double o_end; |
|
90 |
|
91 int i_samples; |
|
92 int o_samples; |
|
93 |
|
94 //void *i_buf; |
|
95 |
|
96 Functable *ft; |
|
97 |
|
98 double *out_tmp; |
|
99 }; |
|
100 #ifdef __SYMBIAN32__ |
|
101 IMPORT_C |
|
102 #endif |
|
103 |
|
104 |
|
105 void resample_init (void); |
|
106 void resample_cleanup (void); |
|
107 #ifdef __SYMBIAN32__ |
|
108 IMPORT_C |
|
109 #endif |
|
110 |
|
111 |
|
112 ResampleState *resample_new (void); |
|
113 #ifdef __SYMBIAN32__ |
|
114 IMPORT_C |
|
115 #endif |
|
116 |
|
117 void resample_free (ResampleState *state); |
|
118 #ifdef __SYMBIAN32__ |
|
119 IMPORT_C |
|
120 #endif |
|
121 |
|
122 |
|
123 void resample_add_input_data (ResampleState * r, void *data, int size, |
|
124 ResampleCallback free_func, void *closure); |
|
125 #ifdef __SYMBIAN32__ |
|
126 IMPORT_C |
|
127 #endif |
|
128 |
|
129 void resample_input_eos (ResampleState *r); |
|
130 #ifdef __SYMBIAN32__ |
|
131 IMPORT_C |
|
132 #endif |
|
133 |
|
134 void resample_input_flush (ResampleState *r); |
|
135 #ifdef __SYMBIAN32__ |
|
136 IMPORT_C |
|
137 #endif |
|
138 |
|
139 void resample_input_pushthrough (ResampleState *r); |
|
140 #ifdef __SYMBIAN32__ |
|
141 IMPORT_C |
|
142 #endif |
|
143 |
|
144 |
|
145 int resample_get_output_size_for_input (ResampleState * r, int size); |
|
146 #ifdef __SYMBIAN32__ |
|
147 IMPORT_C |
|
148 #endif |
|
149 |
|
150 int resample_get_input_size_for_output (ResampleState * r, int size); |
|
151 #ifdef __SYMBIAN32__ |
|
152 IMPORT_C |
|
153 #endif |
|
154 |
|
155 |
|
156 int resample_get_output_size (ResampleState *r); |
|
157 #ifdef __SYMBIAN32__ |
|
158 IMPORT_C |
|
159 #endif |
|
160 |
|
161 int resample_get_output_data (ResampleState *r, void *data, int size); |
|
162 #ifdef __SYMBIAN32__ |
|
163 IMPORT_C |
|
164 #endif |
|
165 |
|
166 |
|
167 void resample_set_filter_length (ResampleState *r, int length); |
|
168 #ifdef __SYMBIAN32__ |
|
169 IMPORT_C |
|
170 #endif |
|
171 |
|
172 void resample_set_input_rate (ResampleState *r, double rate); |
|
173 #ifdef __SYMBIAN32__ |
|
174 IMPORT_C |
|
175 #endif |
|
176 |
|
177 void resample_set_output_rate (ResampleState *r, double rate); |
|
178 #ifdef __SYMBIAN32__ |
|
179 IMPORT_C |
|
180 #endif |
|
181 |
|
182 void resample_set_n_channels (ResampleState *r, int n_channels); |
|
183 #ifdef __SYMBIAN32__ |
|
184 IMPORT_C |
|
185 #endif |
|
186 |
|
187 void resample_set_format (ResampleState *r, ResampleFormat format); |
|
188 #ifdef __SYMBIAN32__ |
|
189 IMPORT_C |
|
190 #endif |
|
191 |
|
192 void resample_set_method (ResampleState *r, int method); |
|
193 #ifdef __SYMBIAN32__ |
|
194 IMPORT_C |
|
195 #endif |
|
196 |
|
197 int resample_format_size (ResampleFormat format); |
|
198 |
|
199 #endif /* __RESAMPLE_H__ */ |
|
200 |