[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 | |
---|
[96fb8ad] | 23 | #include "aubio_priv.h" |
---|
[6c7d49b] | 24 | #include "fvec.h" |
---|
[0af05d3] | 25 | #include "temporal/resampler.h" |
---|
[96fb8ad] | 26 | |
---|
[16ed726] | 27 | #if HAVE_SAMPLERATE |
---|
| 28 | |
---|
| 29 | #include <samplerate.h> /* from libsamplerate */ |
---|
| 30 | |
---|
[bafe71d] | 31 | struct _aubio_resampler_t |
---|
| 32 | { |
---|
| 33 | SRC_DATA *proc; |
---|
| 34 | SRC_STATE *stat; |
---|
| 35 | smpl_t ratio; |
---|
| 36 | uint_t type; |
---|
[96fb8ad] | 37 | }; |
---|
| 38 | |
---|
[bafe71d] | 39 | aubio_resampler_t * |
---|
| 40 | new_aubio_resampler (smpl_t ratio, uint_t type) |
---|
| 41 | { |
---|
| 42 | aubio_resampler_t *s = AUBIO_NEW (aubio_resampler_t); |
---|
| 43 | int error = 0; |
---|
| 44 | s->stat = src_new (type, 1, &error); /* only one channel */ |
---|
[927f630] | 45 | if (error) { |
---|
| 46 | AUBIO_ERR ("Failed creating resampler: %s\n", src_strerror (error)); |
---|
| 47 | del_aubio_resampler(s); |
---|
| 48 | return NULL; |
---|
| 49 | } |
---|
[bafe71d] | 50 | s->proc = AUBIO_NEW (SRC_DATA); |
---|
| 51 | s->ratio = ratio; |
---|
| 52 | return s; |
---|
[96fb8ad] | 53 | } |
---|
| 54 | |
---|
[bafe71d] | 55 | void |
---|
| 56 | del_aubio_resampler (aubio_resampler_t * s) |
---|
| 57 | { |
---|
[927f630] | 58 | if (s->stat) src_delete (s->stat); |
---|
[bafe71d] | 59 | AUBIO_FREE (s->proc); |
---|
| 60 | AUBIO_FREE (s); |
---|
[96fb8ad] | 61 | } |
---|
| 62 | |
---|
[bafe71d] | 63 | void |
---|
| 64 | aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output) |
---|
| 65 | { |
---|
| 66 | s->proc->input_frames = input->length; |
---|
| 67 | s->proc->output_frames = output->length; |
---|
| 68 | s->proc->src_ratio = (double) s->ratio; |
---|
[741bdda] | 69 | /* make SRC_PROC data point to input outputs */ |
---|
| 70 | s->proc->data_in = (float *) input->data; |
---|
| 71 | s->proc->data_out = (float *) output->data; |
---|
| 72 | /* do resampling */ |
---|
| 73 | src_process (s->stat, s->proc); |
---|
[bafe71d] | 74 | } |
---|
[b093845] | 75 | |
---|
[16ed726] | 76 | #else |
---|
| 77 | struct _aubio_resampler_t |
---|
| 78 | { |
---|
[e9270a4] | 79 | void *dummy; |
---|
[16ed726] | 80 | }; |
---|
| 81 | |
---|
| 82 | aubio_resampler_t * |
---|
| 83 | new_aubio_resampler (smpl_t ratio UNUSED, uint_t type UNUSED) |
---|
| 84 | { |
---|
| 85 | AUBIO_ERR ("aubio was not compiled with libsamplerate\n"); |
---|
| 86 | return NULL; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void |
---|
[741bdda] | 90 | del_aubio_resampler (aubio_resampler_t * s UNUSED) |
---|
[16ed726] | 91 | { |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void |
---|
[741bdda] | 95 | aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED) |
---|
[16ed726] | 96 | { |
---|
| 97 | } |
---|
[b093845] | 98 | #endif /* HAVE_SAMPLERATE */ |
---|