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 typedef void (*aubio_source_do_t)(aubio_source_t * s, fvec_t * data, uint_t * read);
37 typedef void (*aubio_source_do_multi_t)(aubio_source_t * s, fmat_t * data, uint_t * read);
38 typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
39 typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
40 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
41 typedef uint_t (*del_aubio_source_t)(aubio_source_t * s);
43 struct _aubio_source_t {
45 aubio_source_do_t s_do;
46 aubio_source_do_multi_t s_do_multi;
47 aubio_source_get_samplerate_t s_get_samplerate;
48 aubio_source_get_channels_t s_get_channels;
49 aubio_source_seek_t s_seek;
50 del_aubio_source_t s_del;
53 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
54 aubio_source_t * s = AUBIO_NEW(aubio_source_t);
56 s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
58 s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
59 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
60 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
61 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
62 s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
63 s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
66 #endif /* HAVE_LIBAV */
68 s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
70 s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
71 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
72 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
73 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
74 s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
75 s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
78 #endif /* __APPLE__ */
80 s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
82 s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
83 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
84 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
85 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
86 s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
87 s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
90 #endif /* HAVE_SNDFILE */
91 AUBIO_ERROR("failed creating aubio source with %s\n", uri);
96 void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
97 s->s_do((void *)s->source, data, read);
100 void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
101 s->s_do_multi((void *)s->source, data, read);
104 void del_aubio_source(aubio_source_t * s) {
106 s->s_del((void *)s->source);
110 uint_t aubio_source_get_samplerate(aubio_source_t * s) {
111 return s->s_get_samplerate((void *)s->source);
114 uint_t aubio_source_get_channels(aubio_source_t * s) {
115 return s->s_get_channels((void *)s->source);
118 uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
119 return s->s_seek((void *)s->source, seek);