1 | /* |
---|
2 | Copyright (C) 2012 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/source.h" |
---|
26 | #ifdef HAVE_LIBAV |
---|
27 | #include "io/source_avcodec.h" |
---|
28 | #endif /* HAVE_LIBAV */ |
---|
29 | #ifdef __APPLE__ |
---|
30 | #include "io/source_apple_audio.h" |
---|
31 | #endif /* __APPLE__ */ |
---|
32 | #ifdef HAVE_SNDFILE |
---|
33 | #include "io/source_sndfile.h" |
---|
34 | #endif /* HAVE_SNDFILE */ |
---|
35 | |
---|
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); |
---|
42 | |
---|
43 | struct _aubio_source_t { |
---|
44 | void *source; |
---|
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; |
---|
51 | }; |
---|
52 | |
---|
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); |
---|
55 | #if HAVE_LIBAV |
---|
56 | s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); |
---|
57 | if (s->source) { |
---|
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); |
---|
64 | return s; |
---|
65 | } |
---|
66 | #endif /* HAVE_LIBAV */ |
---|
67 | #ifdef __APPLE__ |
---|
68 | s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); |
---|
69 | if (s->source) { |
---|
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); |
---|
76 | return s; |
---|
77 | } |
---|
78 | #endif /* __APPLE__ */ |
---|
79 | #if HAVE_SNDFILE |
---|
80 | s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); |
---|
81 | if (s->source) { |
---|
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); |
---|
88 | return s; |
---|
89 | } |
---|
90 | #endif /* HAVE_SNDFILE */ |
---|
91 | AUBIO_ERROR("failed creating aubio source with %s\n", uri); |
---|
92 | AUBIO_FREE(s); |
---|
93 | return NULL; |
---|
94 | } |
---|
95 | |
---|
96 | void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) { |
---|
97 | s->s_do((void *)s->source, data, read); |
---|
98 | } |
---|
99 | |
---|
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); |
---|
102 | } |
---|
103 | |
---|
104 | void del_aubio_source(aubio_source_t * s) { |
---|
105 | if (!s) return; |
---|
106 | s->s_del((void *)s->source); |
---|
107 | AUBIO_FREE(s); |
---|
108 | } |
---|
109 | |
---|
110 | uint_t aubio_source_get_samplerate(aubio_source_t * s) { |
---|
111 | return s->s_get_samplerate((void *)s->source); |
---|
112 | } |
---|
113 | |
---|
114 | uint_t aubio_source_get_channels(aubio_source_t * s) { |
---|
115 | return s->s_get_channels((void *)s->source); |
---|
116 | } |
---|
117 | |
---|
118 | uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) { |
---|
119 | return s->s_seek((void *)s->source, seek); |
---|
120 | } |
---|