source: src/io/source.c @ c18981e

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

wscript, src/io/*.c: use custom defines instead of APPLE

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