source: src/io/source.c @ 549928e

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

wscript: make sure all libav libraries are installed to build source_avcodec

Signed-off-by: Paul Brossier <piem@piem.org>

  • Property mode set to 100644
File size: 4.4 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 */
35
36typedef void (*aubio_source_do_t)(aubio_source_t * s, fvec_t * data, uint_t * read);
37typedef void (*aubio_source_do_multi_t)(aubio_source_t * s, fmat_t * data, uint_t * read);
38typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
39typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
40typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
41typedef uint_t (*del_aubio_source_t)(aubio_source_t * s);
[9316173]42
43struct _aubio_source_t { 
[3504dfe7]44  void *source;
[1b0755d]45  aubio_source_do_t s_do;
46  aubio_source_do_multi_t s_do_multi;
47  aubio_source_get_samplerate_t s_get_samplerate;
48  aubio_source_get_channels_t s_get_channels;
49  aubio_source_seek_t s_seek;
50  del_aubio_source_t s_del;
[9316173]51};
52
[afbd7e7]53aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
[3504dfe7]54  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
[549928e]55#if HAVE_LIBAV
[1b0755d]56  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
57  if (s->source) {
58    s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
59    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
60    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
61    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
62    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
63    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
64    return s;
65  }
[549928e]66#endif /* HAVE_LIBAV */
[3504dfe7]67#ifdef __APPLE__
[42e6a5e]68  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
[1b0755d]69  if (s->source) {
70    s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
71    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
72    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
73    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
74    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
75    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
76    return s;
77  }
78#endif /* __APPLE__ */
[afbd7e7]79#if HAVE_SNDFILE
[42e6a5e]80  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
[1b0755d]81  if (s->source) {
82    s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
83    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
84    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
85    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
86    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
87    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
88    return s;
89  }
[afbd7e7]90#endif /* HAVE_SNDFILE */
[9a226ef]91  AUBIO_ERROR("failed creating aubio source with %s\n", uri);
[e3b5962]92  AUBIO_FREE(s);
93  return NULL;
[9316173]94}
95
[3504dfe7]96void aubio_source_do(aubio_source_t * s, fvec_t * data, uint_t * read) {
[1b0755d]97  s->s_do((void *)s->source, data, read);
[9316173]98}
99
[4865e4b]100void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
[1b0755d]101  s->s_do_multi((void *)s->source, data, read);
[4865e4b]102}
103
[9316173]104void del_aubio_source(aubio_source_t * s) {
[32df658]105  if (!s) return;
[1b0755d]106  s->s_del((void *)s->source);
[3504dfe7]107  AUBIO_FREE(s);
[9316173]108}
109
[944c7e1]110uint_t aubio_source_get_samplerate(aubio_source_t * s) {
[1b0755d]111  return s->s_get_samplerate((void *)s->source);
[944c7e1]112}
113
[4865e4b]114uint_t aubio_source_get_channels(aubio_source_t * s) {
[1b0755d]115  return s->s_get_channels((void *)s->source);
[4865e4b]116}
117
[7982203]118uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
[1b0755d]119  return s->s_seek((void *)s->source, seek);
[7982203]120}
Note: See TracBrowser for help on using the repository browser.