]> git.pld-linux.org Git - packages/allegro5.git/blame - allegro-alsa9.patch
- now there is alsa on sparc*
[packages/allegro5.git] / allegro-alsa9.patch
CommitLineData
3a824aa5 1--- allegro/include/allegro/platform/alunix.h.orig Sun Dec 8 20:11:31 2002
2+++ allegro/include/allegro/platform/alunix.h Sun Jan 26 13:29:31 2003
3@@ -157,6 +157,37 @@
4
5 #endif /* ALLEGRO_WITH_ALSAMIDI */
6
7+#ifdef ALLEGRO_WITH_ALSA9DIGI
8+
9+#define DIGI_ALSA9 AL_ID('A','L','S','9')
10+
11+#ifndef ALLEGRO_WITH_MODULES
12+
13+AL_VAR(DIGI_DRIVER, digi_alsa9);
14+
15+#define DIGI_DRIVER_ALSA9 \
16+ { DIGI_ALSA9, &digi_alsa9, TRUE },
17+
18+#endif
19+
20+#endif /* ALLEGRO_WITH_ALSA9DIGI */
21+
22+
23+#ifdef ALLEGRO_WITH_ALSA9MIDI
24+
25+#define MIDI_ALSA9 AL_ID('A','M','I','9')
26+
27+#ifndef ALLEGRO_WITH_MODULES
28+
29+AL_VAR(MIDI_DRIVER, midi_alsa9);
30+
31+#define MIDI_DRIVER_ALSA9 \
32+ { MIDI_ALSA9, &midi_alsa9, TRUE },
33+
34+#endif
35+
36+#endif /* ALLEGRO_WITH_ALSA9MIDI */
37+
38
39
40 /************************************/
3a824aa5 41diff -uNr allegro-4.1.6.old/aclocal.m4 allegro-4.1.6/aclocal.m4
42--- allegro-4.1.6.old/aclocal.m4 Sat Nov 30 12:13:21 2002
43+++ allegro-4.1.6/aclocal.m4 Fri Dec 6 17:40:10 2002
44@@ -363,6 +363,60 @@
45 fi])
46
47 dnl
48+dnl Test for ALSA9 DIGI driver.
49+dnl
50+dnl Variables:
51+dnl allegro_enable_alsa9digi=(yes|)
52+dnl allegro_cv_support_alsa9digi=(yes|)
53+dnl
54+AC_DEFUN(ALLEGRO_ACTEST_ALSA9DIGI,
55+[AC_ARG_ENABLE(alsa9digi,
56+[ --enable-alsa9digi[=x] enable building ALSA9 DIGI driver [default=yes]],
57+test "X$enableval" != "Xno" && allegro_enable_alsa9digi=yes,
58+allegro_enable_alsa9digi=yes)
59+
60+if test -n "$allegro_enable_alsa9digi"; then
61+ AC_CACHE_CHECK(for supported ALSA9 version for digital sound,
62+ allegro_cv_support_alsa9digi,
63+ AC_TRY_RUN([#include <alsa/asoundlib.h>
64+ int main (void) { return SND_LIB_MAJOR != 0 || SND_LIB_MINOR != 9; }],
65+ allegro_cv_support_alsa9digi=yes,
66+ allegro_cv_support_alsa9digi=no,
67+ allegro_cv_support_alsa9digi=no))
68+ if test "X$allegro_cv_support_alsa9digi" = "Xyes" &&
69+ test -z "$allegro_support_modules"; then
70+ LIBS="-lasound $LIBS"
71+ fi
72+fi])
73+
74+dnl
75+dnl Test for ALSA9 MIDI driver.
76+dnl
77+dnl Variables:
78+dnl allegro_enable_alsa9midi=(yes|)
79+dnl allegro_support_alsa9midi=(yes|)
80+dnl
81+AC_DEFUN(ALLEGRO_ACTEST_ALSA9MIDI,
82+[AC_ARG_ENABLE(alsa9midi,
83+[ --enable-alsa9midi[=x] enable building ALSA9 MIDI driver [default=yes]],
84+test "X$enableval" != "Xno" && allegro_enable_alsa9midi=yes,
85+allegro_enable_alsa9midi=yes)
86+
87+if test -n "$allegro_enable_alsa9midi"; then
88+ AC_CACHE_CHECK(for supported ALSA9 version for MIDI,
89+ allegro_cv_support_alsa9midi,
90+ AC_TRY_RUN([#include <alsa/asoundlib.h>
91+ int main (void) { return SND_LIB_MAJOR != 0 || SND_LIB_MINOR != 9; }],
92+ allegro_cv_support_alsa9midi=yes,
93+ allegro_cv_support_alsa9midi=no,
94+ allegro_cv_support_alsa9midi=no))
95+ if test "X$allegro_cv_support_alsa9midi" = "Xyes" &&
96+ test -z "$allegro_support_modules"; then
97+ LIBS="-lasound $LIBS"
98+ fi
99+fi])
100+
101+dnl
102 dnl Test for ESD DIGI driver.
103 dnl
104 dnl Variables:
105diff -uNr allegro-4.1.6.old/allegro.mft allegro-4.1.6/allegro.mft
106--- allegro-4.1.6.old/allegro.mft Sat Nov 30 12:18:28 2002
107+++ allegro-4.1.6/allegro.mft Fri Dec 6 17:40:10 2002
108@@ -685,6 +685,8 @@
109 allegro/src/unix/
110 allegro/src/unix/alsa.c
111 allegro/src/unix/alsamidi.c
112+allegro/src/unix/alsa9.c
113+allegro/src/unix/alsa9midi.c
114 allegro/src/unix/arts.c
115 allegro/src/unix/sgial.c
116 allegro/src/unix/udjgpp.c
59b3b08e
JB
117--- allegro-4.1.11/configure.in.orig 2003-06-30 01:27:00.000000000 +0200
118+++ allegro-4.1.11/configure.in 2003-08-28 22:06:21.582127920 +0200
119@@ -313,6 +313,23 @@
120 _disabled_modules="alsamidi $_disabled_modules"
3a824aa5 121 fi
122
123+dnl Test for ALSA9 drivers.
124+ALLEGRO_ACTEST_ALSA9DIGI
125+if test "$allegro_cv_support_alsa9digi" = yes; then
59b3b08e
JB
126+ AC_DEFINE(ALLEGRO_WITH_ALSA9DIGI,1,[Define if ALSA9 DIGI driver is supported.])
127+ _enabled_modules="alsa9digi $_enabled_modules"
128+else
129+ _disabled_modules="alsa9digi $_disabled_modules"
3a824aa5 130+fi
131+
132+ALLEGRO_ACTEST_ALSA9MIDI
133+if test "$allegro_cv_support_alsa9midi" = yes; then
59b3b08e
JB
134+ AC_DEFINE(ALLEGRO_WITH_ALSA9MIDI,1,[Define if ALSA9 MIDI driver is supported.])
135+ _enabled_modules="alsa9midi $_enabled_modules"
136+else
137+ _disabled_modules="alsa9midi $_disabled_modules"
3a824aa5 138+fi
139+
140 dnl Test for ESD drivers.
141 ALLEGRO_ACTEST_ESDDIGI
142 if test -n "$allegro_support_esddigi"; then
59b3b08e 143@@ -558,6 +575,16 @@
3a824aa5 144 ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsamidi.so"
145 fi
146
147+ dnl ALSA9 DIGI.
148+ if test "X$allegro_cv_support_alsa9digi" = "Xyes"; then
149+ ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsa9digi.so"
150+ fi
151+
152+ dnl ALSA9 MIDI.
153+ if test "X$allegro_cv_support_alsa9midi" = "Xyes"; then
154+ ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsa9midi.so"
155+ fi
156+
157 dnl ESD DIGI.
158 if test "X$allegro_support_esddigi" = "Xyes"; then
159 ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-esddigi.so"
160diff -uNr allegro-4.1.6.old/makefile.in allegro-4.1.6/makefile.in
161--- allegro-4.1.6.old/makefile.in Fri Dec 6 17:39:38 2002
162+++ allegro-4.1.6/makefile.in Fri Dec 6 17:40:10 2002
163@@ -526,6 +526,8 @@
164 $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh dga2 -lXxf86dga $(ALLEGRO_MODULE_DGA2_FILES)' >> makefile.dep
165 $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh alsadigi -lasound $(ALLEGRO_MODULE_ALSADIGI_FILES)' >>makefile.dep
166 $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh alsamidi -lasound $(ALLEGRO_MODULE_ALSAMIDI_FILES)' >>makefile.dep
167+ $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh alsa9digi -lasound $(ALLEGRO_MODULE_ALSA9DIGI_FILES)' >>makefile.dep
168+ $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh alsa9midi -lasound $(ALLEGRO_MODULE_ALSA9MIDI_FILES)' >>makefile.dep
169 $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh esddigi "\`esd-config --libs\`" $(ALLEGRO_MODULE_ESD_FILES)' >>makefile.dep
170 $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh artsdigi "\`artsc-config --libs\`" $(ALLEGRO_MODULE_ARTS_FILES)' >>makefile.dep
171 $(SHELL) -c 'cd $(srcdir) && misc/depmod.sh sgialdigi -laudio $(ALLEGRO_MODULE_SGIAL_FILES)' >>makefile.dep
172diff -uNr allegro-4.1.6.old/makefile.lst allegro-4.1.6/makefile.lst
173--- allegro-4.1.6.old/makefile.lst Sat Nov 30 12:13:21 2002
174+++ allegro-4.1.6/makefile.lst Fri Dec 6 17:40:10 2002
175@@ -268,6 +268,8 @@
176 ALLEGRO_SRC_UNIX_FILES = \
177 src/unix/alsa.c \
178 src/unix/alsamidi.c \
179+ src/unix/alsa9.c \
180+ src/unix/alsa9midi.c \
181 src/unix/arts.c \
182 src/unix/sgial.c \
183 src/unix/udjgpp.c \
184@@ -350,6 +352,12 @@
185 ALLEGRO_MODULE_ALSAMIDI_FILES = \
186 src/unix/alsamidi.c
187
188+ALLEGRO_MODULE_ALSA9DIGI_FILES = \
189+ src/unix/alsa9.c
190+
191+ALLEGRO_MODULE_ALSA9MIDI_FILES = \
192+ src/unix/alsa9midi.c
193+
194 ALLEGRO_MODULE_ESD_FILES = \
195 src/unix/uesd.c
196
197diff -uNr allegro-4.1.6.old/modules.lst allegro-4.1.6/modules.lst
198--- allegro-4.1.6.old/modules.lst Sat Nov 30 12:13:21 2002
199+++ allegro-4.1.6/modules.lst Fri Dec 6 17:40:10 2002
200@@ -9,3 +9,5 @@
201 alleg-sgialdigi.so
202 alleg-alsadigi.so
203 alleg-alsamidi.so
204+alleg-alsa9digi.so
205+alleg-alsa9midi.so
206diff -uNr allegro-4.1.6.old/setup/setup.c allegro-4.1.6/setup/setup.c
207--- allegro-4.1.6.old/setup/setup.c Sat Nov 30 12:13:22 2002
208+++ allegro-4.1.6/setup/setup.c Fri Dec 6 17:42:22 2002
209@@ -234,6 +234,17 @@
210 { "alsa_rawmidi_card", param_int, "", "", NULL, "Card:", NULL, NULL, "ALSA RawMIDI card number" },
211 { "alsa_rawmidi_device",param_int, "", "", NULL, "Dev:", NULL, NULL, "ALSA RawMIDI device number" },
212 #endif
213+
214+ #ifdef DIGI_ALSA9
215+ { "alsa_card", param_int, "", "", NULL, "Card:", NULL, NULL, "ALSA card number" },
216+ { "alsa_pcmdevice", param_int, "", "", NULL, "Dev:", NULL, NULL, "ALSA PCM device number" },
217+ { "alsa_numfrags", param_int, "", "", NULL, "NumFr:", NULL, NULL, "Number of fragments (use 2, other values make little difference)" },
218+ #endif
219+
220+ #ifdef MIDI_ALSA9
221+ { "alsa_rawmidi_card", param_int, "", "", NULL, "Card:", NULL, NULL, "ALSA RawMIDI card number" },
222+ { "alsa_rawmidi_device",param_int, "", "", NULL, "Dev:", NULL, NULL, "ALSA RawMIDI device number" },
223+ #endif
224
225 #ifdef MIDI_BEOS
226 { "be_midi_quality", param_int, "", "1", NULL, "Qual:", NULL, NULL, "BeOS MIDI synthetizer instruments quality (0 = low, 1 = high)" },
227@@ -432,6 +443,16 @@
228 }
229 #endif
230
231+ #ifdef DIGI_ALSA9
232+ case DIGI_ALSA9:
233+ {
234+ static char *param[] = {"flip_pan", "sound_bits", "sound_stereo", "alsa_numfrags", "alsa_card", "alsa_pcmdevice", "sound_freq", "digi_volume", NULL};
235+ digi_cards[c].param = uconvert_static_string_array(param);
236+ digi_cards[c].desc = uconvert_static_string("ALSA Sound System");
237+ break;
238+ }
239+ #endif
240+
241 #ifdef DIGI_BEOS
242 case DIGI_BEOS:
243 {
244@@ -550,6 +571,16 @@
245 {
246 static char *param[] = {"22", "alsa_rawmidi_card", "alsa_rawmidi_device", "", "midi_volume", NULL};
247 midi_cards[c].param = uconvert_static_string_array(param);
248+ midi_cards[c].desc = uconvert_static_string("ALSA RawMIDI");
249+ break;
250+ }
251+ #endif
252+
253+ #ifdef MIDI_ALSA9
254+ case MIDI_ALSA9:
255+ {
256+ static char *param[] = {"22", "alsa_rawmidi_card", "alsa_rawmidi_device", "", "midi_volume", NULL};
257+ midi_cards[c].param = uconvert_static_string_array(param);
258 midi_cards[c].desc = uconvert_static_string("ALSA RawMIDI");
259 break;
260 }
261diff -uNr allegro-4.1.6.old/src/unix/alsa9.c allegro-4.1.6/src/unix/alsa9.c
262--- allegro-4.1.6.old/src/unix/alsa9.c Thu Jan 1 01:00:00 1970
263+++ allegro-4.1.6/src/unix/alsa9.c Mon Oct 28 21:20:48 2002
264@@ -0,0 +1,428 @@
265+/* ______ ___ ___
266+ * /\ _ \ /\_ \ /\_ \
267+ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
268+ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
269+ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
270+ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
271+ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
272+ * /\____/
273+ * \_/__/
274+ *
275+ * ALSA 0.9 sound driver.
276+ *
277+ * By Grzegorz Godlewski based on Alsa 0.5, OSS and MPlayer 0.9
278+ *
279+ * See readme.txt for copyright information.
280+ */
281+
282+
283+#include "allegro.h"
284+
285+#if (defined DIGI_ALSA9) && ((!defined ALLEGRO_WITH_MODULES) || (defined ALLEGRO_MODULE))
286+
287+#include "allegro/internal/aintern.h"
288+#ifdef ALLEGRO_QNX
289+#include "allegro/platform/aintqnx.h"
290+#else
291+#include "allegro/platform/aintunix.h"
292+#endif
293+
294+#ifndef SCAN_DEPEND
295+ #include <string.h>
296+ #include <alsa/asoundlib.h>
297+#endif
298+
299+#ifndef SND_PCM_FORMAT_S16_NE
300+ #ifdef ALLEGRO_BIG_ENDIAN
301+ #define SND_PCM_FORMAT_S16_NE SND_PCM_FORMAT_S16_BE
302+ #else
303+ #define SND_PCM_FORMAT_S16_NE SND_PCM_FORMAT_S16_LE
304+ #endif
305+#endif
306+#ifndef SND_PCM_FORMAT_U16_NE
307+ #ifdef ALLEGRO_BIG_ENDIAN
308+ #define SND_PCM_FORMAT_U16_NE SND_PCM_FORMAT_U16_BE
309+ #else
310+ #define SND_PCM_FORMAT_U16_NE SND_PCM_FORMAT_U16_LE
311+ #endif
312+#endif
313+
314+
315+#define ALSA9_DEFAULT_NUMFRAGS 2
316+#define ALSA9_DEFAULT_FRAGSIZE 8192
317+
318+static snd_pcm_t *pcm_handle=NULL;
319+static int alsa9_bufsize;
320+static unsigned char *alsa9_bufdata;
321+static int alsa9_bits, alsa9_signed, alsa9_rate, alsa9_stereo;
322+static int periods,periodsize;
323+
324+static char alsa9_desc[256] = EMPTY_STRING;
325+
326+
327+
328+static int alsa9_detect(int input);
329+static int alsa9_init(int input, int voices);
330+static void alsa9_exit(int input);
331+static int alsa9_mixer_volume(int volume);
332+static int alsa9_buffer_size(void);
333+
334+
335+
336+DIGI_DRIVER digi_alsa9 =
337+{
338+ DIGI_ALSA9,
339+ empty_string,
340+ empty_string,
341+ "ALSA9",
342+ 0,
343+ 0,
344+ MIXER_MAX_SFX,
345+ MIXER_DEF_SFX,
346+
347+ alsa9_detect,
348+ alsa9_init,
349+ alsa9_exit,
350+ alsa9_mixer_volume,
351+
352+ NULL,
353+ NULL,
354+ alsa9_buffer_size,
355+ _mixer_init_voice,
356+ _mixer_release_voice,
357+ _mixer_start_voice,
358+ _mixer_stop_voice,
359+ _mixer_loop_voice,
360+
361+ _mixer_get_position,
362+ _mixer_set_position,
363+
364+ _mixer_get_volume,
365+ _mixer_set_volume,
366+ _mixer_ramp_volume,
367+ _mixer_stop_volume_ramp,
368+
369+ _mixer_get_frequency,
370+ _mixer_set_frequency,
371+ _mixer_sweep_frequency,
372+ _mixer_stop_frequency_sweep,
373+
374+ _mixer_get_pan,
375+ _mixer_set_pan,
376+ _mixer_sweep_pan,
377+ _mixer_stop_pan_sweep,
378+
379+ _mixer_set_echo,
380+ _mixer_set_tremolo,
381+ _mixer_set_vibrato,
382+ 0, 0,
383+ 0,
384+ 0,
385+ 0,
386+ 0,
387+ 0,
388+ 0
389+};
390+
391+
392+
393+/* alsa9_buffer_size:
394+ * Returns the current DMA buffer size, for use by the audiostream code.
395+ */
396+static int alsa9_buffer_size()
397+{
398+ return alsa9_bufsize;
399+}
400+
401+/* alsa9_update:
402+ * Update data.
403+ */
404+static void alsa9_update(int threaded)
405+{
406+ int frames;
407+
408+ if (!pcm_handle) {
409+ printf("alsa-play: device configuration error");
410+ return;
411+ }
412+
413+ frames = periodsize >> ((alsa9_stereo)?3:2);
414+ while (snd_pcm_writei(pcm_handle, alsa9_bufdata, frames) <0)
415+ {
416+ snd_pcm_prepare(pcm_handle);
417+ }
418+ _mix_some_samples((unsigned long) alsa9_bufdata, 0, alsa9_signed);
419+}
420+
421+
422+
423+/* alsa9_detect:
424+ * Detect driver presence.
425+ */
426+static int alsa9_detect(int input)
427+{
428+ snd_pcm_t *handle;
429+ int card, device;
430+ char tmp1[128], tmp2[128];
431+ int ret = FALSE;
432+ snd_pcm_hw_params_t *hwparams;
433+ char pcm_name[128];
434+
435+ card = get_config_int(uconvert_ascii("sound", tmp1),
436+ uconvert_ascii("alsa_card", tmp2),
437+ 0);
438+
439+ device = get_config_int(uconvert_ascii("sound", tmp1),
440+ uconvert_ascii("alsa_pcmdevice", tmp2),
441+ 0);
442+
443+
444+ sprintf(pcm_name,"plughw:%d,%d",card,device);
445+ snd_pcm_hw_params_alloca(&hwparams);
446+
447+ if (!(snd_pcm_open(&handle, pcm_name, SND_PCM_STREAM_PLAYBACK , 0) < 0)) {
448+ if (!(snd_pcm_hw_params_any(handle, hwparams) < 0)) {
449+ ret = TRUE;
450+ }
451+ snd_pcm_close(handle);
452+ }
453+
454+ return ret;
455+}
456+
457+
458+
459+/* alsa9_init:
460+ * ALSA9 init routine.
461+ */
462+static int alsa9_init(int input, int voices)
463+{
464+ int card, device;
465+ int format, bps; //, fragsize, numfrags;
466+ char tmp1[128], tmp2[128];
467+ int exact_rate;
468+ int dir;
469+
470+ snd_pcm_hw_params_t *hwparams;
471+ char pcm_name[128];
472+
473+ if (input) {
474+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Input is not supported"));
475+ return -1;
476+ }
477+
478+ /* Load config. */
479+ card = get_config_int(uconvert_ascii("sound", tmp1),
480+ uconvert_ascii("alsadigi_card", tmp2),
481+ 0); //snd_defaults_card());
482+
483+ device = get_config_int(uconvert_ascii("sound", tmp1),
484+ uconvert_ascii("alsadigi_pcmdevice", tmp2),
485+ 0); //snd_defaults_pcm_device());
486+
487+ periodsize = get_config_int(uconvert_ascii("sound", tmp1),
488+ uconvert_ascii("alsa_fragsize", tmp2),
489+ ALSA9_DEFAULT_FRAGSIZE);
490+
491+ periods = get_config_int(uconvert_ascii("sound", tmp1),
492+ uconvert_ascii("alsa_numfrags", tmp2),
493+ ALSA9_DEFAULT_NUMFRAGS);
494+
495+ sprintf(pcm_name,"plughw:%d,%d",card,device);
496+ snd_pcm_hw_params_alloca(&hwparams);
497+
498+ /* Open PCM device. */
499+ if (snd_pcm_open(&pcm_handle, pcm_name, (SND_PCM_STREAM_PLAYBACK), 0) < 0) {
500+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not open card/pcm device"));
501+ goto error;
502+ }
503+
504+ /* Init hwparams with full configuration space */
505+ if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
506+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not configure this PCM device"));
507+ goto error;
508+ }
509+
510+ if (snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
511+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error setting access"));
512+ goto error;
513+ }
514+
515+ /* Set format variables. */
516+ alsa9_bits = (_sound_bits == 8) ? 8 : 16;
517+ alsa9_stereo = (_sound_stereo) ? 1 : 0;
518+ alsa9_rate = (_sound_freq > 0) ? _sound_freq : 44100;
519+
520+ format = ((alsa9_bits == 16) ? SND_PCM_FORMAT_S16_NE : SND_PCM_FORMAT_S8);
521+
522+ alsa9_signed = 0;
523+ bps = alsa9_rate * (alsa9_stereo ? 2 : 1);
524+ switch (format) {
525+ case SND_PCM_FORMAT_S8:
526+ alsa9_signed = 1;
527+ case SND_PCM_FORMAT_U8:
528+ alsa9_bits = 8;
529+ break;
530+ case SND_PCM_FORMAT_S16_NE:
531+ alsa9_signed = 1;
532+ case SND_PCM_FORMAT_U16_NE:
533+ alsa9_bits = 16;
534+ bps <<= 1;
535+ if (sizeof(short) != 2) {
536+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
537+ goto error;
538+ }
539+ break;
540+ default:
541+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
542+ goto error;
543+ }
544+
545+ /* Set sample format */
546+ if (snd_pcm_hw_params_set_format(pcm_handle, hwparams, format) < 0) {
547+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error setting format"));
548+ goto error;
549+ }
550+
551+
552+ /* Set sample rate. If the exact rate is not supported */
553+ /* by the hardware, use nearest possible rate. */
554+ exact_rate=snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, alsa9_rate, &dir);
555+ if (dir!=0)
556+ {
557+ //fprintf(stderr, "The rate %d Hz is not supported by your hardware.\n
558+ // ==> Using %d Hz instead.\n", rate, exact_rate);
559+// ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("The rate is not supported by your hardware"));
560+// goto error;
561+ }
562+
563+ /* Set number of channels */
564+ if (snd_pcm_hw_params_set_channels(pcm_handle, hwparams, (alsa9_stereo) ? 2:1) < 0) {
565+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error setting channels"));
566+ goto error;
567+ }
568+
569+ /* Set number of numfrags. numfrags used to be called fragments. */
570+ if (snd_pcm_hw_params_set_periods(pcm_handle, hwparams, periods, 0) < 0) {
571+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error setting numfrags"));
572+ goto error;
573+ }
574+
575+ alsa9_bufsize=(periodsize * periods)>>2;
576+ /* Set buffer size (in frames). The resulting latency is given by */
577+ /* latency = fragsize * numfrags / (rate * bytes_per_frame) */
578+ if (snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, alsa9_bufsize) < 0) {
579+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error setting buffersize"));
580+ goto error;
581+ }
582+
583+ /* Apply HW parameter settings to */
584+ /* PCM device and prepare device */
585+ if (snd_pcm_hw_params(pcm_handle, hwparams) < 0) {
586+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Error setting HW params"));
587+ goto error;
588+ }
589+
590+ alsa9_bufdata = malloc(alsa9_bufsize);
591+
592+ if (!alsa9_bufdata) {
593+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not allocate audio buffer"));
594+ goto error;
595+ }
596+
597+ /* Initialise mixer. */
598+ digi_alsa9.voices = voices;
599+
600+ if (_mixer_init(alsa9_bufsize / (alsa9_bits / 8), alsa9_rate,
601+ alsa9_stereo, ((alsa9_bits == 16) ? 1 : 0),
602+ &digi_alsa9.voices) != 0) {
603+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not init software mixer"));
604+ goto error;
605+ }
606+
607+ _mix_some_samples((unsigned long) alsa9_bufdata, 0, alsa9_signed);
608+
609+ /* Add audio interrupt. */
610+ _unix_bg_man->register_func(alsa9_update);
611+
612+ uszprintf(alsa9_desc, sizeof(alsa9_desc),
613+ get_config_text("Card #%d, device #%d: %d bits, %s, %d bps, %s"),
614+ card, device, alsa9_bits,
615+ uconvert_ascii((alsa9_signed ? "signed" : "unsigned"), tmp1),
616+ alsa9_rate,
617+ uconvert_ascii((alsa9_stereo ? "stereo" : "mono"), tmp2));
618+
619+ digi_driver->desc = alsa9_desc;
620+ return 0;
621+
622+ error:
623+
624+ if (pcm_handle) {
625+ snd_pcm_close(pcm_handle);
626+ pcm_handle = NULL;
627+ }
628+
629+ return -1;
630+}
631+
632+
633+
634+/* alsa9_exit:
635+ * Shutdown ALSA9 driver.
636+ */
637+static void alsa9_exit(int input)
638+{
639+ if (input) {
640+ return;
641+ }
642+
643+ _unix_bg_man->unregister_func(alsa9_update);
644+
645+ free(alsa9_bufdata);
646+ alsa9_bufdata = NULL;
647+
648+ _mixer_exit();
649+
650+ snd_pcm_close(pcm_handle);
651+}
652+
653+
654+
655+/* alsa9_mixer_volume:
656+ * Set mixer volume (0-255)
657+ */
658+static int alsa9_mixer_volume(int volume)
659+{
660+ /* TODO */
661+#if 0
662+ snd_mixer_t *handle;
663+ int card, device;
664+
665+ if (snd_mixer_open(&handle, card, device) == 0) {
666+ /* do something special */
667+ snd_mixer_close(handle);
668+ return 0;
669+ }
670+
671+ return -1;
672+#else
673+ return 0;
674+#endif
675+}
676+
677+
678+
679+#ifdef ALLEGRO_MODULE
680+
681+/* _module_init:
682+ * Called when loaded as a dynamically linked module.
683+ */
684+void _module_init(int system_driver)
685+{
686+ _unix_register_digi_driver(DIGI_ALSA9, &digi_alsa9, TRUE, TRUE);
687+}
688+
689+#endif
690+
691+#endif
692+
693diff -uNr allegro-4.1.6.old/src/unix/alsa9midi.c allegro-4.1.6/src/unix/alsa9midi.c
694--- allegro-4.1.6.old/src/unix/alsa9midi.c Thu Jan 1 01:00:00 1970
695+++ allegro-4.1.6/src/unix/alsa9midi.c Mon Oct 28 20:51:06 2002
696@@ -0,0 +1,251 @@
697+/* ______ ___ ___
698+ * /\ _ \ /\_ \ /\_ \
699+ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
700+ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
701+ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
702+ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
703+ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
704+ * /\____/
705+ * \_/__/
706+ *
707+ * ALSA 0.9 RawMIDI Sound driver.
708+ *
709+ * By Grzegorz Godlewski based on 0.5 version
710+ *
711+ * See readme.txt for copyright information.
712+ */
713+
714+#include "allegro.h"
715+
716+#if (defined MIDI_ALSA9) && ((!defined ALLEGRO_WITH_MODULES) || (defined ALLEGRO_MODULE))
717+
718+#include "allegro/internal/aintern.h"
719+#ifdef ALLEGRO_QNX
720+#include "allegro/platform/aintqnx.h"
721+#else
722+#include "allegro/platform/aintunix.h"
723+#endif
724+
725+#ifndef SCAN_DEPEND
726+ #include <stdlib.h>
727+ #include <stdio.h>
728+ #include <string.h>
729+ #include <errno.h>
730+ #include <sys/asoundlib.h>
731+#endif
732+
733+/* external interface to the ALSA9 rawmidi driver */
734+static int alsa9_rawmidi_detect(int input);
735+static int alsa9_rawmidi_init(int input, int voices);
736+static void alsa9_rawmidi_exit(int input);
737+static void alsa9_rawmidi_output(int data);
738+
739+static char alsa9_rawmidi_desc[256];
740+
741+static snd_rawmidi_t *rawmidi_handle = NULL;
742+
743+MIDI_DRIVER midi_alsa9 =
744+{
745+ MIDI_ALSA9, /* id */
746+ empty_string, /* name */
747+ empty_string, /* desc */
748+ "ALSA9 RawMIDI", /* ASCII name */
749+ 0, 0, 0xFFFF, 0, -1, -1, /* voices, basevoice, max_voices, def_voices, xmin, xmax */
750+ alsa9_rawmidi_detect, /* detect */
751+ alsa9_rawmidi_init, /* init */
752+ alsa9_rawmidi_exit, /* exit */
753+ NULL, /* mixer_volume */
754+ alsa9_rawmidi_output, /* raw_midi */
755+ _dummy_load_patches, /* load_patches */
756+ _dummy_adjust_patches, /* adjust_patches */
757+ _dummy_key_on, /* key_on */
758+ _dummy_noop1, /* key_off */
759+ _dummy_noop2, /* set_volume */
760+ _dummy_noop3, /* set_pitch */
761+ _dummy_noop2, /* set_pan */
762+ _dummy_noop2 /* set_vibrato */
763+};
764+
765+/* alsa9_rawmidi_detect:
766+ * ALSA9 RawMIDI detection.
767+ */
768+static int alsa9_rawmidi_detect(int input)
769+{
770+ int card = -1;
771+ int device = -1;
772+ int ret = FALSE, err;
773+ char tmp1[128], tmp2[128], temp[256];
774+ snd_rawmidi_t *handle = NULL;
775+ char pcm_name[128];
776+
777+ if(input) {
778+ /* Input not supported.
779+ card = get_config_int(uconvert_ascii("sound", tmp1),
780+ uconvert_ascii("alsa_rawmidi_input_card", tmp2),
781+ 0); // snd_defaults_rawmidi_card());
782+
783+ device = get_config_int(uconvert_ascii("sound", tmp1),
784+ uconvert_ascii("alsa_rawmidi_input_device", tmp2),
785+ 0); // snd_defaults_rawmidi_device());
786+
787+ sprintf(pcm_name,"plughw:%d,%d",card,device);
788+ if ((err = snd_rawmidi_open(&handle, NULL,pcm_name, SND_RAWMIDI_OPEN_INPUT)) < 0) {
789+ snprintf(temp, sizeof(temp), "Could not open card/rawmidi device: %s", snd_strerror(err));
790+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(temp));
791+ ret = FALSE;
792+ }
793+
794+ snd_rawmidi_close(handle);
795+ */
796+ ret = FALSE;
797+
798+ }
799+ else {
800+
801+ card = get_config_int(uconvert_ascii("sound", tmp1),
802+ uconvert_ascii("alsa_rawmidi_card", tmp2),
803+ 0); // snd_defaults_rawmidi_card());
804+
805+ device = get_config_int(uconvert_ascii("sound", tmp1),
806+ uconvert_ascii("alsa_rawmidi_device", tmp2),
807+ 0); // snd_defaults_rawmidi_device());
808+
809+ sprintf(pcm_name,"plughw:%d,%d",card,device);
810+// if ((err = snd_rawmidi_open(NULL,&handle, pcm_name, SND_RAWMIDI_APPEND)) < 0) {
811+ if ((err = snd_rawmidi_open(NULL,&handle, "default", SND_RAWMIDI_APPEND)) < 0) {
812+ snprintf(temp, sizeof(temp), "Could not open card/rawmidi device: %s", snd_strerror(err));
813+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(temp));
814+ ret = FALSE;
815+ }
816+
817+ snd_rawmidi_close(handle);
818+
819+ ret = TRUE;
820+ }
821+
822+ return ret;
823+}
824+
825+/* alsa9_rawmidi_init:
826+ * Setup the ALSA RawMIDI interface.
827+ */
828+static int alsa9_rawmidi_init(int input, int voices)
829+{
830+ int card = -1;
831+ int device = -1;
832+ int ret = -1, err;
833+ char tmp1[128], tmp2[128], temp[256];
834+// snd_rawmidi_info_t info;
835+ char pcm_name[128];
836+
837+ if(input) {
838+ /* Input not supported
839+ card = get_config_int(uconvert_ascii("sound", tmp1),
840+ uconvert_ascii("alsa_rawmidi_input_card", tmp2),
841+ 0); // snd_defaults_rawmidi_card());
842+
843+ device = get_config_int(uconvert_ascii("sound", tmp1),
844+ uconvert_ascii("alsa_rawmidi_input_device", tmp2),
845+ 0); // snd_defaults_rawmidi_device());
846+
847+ sprintf(pcm_name,"plughw:%d,%d",card,device);
848+ if ((err = snd_rawmidi_open(&rawmidi_handle, NULL,pcm_name, SND_RAWMIDI_OPEN_INPUT)) < 0) {
849+ snprintf(temp, sizeof(temp), "Could not open card/rawmidi device: %s", snd_strerror(err));
850+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(temp));
851+ ret = -1;
852+ }
853+ */
854+ ret = -1;
855+
856+ }
857+ else {
858+
859+ card = get_config_int(uconvert_ascii("sound", tmp1),
860+ uconvert_ascii("alsa_rawmidi_card", tmp2),
861+ 0); // snd_defaults_rawmidi_card());
862+
863+ device = get_config_int(uconvert_ascii("sound", tmp1),
864+ uconvert_ascii("alsa_rawmidi_device", tmp2),
865+ 0); // snd_defaults_rawmidi_device());
866+
867+ sprintf(pcm_name,"plughw:%d,%d",card,device);
868+
869+// if ((err = snd_rawmidi_open(NULL,&rawmidi_handle, pcm_name, SND_RAWMIDI_APPEND)) < 0) {
870+ if ((err = snd_rawmidi_open(NULL,&rawmidi_handle, "default", SND_RAWMIDI_APPEND)) < 0) {
871+ snprintf(temp, sizeof(temp), "Could not open card/rawmidi device: %s", snd_strerror(err));
872+ ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(temp));
873+ ret = -1;
874+ }
875+
876+ ret = 0;
877+ }
878+
879+ if(rawmidi_handle) {
880+ snd_rawmidi_block_mode(rawmidi_handle, 1);
881+// snd_rawmidi_info(rawmidi_handle, &info);
882+
883+// strcpy(alsa9_rawmidi_desc, info.name);
884+// midi_alsa9.desc = alsa9_rawmidi_desc;
885+
886+ LOCK_VARIABLE(alsa9_rawmidi_desc);
887+ LOCK_VARIABLE(rawmidi_handle);
888+ LOCK_VARIABLE(midi_alsa9);
889+ LOCK_FUNCTION(alsa9_rawmidi_output);
890+ }
891+
892+ return ret;
893+}
894+
895+/* alsa9_rawmidi_exit:
896+ * Clean up.
897+ */
898+static void alsa9_rawmidi_exit(int input)
899+{
900+ if(rawmidi_handle) {
901+ snd_rawmidi_output_drain(rawmidi_handle);
902+ snd_rawmidi_close(rawmidi_handle);
903+ }
904+
905+ rawmidi_handle = NULL;
906+}
907+
908+/* alsa9_rawmidi_output:
909+ * Outputs MIDI data.
910+ */
911+static void alsa9_rawmidi_output(int data)
912+{
913+ int err;
914+
915+ err = snd_rawmidi_write(rawmidi_handle, &data, sizeof(char));
916+
917+}
918+END_OF_STATIC_FUNCTION(alsa9_rawmidi_output);
919+
920+/* alsa9_rawmidi_input:
921+ * Reads MIDI data.
922+ * not supported...
923+static INLINE int alsa9_rawmidi_input(void)
924+{
925+ char data = 0;
926+
927+ if(snd_rawmidi_read(rawmidi_handle, &data, sizeof(char)) > 0)
928+ return data;
929+ else
930+ return 0;
931+}
932+*/
933+
934+#ifdef ALLEGRO_MODULE
935+
936+/* _module_init:
937+ * Called when loaded as a dynamically linked module.
938+ */
939+void _module_init(int system_driver)
940+{
941+ _unix_register_midi_driver(MIDI_ALSA9, &midi_alsa9, TRUE, TRUE);
942+}
943+
944+#endif /* ALLEGRO_MODULE */
945+
946+#endif /* MIDI_ALSA9 */
947+
This page took 0.190214 seconds and 4 git commands to generate.