source: src/io/source.c @ eef6335

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since eef6335 was a9516b3, checked in by Paul Brossier <piem@piem.org>, 8 years ago

src/io/source.c: add error message when aubio was compiled with no source

  • Property mode set to 100644
File size: 6.3 KB
Line 
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 "aubio_priv.h"
22#include "fvec.h"
23#include "fmat.h"
24#include "io/source.h"
25#ifdef HAVE_LIBAV
26#include "io/source_avcodec.h"
27#endif /* HAVE_LIBAV */
28#ifdef HAVE_SOURCE_APPLE_AUDIO
29#include "io/source_apple_audio.h"
30#endif /* HAVE_SOURCE_APPLE_AUDIO */
31#ifdef HAVE_SNDFILE
32#include "io/source_sndfile.h"
33#endif /* HAVE_SNDFILE */
34#ifdef HAVE_WAVREAD
35#include "io/source_wavread.h"
36#endif /* HAVE_WAVREAD */
37
38typedef void (*aubio_source_do_t)(aubio_source_t * s, fvec_t * data, uint_t * read);
39typedef void (*aubio_source_do_multi_t)(aubio_source_t * s, fmat_t * data, uint_t * read);
40typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
41typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
42typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s);
43typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
44typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
45typedef void (*del_aubio_source_t)(aubio_source_t * s);
46
47struct _aubio_source_t { 
48  void *source;
49  aubio_source_do_t s_do;
50  aubio_source_do_multi_t s_do_multi;
51  aubio_source_get_samplerate_t s_get_samplerate;
52  aubio_source_get_channels_t s_get_channels;
53  aubio_source_get_duration_t s_get_duration;
54  aubio_source_seek_t s_seek;
55  aubio_source_close_t s_close;
56  del_aubio_source_t s_del;
57};
58
59aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
60  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
61#ifdef HAVE_LIBAV
62  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
63  if (s->source) {
64    s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
65    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
66    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
67    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
68    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
69    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
70    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
71    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
72    return s;
73  }
74#endif /* HAVE_LIBAV */
75#ifdef HAVE_SOURCE_APPLE_AUDIO
76  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
77  if (s->source) {
78    s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
79    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
80    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
81    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
82    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
83    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
84    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
85    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
86    return s;
87  }
88#endif /* HAVE_SOURCE_APPLE_AUDIO */
89#ifdef HAVE_SNDFILE
90  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
91  if (s->source) {
92    s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
93    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
94    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
95    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
96    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
97    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
98    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
99    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
100    return s;
101  }
102#endif /* HAVE_SNDFILE */
103#ifdef HAVE_WAVREAD
104  s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
105  if (s->source) {
106    s->s_do = (aubio_source_do_t)(aubio_source_wavread_do);
107    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_wavread_do_multi);
108    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
109    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
110    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
111    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
112    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
113    s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
114    return s;
115  }
116#else /* failover message */
117#if !(defined(HAVE_LIBAV) || defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SNDFILE))
118  AUBIO_ERROR("source: failed creating aubio source with %s"
119     " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
120#endif /* failover */
121#endif /* HAVE_WAVREAD */
122  AUBIO_FREE(s);
123  return NULL;
124}
125
126void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
127  s->s_do((void *)s->source, data, read);
128}
129
130void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
131  s->s_do_multi((void *)s->source, data, read);
132}
133
134uint_t aubio_source_close(aubio_source_t * s) {
135  return s->s_close((void *)s->source);
136}
137
138void del_aubio_source(aubio_source_t * s) {
139  if (!s) return;
140  s->s_del((void *)s->source);
141  AUBIO_FREE(s);
142}
143
144uint_t aubio_source_get_samplerate(aubio_source_t * s) {
145  return s->s_get_samplerate((void *)s->source);
146}
147
148uint_t aubio_source_get_channels(aubio_source_t * s) {
149  return s->s_get_channels((void *)s->source);
150}
151
152uint_t aubio_source_get_duration(aubio_source_t *s) {
153  return s->s_get_duration((void *)s->source);
154}
155
156uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
157  return s->s_seek((void *)s->source, seek);
158}
Note: See TracBrowser for help on using the repository browser.