source: src/io/source.c @ dba9b33

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

src/io/source*: add _close function

  • Property mode set to 100644
File size: 5.6 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);
[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;
53  aubio_source_seek_t s_seek;
[422452b]54  aubio_source_close_t s_close;
[1b0755d]55  del_aubio_source_t s_del;
[9316173]56};
57
[afbd7e7]58aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
[3504dfe7]59  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
[549928e]60#if HAVE_LIBAV
[1b0755d]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);
[422452b]68    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
[1b0755d]69    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
70    return s;
71  }
[549928e]72#endif /* HAVE_LIBAV */
[3504dfe7]73#ifdef __APPLE__
[42e6a5e]74  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
[1b0755d]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);
[422452b]81    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
[1b0755d]82    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
83    return s;
84  }
85#endif /* __APPLE__ */
[afbd7e7]86#if HAVE_SNDFILE
[42e6a5e]87  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
[1b0755d]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);
[422452b]94    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
[1b0755d]95    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
96    return s;
97  }
[afbd7e7]98#endif /* HAVE_SNDFILE */
[52efae1]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);
[422452b]107    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
[52efae1]108    s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
109    return s;
110  }
111#endif /* HAVE_WAVREAD */
[5ab8e59]112  AUBIO_ERROR("source: failed creating aubio source with %s"
113     " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
[e3b5962]114  AUBIO_FREE(s);
115  return NULL;
[9316173]116}
117
[3504dfe7]118void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
[1b0755d]119  s->s_do((void *)s->source, data, read);
[9316173]120}
121
[4865e4b]122void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
[1b0755d]123  s->s_do_multi((void *)s->source, data, read);
[4865e4b]124}
125
[422452b]126uint_t aubio_source_close(aubio_source_t * s) {
127  return s->s_close((void *)s->source);
128}
129
[9316173]130void del_aubio_source(aubio_source_t * s) {
[32df658]131  if (!s) return;
[1b0755d]132  s->s_del((void *)s->source);
[3504dfe7]133  AUBIO_FREE(s);
[9316173]134}
135
[944c7e1]136uint_t aubio_source_get_samplerate(aubio_source_t * s) {
[1b0755d]137  return s->s_get_samplerate((void *)s->source);
[944c7e1]138}
139
[4865e4b]140uint_t aubio_source_get_channels(aubio_source_t * s) {
[1b0755d]141  return s->s_get_channels((void *)s->source);
[4865e4b]142}
143
[7982203]144uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
[1b0755d]145  return s->s_seek((void *)s->source, seek);
[7982203]146}
Note: See TracBrowser for help on using the repository browser.