summaryrefslogtreecommitdiff
path: root/src/io/sink.c
blob: a13316a24c0b2e6822416af6e6e988e06dcb4fad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
  Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org>

  This file is part of aubio.

  aubio is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  aubio is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with aubio.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "config.h"
#include "aubio_priv.h"
#include "fvec.h"
#include "fmat.h"
#include "io/sink.h"
#ifdef HAVE_SINK_APPLE_AUDIO
#include "io/sink_apple_audio.h"
#endif /* HAVE_SINK_APPLE_AUDIO */
#ifdef HAVE_SNDFILE
#include "io/sink_sndfile.h"
#endif
#ifdef HAVE_WAVWRITE
#include "io/sink_wavwrite.h"
#endif

typedef void (*aubio_sink_do_t)(aubio_sink_t * s, fvec_t * data, uint_t write);
typedef void (*aubio_sink_do_multi_t)(aubio_sink_t * s, fmat_t * data, uint_t write);
typedef uint_t (*aubio_sink_preset_samplerate_t)(aubio_sink_t * s, uint_t samplerate);
typedef uint_t (*aubio_sink_preset_channels_t)(aubio_sink_t * s, uint_t channels);
typedef uint_t (*aubio_sink_get_samplerate_t)(aubio_sink_t * s);
typedef uint_t (*aubio_sink_get_channels_t)(aubio_sink_t * s);
typedef uint_t (*aubio_sink_close_t)(aubio_sink_t * s);
typedef void (*del_aubio_sink_t)(aubio_sink_t * s);

struct _aubio_sink_t { 
  void *sink;
  aubio_sink_do_t s_do;
  aubio_sink_do_multi_t s_do_multi;
  aubio_sink_preset_samplerate_t s_preset_samplerate;
  aubio_sink_preset_channels_t s_preset_channels;
  aubio_sink_get_samplerate_t s_get_samplerate;
  aubio_sink_get_channels_t s_get_channels;
  aubio_sink_close_t s_close;
  del_aubio_sink_t s_del;
};

aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
#ifdef HAVE_SINK_APPLE_AUDIO
  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do);
    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_apple_audio_do_multi);
    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_apple_audio_preset_samplerate);
    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_apple_audio_preset_channels);
    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_apple_audio_get_samplerate);
    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_apple_audio_get_channels);
    s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio);
    return s;
  }
#endif /* HAVE_SINK_APPLE_AUDIO */
#ifdef HAVE_SNDFILE
  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do);
    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_sndfile_do_multi);
    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_sndfile_preset_samplerate);
    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_sndfile_preset_channels);
    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_sndfile_get_samplerate);
    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_sndfile_get_channels);
    s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile);
    return s;
  }
#endif /* HAVE_SNDFILE */
#ifdef HAVE_WAVWRITE
  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do);
    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_wavwrite_do_multi);
    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_wavwrite_preset_samplerate);
    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_wavwrite_preset_channels);
    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_wavwrite_get_samplerate);
    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_wavwrite_get_channels);
    s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite);
    return s;
  }
#endif /* HAVE_WAVWRITE */
  AUBIO_ERROR("sink: failed creating %s with samplerate %dHz\n",
      uri, samplerate);
  AUBIO_FREE(s);
  return NULL;
}

void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) {
  s->s_do((void *)s->sink, write_data, write);
}

void aubio_sink_do_multi(aubio_sink_t * s, fmat_t * write_data, uint_t write) {
  s->s_do_multi((void *)s->sink, write_data, write);
}

uint_t aubio_sink_preset_samplerate(aubio_sink_t * s, uint_t samplerate) {
  return s->s_preset_samplerate((void *)s->sink, samplerate);
}

uint_t aubio_sink_preset_channels(aubio_sink_t * s, uint_t channels) {
  return s->s_preset_channels((void *)s->sink, channels);
}

uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) {
  return s->s_get_samplerate((void *)s->sink);
}

uint_t aubio_sink_get_channels(const aubio_sink_t * s) {
  return s->s_get_channels((void *)s->sink);
}

uint_t aubio_sink_close(aubio_sink_t *s) {
  return s->s_close((void *)s->sink);
}

void del_aubio_sink(aubio_sink_t * s) {
  if (!s) return;
  s->s_del((void *)s->sink);
  AUBIO_FREE(s);
  return;
}