source: src/temporal/resampler.c @ 3388e1a

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

src/aubio_priv.h: move include config.h here

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