[9316173] | 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" |
---|
[4865e4b] | 24 | #include "fmat.h" |
---|
[9316173] | 25 | #include "io/source.h" |
---|
[549928e] | 26 | #ifdef HAVE_LIBAV |
---|
[1b0755d] | 27 | #include "io/source_avcodec.h" |
---|
[549928e] | 28 | #endif /* HAVE_LIBAV */ |
---|
[9209c79] | 29 | #ifdef HAVE_SOURCE_APPLE_AUDIO |
---|
[c9b99fd] | 30 | #include "io/source_apple_audio.h" |
---|
[9209c79] | 31 | #endif /* HAVE_SOURCE_APPLE_AUDIO */ |
---|
[afbd7e7] | 32 | #ifdef HAVE_SNDFILE |
---|
| 33 | #include "io/source_sndfile.h" |
---|
[1b0755d] | 34 | #endif /* HAVE_SNDFILE */ |
---|
[52efae1] | 35 | #ifdef HAVE_WAVREAD |
---|
| 36 | #include "io/source_wavread.h" |
---|
| 37 | #endif /* HAVE_WAVREAD */ |
---|
[1b0755d] | 38 | |
---|
| 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); |
---|
[857f8871] | 43 | typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s); |
---|
[1b0755d] | 44 | typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek); |
---|
[422452b] | 45 | typedef uint_t (*aubio_source_close_t)(aubio_source_t * s); |
---|
[082c88b] | 46 | typedef void (*del_aubio_source_t)(aubio_source_t * s); |
---|
[9316173] | 47 | |
---|
| 48 | struct _aubio_source_t { |
---|
[3504dfe7] | 49 | void *source; |
---|
[1b0755d] | 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; |
---|
[857f8871] | 54 | aubio_source_get_duration_t s_get_duration; |
---|
[1b0755d] | 55 | aubio_source_seek_t s_seek; |
---|
[422452b] | 56 | aubio_source_close_t s_close; |
---|
[1b0755d] | 57 | del_aubio_source_t s_del; |
---|
[9316173] | 58 | }; |
---|
| 59 | |
---|
[ae5d58a] | 60 | aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) { |
---|
[3504dfe7] | 61 | aubio_source_t * s = AUBIO_NEW(aubio_source_t); |
---|
[de66709] | 62 | #ifdef HAVE_LIBAV |
---|
[1b0755d] | 63 | s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); |
---|
| 64 | if (s->source) { |
---|
| 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); |
---|
[857f8871] | 69 | s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration); |
---|
[1b0755d] | 70 | s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek); |
---|
[422452b] | 71 | s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close); |
---|
[1b0755d] | 72 | s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec); |
---|
| 73 | return s; |
---|
| 74 | } |
---|
[549928e] | 75 | #endif /* HAVE_LIBAV */ |
---|
[9209c79] | 76 | #ifdef HAVE_SOURCE_APPLE_AUDIO |
---|
[42e6a5e] | 77 | s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); |
---|
[1b0755d] | 78 | if (s->source) { |
---|
| 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); |
---|
[857f8871] | 83 | s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration); |
---|
[1b0755d] | 84 | s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek); |
---|
[422452b] | 85 | s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close); |
---|
[1b0755d] | 86 | s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio); |
---|
| 87 | return s; |
---|
| 88 | } |
---|
[9209c79] | 89 | #endif /* HAVE_SOURCE_APPLE_AUDIO */ |
---|
[de66709] | 90 | #ifdef HAVE_SNDFILE |
---|
[42e6a5e] | 91 | s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); |
---|
[1b0755d] | 92 | if (s->source) { |
---|
| 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); |
---|
[857f8871] | 97 | s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration); |
---|
[1b0755d] | 98 | s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek); |
---|
[422452b] | 99 | s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close); |
---|
[1b0755d] | 100 | s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile); |
---|
| 101 | return s; |
---|
| 102 | } |
---|
[afbd7e7] | 103 | #endif /* HAVE_SNDFILE */ |
---|
[de66709] | 104 | #ifdef HAVE_WAVREAD |
---|
[52efae1] | 105 | s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size); |
---|
| 106 | if (s->source) { |
---|
| 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); |
---|
[857f8871] | 111 | s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration); |
---|
[52efae1] | 112 | s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek); |
---|
[422452b] | 113 | s->s_close = (aubio_source_close_t)(aubio_source_wavread_close); |
---|
[52efae1] | 114 | s->s_del = (del_aubio_source_t)(del_aubio_source_wavread); |
---|
| 115 | return s; |
---|
| 116 | } |
---|
| 117 | #endif /* HAVE_WAVREAD */ |
---|
[cb1fad8] | 118 | //AUBIO_ERROR("source: failed creating aubio source with %s" |
---|
| 119 | // " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size); |
---|
[e3b5962] | 120 | AUBIO_FREE(s); |
---|
| 121 | return NULL; |
---|
[9316173] | 122 | } |
---|
| 123 | |
---|
[3504dfe7] | 124 | void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) { |
---|
[1b0755d] | 125 | s->s_do((void *)s->source, data, read); |
---|
[9316173] | 126 | } |
---|
| 127 | |
---|
[4865e4b] | 128 | void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) { |
---|
[1b0755d] | 129 | s->s_do_multi((void *)s->source, data, read); |
---|
[4865e4b] | 130 | } |
---|
| 131 | |
---|
[422452b] | 132 | uint_t aubio_source_close(aubio_source_t * s) { |
---|
| 133 | return s->s_close((void *)s->source); |
---|
| 134 | } |
---|
| 135 | |
---|
[9316173] | 136 | void del_aubio_source(aubio_source_t * s) { |
---|
[32df658] | 137 | if (!s) return; |
---|
[1b0755d] | 138 | s->s_del((void *)s->source); |
---|
[3504dfe7] | 139 | AUBIO_FREE(s); |
---|
[9316173] | 140 | } |
---|
| 141 | |
---|
[944c7e1] | 142 | uint_t aubio_source_get_samplerate(aubio_source_t * s) { |
---|
[1b0755d] | 143 | return s->s_get_samplerate((void *)s->source); |
---|
[944c7e1] | 144 | } |
---|
| 145 | |
---|
[4865e4b] | 146 | uint_t aubio_source_get_channels(aubio_source_t * s) { |
---|
[1b0755d] | 147 | return s->s_get_channels((void *)s->source); |
---|
[4865e4b] | 148 | } |
---|
| 149 | |
---|
[857f8871] | 150 | uint_t aubio_source_get_duration(aubio_source_t *s) { |
---|
| 151 | return s->s_get_duration((void *)s->source); |
---|
| 152 | } |
---|
| 153 | |
---|
[7982203] | 154 | uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) { |
---|
[1b0755d] | 155 | return s->s_seek((void *)s->source, seek); |
---|
[7982203] | 156 | } |
---|