change license from GPLv3 to GPLv3 or later
[mmq.git] / ao.c
blob9c0641e1ffba119fefbb3742dc6d0b0d1eadae1d
1 /* MMQ_AO_IMPL should be defined by the Makefile */
2 #ifndef MMQ_AO_IMPL
3 # error MMQ_AO_IMPL not defined
4 #endif
5 #include "mmq.h"
7 struct afmt g_next_afmt;
8 static struct afmt current;
9 unsigned long g_sample_size;
11 static int matches_current(void)
13 /* no using memcmp because of potential padding */
14 return ((g_next_afmt.rate == current.rate) &&
15 (g_next_afmt.bits == current.bits) &&
16 (g_next_afmt.channels == current.channels));
19 /* this should statically define _my_open, _my_close */
20 #include MMQ_AO_IMPL
22 int audio_open(void)
24 int rv;
26 if (matches_current())
27 return 0;
28 if (g_next_afmt.channels != 2) {
29 warn("only 2 channel output is supported for now\n");
30 g_state = STATE_NEXT;
31 return -1;
33 audio_close(1);
35 rv = _my_open(&g_next_afmt);
36 if (rv < 0) {
37 warn("ao_open failed\n");
38 g_state = STATE_NEXT;
39 } else {
40 memcpy(&current, &g_next_afmt, sizeof(struct afmt));
41 emit("a%u:%u:%u\n",
42 current.rate, current.bits, current.channels);
45 return rv;
48 void audio_close(int graceful)
50 _my_close(graceful);
51 memset(&current, 0, sizeof(struct afmt));
54 int audio_inject(void *buf, long samples, conv_fn conv_i)
56 if (likely(g_state == STATE_PLAY))
57 return _my_inject(buf, samples, conv_i);
59 return -1;
62 long audio_copy(void *dst, void *src, long samples, long offset)
64 src = (char *)src + (offset * g_sample_size);
65 memcpy(dst, src, samples * g_sample_size);
67 return samples;