source: src/io/sink.c @ 1dfe409

feature/autosinkfeature/cnnfeature/crepefix/ffmpeg5
Last change on this file since 1dfe409 was 1dfe409, checked in by Paul Brossier <piem@piem.org>, 5 years ago

Merge branch 'master' into feature/autosink

  • Property mode set to 100644
File size: 9.1 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 "aubio_priv.h"
22#include "fvec.h"
[4ed4b1f]23#include "fmat.h"
[9316173]24#include "io/sink.h"
[9209c79]25#ifdef HAVE_SINK_APPLE_AUDIO
[8aed26d]26#include "io/sink_apple_audio.h"
[9209c79]27#endif /* HAVE_SINK_APPLE_AUDIO */
[8aed26d]28#ifdef HAVE_SNDFILE
29#include "io/sink_sndfile.h"
30#endif
[52ca8a3]31#ifdef HAVE_WAVWRITE
32#include "io/sink_wavwrite.h"
33#endif
[9316173]34
[4b7747d]35typedef void (*aubio_sink_do_t)(aubio_sink_t * s, fvec_t * data, uint_t write);
[4ed4b1f]36typedef void (*aubio_sink_do_multi_t)(aubio_sink_t * s, fmat_t * data, uint_t write);
37typedef uint_t (*aubio_sink_preset_samplerate_t)(aubio_sink_t * s, uint_t samplerate);
38typedef uint_t (*aubio_sink_preset_channels_t)(aubio_sink_t * s, uint_t channels);
[4b7747d]39typedef uint_t (*aubio_sink_get_samplerate_t)(aubio_sink_t * s);
40typedef uint_t (*aubio_sink_get_channels_t)(aubio_sink_t * s);
[a9fd272]41typedef uint_t (*aubio_sink_close_t)(aubio_sink_t * s);
[082c88b]42typedef void (*del_aubio_sink_t)(aubio_sink_t * s);
[4b7747d]43
[9316173]44struct _aubio_sink_t { 
[8aed26d]45  void *sink;
[4b7747d]46  aubio_sink_do_t s_do;
47  aubio_sink_do_multi_t s_do_multi;
[4ed4b1f]48  aubio_sink_preset_samplerate_t s_preset_samplerate;
49  aubio_sink_preset_channels_t s_preset_channels;
[4b7747d]50  aubio_sink_get_samplerate_t s_get_samplerate;
51  aubio_sink_get_channels_t s_get_channels;
[a9fd272]52  aubio_sink_close_t s_close;
[4b7747d]53  del_aubio_sink_t s_del;
[9316173]54};
55
[20ce2ad]56extern uint_t aubio_str_path_has_extension(const char_t *filename,
57    const char_t *pattern);
58
[56174a2]59#ifdef HAVE_VORBISENC
60typedef struct _aubio_sink_vorbis_t aubio_sink_vorbis_t;
61extern aubio_sink_vorbis_t * new_aubio_sink_vorbis(const char_t *uri,
62    uint_t samplerate);
63extern void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s);
64extern uint_t aubio_sink_vorbis_open(aubio_sink_vorbis_t *s);
65extern uint_t aubio_sink_vorbis_close(aubio_sink_vorbis_t *s);
66extern uint_t aubio_sink_vorbis_preset_channels(aubio_sink_vorbis_t *s,
67    uint_t channels);
68extern uint_t aubio_sink_vorbis_preset_samplerate(aubio_sink_vorbis_t *s,
69    uint_t samplerate);
70extern uint_t aubio_sink_vorbis_get_channels(aubio_sink_vorbis_t *s);
71extern uint_t aubio_sink_vorbis_get_samplerate(aubio_sink_vorbis_t *s);
72extern void aubio_sink_vorbis_do(aubio_sink_vorbis_t *s, fvec_t*
73    write_data, uint_t write);
74extern void aubio_sink_vorbis_do_multi(aubio_sink_vorbis_t *s, fmat_t*
75    write_data, uint_t write);
76#endif /* HAVE_VORBISENC */
77
[1a30c43]78#ifdef HAVE_FLAC
79typedef struct _aubio_sink_flac_t aubio_sink_flac_t;
80extern aubio_sink_flac_t * new_aubio_sink_flac(const char_t *uri,
81    uint_t samplerate);
82extern void del_aubio_sink_flac (aubio_sink_flac_t *s);
83extern uint_t aubio_sink_flac_open(aubio_sink_flac_t *s);
84extern uint_t aubio_sink_flac_close(aubio_sink_flac_t *s);
85extern uint_t aubio_sink_flac_preset_channels(aubio_sink_flac_t *s,
86    uint_t channels);
87extern uint_t aubio_sink_flac_preset_samplerate(aubio_sink_flac_t *s,
88    uint_t samplerate);
89extern uint_t aubio_sink_flac_get_channels(aubio_sink_flac_t *s);
90extern uint_t aubio_sink_flac_get_samplerate(aubio_sink_flac_t *s);
91extern void aubio_sink_flac_do(aubio_sink_flac_t *s, fvec_t*
92    write_data, uint_t write);
93extern void aubio_sink_flac_do_multi(aubio_sink_flac_t *s, fmat_t*
94    write_data, uint_t write);
95#endif /* HAVE_FLAC */
96
[ae5d58a]97aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
[4d75b46]98  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
[56174a2]99
100#ifdef HAVE_VORBISENC
101  // check if this uri could be for us
[20ce2ad]102  if (aubio_str_path_has_extension(uri, "ogg")) {
[56174a2]103    s->sink = (void *)new_aubio_sink_vorbis(uri, samplerate);
104    if (s->sink) {
105      s->s_do = (aubio_sink_do_t)(aubio_sink_vorbis_do);
106      s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_vorbis_do_multi);
107      s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_vorbis_preset_samplerate);
108      s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_vorbis_preset_channels);
109      s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_vorbis_get_samplerate);
110      s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_vorbis_get_channels);
111      s->s_close = (aubio_sink_close_t)(aubio_sink_vorbis_close);
112      s->s_del = (del_aubio_sink_t)(del_aubio_sink_vorbis);
113      return s;
114    }
115  }
116#endif /* HAVE_VORBISENC */
117
[1a30c43]118#ifdef HAVE_FLAC
119  // check if this uri could be for us
[20ce2ad]120  if (aubio_str_path_has_extension(uri, "flac")) {
[1a30c43]121    s->sink = (void *)new_aubio_sink_flac(uri, samplerate);
122    if (s->sink) {
123      s->s_do = (aubio_sink_do_t)(aubio_sink_flac_do);
124      s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_flac_do_multi);
125      s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_flac_preset_samplerate);
126      s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_flac_preset_channels);
127      s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_flac_get_samplerate);
128      s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_flac_get_channels);
129      s->s_close = (aubio_sink_close_t)(aubio_sink_flac_close);
130      s->s_del = (del_aubio_sink_t)(del_aubio_sink_flac);
131      return s;
132    }
133  }
134#endif /* HAVE_FLAC */
135
[9209c79]136#ifdef HAVE_SINK_APPLE_AUDIO
[8aed26d]137  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
[4b7747d]138  if (s->sink) {
139    s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do);
[4ed4b1f]140    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_apple_audio_do_multi);
141    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_apple_audio_preset_samplerate);
142    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_apple_audio_preset_channels);
143    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_apple_audio_get_samplerate);
144    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_apple_audio_get_channels);
[a9fd272]145    s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close);
[4b7747d]146    s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio);
147    return s;
148  }
[9209c79]149#endif /* HAVE_SINK_APPLE_AUDIO */
[de66709]150#ifdef HAVE_SNDFILE
[8aed26d]151  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
[4b7747d]152  if (s->sink) {
153    s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do);
[4ed4b1f]154    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_sndfile_do_multi);
155    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_sndfile_preset_samplerate);
156    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_sndfile_preset_channels);
157    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_sndfile_get_samplerate);
158    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_sndfile_get_channels);
[a9fd272]159    s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close);
[4b7747d]160    s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile);
161    return s;
162  }
[8aed26d]163#endif /* HAVE_SNDFILE */
[de66709]164#ifdef HAVE_WAVWRITE
[52ca8a3]165  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
166  if (s->sink) {
167    s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do);
[4ed4b1f]168    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_wavwrite_do_multi);
169    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_wavwrite_preset_samplerate);
170    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_wavwrite_preset_channels);
171    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_wavwrite_get_samplerate);
172    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_wavwrite_get_channels);
[a9fd272]173    s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close);
[52ca8a3]174    s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite);
175    return s;
176  }
177#endif /* HAVE_WAVWRITE */
[dcecaec]178#if !defined(HAVE_WAVWRITE) && \
179  !defined(HAVE_SNDFILE) && \
[2de7cfa]180  !defined(HAVE_SINK_APPLE_AUDIO) && \
181  !defined(HAVE_VORBISENC) && \
182  !defined(HAVE_FLAC)
[dcecaec]183  AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
[ad2eac2]184#endif
[0f5d372]185  del_aubio_sink(s);
[779966b]186  return NULL;
[9316173]187}
188
[8aed26d]189void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) {
[4b7747d]190  s->s_do((void *)s->sink, write_data, write);
[9316173]191}
192
[4ed4b1f]193void aubio_sink_do_multi(aubio_sink_t * s, fmat_t * write_data, uint_t write) {
194  s->s_do_multi((void *)s->sink, write_data, write);
195}
196
197uint_t aubio_sink_preset_samplerate(aubio_sink_t * s, uint_t samplerate) {
198  return s->s_preset_samplerate((void *)s->sink, samplerate);
199}
200
201uint_t aubio_sink_preset_channels(aubio_sink_t * s, uint_t channels) {
202  return s->s_preset_channels((void *)s->sink, channels);
203}
204
[ae5d58a]205uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) {
[4ed4b1f]206  return s->s_get_samplerate((void *)s->sink);
207}
208
[ae5d58a]209uint_t aubio_sink_get_channels(const aubio_sink_t * s) {
[4ed4b1f]210  return s->s_get_channels((void *)s->sink);
211}
212
[a9fd272]213uint_t aubio_sink_close(aubio_sink_t *s) {
214  return s->s_close((void *)s->sink);
215}
216
[9316173]217void del_aubio_sink(aubio_sink_t * s) {
[ba9e3a8]218  //AUBIO_ASSERT(s);
[2bfbf33]219  if (s && s->s_del && s->sink)
[0f5d372]220    s->s_del((void *)s->sink);
[4d75b46]221  AUBIO_FREE(s);
[9316173]222}
Note: See TracBrowser for help on using the repository browser.