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/>.
22 #include "aubio_priv.h"
25 #include "io/source.h"
27 #include "io/source_avcodec.h"
28 #endif /* HAVE_LIBAV */
30 #include "io/source_apple_audio.h"
31 #endif /* __APPLE__ */
33 #include "io/source_sndfile.h"
34 #endif /* HAVE_SNDFILE */
36 #include "io/source_wavread.h"
37 #endif /* HAVE_WAVREAD */
39 typedef void (*aubio_source_do_t)(aubio_source_t * s, fvec_t * data, uint_t * read);
40 typedef void (*aubio_source_do_multi_t)(aubio_source_t * s, fmat_t * data, uint_t * read);
41 typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
42 typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
43 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
44 typedef uint_t (*del_aubio_source_t)(aubio_source_t * s);
46 struct _aubio_source_t {
48 aubio_source_do_t s_do;
49 aubio_source_do_multi_t s_do_multi;
50 aubio_source_get_samplerate_t s_get_samplerate;
51 aubio_source_get_channels_t s_get_channels;
52 aubio_source_seek_t s_seek;
53 del_aubio_source_t s_del;
56 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
57 aubio_source_t * s = AUBIO_NEW(aubio_source_t);
59 s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
61 s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
62 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
63 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
64 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
65 s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
66 s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
69 #endif /* HAVE_LIBAV */
71 s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
73 s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
74 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
75 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
76 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
77 s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
78 s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
81 #endif /* __APPLE__ */
83 s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
85 s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
86 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
87 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
88 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
89 s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
90 s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
93 #endif /* HAVE_SNDFILE */
95 s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
97 s->s_do = (aubio_source_do_t)(aubio_source_wavread_do);
98 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_wavread_do_multi);
99 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
100 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
101 s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
102 s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
105 #endif /* HAVE_WAVREAD */
106 AUBIO_ERROR("failed creating aubio source with %s\n", uri);
111 void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
112 s->s_do((void *)s->source, data, read);
115 void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
116 s->s_do_multi((void *)s->source, data, read);
119 void del_aubio_source(aubio_source_t * s) {
121 s->s_del((void *)s->source);
125 uint_t aubio_source_get_samplerate(aubio_source_t * s) {
126 return s->s_get_samplerate((void *)s->source);
129 uint_t aubio_source_get_channels(aubio_source_t * s) {
130 return s->s_get_channels((void *)s->source);
133 uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
134 return s->s_seek((void *)s->source, seek);