root / audio / fmodaudio.c @ 977d5710
History | View | Annotate | Download (12.2 kB)
1 | 85571bc7 | bellard | /*
|
---|---|---|---|
2 | 85571bc7 | bellard | * QEMU FMOD audio output driver
|
3 | 85571bc7 | bellard | *
|
4 | 85571bc7 | bellard | * Copyright (c) 2004 Vassili Karpov (malc)
|
5 | 85571bc7 | bellard | *
|
6 | 85571bc7 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 85571bc7 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 85571bc7 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 85571bc7 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 85571bc7 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 85571bc7 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 85571bc7 | bellard | *
|
13 | 85571bc7 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 85571bc7 | bellard | * all copies or substantial portions of the Software.
|
15 | 85571bc7 | bellard | *
|
16 | 85571bc7 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 85571bc7 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 85571bc7 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 85571bc7 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 85571bc7 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 85571bc7 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 85571bc7 | bellard | * THE SOFTWARE.
|
23 | 85571bc7 | bellard | */
|
24 | 85571bc7 | bellard | #include <fmod.h> |
25 | 85571bc7 | bellard | #include <fmod_errors.h> |
26 | 85571bc7 | bellard | #include "vl.h" |
27 | 85571bc7 | bellard | |
28 | fb065187 | bellard | #include "audio/audio_int.h" |
29 | fb065187 | bellard | |
30 | fb065187 | bellard | typedef struct FMODVoice { |
31 | fb065187 | bellard | HWVoice hw; |
32 | fb065187 | bellard | unsigned int old_pos; |
33 | fb065187 | bellard | FSOUND_SAMPLE *fmod_sample; |
34 | fb065187 | bellard | int channel;
|
35 | fb065187 | bellard | } FMODVoice; |
36 | fb065187 | bellard | |
37 | fb065187 | bellard | #define dolog(...) AUD_log ("fmod", __VA_ARGS__) |
38 | fb065187 | bellard | #ifdef DEBUG
|
39 | fb065187 | bellard | #define ldebug(...) dolog (__VA_ARGS__)
|
40 | fb065187 | bellard | #else
|
41 | fb065187 | bellard | #define ldebug(...)
|
42 | fb065187 | bellard | #endif
|
43 | 85571bc7 | bellard | |
44 | 85571bc7 | bellard | #define QC_FMOD_DRV "QEMU_FMOD_DRV" |
45 | 85571bc7 | bellard | #define QC_FMOD_FREQ "QEMU_FMOD_FREQ" |
46 | 85571bc7 | bellard | #define QC_FMOD_SAMPLES "QEMU_FMOD_SAMPLES" |
47 | 85571bc7 | bellard | #define QC_FMOD_CHANNELS "QEMU_FMOD_CHANNELS" |
48 | 85571bc7 | bellard | #define QC_FMOD_BUFSIZE "QEMU_FMOD_BUFSIZE" |
49 | 85571bc7 | bellard | #define QC_FMOD_THRESHOLD "QEMU_FMOD_THRESHOLD" |
50 | 85571bc7 | bellard | |
51 | 85571bc7 | bellard | static struct { |
52 | 85571bc7 | bellard | int nb_samples;
|
53 | 85571bc7 | bellard | int freq;
|
54 | 85571bc7 | bellard | int nb_channels;
|
55 | 85571bc7 | bellard | int bufsize;
|
56 | 85571bc7 | bellard | int threshold;
|
57 | 85571bc7 | bellard | } conf = { |
58 | 85571bc7 | bellard | 2048,
|
59 | 85571bc7 | bellard | 44100,
|
60 | 85571bc7 | bellard | 1,
|
61 | 85571bc7 | bellard | 0,
|
62 | 85571bc7 | bellard | 128
|
63 | 85571bc7 | bellard | }; |
64 | 85571bc7 | bellard | |
65 | 85571bc7 | bellard | #define errstr() FMOD_ErrorString (FSOUND_GetError ())
|
66 | 85571bc7 | bellard | |
67 | 85571bc7 | bellard | static int fmod_hw_write (SWVoice *sw, void *buf, int len) |
68 | 85571bc7 | bellard | { |
69 | 85571bc7 | bellard | return pcm_hw_write (sw, buf, len);
|
70 | 85571bc7 | bellard | } |
71 | 85571bc7 | bellard | |
72 | 85571bc7 | bellard | static void fmod_clear_sample (FMODVoice *fmd) |
73 | 85571bc7 | bellard | { |
74 | 85571bc7 | bellard | HWVoice *hw = &fmd->hw; |
75 | 85571bc7 | bellard | int status;
|
76 | 85571bc7 | bellard | void *p1 = 0, *p2 = 0; |
77 | 85571bc7 | bellard | unsigned int len1 = 0, len2 = 0; |
78 | 85571bc7 | bellard | |
79 | 85571bc7 | bellard | status = FSOUND_Sample_Lock ( |
80 | 85571bc7 | bellard | fmd->fmod_sample, |
81 | 85571bc7 | bellard | 0,
|
82 | 85571bc7 | bellard | hw->samples << hw->shift, |
83 | 85571bc7 | bellard | &p1, |
84 | 85571bc7 | bellard | &p2, |
85 | 85571bc7 | bellard | &len1, |
86 | 85571bc7 | bellard | &len2 |
87 | 85571bc7 | bellard | ); |
88 | 85571bc7 | bellard | |
89 | 85571bc7 | bellard | if (!status) {
|
90 | 85571bc7 | bellard | dolog ("Failed to lock sample\nReason: %s\n", errstr ());
|
91 | 85571bc7 | bellard | return;
|
92 | 85571bc7 | bellard | } |
93 | 85571bc7 | bellard | |
94 | 85571bc7 | bellard | if ((len1 & hw->align) || (len2 & hw->align)) {
|
95 | 85571bc7 | bellard | dolog ("Locking sample returned unaligned length %d, %d\n",
|
96 | 85571bc7 | bellard | len1, len2); |
97 | 85571bc7 | bellard | goto fail;
|
98 | 85571bc7 | bellard | } |
99 | 85571bc7 | bellard | |
100 | 85571bc7 | bellard | if (len1 + len2 != hw->samples << hw->shift) {
|
101 | 85571bc7 | bellard | dolog ("Locking sample returned incomplete length %d, %d\n",
|
102 | 85571bc7 | bellard | len1 + len2, hw->samples << hw->shift); |
103 | 85571bc7 | bellard | goto fail;
|
104 | 85571bc7 | bellard | } |
105 | 85571bc7 | bellard | pcm_hw_clear (hw, p1, hw->samples); |
106 | 85571bc7 | bellard | |
107 | 85571bc7 | bellard | fail:
|
108 | 85571bc7 | bellard | status = FSOUND_Sample_Unlock (fmd->fmod_sample, p1, p2, len1, len2); |
109 | 85571bc7 | bellard | if (!status) {
|
110 | 85571bc7 | bellard | dolog ("Failed to unlock sample\nReason: %s\n", errstr ());
|
111 | 85571bc7 | bellard | } |
112 | 85571bc7 | bellard | } |
113 | 85571bc7 | bellard | |
114 | 85571bc7 | bellard | static int fmod_write_sample (HWVoice *hw, uint8_t *dst, st_sample_t *src, |
115 | 85571bc7 | bellard | int src_size, int src_pos, int dst_len) |
116 | 85571bc7 | bellard | { |
117 | 85571bc7 | bellard | int src_len1 = dst_len, src_len2 = 0, pos = src_pos + dst_len; |
118 | 85571bc7 | bellard | st_sample_t *src1 = src + src_pos, *src2 = 0;
|
119 | 85571bc7 | bellard | |
120 | 85571bc7 | bellard | if (src_pos + dst_len > src_size) {
|
121 | 85571bc7 | bellard | src_len1 = src_size - src_pos; |
122 | 85571bc7 | bellard | src2 = src; |
123 | 85571bc7 | bellard | src_len2 = dst_len - src_len1; |
124 | 85571bc7 | bellard | pos = src_len2; |
125 | 85571bc7 | bellard | } |
126 | 85571bc7 | bellard | |
127 | 85571bc7 | bellard | if (src_len1) {
|
128 | 85571bc7 | bellard | hw->clip (dst, src1, src_len1); |
129 | 85571bc7 | bellard | memset (src1, 0, src_len1 * sizeof (st_sample_t)); |
130 | 85571bc7 | bellard | advance (dst, src_len1); |
131 | 85571bc7 | bellard | } |
132 | 85571bc7 | bellard | |
133 | 85571bc7 | bellard | if (src_len2) {
|
134 | 85571bc7 | bellard | hw->clip (dst, src2, src_len2); |
135 | 85571bc7 | bellard | memset (src2, 0, src_len2 * sizeof (st_sample_t)); |
136 | 85571bc7 | bellard | } |
137 | 85571bc7 | bellard | return pos;
|
138 | 85571bc7 | bellard | } |
139 | 85571bc7 | bellard | |
140 | 85571bc7 | bellard | static int fmod_unlock_sample (FMODVoice *fmd, void *p1, void *p2, |
141 | 85571bc7 | bellard | unsigned int blen1, unsigned int blen2) |
142 | 85571bc7 | bellard | { |
143 | 85571bc7 | bellard | int status = FSOUND_Sample_Unlock (fmd->fmod_sample, p1, p2, blen1, blen2);
|
144 | 85571bc7 | bellard | if (!status) {
|
145 | 85571bc7 | bellard | dolog ("Failed to unlock sample\nReason: %s\n", errstr ());
|
146 | 85571bc7 | bellard | return -1; |
147 | 85571bc7 | bellard | } |
148 | 85571bc7 | bellard | return 0; |
149 | 85571bc7 | bellard | } |
150 | 85571bc7 | bellard | |
151 | 85571bc7 | bellard | static int fmod_lock_sample (FMODVoice *fmd, int pos, int len, |
152 | 85571bc7 | bellard | void **p1, void **p2, |
153 | 85571bc7 | bellard | unsigned int *blen1, unsigned int *blen2) |
154 | 85571bc7 | bellard | { |
155 | 85571bc7 | bellard | HWVoice *hw = &fmd->hw; |
156 | 85571bc7 | bellard | int status;
|
157 | 85571bc7 | bellard | |
158 | 85571bc7 | bellard | status = FSOUND_Sample_Lock ( |
159 | 85571bc7 | bellard | fmd->fmod_sample, |
160 | 85571bc7 | bellard | pos << hw->shift, |
161 | 85571bc7 | bellard | len << hw->shift, |
162 | 85571bc7 | bellard | p1, |
163 | 85571bc7 | bellard | p2, |
164 | 85571bc7 | bellard | blen1, |
165 | 85571bc7 | bellard | blen2 |
166 | 85571bc7 | bellard | ); |
167 | 85571bc7 | bellard | |
168 | 85571bc7 | bellard | if (!status) {
|
169 | 85571bc7 | bellard | dolog ("Failed to lock sample\nReason: %s\n", errstr ());
|
170 | 85571bc7 | bellard | return -1; |
171 | 85571bc7 | bellard | } |
172 | 85571bc7 | bellard | |
173 | 85571bc7 | bellard | if ((*blen1 & hw->align) || (*blen2 & hw->align)) {
|
174 | 85571bc7 | bellard | dolog ("Locking sample returned unaligned length %d, %d\n",
|
175 | 85571bc7 | bellard | *blen1, *blen2); |
176 | 85571bc7 | bellard | fmod_unlock_sample (fmd, *p1, *p2, *blen1, *blen2); |
177 | 85571bc7 | bellard | return -1; |
178 | 85571bc7 | bellard | } |
179 | 85571bc7 | bellard | return 0; |
180 | 85571bc7 | bellard | } |
181 | 85571bc7 | bellard | |
182 | 85571bc7 | bellard | static void fmod_hw_run (HWVoice *hw) |
183 | 85571bc7 | bellard | { |
184 | 85571bc7 | bellard | FMODVoice *fmd = (FMODVoice *) hw; |
185 | 85571bc7 | bellard | int rpos, live, decr;
|
186 | 85571bc7 | bellard | void *p1 = 0, *p2 = 0; |
187 | 85571bc7 | bellard | unsigned int blen1 = 0, blen2 = 0; |
188 | 85571bc7 | bellard | unsigned int len1 = 0, len2 = 0; |
189 | 85571bc7 | bellard | int nb_active;
|
190 | 85571bc7 | bellard | |
191 | 85571bc7 | bellard | live = pcm_hw_get_live2 (hw, &nb_active); |
192 | 85571bc7 | bellard | if (live <= 0) { |
193 | 85571bc7 | bellard | return;
|
194 | 85571bc7 | bellard | } |
195 | 85571bc7 | bellard | |
196 | 85571bc7 | bellard | if (!hw->pending_disable
|
197 | 85571bc7 | bellard | && nb_active |
198 | 85571bc7 | bellard | && conf.threshold |
199 | 85571bc7 | bellard | && live <= conf.threshold) { |
200 | 85571bc7 | bellard | ldebug ("live=%d nb_active=%d\n", live, nb_active);
|
201 | 85571bc7 | bellard | return;
|
202 | 85571bc7 | bellard | } |
203 | 85571bc7 | bellard | |
204 | 85571bc7 | bellard | decr = live; |
205 | 85571bc7 | bellard | |
206 | 85571bc7 | bellard | #if 1 |
207 | 85571bc7 | bellard | if (fmd->channel >= 0) { |
208 | 85571bc7 | bellard | int pos2 = (fmd->old_pos + decr) % hw->samples;
|
209 | 85571bc7 | bellard | int pos = FSOUND_GetCurrentPosition (fmd->channel);
|
210 | 85571bc7 | bellard | |
211 | 85571bc7 | bellard | if (fmd->old_pos < pos && pos2 >= pos) {
|
212 | 85571bc7 | bellard | decr = pos - fmd->old_pos - (pos2 == pos) - 1;
|
213 | 85571bc7 | bellard | } |
214 | 85571bc7 | bellard | else if (fmd->old_pos > pos && pos2 >= pos && pos2 < fmd->old_pos) { |
215 | 85571bc7 | bellard | decr = (hw->samples - fmd->old_pos) + pos - (pos2 == pos) - 1;
|
216 | 85571bc7 | bellard | } |
217 | 85571bc7 | bellard | /* ldebug ("pos=%d pos2=%d old=%d live=%d decr=%d\n", */
|
218 | 85571bc7 | bellard | /* pos, pos2, fmd->old_pos, live, decr); */
|
219 | 85571bc7 | bellard | } |
220 | 85571bc7 | bellard | #endif
|
221 | 85571bc7 | bellard | |
222 | 85571bc7 | bellard | if (decr <= 0) { |
223 | 85571bc7 | bellard | return;
|
224 | 85571bc7 | bellard | } |
225 | 85571bc7 | bellard | |
226 | 85571bc7 | bellard | if (fmod_lock_sample (fmd, fmd->old_pos, decr, &p1, &p2, &blen1, &blen2)) {
|
227 | 85571bc7 | bellard | return;
|
228 | 85571bc7 | bellard | } |
229 | 85571bc7 | bellard | |
230 | 85571bc7 | bellard | len1 = blen1 >> hw->shift; |
231 | 85571bc7 | bellard | len2 = blen2 >> hw->shift; |
232 | 85571bc7 | bellard | ldebug ("%p %p %d %d %d %d\n", p1, p2, len1, len2, blen1, blen2);
|
233 | 85571bc7 | bellard | decr = len1 + len2; |
234 | 85571bc7 | bellard | rpos = hw->rpos; |
235 | 85571bc7 | bellard | |
236 | 85571bc7 | bellard | if (len1) {
|
237 | 85571bc7 | bellard | rpos = fmod_write_sample (hw, p1, hw->mix_buf, hw->samples, rpos, len1); |
238 | 85571bc7 | bellard | } |
239 | 85571bc7 | bellard | |
240 | 85571bc7 | bellard | if (len2) {
|
241 | 85571bc7 | bellard | rpos = fmod_write_sample (hw, p2, hw->mix_buf, hw->samples, rpos, len2); |
242 | 85571bc7 | bellard | } |
243 | 85571bc7 | bellard | |
244 | 85571bc7 | bellard | fmod_unlock_sample (fmd, p1, p2, blen1, blen2); |
245 | 85571bc7 | bellard | |
246 | 85571bc7 | bellard | pcm_hw_dec_live (hw, decr); |
247 | 85571bc7 | bellard | hw->rpos = rpos % hw->samples; |
248 | 85571bc7 | bellard | fmd->old_pos = (fmd->old_pos + decr) % hw->samples; |
249 | 85571bc7 | bellard | } |
250 | 85571bc7 | bellard | |
251 | 85571bc7 | bellard | static int AUD_to_fmodfmt (audfmt_e fmt, int stereo) |
252 | 85571bc7 | bellard | { |
253 | 85571bc7 | bellard | int mode = FSOUND_LOOP_NORMAL;
|
254 | 85571bc7 | bellard | |
255 | 85571bc7 | bellard | switch (fmt) {
|
256 | 85571bc7 | bellard | case AUD_FMT_S8:
|
257 | 85571bc7 | bellard | mode |= FSOUND_SIGNED | FSOUND_8BITS; |
258 | 85571bc7 | bellard | break;
|
259 | 85571bc7 | bellard | |
260 | 85571bc7 | bellard | case AUD_FMT_U8:
|
261 | 85571bc7 | bellard | mode |= FSOUND_UNSIGNED | FSOUND_8BITS; |
262 | 85571bc7 | bellard | break;
|
263 | 85571bc7 | bellard | |
264 | 85571bc7 | bellard | case AUD_FMT_S16:
|
265 | 85571bc7 | bellard | mode |= FSOUND_SIGNED | FSOUND_16BITS; |
266 | 85571bc7 | bellard | break;
|
267 | 85571bc7 | bellard | |
268 | 85571bc7 | bellard | case AUD_FMT_U16:
|
269 | 85571bc7 | bellard | mode |= FSOUND_UNSIGNED | FSOUND_16BITS; |
270 | 85571bc7 | bellard | break;
|
271 | 85571bc7 | bellard | |
272 | 85571bc7 | bellard | default:
|
273 | 85571bc7 | bellard | dolog ("Internal logic error: Bad audio format %d\nAborting\n", fmt);
|
274 | 85571bc7 | bellard | exit (EXIT_FAILURE); |
275 | 85571bc7 | bellard | } |
276 | 85571bc7 | bellard | mode |= stereo ? FSOUND_STEREO : FSOUND_MONO; |
277 | 85571bc7 | bellard | return mode;
|
278 | 85571bc7 | bellard | } |
279 | 85571bc7 | bellard | |
280 | 85571bc7 | bellard | static void fmod_hw_fini (HWVoice *hw) |
281 | 85571bc7 | bellard | { |
282 | 85571bc7 | bellard | FMODVoice *fmd = (FMODVoice *) hw; |
283 | 85571bc7 | bellard | |
284 | 85571bc7 | bellard | if (fmd->fmod_sample) {
|
285 | 85571bc7 | bellard | FSOUND_Sample_Free (fmd->fmod_sample); |
286 | 85571bc7 | bellard | fmd->fmod_sample = 0;
|
287 | 85571bc7 | bellard | |
288 | 85571bc7 | bellard | if (fmd->channel >= 0) { |
289 | 85571bc7 | bellard | FSOUND_StopSound (fmd->channel); |
290 | 85571bc7 | bellard | } |
291 | 85571bc7 | bellard | } |
292 | 85571bc7 | bellard | } |
293 | 85571bc7 | bellard | |
294 | 85571bc7 | bellard | static int fmod_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt) |
295 | 85571bc7 | bellard | { |
296 | 85571bc7 | bellard | int bits16, mode, channel;
|
297 | 85571bc7 | bellard | FMODVoice *fmd = (FMODVoice *) hw; |
298 | 85571bc7 | bellard | |
299 | 85571bc7 | bellard | mode = AUD_to_fmodfmt (fmt, nchannels == 2 ? 1 : 0); |
300 | 85571bc7 | bellard | fmd->fmod_sample = FSOUND_Sample_Alloc ( |
301 | 85571bc7 | bellard | FSOUND_FREE, /* index */
|
302 | 85571bc7 | bellard | conf.nb_samples, /* length */
|
303 | 85571bc7 | bellard | mode, /* mode */
|
304 | 85571bc7 | bellard | freq, /* freq */
|
305 | 85571bc7 | bellard | 255, /* volume */ |
306 | 85571bc7 | bellard | 128, /* pan */ |
307 | 85571bc7 | bellard | 255 /* priority */ |
308 | 85571bc7 | bellard | ); |
309 | 85571bc7 | bellard | |
310 | 85571bc7 | bellard | if (!fmd->fmod_sample) {
|
311 | 85571bc7 | bellard | dolog ("Failed to allocate FMOD sample\nReason: %s\n", errstr ());
|
312 | 85571bc7 | bellard | return -1; |
313 | 85571bc7 | bellard | } |
314 | 85571bc7 | bellard | |
315 | 85571bc7 | bellard | channel = FSOUND_PlaySoundEx (FSOUND_FREE, fmd->fmod_sample, 0, 1); |
316 | 85571bc7 | bellard | if (channel < 0) { |
317 | 85571bc7 | bellard | dolog ("Failed to start playing sound\nReason: %s\n", errstr ());
|
318 | 85571bc7 | bellard | FSOUND_Sample_Free (fmd->fmod_sample); |
319 | 85571bc7 | bellard | return -1; |
320 | 85571bc7 | bellard | } |
321 | 85571bc7 | bellard | fmd->channel = channel; |
322 | 85571bc7 | bellard | |
323 | 85571bc7 | bellard | hw->freq = freq; |
324 | 85571bc7 | bellard | hw->fmt = fmt; |
325 | 85571bc7 | bellard | hw->nchannels = nchannels; |
326 | 85571bc7 | bellard | bits16 = fmt == AUD_FMT_U16 || fmt == AUD_FMT_S16; |
327 | 85571bc7 | bellard | hw->bufsize = conf.nb_samples << (nchannels == 2) << bits16;
|
328 | 85571bc7 | bellard | return 0; |
329 | 85571bc7 | bellard | } |
330 | 85571bc7 | bellard | |
331 | 85571bc7 | bellard | static int fmod_hw_ctl (HWVoice *hw, int cmd, ...) |
332 | 85571bc7 | bellard | { |
333 | 85571bc7 | bellard | int status;
|
334 | 85571bc7 | bellard | FMODVoice *fmd = (FMODVoice *) hw; |
335 | 85571bc7 | bellard | |
336 | 85571bc7 | bellard | switch (cmd) {
|
337 | 85571bc7 | bellard | case VOICE_ENABLE:
|
338 | 85571bc7 | bellard | fmod_clear_sample (fmd); |
339 | 85571bc7 | bellard | status = FSOUND_SetPaused (fmd->channel, 0);
|
340 | 85571bc7 | bellard | if (!status) {
|
341 | 85571bc7 | bellard | dolog ("Failed to resume channel %d\nReason: %s\n",
|
342 | 85571bc7 | bellard | fmd->channel, errstr ()); |
343 | 85571bc7 | bellard | } |
344 | 85571bc7 | bellard | break;
|
345 | 85571bc7 | bellard | |
346 | 85571bc7 | bellard | case VOICE_DISABLE:
|
347 | 85571bc7 | bellard | status = FSOUND_SetPaused (fmd->channel, 1);
|
348 | 85571bc7 | bellard | if (!status) {
|
349 | 85571bc7 | bellard | dolog ("Failed to pause channel %d\nReason: %s\n",
|
350 | 85571bc7 | bellard | fmd->channel, errstr ()); |
351 | 85571bc7 | bellard | } |
352 | 85571bc7 | bellard | break;
|
353 | 85571bc7 | bellard | } |
354 | 85571bc7 | bellard | return 0; |
355 | 85571bc7 | bellard | } |
356 | 85571bc7 | bellard | |
357 | 85571bc7 | bellard | static struct { |
358 | 85571bc7 | bellard | const char *name; |
359 | 85571bc7 | bellard | int type;
|
360 | 85571bc7 | bellard | } drvtab[] = { |
361 | 85571bc7 | bellard | {"none", FSOUND_OUTPUT_NOSOUND},
|
362 | 85571bc7 | bellard | #ifdef _WIN32
|
363 | 85571bc7 | bellard | {"winmm", FSOUND_OUTPUT_WINMM},
|
364 | 85571bc7 | bellard | {"dsound", FSOUND_OUTPUT_DSOUND},
|
365 | 85571bc7 | bellard | {"a3d", FSOUND_OUTPUT_A3D},
|
366 | 85571bc7 | bellard | {"asio", FSOUND_OUTPUT_ASIO},
|
367 | 85571bc7 | bellard | #endif
|
368 | 85571bc7 | bellard | #ifdef __linux__
|
369 | 85571bc7 | bellard | {"oss", FSOUND_OUTPUT_OSS},
|
370 | 85571bc7 | bellard | {"alsa", FSOUND_OUTPUT_ALSA},
|
371 | 85571bc7 | bellard | {"esd", FSOUND_OUTPUT_ESD},
|
372 | 85571bc7 | bellard | #endif
|
373 | 85571bc7 | bellard | #ifdef __APPLE__
|
374 | 85571bc7 | bellard | {"mac", FSOUND_OUTPUT_MAC},
|
375 | 85571bc7 | bellard | #endif
|
376 | 85571bc7 | bellard | #if 0
|
377 | 85571bc7 | bellard | {"xbox", FSOUND_OUTPUT_XBOX},
|
378 | 85571bc7 | bellard | {"ps2", FSOUND_OUTPUT_PS2},
|
379 | 85571bc7 | bellard | {"gcube", FSOUND_OUTPUT_GC},
|
380 | 85571bc7 | bellard | #endif
|
381 | 85571bc7 | bellard | {"nort", FSOUND_OUTPUT_NOSOUND_NONREALTIME}
|
382 | 85571bc7 | bellard | }; |
383 | 85571bc7 | bellard | |
384 | 85571bc7 | bellard | static void *fmod_audio_init (void) |
385 | 85571bc7 | bellard | { |
386 | 85571bc7 | bellard | int i;
|
387 | 85571bc7 | bellard | double ver;
|
388 | 85571bc7 | bellard | int status;
|
389 | 85571bc7 | bellard | int output_type = -1; |
390 | 85571bc7 | bellard | const char *drv = audio_get_conf_str (QC_FMOD_DRV, NULL); |
391 | 85571bc7 | bellard | |
392 | 85571bc7 | bellard | ver = FSOUND_GetVersion (); |
393 | 85571bc7 | bellard | if (ver < FMOD_VERSION) {
|
394 | 85571bc7 | bellard | dolog ("Wrong FMOD version %f, need at least %f\n", ver, FMOD_VERSION);
|
395 | 85571bc7 | bellard | return NULL; |
396 | 85571bc7 | bellard | } |
397 | 85571bc7 | bellard | |
398 | 85571bc7 | bellard | if (drv) {
|
399 | 85571bc7 | bellard | int found = 0; |
400 | 85571bc7 | bellard | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
401 | 85571bc7 | bellard | if (!strcmp (drv, drvtab[i].name)) {
|
402 | 85571bc7 | bellard | output_type = drvtab[i].type; |
403 | 85571bc7 | bellard | found = 1;
|
404 | 85571bc7 | bellard | break;
|
405 | 85571bc7 | bellard | } |
406 | 85571bc7 | bellard | } |
407 | 85571bc7 | bellard | if (!found) {
|
408 | 85571bc7 | bellard | dolog ("Unknown FMOD output driver `%s'\n", drv);
|
409 | 85571bc7 | bellard | } |
410 | 85571bc7 | bellard | } |
411 | 85571bc7 | bellard | |
412 | 85571bc7 | bellard | if (output_type != -1) { |
413 | 85571bc7 | bellard | status = FSOUND_SetOutput (output_type); |
414 | 85571bc7 | bellard | if (!status) {
|
415 | 85571bc7 | bellard | dolog ("FSOUND_SetOutput(%d) failed\nReason: %s\n",
|
416 | 85571bc7 | bellard | output_type, errstr ()); |
417 | 85571bc7 | bellard | return NULL; |
418 | 85571bc7 | bellard | } |
419 | 85571bc7 | bellard | } |
420 | 85571bc7 | bellard | |
421 | 85571bc7 | bellard | conf.freq = audio_get_conf_int (QC_FMOD_FREQ, conf.freq); |
422 | 85571bc7 | bellard | conf.nb_samples = audio_get_conf_int (QC_FMOD_SAMPLES, conf.nb_samples); |
423 | 85571bc7 | bellard | conf.nb_channels = |
424 | 85571bc7 | bellard | audio_get_conf_int (QC_FMOD_CHANNELS, |
425 | 85571bc7 | bellard | (audio_state.nb_hw_voices > 1
|
426 | 85571bc7 | bellard | ? audio_state.nb_hw_voices |
427 | 85571bc7 | bellard | : conf.nb_channels)); |
428 | 85571bc7 | bellard | conf.bufsize = audio_get_conf_int (QC_FMOD_BUFSIZE, conf.bufsize); |
429 | 85571bc7 | bellard | conf.threshold = audio_get_conf_int (QC_FMOD_THRESHOLD, conf.threshold); |
430 | 85571bc7 | bellard | |
431 | 85571bc7 | bellard | if (conf.bufsize) {
|
432 | 85571bc7 | bellard | status = FSOUND_SetBufferSize (conf.bufsize); |
433 | 85571bc7 | bellard | if (!status) {
|
434 | 85571bc7 | bellard | dolog ("FSOUND_SetBufferSize (%d) failed\nReason: %s\n",
|
435 | 85571bc7 | bellard | conf.bufsize, errstr ()); |
436 | 85571bc7 | bellard | } |
437 | 85571bc7 | bellard | } |
438 | 85571bc7 | bellard | |
439 | 85571bc7 | bellard | status = FSOUND_Init (conf.freq, conf.nb_channels, 0);
|
440 | 85571bc7 | bellard | if (!status) {
|
441 | 85571bc7 | bellard | dolog ("FSOUND_Init failed\nReason: %s\n", errstr ());
|
442 | 85571bc7 | bellard | return NULL; |
443 | 85571bc7 | bellard | } |
444 | 85571bc7 | bellard | |
445 | 85571bc7 | bellard | return &conf;
|
446 | 85571bc7 | bellard | } |
447 | 85571bc7 | bellard | |
448 | 85571bc7 | bellard | static void fmod_audio_fini (void *opaque) |
449 | 85571bc7 | bellard | { |
450 | 85571bc7 | bellard | FSOUND_Close (); |
451 | 85571bc7 | bellard | } |
452 | 85571bc7 | bellard | |
453 | 85571bc7 | bellard | struct pcm_ops fmod_pcm_ops = {
|
454 | 85571bc7 | bellard | fmod_hw_init, |
455 | 85571bc7 | bellard | fmod_hw_fini, |
456 | 85571bc7 | bellard | fmod_hw_run, |
457 | 85571bc7 | bellard | fmod_hw_write, |
458 | 85571bc7 | bellard | fmod_hw_ctl |
459 | 85571bc7 | bellard | }; |
460 | 85571bc7 | bellard | |
461 | 85571bc7 | bellard | struct audio_output_driver fmod_output_driver = {
|
462 | 85571bc7 | bellard | "fmod",
|
463 | 85571bc7 | bellard | fmod_audio_init, |
464 | 85571bc7 | bellard | fmod_audio_fini, |
465 | 85571bc7 | bellard | &fmod_pcm_ops, |
466 | 85571bc7 | bellard | 1,
|
467 | 85571bc7 | bellard | INT_MAX, |
468 | 85571bc7 | bellard | sizeof (FMODVoice)
|
469 | 85571bc7 | bellard | }; |