chiark / gitweb /
Uniform audio command back end now rate limited.
[disorder] / lib / uaudio.h
CommitLineData
7a2c7068
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2009 Richard Kettlewell
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** @file lib/uaudio.h
20 * @brief Uniform audio interface
21 */
22
23#ifndef UAUDIO_H
24#define UAUDIO_H
25
4fd38868
RK
26extern int uaudio_rate;
27extern int uaudio_bits;
28extern int uaudio_channels;
29extern int uaudio_signed;
30extern size_t uaudio_sample_size;
31
7a2c7068
RK
32/** @brief Callback to get audio data
33 * @param buffer Where to put audio data
34 * @param max_samples How many samples to supply
35 * @param userdata As passed to uaudio_open()
36 * @return Number of samples filled
7a2c7068 37 */
4fd38868 38typedef size_t uaudio_callback(void *buffer,
7a2c7068
RK
39 size_t max_samples,
40 void *userdata);
41
4fd38868
RK
42/** @brief Callback to play audio data
43 * @param buffer Pointer to audio buffer
44 * @param samples Number of samples to play
45 * @return Number of samples played
46 *
47 * Used with uaudio_thread_start() etc.
48 */
49typedef size_t uaudio_playcallback(void *buffer, size_t samples);
50
7a2c7068
RK
51/** @brief Audio API definition */
52struct uaudio {
53 /** @brief Name of this API */
54 const char *name;
55
56 /** @brief List of options, terminated by NULL */
57 const char *const *options;
58
59 /** @brief Do slow setup
60 * @param ua Handle returned by uaudio_open()
61 * @param callback Called for audio data
62 * @param userdata Passed to @p callback
63 *
64 * This does resource-intensive setup for the output device.
65 *
66 * For instance it might open mixable audio devices or network sockets. It
67 * will create any background thread required. However, it must not exclude
68 * other processes from outputting sound.
69 */
70 void (*start)(uaudio_callback *callback,
71 void *userdata);
72
73 /** @brief Tear down
74 * @param ua Handle returned by uaudio_open()
75 *
76 * This undoes the effect of @c start.
77 */
78 void (*stop)(void);
79
80 /** @brief Enable output
81 *
82 * A background thread will start calling @c callback as set by @c
83 * start and playing the audio data received from it.
84 */
85 void (*activate)(void);
86
87 /** @brief Disable output
88 *
89 * The background thread will stop calling @c callback.
90 */
91 void (*deactivate)(void);
92
93};
4fd38868
RK
94
95void uaudio_set_format(int rate, int channels, int samplesize, int signed_);
7a2c7068 96void uaudio_set(const char *name, const char *value);
dfa51bb7 97char *uaudio_get(const char *name);
4fd38868
RK
98void uaudio_thread_start(uaudio_callback *callback,
99 void *userdata,
100 uaudio_playcallback *playcallback,
101 size_t min,
102 size_t max);
103void uaudio_thread_stop(void);
104void uaudio_thread_activate(void);
105void uaudio_thread_deactivate(void);
ec57f6c9
RK
106void uaudio_schedule_synchronize(void);
107void uaudio_schedule_update(size_t written_samples);
108void uaudio_schedule_init(void);
109
110extern uint64_t uaudio_schedule_timestamp;
111extern int uaudio_schedule_reactivated;
7a2c7068
RK
112
113#if HAVE_COREAUDIO_AUDIOHARDWARE_H
114extern const struct uaudio uaudio_coreaudio;
66288757
RK
115#ifndef UAUDIO_DEFAULT
116# define UAUDIO_DEFAULT uaudio_coreaudio
117#endif
7a2c7068
RK
118#endif
119
120#if HAVE_ALSA_ASOUNDLIB_H
121extern const struct uaudio uaudio_alsa;
66288757
RK
122#ifndef UAUDIO_DEFAULT
123# define UAUDIO_DEFAULT uaudio_alsa
124#endif
7a2c7068
RK
125#endif
126
127#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
128extern const struct uaudio uaudio_oss;
66288757
RK
129#ifndef UAUDIO_DEFAULT
130# define UAUDIO_DEFAULT uaudio_oss
131#endif
7a2c7068
RK
132#endif
133
134extern const struct uaudio uaudio_rtp;
66288757
RK
135#ifndef UAUDIO_DEFAULT
136# define UAUDIO_DEFAULT uaudio_rtp
137#endif
7a2c7068 138
66288757 139extern const struct uaudio uaudio_command;
7a2c7068
RK
140
141#endif /* UAUDIO_H */
142
143/*
144Local Variables:
145c-basic-offset:2
146comment-column:40
147fill-column:79
148indent-tabs-mode:nil
149End:
150*/