source: src/temporal/resampler.c @ 488381e

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since 488381e was fe0fa26, checked in by Paul Brossier <piem@piem.org>, 8 years ago

src/temporal/resampler.c: throw an error when using libsamplerate with doubles

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[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
[de66709]27#ifdef HAVE_SAMPLERATE
[16ed726]28
[fe0fa26]29#if HAVE_AUBIO_DOUBLE
30#error "Should not use libsamplerate with aubio in double precision"
31#endif
32
[16ed726]33#include <samplerate.h>         /* from libsamplerate */
34
[bafe71d]35struct _aubio_resampler_t
36{
37  SRC_DATA *proc;
38  SRC_STATE *stat;
39  smpl_t ratio;
40  uint_t type;
[96fb8ad]41};
42
[bafe71d]43aubio_resampler_t *
44new_aubio_resampler (smpl_t ratio, uint_t type)
45{
46  aubio_resampler_t *s = AUBIO_NEW (aubio_resampler_t);
47  int error = 0;
48  s->stat = src_new (type, 1, &error);  /* only one channel */
[927f630]49  if (error) {
50    AUBIO_ERR ("Failed creating resampler: %s\n", src_strerror (error));
51    del_aubio_resampler(s);
52    return NULL;
53  }
[bafe71d]54  s->proc = AUBIO_NEW (SRC_DATA);
55  s->ratio = ratio;
56  return s;
[96fb8ad]57}
58
[bafe71d]59void
60del_aubio_resampler (aubio_resampler_t * s)
61{
[927f630]62  if (s->stat) src_delete (s->stat);
[bafe71d]63  AUBIO_FREE (s->proc);
64  AUBIO_FREE (s);
[96fb8ad]65}
66
[bafe71d]67void
[23493b5]68aubio_resampler_do (aubio_resampler_t * s, const fvec_t * input, fvec_t * output)
[bafe71d]69{
70  s->proc->input_frames = input->length;
71  s->proc->output_frames = output->length;
72  s->proc->src_ratio = (double) s->ratio;
[741bdda]73  /* make SRC_PROC data point to input outputs */
74  s->proc->data_in = (float *) input->data;
75  s->proc->data_out = (float *) output->data;
76  /* do resampling */
77  src_process (s->stat, s->proc);
[bafe71d]78}
[b093845]79
[16ed726]80#else
81struct _aubio_resampler_t
82{
[e9270a4]83  void *dummy;
[16ed726]84};
85
86aubio_resampler_t *
87new_aubio_resampler (smpl_t ratio UNUSED, uint_t type UNUSED)
88{
89  AUBIO_ERR ("aubio was not compiled with libsamplerate\n");
90  return NULL;
91}
92
93void
[741bdda]94del_aubio_resampler (aubio_resampler_t * s UNUSED)
[16ed726]95{
96}
97
98void
[23493b5]99aubio_resampler_do (aubio_resampler_t * s UNUSED, const fvec_t * input UNUSED, fvec_t * output UNUSED)
[16ed726]100{
101}
[b093845]102#endif /* HAVE_SAMPLERATE */
Note: See TracBrowser for help on using the repository browser.