2 * This file is part of DisOrder.
3 * Copyright (C) 2009 Richard Kettlewell
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.
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.
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/>.
19 /** @file lib/uaudio.h
20 * @brief Uniform audio interface
26 extern int uaudio_rate;
27 extern int uaudio_bits;
28 extern int uaudio_channels;
29 extern int uaudio_signed;
30 extern size_t uaudio_sample_size;
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
38 typedef size_t uaudio_callback(void *buffer,
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
47 * Used with uaudio_thread_start() etc.
49 typedef size_t uaudio_playcallback(void *buffer, size_t samples);
51 /** @brief Audio API definition */
53 /** @brief Name of this API */
56 /** @brief List of options, terminated by NULL */
57 const char *const *options;
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
64 * This does resource-intensive setup for the output device.
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.
70 void (*start)(uaudio_callback *callback,
74 * @param ua Handle returned by uaudio_open()
76 * This undoes the effect of @c start.
80 /** @brief Enable output
82 * A background thread will start calling @c callback as set by @c
83 * start and playing the audio data received from it.
85 void (*activate)(void);
87 /** @brief Disable output
89 * The background thread will stop calling @c callback.
91 void (*deactivate)(void);
93 /** @brief Open mixer device */
94 void (*open_mixer)(void);
96 /** @brief Closer mixer device */
97 void (*close_mixer)(void);
100 * @param left Where to put the left-channel value
101 * @param right Where to put the right-channel value
103 * 0 is silent and 100 is maximum volume.
105 void (*get_volume)(int *left, int *right);
107 /** @brief Set volume
108 * @param left Pointer to left-channel value (updated)
109 * @param right Pointer to right-channel value (updated)
111 * The values are updated with those actually set by the underlying system
114 * 0 is silent and 100 is maximum volume.
116 void (*set_volume)(int *left, int *right);
118 /** @brief Set configuration */
119 void (*configure)(void);
123 void uaudio_set_format(int rate, int channels, int samplesize, int signed_);
124 void uaudio_set(const char *name, const char *value);
125 char *uaudio_get(const char *name, const char *default_value);
126 void uaudio_thread_start(uaudio_callback *callback,
128 uaudio_playcallback *playcallback,
131 void uaudio_thread_stop(void);
132 void uaudio_thread_activate(void);
133 void uaudio_thread_deactivate(void);
134 void uaudio_schedule_synchronize(void);
135 void uaudio_schedule_update(size_t written_samples);
136 void uaudio_schedule_init(void);
137 const struct uaudio *uaudio_find(const char *name);
139 extern uint64_t uaudio_schedule_timestamp;
140 extern int uaudio_schedule_reactivated;
142 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
143 extern const struct uaudio uaudio_coreaudio;
146 #if HAVE_ALSA_ASOUNDLIB_H
147 extern const struct uaudio uaudio_alsa;
150 #if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
151 extern const struct uaudio uaudio_oss;
154 extern const struct uaudio uaudio_rtp;
156 extern const struct uaudio uaudio_command;
158 extern const struct uaudio *const uaudio_apis[];
160 #endif /* UAUDIO_H */