source: src/io/source.c @ fa69546

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since fa69546 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
RevLine 
[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 "aubio_priv.h"
22#include "fvec.h"
[4865e4b]23#include "fmat.h"
[9316173]24#include "io/source.h"
[549928e]25#ifdef HAVE_LIBAV
[1b0755d]26#include "io/source_avcodec.h"
[549928e]27#endif /* HAVE_LIBAV */
[9209c79]28#ifdef HAVE_SOURCE_APPLE_AUDIO
[c9b99fd]29#include "io/source_apple_audio.h"
[9209c79]30#endif /* HAVE_SOURCE_APPLE_AUDIO */
[afbd7e7]31#ifdef HAVE_SNDFILE
32#include "io/source_sndfile.h"
[1b0755d]33#endif /* HAVE_SNDFILE */
[52efae1]34#ifdef HAVE_WAVREAD
35#include "io/source_wavread.h"
36#endif /* HAVE_WAVREAD */
[1b0755d]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);
[857f8871]42typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s);
[1b0755d]43typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
[422452b]44typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
[082c88b]45typedef void (*del_aubio_source_t)(aubio_source_t * s);
[9316173]46
47struct _aubio_source_t { 
[3504dfe7]48  void *source;
[1b0755d]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;
[857f8871]53  aubio_source_get_duration_t s_get_duration;
[1b0755d]54  aubio_source_seek_t s_seek;
[422452b]55  aubio_source_close_t s_close;
[1b0755d]56  del_aubio_source_t s_del;
[9316173]57};
58
[ae5d58a]59aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
[3504dfe7]60  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
[de66709]61#ifdef HAVE_LIBAV
[1b0755d]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);
[857f8871]68    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
[1b0755d]69    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
[422452b]70    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
[1b0755d]71    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
72    return s;
73  }
[549928e]74#endif /* HAVE_LIBAV */
[9209c79]75#ifdef HAVE_SOURCE_APPLE_AUDIO
[42e6a5e]76  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
[1b0755d]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);
[857f8871]82    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
[1b0755d]83    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
[422452b]84    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
[1b0755d]85    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
86    return s;
87  }
[9209c79]88#endif /* HAVE_SOURCE_APPLE_AUDIO */
[de66709]89#ifdef HAVE_SNDFILE
[42e6a5e]90  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
[1b0755d]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);
[857f8871]96    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
[1b0755d]97    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
[422452b]98    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
[1b0755d]99    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
100    return s;
101  }
[afbd7e7]102#endif /* HAVE_SNDFILE */
[de66709]103#ifdef HAVE_WAVREAD
[52efae1]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);
[857f8871]110    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
[52efae1]111    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
[422452b]112    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
[52efae1]113    s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
114    return s;
115  }
[a9516b3]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 */
[52efae1]121#endif /* HAVE_WAVREAD */
[e3b5962]122  AUBIO_FREE(s);
123  return NULL;
[9316173]124}
125
[3504dfe7]126void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
[1b0755d]127  s->s_do((void *)s->source, data, read);
[9316173]128}
129
[4865e4b]130void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
[1b0755d]131  s->s_do_multi((void *)s->source, data, read);
[4865e4b]132}
133
[422452b]134uint_t aubio_source_close(aubio_source_t * s) {
135  return s->s_close((void *)s->source);
136}
137
[9316173]138void del_aubio_source(aubio_source_t * s) {
[32df658]139  if (!s) return;
[1b0755d]140  s->s_del((void *)s->source);
[3504dfe7]141  AUBIO_FREE(s);
[9316173]142}
143
[944c7e1]144uint_t aubio_source_get_samplerate(aubio_source_t * s) {
[1b0755d]145  return s->s_get_samplerate((void *)s->source);
[944c7e1]146}
147
[4865e4b]148uint_t aubio_source_get_channels(aubio_source_t * s) {
[1b0755d]149  return s->s_get_channels((void *)s->source);
[4865e4b]150}
151
[857f8871]152uint_t aubio_source_get_duration(aubio_source_t *s) {
153  return s->s_get_duration((void *)s->source);
154}
155
[7982203]156uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
[1b0755d]157  return s->s_seek((void *)s->source, seek);
[7982203]158}
Note: See TracBrowser for help on using the repository browser.