source: src/io/source.c @ 5ab8e59

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

src/io/source{,_wavread}.c: improve error message

  • Property mode set to 100644
File size: 5.1 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 "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
39typedef void (*aubio_source_do_t)(aubio_source_t * s, fvec_t * data, uint_t * read);
40typedef void (*aubio_source_do_multi_t)(aubio_source_t * s, fmat_t * data, uint_t * read);
41typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
42typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
43typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
44typedef uint_t (*del_aubio_source_t)(aubio_source_t * s);
[9316173]45
46struct _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]56aubio_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 */
[5ab8e59]106  AUBIO_ERROR("source: failed creating aubio source with %s"
107     " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
[e3b5962]108  AUBIO_FREE(s);
109  return NULL;
[9316173]110}
111
[3504dfe7]112void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
[1b0755d]113  s->s_do((void *)s->source, data, read);
[9316173]114}
115
[4865e4b]116void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
[1b0755d]117  s->s_do_multi((void *)s->source, data, read);
[4865e4b]118}
119
[9316173]120void del_aubio_source(aubio_source_t * s) {
[32df658]121  if (!s) return;
[1b0755d]122  s->s_del((void *)s->source);
[3504dfe7]123  AUBIO_FREE(s);
[9316173]124}
125
[944c7e1]126uint_t aubio_source_get_samplerate(aubio_source_t * s) {
[1b0755d]127  return s->s_get_samplerate((void *)s->source);
[944c7e1]128}
129
[4865e4b]130uint_t aubio_source_get_channels(aubio_source_t * s) {
[1b0755d]131  return s->s_get_channels((void *)s->source);
[4865e4b]132}
133
[7982203]134uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
[1b0755d]135  return s->s_seek((void *)s->source, seek);
[7982203]136}
Note: See TracBrowser for help on using the repository browser.