[96fb8ad] | 1 | /* |
---|
[e6a78ea] | 2 | Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org> |
---|
| 3 | |
---|
| 4 | This file is part of aubio. |
---|
| 5 | |
---|
| 6 | aubio is free software: you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | (at your option) any later version. |
---|
| 10 | |
---|
| 11 | aubio is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | |
---|
[96fb8ad] | 19 | */ |
---|
| 20 | |
---|
[020d80e] | 21 | #include "config.h" |
---|
| 22 | |
---|
[b093845] | 23 | #if HAVE_SAMPLERATE |
---|
[96fb8ad] | 24 | |
---|
| 25 | #include <samplerate.h> /* from libsamplerate */ |
---|
| 26 | |
---|
| 27 | #include "aubio_priv.h" |
---|
[6c7d49b] | 28 | #include "fvec.h" |
---|
[0af05d3] | 29 | #include "temporal/resampler.h" |
---|
[96fb8ad] | 30 | |
---|
| 31 | struct _aubio_resampler_t { |
---|
[3c86eb1] | 32 | SRC_DATA *proc; |
---|
[96fb8ad] | 33 | SRC_STATE *stat; |
---|
[fe9c314] | 34 | smpl_t ratio; |
---|
[96fb8ad] | 35 | uint_t type; |
---|
| 36 | }; |
---|
| 37 | |
---|
[fe9c314] | 38 | aubio_resampler_t * new_aubio_resampler(smpl_t ratio, uint_t type) { |
---|
[96fb8ad] | 39 | aubio_resampler_t * s = AUBIO_NEW(aubio_resampler_t); |
---|
[3c86eb1] | 40 | int error = 0; |
---|
| 41 | s->stat = src_new (type, 1, &error) ; /* only one channel */ |
---|
[96fb8ad] | 42 | s->proc = AUBIO_NEW(SRC_DATA); |
---|
| 43 | if (error) AUBIO_ERR("%s\n",src_strerror(error)); |
---|
| 44 | s->ratio = ratio; |
---|
| 45 | return s; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void del_aubio_resampler(aubio_resampler_t *s) { |
---|
| 49 | src_delete(s->stat); |
---|
[0d439322] | 50 | AUBIO_FREE(s->proc); |
---|
[96fb8ad] | 51 | AUBIO_FREE(s); |
---|
| 52 | } |
---|
| 53 | |
---|
[06f2d78] | 54 | void aubio_resampler_do (aubio_resampler_t *s, |
---|
[96fb8ad] | 55 | fvec_t * input, fvec_t * output) { |
---|
| 56 | uint_t i ; |
---|
| 57 | s->proc->input_frames = input->length; |
---|
| 58 | s->proc->output_frames = output->length; |
---|
[fe9c314] | 59 | s->proc->src_ratio = (double)s->ratio; |
---|
[96fb8ad] | 60 | for (i = 0 ; i< input->channels; i++) |
---|
| 61 | { |
---|
| 62 | /* make SRC_PROC data point to input outputs */ |
---|
[e7b3629] | 63 | s->proc->data_in = (float *)input->data[i]; |
---|
| 64 | s->proc->data_out= (float *)output->data[i]; |
---|
[96fb8ad] | 65 | /* do resampling */ |
---|
| 66 | src_process (s->stat, s->proc) ; |
---|
| 67 | } |
---|
| 68 | } |
---|
[b093845] | 69 | |
---|
| 70 | #endif /* HAVE_SAMPLERATE */ |
---|