annotate libao2/ao_openal.c @ 17798:2d02868030f0

double muxing examples (cant hurt to explictly mention the most common)
author michael
date Fri, 10 Mar 2006 14:23:22 +0000
parents 87c049a38c36
children 5c8acc972551
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17633
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
1 /*
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
2 * ao_openal.c - OpenAL audio output driver for MPlayer
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
3 *
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
4 * This driver is under the same license as MPlayer.
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
5 * (http://www.mplayerhq.hu)
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
6 *
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
7 * Copyleft 2006 by Reimar Döffinger (Reimar.Doeffinger@stud.uni-karlsruhe.de)
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
8 */
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
9
17644
87c049a38c36 include stdlib.h and stdio.h, they tend to be useful :-)
reimar
parents: 17633
diff changeset
10 #include <stdlib.h>
87c049a38c36 include stdlib.h and stdio.h, they tend to be useful :-)
reimar
parents: 17633
diff changeset
11 #include <stdio.h>
17633
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
12 #include <inttypes.h>
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
13 #include <AL/alc.h>
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
14 #include <AL/al.h>
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
15
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
16 #include "config.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
17 #include "mp_msg.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
18 #include "help_mp.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
19
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
20 #include "audio_out.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
21 #include "audio_out_internal.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
22 #include "libaf/af_format.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
23 #include "osdep/timer.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
24 #include "subopt-helper.h"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
25
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
26 static ao_info_t info =
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
27 {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
28 "OpenAL audio output",
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
29 "openal",
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
30 "Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>",
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
31 ""
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
32 };
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
33
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
34 LIBAO_EXTERN(openal)
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
35
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
36 #define MAX_CHANS 6
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
37 #define NUM_BUF 128
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
38 #define CHUNK_SIZE 512
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
39 static ALuint buffers[MAX_CHANS][NUM_BUF];
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
40 static ALuint sources[MAX_CHANS];
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
41
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
42 static int cur_buf[MAX_CHANS];
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
43 static int unqueue_buf[MAX_CHANS];
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
44 static int16_t *tmpbuf;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
45
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
46
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
47 static int control(int cmd, void *arg) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
48 return CONTROL_UNKNOWN;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
49 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
50
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
51 /**
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
52 * \brief print suboption usage help
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
53 */
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
54 static void print_help(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
55 mp_msg(MSGT_AO, MSGL_FATAL,
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
56 "\n-ao openal commandline help:\n"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
57 "Example: mplayer -ao openal\n"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
58 "\nOptions:\n"
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
59 );
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
60 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
61
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
62 static int init(int rate, int channels, int format, int flags) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
63 ALCdevice *dev = NULL;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
64 ALCcontext *ctx = NULL;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
65 ALint bufrate;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
66 int i;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
67 opt_t subopts[] = {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
68 {NULL}
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
69 };
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
70 if (subopt_parse(ao_subdevice, subopts) != 0) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
71 print_help();
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
72 return 0;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
73 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
74 if (channels > MAX_CHANS) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
75 mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] Invalid number of channels: %i\n", channels);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
76 goto err_out;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
77 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
78 dev = alcOpenDevice(NULL);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
79 if (!dev) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
80 mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n");
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
81 goto err_out;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
82 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
83 ctx = alcCreateContext(dev, NULL);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
84 alcMakeContextCurrent(ctx);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
85 for (i = 0; i < channels; i++) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
86 cur_buf[i] = 0;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
87 unqueue_buf[i] = 0;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
88 alGenBuffers(NUM_BUF, buffers[i]);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
89 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
90 alGenSources(channels, sources);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
91 alSource3f(sources[0], AL_POSITION, 0, 0, 10);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
92 ao_data.channels = channels;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
93 alGetBufferi(buffers[0][0], AL_FREQUENCY, &bufrate);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
94 ao_data.samplerate = rate = bufrate;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
95 ao_data.format = AF_FORMAT_S16_NE;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
96 ao_data.bps = channels * rate * 2;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
97 ao_data.buffersize = CHUNK_SIZE * NUM_BUF;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
98 ao_data.outburst = channels * CHUNK_SIZE;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
99 tmpbuf = (int16_t *)malloc(CHUNK_SIZE);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
100 return 1;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
101
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
102 err_out:
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
103 return 0;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
104 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
105
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
106 // close audio device
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
107 static void uninit(int immed) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
108 ALCcontext *ctx = alcGetCurrentContext();
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
109 ALCdevice *dev = alcGetContextsDevice(ctx);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
110 free(tmpbuf);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
111 if (!immed) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
112 ALint state;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
113 alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
114 while (state == AL_PLAYING) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
115 usec_sleep(10000);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
116 alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
117 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
118 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
119 reset();
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
120 alcMakeContextCurrent(NULL);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
121 alcDestroyContext(ctx);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
122 alcCloseDevice(dev);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
123 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
124
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
125 static void unqueue_buffers(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
126 ALint p;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
127 int s, i;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
128 for (s = 0; s < ao_data.channels; s++) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
129 alGetSourcei(sources[s], AL_BUFFERS_PROCESSED, &p);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
130 for (i = 0; i < p; i++) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
131 alSourceUnqueueBuffers(sources[s], 1, &buffers[s][unqueue_buf[s]]);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
132 unqueue_buf[s] = (unqueue_buf[s] + 1) % NUM_BUF;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
133 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
134 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
135 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
136
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
137 /**
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
138 * \brief stop playing and empty buffers (for seeking/pause)
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
139 */
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
140 static void reset(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
141 alSourceRewindv(ao_data.channels, sources);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
142 unqueue_buffers();
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
143 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
144
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
145 /**
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
146 * \brief stop playing, keep buffers (for pause)
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
147 */
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
148 static void audio_pause(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
149 alSourcePausev(ao_data.channels, sources);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
150 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
151
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
152 /**
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
153 * \brief resume playing, after audio_pause()
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
154 */
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
155 static void audio_resume(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
156 alSourcePlayv(ao_data.channels, sources);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
157 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
158
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
159 static int get_space(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
160 ALint queued;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
161 unqueue_buffers();
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
162 alGetSourcei(sources[0], AL_BUFFERS_QUEUED, &queued);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
163 return (NUM_BUF - queued) * CHUNK_SIZE * ao_data.channels;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
164 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
165
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
166 /**
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
167 * \brief write data into buffer and reset underrun flag
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
168 */
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
169 static int play(void *data, int len, int flags) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
170 ALint state;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
171 int i, j, k;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
172 int ch;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
173 int16_t *d = data;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
174 len /= ao_data.outburst;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
175 for (i = 0; i < len; i++) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
176 for (ch = 0; ch < ao_data.channels; ch++) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
177 for (j = 0, k = ch; j < CHUNK_SIZE / 2; j++, k += ao_data.channels)
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
178 tmpbuf[j] = d[k];
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
179 alBufferData(buffers[ch][cur_buf[ch]], AL_FORMAT_MONO16, tmpbuf,
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
180 CHUNK_SIZE, ao_data.samplerate);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
181 alSourceQueueBuffers(sources[ch], 1, &buffers[ch][cur_buf[ch]]);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
182 cur_buf[ch] = (cur_buf[ch] + 1) % NUM_BUF;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
183 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
184 d += ao_data.channels * CHUNK_SIZE / 2;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
185 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
186 alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
187 if (state != AL_PLAYING) // checked here in case of an underrun
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
188 alSourcePlayv(ao_data.channels, sources);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
189 return len * ao_data.outburst;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
190 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
191
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
192 static float get_delay(void) {
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
193 ALint queued;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
194 unqueue_buffers();
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
195 alGetSourcei(sources[0], AL_BUFFERS_QUEUED, &queued);
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
196 return queued * CHUNK_SIZE / 2 / (float)ao_data.samplerate;
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
197 }
e0ef5688cce7 OpenAL audio support, actual output is mono-only (no positioning yet).
reimar
parents:
diff changeset
198