source: src/io/source.c @ 2434566

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

src/io/{sink,source}.c: clarify failover messages

  • 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  }
116#endif /* HAVE_WAVREAD */
[dcecaec]117#if !defined(HAVE_WAVREAD) && \
118  !defined(HAVE_LIBAV) && \
119  !defined(HAVE_SOURCE_APPLE_AUDIO) && \
120  !defined(HAVE_SNDFILE)
121  AUBIO_ERROR("source: failed creating with %s at %dHz with hop size %d"
122     " (no source built-in)\n", uri, samplerate, hop_size);
123#endif
[e3b5962]124  AUBIO_FREE(s);
125  return NULL;
[9316173]126}
127
[3504dfe7]128void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
[1b0755d]129  s->s_do((void *)s->source, data, read);
[9316173]130}
131
[4865e4b]132void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
[1b0755d]133  s->s_do_multi((void *)s->source, data, read);
[4865e4b]134}
135
[422452b]136uint_t aubio_source_close(aubio_source_t * s) {
137  return s->s_close((void *)s->source);
138}
139
[9316173]140void del_aubio_source(aubio_source_t * s) {
[32df658]141  if (!s) return;
[1b0755d]142  s->s_del((void *)s->source);
[3504dfe7]143  AUBIO_FREE(s);
[9316173]144}
145
[944c7e1]146uint_t aubio_source_get_samplerate(aubio_source_t * s) {
[1b0755d]147  return s->s_get_samplerate((void *)s->source);
[944c7e1]148}
149
[4865e4b]150uint_t aubio_source_get_channels(aubio_source_t * s) {
[1b0755d]151  return s->s_get_channels((void *)s->source);
[4865e4b]152}
153
[857f8871]154uint_t aubio_source_get_duration(aubio_source_t *s) {
155  return s->s_get_duration((void *)s->source);
156}
157
[7982203]158uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
[1b0755d]159  return s->s_seek((void *)s->source, seek);
[7982203]160}
Note: See TracBrowser for help on using the repository browser.