source: src/temporal/resampler.c @ b8ee46c

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since b8ee46c was 16ed726, checked in by Paul Brossier <piem@piem.org>, 15 years ago

src/temporal/resampler.h: add dummy functions in case samplerate is not built in

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