2 Copyright (C) 2012 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
21 #include "aubio_priv.h"
24 #include "io/source.h"
26 #include "io/source_avcodec.h"
27 #endif /* HAVE_LIBAV */
28 #ifdef HAVE_SOURCE_APPLE_AUDIO
29 #include "io/source_apple_audio.h"
30 #endif /* HAVE_SOURCE_APPLE_AUDIO */
32 #include "io/source_sndfile.h"
33 #endif /* HAVE_SNDFILE */
35 #include "io/source_wavread.h"
36 #endif /* HAVE_WAVREAD */
38 typedef void (*aubio_source_do_t)(aubio_source_t * s, fvec_t * data, uint_t * read);
39 typedef void (*aubio_source_do_multi_t)(aubio_source_t * s, fmat_t * data, uint_t * read);
40 typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
41 typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
42 typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s);
43 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
44 typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
45 typedef void (*del_aubio_source_t)(aubio_source_t * s);
47 struct _aubio_source_t {
49 aubio_source_do_t s_do;
50 aubio_source_do_multi_t s_do_multi;
51 aubio_source_get_samplerate_t s_get_samplerate;
52 aubio_source_get_channels_t s_get_channels;
53 aubio_source_get_duration_t s_get_duration;
54 aubio_source_seek_t s_seek;
55 aubio_source_close_t s_close;
56 del_aubio_source_t s_del;
59 aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
60 aubio_source_t * s = AUBIO_NEW(aubio_source_t);
62 s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
64 s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
65 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
66 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
67 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
68 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
69 s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
70 s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
71 s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
74 #endif /* HAVE_LIBAV */
75 #ifdef HAVE_SOURCE_APPLE_AUDIO
76 s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
78 s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
79 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
80 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
81 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
82 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
83 s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
84 s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
85 s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
88 #endif /* HAVE_SOURCE_APPLE_AUDIO */
90 s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
92 s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
93 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
94 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
95 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
96 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
97 s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
98 s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
99 s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
102 #endif /* HAVE_SNDFILE */
104 s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
106 s->s_do = (aubio_source_do_t)(aubio_source_wavread_do);
107 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_wavread_do_multi);
108 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
109 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
110 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
111 s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
112 s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
113 s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
116 #endif /* HAVE_WAVREAD */
117 #if !defined(HAVE_WAVREAD) && \
118 !defined(HAVE_LIBAV) && \
119 !defined(HAVE_SOURCE_APPLE_AUDIO) && \
120 !defined(HAVE_SNDFILE)
121 AUBIO_ERROR("source: failed creating with %s at %dHz with hop size %d"
122 " (no source built-in)\n", uri, samplerate, hop_size);
128 void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
129 s->s_do((void *)s->source, data, read);
132 void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
133 s->s_do_multi((void *)s->source, data, read);
136 uint_t aubio_source_close(aubio_source_t * s) {
137 return s->s_close((void *)s->source);
140 void del_aubio_source(aubio_source_t * s) {
142 if (s->s_del && s->source)
143 s->s_del((void *)s->source);
147 uint_t aubio_source_get_samplerate(aubio_source_t * s) {
148 return s->s_get_samplerate((void *)s->source);
151 uint_t aubio_source_get_channels(aubio_source_t * s) {
152 return s->s_get_channels((void *)s->source);
155 uint_t aubio_source_get_duration(aubio_source_t *s) {
156 return s->s_get_duration((void *)s->source);
159 uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
160 return s->s_seek((void *)s->source, seek);