egra: draw ttf glyph with vertical gradient
[iv.d.git] / alsa.d
blobadfe270363be9e56294bd1ee4f0beb7864f32158
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
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, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module iv.alsa /*is aliced*/;
18 pragma(lib, "asound");
20 import iv.alice;
21 import core.stdc.config;
22 import core.sys.posix.poll;
24 extern(C):
25 nothrow @trusted: @nogc:
26 const(char)* snd_strerror (int errnum);
29 #ifdef __GLIBC__
30 #if !defined(_POSIX_C_SOURCE) && !defined(_POSIX_SOURCE)
31 struct timeval {
32 time_t tv_sec; /* seconds */
33 long tv_usec; /* microseconds */
36 struct timespec {
37 time_t tv_sec; /* seconds */
38 long tv_nsec; /* nanoseconds */
40 #endif
41 #endif
43 /** Timestamp */
44 typedef struct timeval snd_timestamp_t;
45 /** Hi-res timestamp */
46 typedef struct timespec snd_htimestamp_t;
49 // pcm
50 alias snd_pcm_stream_t = int;
51 enum : int {
52 SND_PCM_STREAM_PLAYBACK,
53 SND_PCM_STREAM_CAPTURE,
56 /** Unsigned frames quantity */
57 alias snd_pcm_uframes_t = c_ulong;
58 /** Signed frames quantity */
59 alias snd_pcm_sframes_t = c_long;
62 /** PCM type */
63 alias snd_pcm_type_t = int;
64 enum : int {
65 /** Kernel level PCM */
66 SND_PCM_TYPE_HW = 0,
67 /** Hooked PCM */
68 SND_PCM_TYPE_HOOKS,
69 /** One or more linked PCM with exclusive access to selected
70 channels */
71 SND_PCM_TYPE_MULTI,
72 /** File writing plugin */
73 SND_PCM_TYPE_FILE,
74 /** Null endpoint PCM */
75 SND_PCM_TYPE_NULL,
76 /** Shared memory client PCM */
77 SND_PCM_TYPE_SHM,
78 /** INET client PCM (not yet implemented) */
79 SND_PCM_TYPE_INET,
80 /** Copying plugin */
81 SND_PCM_TYPE_COPY,
82 /** Linear format conversion PCM */
83 SND_PCM_TYPE_LINEAR,
84 /** A-Law format conversion PCM */
85 SND_PCM_TYPE_ALAW,
86 /** Mu-Law format conversion PCM */
87 SND_PCM_TYPE_MULAW,
88 /** IMA-ADPCM format conversion PCM */
89 SND_PCM_TYPE_ADPCM,
90 /** Rate conversion PCM */
91 SND_PCM_TYPE_RATE,
92 /** Attenuated static route PCM */
93 SND_PCM_TYPE_ROUTE,
94 /** Format adjusted PCM */
95 SND_PCM_TYPE_PLUG,
96 /** Sharing PCM */
97 SND_PCM_TYPE_SHARE,
98 /** Meter plugin */
99 SND_PCM_TYPE_METER,
100 /** Mixing PCM */
101 SND_PCM_TYPE_MIX,
102 /** Attenuated dynamic route PCM (not yet implemented) */
103 SND_PCM_TYPE_DROUTE,
104 /** Loopback server plugin (not yet implemented) */
105 SND_PCM_TYPE_LBSERVER,
106 /** Linear Integer <-> Linear Float format conversion PCM */
107 SND_PCM_TYPE_LINEAR_FLOAT,
108 /** LADSPA integration plugin */
109 SND_PCM_TYPE_LADSPA,
110 /** Direct Mixing plugin */
111 SND_PCM_TYPE_DMIX,
112 /** Jack Audio Connection Kit plugin */
113 SND_PCM_TYPE_JACK,
114 /** Direct Snooping plugin */
115 SND_PCM_TYPE_DSNOOP,
116 /** Direct Sharing plugin */
117 SND_PCM_TYPE_DSHARE,
118 /** IEC958 subframe plugin */
119 SND_PCM_TYPE_IEC958,
120 /** Soft volume plugin */
121 SND_PCM_TYPE_SOFTVOL,
122 /** External I/O plugin */
123 SND_PCM_TYPE_IOPLUG,
124 /** External filter plugin */
125 SND_PCM_TYPE_EXTPLUG,
126 /** Mmap-emulation plugin */
127 SND_PCM_TYPE_MMAP_EMUL,
128 SND_PCM_TYPE_LAST = SND_PCM_TYPE_MMAP_EMUL,
132 enum {
133 /** Non blocking mode (flag for open mode) \hideinitializer */
134 SND_PCM_NONBLOCK = 0x00000001,
135 /** Async notification (flag for open mode) \hideinitializer */
136 SND_PCM_ASYNC = 0x00000002,
137 /** In an abort state (internal, not allowed for open) */
138 SND_PCM_ABORT = 0x00008000,
139 /** Disable automatic (but not forced!) rate resamplinig */
140 SND_PCM_NO_AUTO_RESAMPLE = 0x00010000,
141 /** Disable automatic (but not forced!) channel conversion */
142 SND_PCM_NO_AUTO_CHANNELS = 0x00020000,
143 /** Disable automatic (but not forced!) format conversion */
144 SND_PCM_NO_AUTO_FORMAT = 0x00040000,
145 /** Disable soft volume control */
146 SND_PCM_NO_SOFTVOL = 0x00080000,
149 alias snd_pcm_access_t = int;
150 enum : int {
151 /** mmap access with simple interleaved channels */
152 SND_PCM_ACCESS_MMAP_INTERLEAVED = 0,
153 /** mmap access with simple non interleaved channels */
154 SND_PCM_ACCESS_MMAP_NONINTERLEAVED,
155 /** mmap access with complex placement */
156 SND_PCM_ACCESS_MMAP_COMPLEX,
157 /** snd_pcm_readi/snd_pcm_writei access */
158 SND_PCM_ACCESS_RW_INTERLEAVED,
159 /** snd_pcm_readn/snd_pcm_writen access */
160 SND_PCM_ACCESS_RW_NONINTERLEAVED,
161 SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED,
164 alias snd_pcm_format = int;
165 enum : int {
166 /** Unknown */
167 SND_PCM_FORMAT_UNKNOWN = -1,
168 /** Signed 8 bit */
169 SND_PCM_FORMAT_S8 = 0,
170 /** Unsigned 8 bit */
171 SND_PCM_FORMAT_U8,
172 /** Signed 16 bit Little Endian */
173 SND_PCM_FORMAT_S16_LE,
174 /** Signed 16 bit Big Endian */
175 SND_PCM_FORMAT_S16_BE,
176 /** Unsigned 16 bit Little Endian */
177 SND_PCM_FORMAT_U16_LE,
178 /** Unsigned 16 bit Big Endian */
179 SND_PCM_FORMAT_U16_BE,
180 /** Signed 24 bit Little Endian using low three bytes in 32-bit word */
181 SND_PCM_FORMAT_S24_LE,
182 /** Signed 24 bit Big Endian using low three bytes in 32-bit word */
183 SND_PCM_FORMAT_S24_BE,
184 /** Unsigned 24 bit Little Endian using low three bytes in 32-bit word */
185 SND_PCM_FORMAT_U24_LE,
186 /** Unsigned 24 bit Big Endian using low three bytes in 32-bit word */
187 SND_PCM_FORMAT_U24_BE,
188 /** Signed 32 bit Little Endian */
189 SND_PCM_FORMAT_S32_LE,
190 /** Signed 32 bit Big Endian */
191 SND_PCM_FORMAT_S32_BE,
192 /** Unsigned 32 bit Little Endian */
193 SND_PCM_FORMAT_U32_LE,
194 /** Unsigned 32 bit Big Endian */
195 SND_PCM_FORMAT_U32_BE,
196 /** Float 32 bit Little Endian, Range -1.0 to 1.0 */
197 SND_PCM_FORMAT_FLOAT_LE,
198 /** Float 32 bit Big Endian, Range -1.0 to 1.0 */
199 SND_PCM_FORMAT_FLOAT_BE,
200 /** Float 64 bit Little Endian, Range -1.0 to 1.0 */
201 SND_PCM_FORMAT_FLOAT64_LE,
202 /** Float 64 bit Big Endian, Range -1.0 to 1.0 */
203 SND_PCM_FORMAT_FLOAT64_BE,
204 /** IEC-958 Little Endian */
205 SND_PCM_FORMAT_IEC958_SUBFRAME_LE,
206 /** IEC-958 Big Endian */
207 SND_PCM_FORMAT_IEC958_SUBFRAME_BE,
208 /** Mu-Law */
209 SND_PCM_FORMAT_MU_LAW,
210 /** A-Law */
211 SND_PCM_FORMAT_A_LAW,
212 /** Ima-ADPCM */
213 SND_PCM_FORMAT_IMA_ADPCM,
214 /** MPEG */
215 SND_PCM_FORMAT_MPEG,
216 /** GSM */
217 SND_PCM_FORMAT_GSM,
218 /** Special */
219 SND_PCM_FORMAT_SPECIAL = 31,
220 /** Signed 24bit Little Endian in 3bytes format */
221 SND_PCM_FORMAT_S24_3LE = 32,
222 /** Signed 24bit Big Endian in 3bytes format */
223 SND_PCM_FORMAT_S24_3BE,
224 /** Unsigned 24bit Little Endian in 3bytes format */
225 SND_PCM_FORMAT_U24_3LE,
226 /** Unsigned 24bit Big Endian in 3bytes format */
227 SND_PCM_FORMAT_U24_3BE,
228 /** Signed 20bit Little Endian in 3bytes format */
229 SND_PCM_FORMAT_S20_3LE,
230 /** Signed 20bit Big Endian in 3bytes format */
231 SND_PCM_FORMAT_S20_3BE,
232 /** Unsigned 20bit Little Endian in 3bytes format */
233 SND_PCM_FORMAT_U20_3LE,
234 /** Unsigned 20bit Big Endian in 3bytes format */
235 SND_PCM_FORMAT_U20_3BE,
236 /** Signed 18bit Little Endian in 3bytes format */
237 SND_PCM_FORMAT_S18_3LE,
238 /** Signed 18bit Big Endian in 3bytes format */
239 SND_PCM_FORMAT_S18_3BE,
240 /** Unsigned 18bit Little Endian in 3bytes format */
241 SND_PCM_FORMAT_U18_3LE,
242 /** Unsigned 18bit Big Endian in 3bytes format */
243 SND_PCM_FORMAT_U18_3BE,
244 /* G.723 (ADPCM) 24 kbit/s, 8 samples in 3 bytes */
245 SND_PCM_FORMAT_G723_24,
246 /* G.723 (ADPCM) 24 kbit/s, 1 sample in 1 byte */
247 SND_PCM_FORMAT_G723_24_1B,
248 /* G.723 (ADPCM) 40 kbit/s, 8 samples in 3 bytes */
249 SND_PCM_FORMAT_G723_40,
250 /* G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte */
251 SND_PCM_FORMAT_G723_40_1B,
252 /* Direct Stream Digital (DSD) in 1-byte samples (x8) */
253 SND_PCM_FORMAT_DSD_U8,
254 /* Direct Stream Digital (DSD) in 2-byte samples (x16) */
255 SND_PCM_FORMAT_DSD_U16_LE,
256 SND_PCM_FORMAT_LAST = SND_PCM_FORMAT_DSD_U16_LE,
258 // I snipped a bunch of endian-specific ones!
261 /** PCM state */
262 alias snd_pcm_state_t = int;
263 enum : int {
264 /** Open */
265 SND_PCM_STATE_OPEN = 0,
266 /** Setup installed */
267 SND_PCM_STATE_SETUP,
268 /** Ready to start */
269 SND_PCM_STATE_PREPARED,
270 /** Running */
271 SND_PCM_STATE_RUNNING,
272 /** Stopped: underrun (playback) or overrun (capture) detected */
273 SND_PCM_STATE_XRUN,
274 /** Draining: running (playback) or stopped (capture) */
275 SND_PCM_STATE_DRAINING,
276 /** Paused */
277 SND_PCM_STATE_PAUSED,
278 /** Hardware is suspended */
279 SND_PCM_STATE_SUSPENDED,
280 /** Hardware is disconnected */
281 SND_PCM_STATE_DISCONNECTED,
282 SND_PCM_STATE_LAST = SND_PCM_STATE_DISCONNECTED,
285 struct snd_pcm_t {}
286 struct snd_pcm_hw_params_t {}
287 struct snd_pcm_sw_params_t {}
289 int snd_pcm_open (snd_pcm_t** pcm, const(char)* name, snd_pcm_stream_t stream, int mode);
290 int snd_pcm_close (snd_pcm_t* pcm);
291 const(char)* snd_pcm_name (snd_pcm_t* pcm);
292 snd_pcm_type_t snd_pcm_type (snd_pcm_t* pcm);
293 snd_pcm_stream_t snd_pcm_stream (snd_pcm_t* pcm);
295 int snd_pcm_poll_descriptors_count (snd_pcm_t* pcm);
296 int snd_pcm_poll_descriptors (snd_pcm_t* pcm, pollfd* pfds, uint space);
297 int snd_pcm_poll_descriptors_revents (snd_pcm_t* pcm, pollfd* pfds, uint nfds, ushort* revents);
298 int snd_pcm_nonblock (snd_pcm_t* pcm, int nonblock);
299 int snd_pcm_abort (snd_pcm_t* pcm) { return snd_pcm_nonblock(pcm, 2); }
301 int snd_pcm_prepare (snd_pcm_t* pcm);
302 int snd_pcm_reset (snd_pcm_t* pcm);
303 //int snd_pcm_status (snd_pcm_t* pcm, snd_pcm_status_t *status);
304 int snd_pcm_start (snd_pcm_t* pcm);
305 int snd_pcm_drop (snd_pcm_t* pcm);
306 int snd_pcm_drain (snd_pcm_t* pcm);
307 int snd_pcm_pause (snd_pcm_t* pcm, int enable);
308 snd_pcm_state_t snd_pcm_state (snd_pcm_t* pcm);
309 int snd_pcm_hwsync (snd_pcm_t* pcm);
310 int snd_pcm_delay (snd_pcm_t* pcm, snd_pcm_sframes_t *delayp);
311 int snd_pcm_resume (snd_pcm_t* pcm);
312 int snd_pcm_recover (snd_pcm_t* pcm, int err, int silent);
313 //int snd_pcm_htimestamp (snd_pcm_t* pcm, snd_pcm_uframes_t* avail, snd_htimestamp_t* tstamp);
314 snd_pcm_sframes_t snd_pcm_avail (snd_pcm_t* pcm);
315 snd_pcm_sframes_t snd_pcm_avail_update (snd_pcm_t* pcm);
316 int snd_pcm_avail_delay (snd_pcm_t* pcm, snd_pcm_sframes_t* availp, snd_pcm_sframes_t* delayp);
317 snd_pcm_sframes_t snd_pcm_rewindable (snd_pcm_t* pcm);
318 snd_pcm_sframes_t snd_pcm_rewind (snd_pcm_t* pcm, snd_pcm_uframes_t frames);
319 snd_pcm_sframes_t snd_pcm_forwardable (snd_pcm_t* pcm);
320 snd_pcm_sframes_t snd_pcm_forward (snd_pcm_t* pcm, snd_pcm_uframes_t frames);
321 snd_pcm_sframes_t snd_pcm_writei (snd_pcm_t* pcm, const(void)* buffer, snd_pcm_uframes_t size);
322 snd_pcm_sframes_t snd_pcm_readi (snd_pcm_t* pcm, void* buffer, snd_pcm_uframes_t size);
323 snd_pcm_sframes_t snd_pcm_writen (snd_pcm_t* pcm, void** bufs, snd_pcm_uframes_t size);
324 snd_pcm_sframes_t snd_pcm_readn (snd_pcm_t* pcm, void** bufs, snd_pcm_uframes_t size);
325 int snd_pcm_wait (snd_pcm_t* pcm, int timeout);
327 int snd_pcm_hw_params_current (snd_pcm_t* pcm, snd_pcm_hw_params_t* params);
328 int snd_pcm_hw_params (snd_pcm_t* pcm, snd_pcm_hw_params_t* params);
329 int snd_pcm_hw_params_set_channels(snd_pcm_t*, snd_pcm_hw_params_t*, uint);
330 int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t**);
331 void snd_pcm_hw_params_free(snd_pcm_hw_params_t*);
332 int snd_pcm_hw_params_any(snd_pcm_t*, snd_pcm_hw_params_t*);
333 int snd_pcm_hw_params_set_access(snd_pcm_t*, snd_pcm_hw_params_t*, snd_pcm_access_t);
334 int snd_pcm_hw_params_set_format(snd_pcm_t*, snd_pcm_hw_params_t*, snd_pcm_format);
335 int snd_pcm_hw_params_set_rate_near(snd_pcm_t*, snd_pcm_hw_params_t*, uint*, int*);
336 int snd_pcm_hw_params_set_rate (snd_pcm_t* pcm, snd_pcm_hw_params_t* params, uint val, int dir);
337 int snd_pcm_hw_params_set_buffer_size_near (snd_pcm_t* pcm, snd_pcm_hw_params_t* params, snd_pcm_uframes_t* val);
338 int snd_pcm_hw_params_set_buffer_size (snd_pcm_t* pcm, snd_pcm_hw_params_t* params, snd_pcm_uframes_t val);
340 int snd_pcm_hw_params_set_rate_resample (snd_pcm_t* pcm, snd_pcm_hw_params_t* params, uint val);
342 int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t**);
343 void snd_pcm_sw_params_free(snd_pcm_sw_params_t*);
345 int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
346 int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
347 int snd_pcm_sw_params_set_avail_min(snd_pcm_t*, snd_pcm_sw_params_t*, snd_pcm_uframes_t);
348 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t*, snd_pcm_sw_params_t*, snd_pcm_uframes_t);
349 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t*, snd_pcm_sw_params_t*, snd_pcm_uframes_t);
351 //alias snd_pcm_sframes_t = c_long;
352 //alias snd_pcm_uframes_t = c_ulong;
353 //snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t*, const void*, snd_pcm_uframes_t size);
354 //snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t*, void*, snd_pcm_uframes_t size);
356 //int snd_pcm_wait(snd_pcm_t *pcm, int timeout);
357 //snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t *pcm);
358 //snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm);
360 // raw midi
364 struct snd_rawmidi_t {}
365 int snd_rawmidi_open(snd_rawmidi_t**, snd_rawmidi_t**, const char*, int);
366 int snd_rawmidi_close(snd_rawmidi_t*);
367 int snd_rawmidi_drain(snd_rawmidi_t*);
368 ssize snd_rawmidi_write(snd_rawmidi_t*, const void*, usize);
369 ssize snd_rawmidi_read(snd_rawmidi_t*, void*, usize);
372 // mixer
374 struct snd_mixer_t {}
375 struct snd_mixer_elem_t {}
376 struct snd_mixer_selem_id_t {}
378 alias snd_mixer_elem_callback_t = int function(snd_mixer_elem_t*, uint);
380 int snd_mixer_open(snd_mixer_t**, int mode);
381 int snd_mixer_close(snd_mixer_t*);
382 int snd_mixer_attach(snd_mixer_t*, const char*);
383 int snd_mixer_load(snd_mixer_t*);
385 // FIXME: those aren't actually void*
386 int snd_mixer_selem_register(snd_mixer_t*, void*, void*);
387 int snd_mixer_selem_id_malloc(snd_mixer_selem_id_t**);
388 void snd_mixer_selem_id_free(snd_mixer_selem_id_t*);
389 void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t*, uint);
390 void snd_mixer_selem_id_set_name(snd_mixer_selem_id_t*, const char*);
391 snd_mixer_elem_t* snd_mixer_find_selem(snd_mixer_t*, in snd_mixer_selem_id_t*);
393 // FIXME: the int should be an enum for channel identifier
394 int snd_mixer_selem_get_playback_volume(snd_mixer_elem_t*, int, c_long*);
396 int snd_mixer_selem_get_playback_volume_range(snd_mixer_elem_t*, c_long*, c_long*);
398 int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t*, c_long);
400 void snd_mixer_elem_set_callback(snd_mixer_elem_t*, snd_mixer_elem_callback_t);
401 int snd_mixer_poll_descriptors(snd_mixer_t*, pollfd*, uint space);
403 int snd_mixer_handle_events(snd_mixer_t*);
405 // FIXME: the first int should be an enum for channel identifier
406 int snd_mixer_selem_get_playback_switch(snd_mixer_elem_t*, int, int* value);
407 int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t*, int);
410 int snd_pcm_set_params (snd_pcm_t *pcm, snd_pcm_format format, snd_pcm_access_t access, uint channels, uint rate, int soft_resample, uint latency);
411 int snd_pcm_get_params (snd_pcm_t *pcm, snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t *period_size);
413 int snd_pcm_hw_params_test_rate (snd_pcm_t* pcm, snd_pcm_hw_params_t* params, uint val, int dir);
414 int snd_pcm_hw_params_get_rate_min (const(snd_pcm_hw_params_t)* params, uint* val, int* dir);
415 int snd_pcm_hw_params_get_rate_max (const(snd_pcm_hw_params_t)* params, uint* val, int* dir);
417 alias snd_lib_error_handler_t = void function (const(char)* file, int line, const(char)* function_, int err, const(char)* fmt, ...);
418 int snd_lib_error_set_handler (snd_lib_error_handler_t handler);
420 private void alsa_message_fucker (const(char)* file, int line, const(char)* function_, int err, const(char)* fmt, ...) {}
422 void fuck_alsa_messages () {
423 snd_lib_error_set_handler(&alsa_message_fucker);