[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] | 35 | typedef void (*aubio_sink_do_t)(aubio_sink_t * s, fvec_t * data, uint_t write); |
---|
[4ed4b1f] | 36 | typedef void (*aubio_sink_do_multi_t)(aubio_sink_t * s, fmat_t * data, uint_t write); |
---|
| 37 | typedef uint_t (*aubio_sink_preset_samplerate_t)(aubio_sink_t * s, uint_t samplerate); |
---|
| 38 | typedef uint_t (*aubio_sink_preset_channels_t)(aubio_sink_t * s, uint_t channels); |
---|
[4b7747d] | 39 | typedef uint_t (*aubio_sink_get_samplerate_t)(aubio_sink_t * s); |
---|
| 40 | typedef uint_t (*aubio_sink_get_channels_t)(aubio_sink_t * s); |
---|
[a9fd272] | 41 | typedef uint_t (*aubio_sink_close_t)(aubio_sink_t * s); |
---|
[082c88b] | 42 | typedef void (*del_aubio_sink_t)(aubio_sink_t * s); |
---|
[4b7747d] | 43 | |
---|
[9316173] | 44 | struct _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 | |
---|
[ae5d58a] | 56 | aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) { |
---|
[4d75b46] | 57 | aubio_sink_t * s = AUBIO_NEW(aubio_sink_t); |
---|
[9209c79] | 58 | #ifdef HAVE_SINK_APPLE_AUDIO |
---|
[8aed26d] | 59 | s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate); |
---|
[4b7747d] | 60 | if (s->sink) { |
---|
| 61 | s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do); |
---|
[4ed4b1f] | 62 | s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_apple_audio_do_multi); |
---|
| 63 | s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_apple_audio_preset_samplerate); |
---|
| 64 | s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_apple_audio_preset_channels); |
---|
| 65 | s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_apple_audio_get_samplerate); |
---|
| 66 | s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_apple_audio_get_channels); |
---|
[a9fd272] | 67 | s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close); |
---|
[4b7747d] | 68 | s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio); |
---|
| 69 | return s; |
---|
| 70 | } |
---|
[9209c79] | 71 | #endif /* HAVE_SINK_APPLE_AUDIO */ |
---|
[de66709] | 72 | #ifdef HAVE_SNDFILE |
---|
[8aed26d] | 73 | s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate); |
---|
[4b7747d] | 74 | if (s->sink) { |
---|
| 75 | s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do); |
---|
[4ed4b1f] | 76 | s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_sndfile_do_multi); |
---|
| 77 | s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_sndfile_preset_samplerate); |
---|
| 78 | s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_sndfile_preset_channels); |
---|
| 79 | s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_sndfile_get_samplerate); |
---|
| 80 | s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_sndfile_get_channels); |
---|
[a9fd272] | 81 | s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close); |
---|
[4b7747d] | 82 | s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile); |
---|
| 83 | return s; |
---|
| 84 | } |
---|
[8aed26d] | 85 | #endif /* HAVE_SNDFILE */ |
---|
[de66709] | 86 | #ifdef HAVE_WAVWRITE |
---|
[52ca8a3] | 87 | s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate); |
---|
| 88 | if (s->sink) { |
---|
| 89 | s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do); |
---|
[4ed4b1f] | 90 | s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_wavwrite_do_multi); |
---|
| 91 | s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_wavwrite_preset_samplerate); |
---|
| 92 | s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_wavwrite_preset_channels); |
---|
| 93 | s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_wavwrite_get_samplerate); |
---|
| 94 | s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_wavwrite_get_channels); |
---|
[a9fd272] | 95 | s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close); |
---|
[52ca8a3] | 96 | s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite); |
---|
| 97 | return s; |
---|
| 98 | } |
---|
| 99 | #endif /* HAVE_WAVWRITE */ |
---|
[dcecaec] | 100 | #if !defined(HAVE_WAVWRITE) && \ |
---|
| 101 | !defined(HAVE_SNDFILE) && \ |
---|
| 102 | !defined(HAVE_SINK_APPLE_AUDIO) |
---|
| 103 | AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate); |
---|
[ad2eac2] | 104 | #endif |
---|
[0f5d372] | 105 | del_aubio_sink(s); |
---|
[779966b] | 106 | return NULL; |
---|
[9316173] | 107 | } |
---|
| 108 | |
---|
[8aed26d] | 109 | void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) { |
---|
[4b7747d] | 110 | s->s_do((void *)s->sink, write_data, write); |
---|
[9316173] | 111 | } |
---|
| 112 | |
---|
[4ed4b1f] | 113 | void aubio_sink_do_multi(aubio_sink_t * s, fmat_t * write_data, uint_t write) { |
---|
| 114 | s->s_do_multi((void *)s->sink, write_data, write); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | uint_t aubio_sink_preset_samplerate(aubio_sink_t * s, uint_t samplerate) { |
---|
| 118 | return s->s_preset_samplerate((void *)s->sink, samplerate); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | uint_t aubio_sink_preset_channels(aubio_sink_t * s, uint_t channels) { |
---|
| 122 | return s->s_preset_channels((void *)s->sink, channels); |
---|
| 123 | } |
---|
| 124 | |
---|
[ae5d58a] | 125 | uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) { |
---|
[4ed4b1f] | 126 | return s->s_get_samplerate((void *)s->sink); |
---|
| 127 | } |
---|
| 128 | |
---|
[ae5d58a] | 129 | uint_t aubio_sink_get_channels(const aubio_sink_t * s) { |
---|
[4ed4b1f] | 130 | return s->s_get_channels((void *)s->sink); |
---|
| 131 | } |
---|
| 132 | |
---|
[a9fd272] | 133 | uint_t aubio_sink_close(aubio_sink_t *s) { |
---|
| 134 | return s->s_close((void *)s->sink); |
---|
| 135 | } |
---|
| 136 | |
---|
[9316173] | 137 | void del_aubio_sink(aubio_sink_t * s) { |
---|
[ba9e3a8] | 138 | //AUBIO_ASSERT(s); |
---|
[2bfbf33] | 139 | if (s && s->s_del && s->sink) |
---|
[0f5d372] | 140 | s->s_del((void *)s->sink); |
---|
[4d75b46] | 141 | AUBIO_FREE(s); |
---|
[9316173] | 142 | } |
---|