source: src/io/sink.c @ ea7428a

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

src/: use #ifdef HAVE_FOO, not #if HAVE_FOO

  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[9316173]1/*
[4ed4b1f]2  Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org>
[9316173]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#include "aubio_priv.h"
23#include "fvec.h"
[4ed4b1f]24#include "fmat.h"
[9316173]25#include "io/sink.h"
[9209c79]26#ifdef HAVE_SINK_APPLE_AUDIO
[8aed26d]27#include "io/sink_apple_audio.h"
[9209c79]28#endif /* HAVE_SINK_APPLE_AUDIO */
[8aed26d]29#ifdef HAVE_SNDFILE
30#include "io/sink_sndfile.h"
31#endif
[52ca8a3]32#ifdef HAVE_WAVWRITE
33#include "io/sink_wavwrite.h"
34#endif
[9316173]35
[4b7747d]36typedef void (*aubio_sink_do_t)(aubio_sink_t * s, fvec_t * data, uint_t write);
[4ed4b1f]37typedef void (*aubio_sink_do_multi_t)(aubio_sink_t * s, fmat_t * data, uint_t write);
38typedef uint_t (*aubio_sink_preset_samplerate_t)(aubio_sink_t * s, uint_t samplerate);
39typedef uint_t (*aubio_sink_preset_channels_t)(aubio_sink_t * s, uint_t channels);
[4b7747d]40typedef uint_t (*aubio_sink_get_samplerate_t)(aubio_sink_t * s);
41typedef uint_t (*aubio_sink_get_channels_t)(aubio_sink_t * s);
[a9fd272]42typedef uint_t (*aubio_sink_close_t)(aubio_sink_t * s);
[082c88b]43typedef void (*del_aubio_sink_t)(aubio_sink_t * s);
[4b7747d]44
[9316173]45struct _aubio_sink_t { 
[8aed26d]46  void *sink;
[4b7747d]47  aubio_sink_do_t s_do;
48  aubio_sink_do_multi_t s_do_multi;
[4ed4b1f]49  aubio_sink_preset_samplerate_t s_preset_samplerate;
50  aubio_sink_preset_channels_t s_preset_channels;
[4b7747d]51  aubio_sink_get_samplerate_t s_get_samplerate;
52  aubio_sink_get_channels_t s_get_channels;
[a9fd272]53  aubio_sink_close_t s_close;
[4b7747d]54  del_aubio_sink_t s_del;
[9316173]55};
56
[ae5d58a]57aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
[4d75b46]58  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
[9209c79]59#ifdef HAVE_SINK_APPLE_AUDIO
[8aed26d]60  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
[4b7747d]61  if (s->sink) {
62    s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do);
[4ed4b1f]63    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_apple_audio_do_multi);
64    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_apple_audio_preset_samplerate);
65    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_apple_audio_preset_channels);
66    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_apple_audio_get_samplerate);
67    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_apple_audio_get_channels);
[a9fd272]68    s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close);
[4b7747d]69    s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio);
70    return s;
71  }
[9209c79]72#endif /* HAVE_SINK_APPLE_AUDIO */
[de66709]73#ifdef HAVE_SNDFILE
[8aed26d]74  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
[4b7747d]75  if (s->sink) {
76    s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do);
[4ed4b1f]77    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_sndfile_do_multi);
78    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_sndfile_preset_samplerate);
79    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_sndfile_preset_channels);
80    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_sndfile_get_samplerate);
81    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_sndfile_get_channels);
[a9fd272]82    s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close);
[4b7747d]83    s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile);
84    return s;
85  }
[8aed26d]86#endif /* HAVE_SNDFILE */
[de66709]87#ifdef HAVE_WAVWRITE
[52ca8a3]88  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
89  if (s->sink) {
90    s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do);
[4ed4b1f]91    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_wavwrite_do_multi);
92    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_wavwrite_preset_samplerate);
93    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_wavwrite_preset_channels);
94    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_wavwrite_get_samplerate);
95    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_wavwrite_get_channels);
[a9fd272]96    s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close);
[52ca8a3]97    s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite);
98    return s;
99  }
100#endif /* HAVE_WAVWRITE */
[a9fd272]101  AUBIO_ERROR("sink: failed creating %s with samplerate %dHz\n",
102      uri, samplerate);
[779966b]103  AUBIO_FREE(s);
104  return NULL;
[9316173]105}
106
[8aed26d]107void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) {
[4b7747d]108  s->s_do((void *)s->sink, write_data, write);
[9316173]109}
110
[4ed4b1f]111void aubio_sink_do_multi(aubio_sink_t * s, fmat_t * write_data, uint_t write) {
112  s->s_do_multi((void *)s->sink, write_data, write);
113}
114
115uint_t aubio_sink_preset_samplerate(aubio_sink_t * s, uint_t samplerate) {
116  return s->s_preset_samplerate((void *)s->sink, samplerate);
117}
118
119uint_t aubio_sink_preset_channels(aubio_sink_t * s, uint_t channels) {
120  return s->s_preset_channels((void *)s->sink, channels);
121}
122
[ae5d58a]123uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) {
[4ed4b1f]124  return s->s_get_samplerate((void *)s->sink);
125}
126
[ae5d58a]127uint_t aubio_sink_get_channels(const aubio_sink_t * s) {
[4ed4b1f]128  return s->s_get_channels((void *)s->sink);
129}
130
[a9fd272]131uint_t aubio_sink_close(aubio_sink_t *s) {
132  return s->s_close((void *)s->sink);
133}
134
[9316173]135void del_aubio_sink(aubio_sink_t * s) {
[779966b]136  if (!s) return;
[4b7747d]137  s->s_del((void *)s->sink);
[4d75b46]138  AUBIO_FREE(s);
[9316173]139  return;
140}
Note: See TracBrowser for help on using the repository browser.