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