[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 */ |
---|
[3504dfe7] | 29 | #ifdef __APPLE__ |
---|
[c9b99fd] | 30 | #include "io/source_apple_audio.h" |
---|
[3504dfe7] | 31 | #endif /* __APPLE__ */ |
---|
[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); |
---|
| 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); |
---|
[9316173] | 45 | |
---|
| 46 | struct _aubio_source_t { |
---|
[3504dfe7] | 47 | void *source; |
---|
[1b0755d] | 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; |
---|
[9316173] | 54 | }; |
---|
| 55 | |
---|
[afbd7e7] | 56 | aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) { |
---|
[3504dfe7] | 57 | aubio_source_t * s = AUBIO_NEW(aubio_source_t); |
---|
[549928e] | 58 | #if HAVE_LIBAV |
---|
[1b0755d] | 59 | s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); |
---|
| 60 | if (s->source) { |
---|
| 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); |
---|
| 67 | return s; |
---|
| 68 | } |
---|
[549928e] | 69 | #endif /* HAVE_LIBAV */ |
---|
[3504dfe7] | 70 | #ifdef __APPLE__ |
---|
[42e6a5e] | 71 | s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); |
---|
[1b0755d] | 72 | if (s->source) { |
---|
| 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); |
---|
| 79 | return s; |
---|
| 80 | } |
---|
| 81 | #endif /* __APPLE__ */ |
---|
[afbd7e7] | 82 | #if HAVE_SNDFILE |
---|
[42e6a5e] | 83 | s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); |
---|
[1b0755d] | 84 | if (s->source) { |
---|
| 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); |
---|
| 91 | return s; |
---|
| 92 | } |
---|
[afbd7e7] | 93 | #endif /* HAVE_SNDFILE */ |
---|
[52efae1] | 94 | #if HAVE_WAVREAD |
---|
| 95 | s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size); |
---|
| 96 | if (s->source) { |
---|
| 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); |
---|
| 103 | return s; |
---|
| 104 | } |
---|
| 105 | #endif /* HAVE_WAVREAD */ |
---|
[9a226ef] | 106 | AUBIO_ERROR("failed creating aubio source with %s\n", uri); |
---|
[e3b5962] | 107 | AUBIO_FREE(s); |
---|
| 108 | return NULL; |
---|
[9316173] | 109 | } |
---|
| 110 | |
---|
[3504dfe7] | 111 | void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) { |
---|
[1b0755d] | 112 | s->s_do((void *)s->source, data, read); |
---|
[9316173] | 113 | } |
---|
| 114 | |
---|
[4865e4b] | 115 | void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) { |
---|
[1b0755d] | 116 | s->s_do_multi((void *)s->source, data, read); |
---|
[4865e4b] | 117 | } |
---|
| 118 | |
---|
[9316173] | 119 | void del_aubio_source(aubio_source_t * s) { |
---|
[32df658] | 120 | if (!s) return; |
---|
[1b0755d] | 121 | s->s_del((void *)s->source); |
---|
[3504dfe7] | 122 | AUBIO_FREE(s); |
---|
[9316173] | 123 | } |
---|
| 124 | |
---|
[944c7e1] | 125 | uint_t aubio_source_get_samplerate(aubio_source_t * s) { |
---|
[1b0755d] | 126 | return s->s_get_samplerate((void *)s->source); |
---|
[944c7e1] | 127 | } |
---|
| 128 | |
---|
[4865e4b] | 129 | uint_t aubio_source_get_channels(aubio_source_t * s) { |
---|
[1b0755d] | 130 | return s->s_get_channels((void *)s->source); |
---|
[4865e4b] | 131 | } |
---|
| 132 | |
---|
[7982203] | 133 | uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) { |
---|
[1b0755d] | 134 | return s->s_seek((void *)s->source, seek); |
---|
[7982203] | 135 | } |
---|