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 */
29 #ifdef HAVE_SOURCE_APPLE_AUDIO
30 #include "io/source_apple_audio.h"
31 #endif /* HAVE_SOURCE_APPLE_AUDIO */
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_get_duration_t)(aubio_source_t * s);
44 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
45 typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
46 typedef void (*del_aubio_source_t)(aubio_source_t * s);
48 struct _aubio_source_t {
50 aubio_source_do_t s_do;
51 aubio_source_do_multi_t s_do_multi;
52 aubio_source_get_samplerate_t s_get_samplerate;
53 aubio_source_get_channels_t s_get_channels;
54 aubio_source_get_duration_t s_get_duration;
55 aubio_source_seek_t s_seek;
56 aubio_source_close_t s_close;
57 del_aubio_source_t s_del;
60 aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
61 aubio_source_t * s = AUBIO_NEW(aubio_source_t);
63 s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
65 s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
66 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
67 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
68 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
69 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
70 s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
71 s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
72 s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
75 #endif /* HAVE_LIBAV */
76 #ifdef HAVE_SOURCE_APPLE_AUDIO
77 s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
79 s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
80 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
81 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
82 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
83 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
84 s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
85 s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
86 s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
89 #endif /* HAVE_SOURCE_APPLE_AUDIO */
91 s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
93 s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
94 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
95 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
96 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
97 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
98 s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
99 s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
100 s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
103 #endif /* HAVE_SNDFILE */
105 s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
107 s->s_do = (aubio_source_do_t)(aubio_source_wavread_do);
108 s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_wavread_do_multi);
109 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
110 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
111 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
112 s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
113 s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
114 s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
117 #endif /* HAVE_WAVREAD */
118 AUBIO_ERROR("source: failed creating aubio source with %s"
119 " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
124 void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
125 s->s_do((void *)s->source, data, read);
128 void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
129 s->s_do_multi((void *)s->source, data, read);
132 uint_t aubio_source_close(aubio_source_t * s) {
133 return s->s_close((void *)s->source);
136 void del_aubio_source(aubio_source_t * s) {
138 s->s_del((void *)s->source);
142 uint_t aubio_source_get_samplerate(aubio_source_t * s) {
143 return s->s_get_samplerate((void *)s->source);
146 uint_t aubio_source_get_channels(aubio_source_t * s) {
147 return s->s_get_channels((void *)s->source);
150 uint_t aubio_source_get_duration(aubio_source_t *s) {
151 return s->s_get_duration((void *)s->source);
154 uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
155 return s->s_seek((void *)s->source, seek);