1 | /* |
---|
2 | Copyright (C) 2003 Paul Brossier |
---|
3 | |
---|
4 | This program is free software; you can redistribute it and/or modify |
---|
5 | it under the terms of the GNU General Public License as published by |
---|
6 | the Free Software Foundation; either version 2 of the License, or |
---|
7 | (at your option) any later version. |
---|
8 | |
---|
9 | This program 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 |
---|
12 | GNU General Public License for more details. |
---|
13 | |
---|
14 | You should have received a copy of the GNU General Public License |
---|
15 | along with this program; if not, write to the Free Software |
---|
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
17 | |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_SAMPLERATE |
---|
21 | |
---|
22 | #include <samplerate.h> /* from libsamplerate */ |
---|
23 | |
---|
24 | #include "aubio_priv.h" |
---|
25 | #include "fvec.h" |
---|
26 | #include "temporal/resample.h" |
---|
27 | |
---|
28 | struct _aubio_resampler_t { |
---|
29 | SRC_DATA *proc; |
---|
30 | SRC_STATE *stat; |
---|
31 | float ratio; |
---|
32 | uint_t type; |
---|
33 | }; |
---|
34 | |
---|
35 | aubio_resampler_t * new_aubio_resampler(float ratio, uint_t type) { |
---|
36 | aubio_resampler_t * s = AUBIO_NEW(aubio_resampler_t); |
---|
37 | int error = 0; |
---|
38 | s->stat = src_new (type, 1, &error) ; /* only one channel */ |
---|
39 | s->proc = AUBIO_NEW(SRC_DATA); |
---|
40 | if (error) AUBIO_ERR("%s\n",src_strerror(error)); |
---|
41 | s->ratio = ratio; |
---|
42 | return s; |
---|
43 | } |
---|
44 | |
---|
45 | void del_aubio_resampler(aubio_resampler_t *s) { |
---|
46 | src_delete(s->stat); |
---|
47 | AUBIO_FREE(s->proc); |
---|
48 | AUBIO_FREE(s); |
---|
49 | } |
---|
50 | |
---|
51 | uint_t aubio_resampler_process(aubio_resampler_t *s, |
---|
52 | fvec_t * input, fvec_t * output) { |
---|
53 | uint_t i ; |
---|
54 | s->proc->input_frames = input->length; |
---|
55 | s->proc->output_frames = output->length; |
---|
56 | s->proc->src_ratio = s->ratio; |
---|
57 | for (i = 0 ; i< input->channels; i++) |
---|
58 | { |
---|
59 | /* make SRC_PROC data point to input outputs */ |
---|
60 | s->proc->data_in = (float *)input->data[i]; |
---|
61 | s->proc->data_out= (float *)output->data[i]; |
---|
62 | /* do resampling */ |
---|
63 | src_process (s->stat, s->proc) ; |
---|
64 | } |
---|
65 | return AUBIO_OK; |
---|
66 | } |
---|
67 | |
---|
68 | #endif /* HAVE_SAMPLERATE */ |
---|