1 | /* |
---|
2 | Copyright (C) 2012-2014 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 "fmat.h" |
---|
24 | #include "io/sink.h" |
---|
25 | #ifdef HAVE_SINK_APPLE_AUDIO |
---|
26 | #include "io/sink_apple_audio.h" |
---|
27 | #endif /* HAVE_SINK_APPLE_AUDIO */ |
---|
28 | #ifdef HAVE_SNDFILE |
---|
29 | #include "io/sink_sndfile.h" |
---|
30 | #endif |
---|
31 | #ifdef HAVE_WAVWRITE |
---|
32 | #include "io/sink_wavwrite.h" |
---|
33 | #endif |
---|
34 | |
---|
35 | typedef void (*aubio_sink_do_t)(aubio_sink_t * s, fvec_t * data, uint_t write); |
---|
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); |
---|
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); |
---|
41 | typedef uint_t (*aubio_sink_close_t)(aubio_sink_t * s); |
---|
42 | typedef void (*del_aubio_sink_t)(aubio_sink_t * s); |
---|
43 | |
---|
44 | struct _aubio_sink_t { |
---|
45 | void *sink; |
---|
46 | aubio_sink_do_t s_do; |
---|
47 | aubio_sink_do_multi_t s_do_multi; |
---|
48 | aubio_sink_preset_samplerate_t s_preset_samplerate; |
---|
49 | aubio_sink_preset_channels_t s_preset_channels; |
---|
50 | aubio_sink_get_samplerate_t s_get_samplerate; |
---|
51 | aubio_sink_get_channels_t s_get_channels; |
---|
52 | aubio_sink_close_t s_close; |
---|
53 | del_aubio_sink_t s_del; |
---|
54 | }; |
---|
55 | |
---|
56 | aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) { |
---|
57 | aubio_sink_t * s = AUBIO_NEW(aubio_sink_t); |
---|
58 | #ifdef HAVE_SINK_APPLE_AUDIO |
---|
59 | s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate); |
---|
60 | if (s->sink) { |
---|
61 | s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do); |
---|
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); |
---|
67 | s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close); |
---|
68 | s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio); |
---|
69 | return s; |
---|
70 | } |
---|
71 | #endif /* HAVE_SINK_APPLE_AUDIO */ |
---|
72 | #ifdef HAVE_SNDFILE |
---|
73 | s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate); |
---|
74 | if (s->sink) { |
---|
75 | s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do); |
---|
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); |
---|
81 | s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close); |
---|
82 | s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile); |
---|
83 | return s; |
---|
84 | } |
---|
85 | #endif /* HAVE_SNDFILE */ |
---|
86 | #ifdef HAVE_WAVWRITE |
---|
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); |
---|
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); |
---|
95 | s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close); |
---|
96 | s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite); |
---|
97 | return s; |
---|
98 | } |
---|
99 | #endif /* HAVE_WAVWRITE */ |
---|
100 | //AUBIO_ERROR("sink: failed creating '%s' with samplerate %dHz\n", |
---|
101 | // uri, samplerate); |
---|
102 | AUBIO_FREE(s); |
---|
103 | return NULL; |
---|
104 | } |
---|
105 | |
---|
106 | void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) { |
---|
107 | s->s_do((void *)s->sink, write_data, write); |
---|
108 | } |
---|
109 | |
---|
110 | void aubio_sink_do_multi(aubio_sink_t * s, fmat_t * write_data, uint_t write) { |
---|
111 | s->s_do_multi((void *)s->sink, write_data, write); |
---|
112 | } |
---|
113 | |
---|
114 | uint_t aubio_sink_preset_samplerate(aubio_sink_t * s, uint_t samplerate) { |
---|
115 | return s->s_preset_samplerate((void *)s->sink, samplerate); |
---|
116 | } |
---|
117 | |
---|
118 | uint_t aubio_sink_preset_channels(aubio_sink_t * s, uint_t channels) { |
---|
119 | return s->s_preset_channels((void *)s->sink, channels); |
---|
120 | } |
---|
121 | |
---|
122 | uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) { |
---|
123 | return s->s_get_samplerate((void *)s->sink); |
---|
124 | } |
---|
125 | |
---|
126 | uint_t aubio_sink_get_channels(const aubio_sink_t * s) { |
---|
127 | return s->s_get_channels((void *)s->sink); |
---|
128 | } |
---|
129 | |
---|
130 | uint_t aubio_sink_close(aubio_sink_t *s) { |
---|
131 | return s->s_close((void *)s->sink); |
---|
132 | } |
---|
133 | |
---|
134 | void del_aubio_sink(aubio_sink_t * s) { |
---|
135 | if (!s) return; |
---|
136 | s->s_del((void *)s->sink); |
---|
137 | AUBIO_FREE(s); |
---|
138 | return; |
---|
139 | } |
---|