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
5 #endif /* ALLEGRO_WITH_ALSAMIDI */
7 +#ifdef ALLEGRO_WITH_ALSA9DIGI
9 +#define DIGI_ALSA9 AL_ID('A','L','S','9')
11 +#ifndef ALLEGRO_WITH_MODULES
13 +AL_VAR(DIGI_DRIVER, digi_alsa9);
15 +#define DIGI_DRIVER_ALSA9 \
16 + { DIGI_ALSA9, &digi_alsa9, TRUE },
20 +#endif /* ALLEGRO_WITH_ALSA9DIGI */
23 +#ifdef ALLEGRO_WITH_ALSA9MIDI
25 +#define MIDI_ALSA9 AL_ID('A','M','I','9')
27 +#ifndef ALLEGRO_WITH_MODULES
29 +AL_VAR(MIDI_DRIVER, midi_alsa9);
31 +#define MIDI_DRIVER_ALSA9 \
32 + { MIDI_ALSA9, &midi_alsa9, TRUE },
36 +#endif /* ALLEGRO_WITH_ALSA9MIDI */
40 /************************************/
41 diff -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
48 +dnl Test for ALSA9 DIGI driver.
51 +dnl allegro_enable_alsa9digi=(yes|)
52 +dnl allegro_cv_support_alsa9digi=(yes|)
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)
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"
75 +dnl Test for ALSA9 MIDI driver.
78 +dnl allegro_enable_alsa9midi=(yes|)
79 +dnl allegro_support_alsa9midi=(yes|)
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)
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"
102 dnl Test for ESD DIGI driver.
105 diff -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
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
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
120 _disabled_modules="alsamidi $_disabled_modules"
123 +dnl Test for ALSA9 drivers.
124 +ALLEGRO_ACTEST_ALSA9DIGI
125 +if test "$allegro_cv_support_alsa9digi" = yes; then
126 + AC_DEFINE(ALLEGRO_WITH_ALSA9DIGI,1,[Define if ALSA9 DIGI driver is supported.])
127 + _enabled_modules="alsa9digi $_enabled_modules"
129 + _disabled_modules="alsa9digi $_disabled_modules"
132 +ALLEGRO_ACTEST_ALSA9MIDI
133 +if test "$allegro_cv_support_alsa9midi" = yes; then
134 + AC_DEFINE(ALLEGRO_WITH_ALSA9MIDI,1,[Define if ALSA9 MIDI driver is supported.])
135 + _enabled_modules="alsa9midi $_enabled_modules"
137 + _disabled_modules="alsa9midi $_disabled_modules"
140 dnl Test for ESD drivers.
141 ALLEGRO_ACTEST_ESDDIGI
142 if test -n "$allegro_support_esddigi"; then
144 ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsamidi.so"
148 + if test "X$allegro_cv_support_alsa9digi" = "Xyes"; then
149 + ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsa9digi.so"
153 + if test "X$allegro_cv_support_alsa9midi" = "Xyes"; then
154 + ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsa9midi.so"
158 if test "X$allegro_support_esddigi" = "Xyes"; then
159 ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-esddigi.so"
160 diff -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
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
172 diff -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
176 ALLEGRO_SRC_UNIX_FILES = \
178 src/unix/alsamidi.c \
180 + src/unix/alsa9midi.c \
185 ALLEGRO_MODULE_ALSAMIDI_FILES = \
188 +ALLEGRO_MODULE_ALSA9DIGI_FILES = \
191 +ALLEGRO_MODULE_ALSA9MIDI_FILES = \
192 + src/unix/alsa9midi.c
194 ALLEGRO_MODULE_ESD_FILES = \
197 diff -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
206 diff -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
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" },
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)" },
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" },
226 { "be_midi_quality", param_int, "", "1", NULL, "Qual:", NULL, NULL, "BeOS MIDI synthetizer instruments quality (0 = low, 1 = high)" },
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");
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");
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");
261 diff -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
266 + * /\ _ \ /\_ \ /\_ \
267 + * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
268 + * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
269 + * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
270 + * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
271 + * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
275 + * ALSA 0.9 sound driver.
277 + * By Grzegorz Godlewski based on Alsa 0.5, OSS and MPlayer 0.9
279 + * See readme.txt for copyright information.
283 +#include "allegro.h"
285 +#if (defined DIGI_ALSA9) && ((!defined ALLEGRO_WITH_MODULES) || (defined ALLEGRO_MODULE))
287 +#include "allegro/internal/aintern.h"
289 +#include "allegro/platform/aintqnx.h"
291 +#include "allegro/platform/aintunix.h"
295 + #include <string.h>
296 + #include <alsa/asoundlib.h>
299 +#ifndef SND_PCM_FORMAT_S16_NE
300 + #ifdef ALLEGRO_BIG_ENDIAN
301 + #define SND_PCM_FORMAT_S16_NE SND_PCM_FORMAT_S16_BE
303 + #define SND_PCM_FORMAT_S16_NE SND_PCM_FORMAT_S16_LE
306 +#ifndef SND_PCM_FORMAT_U16_NE
307 + #ifdef ALLEGRO_BIG_ENDIAN
308 + #define SND_PCM_FORMAT_U16_NE SND_PCM_FORMAT_U16_BE
310 + #define SND_PCM_FORMAT_U16_NE SND_PCM_FORMAT_U16_LE
315 +#define ALSA9_DEFAULT_NUMFRAGS 2
316 +#define ALSA9_DEFAULT_FRAGSIZE 8192
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;
324 +static char alsa9_desc[256] = EMPTY_STRING;
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);
336 +DIGI_DRIVER digi_alsa9 =
350 + alsa9_mixer_volume,
356 + _mixer_release_voice,
357 + _mixer_start_voice,
361 + _mixer_get_position,
362 + _mixer_set_position,
366 + _mixer_ramp_volume,
367 + _mixer_stop_volume_ramp,
369 + _mixer_get_frequency,
370 + _mixer_set_frequency,
371 + _mixer_sweep_frequency,
372 + _mixer_stop_frequency_sweep,
377 + _mixer_stop_pan_sweep,
380 + _mixer_set_tremolo,
381 + _mixer_set_vibrato,
393 +/* alsa9_buffer_size:
394 + * Returns the current DMA buffer size, for use by the audiostream code.
396 +static int alsa9_buffer_size()
398 + return alsa9_bufsize;
404 +static void alsa9_update(int threaded)
409 + printf("alsa-play: device configuration error");
413 + frames = periodsize >> ((alsa9_stereo)?3:2);
414 + while (snd_pcm_writei(pcm_handle, alsa9_bufdata, frames) <0)
416 + snd_pcm_prepare(pcm_handle);
418 + _mix_some_samples((unsigned long) alsa9_bufdata, 0, alsa9_signed);
424 + * Detect driver presence.
426 +static int alsa9_detect(int input)
430 + char tmp1[128], tmp2[128];
432 + snd_pcm_hw_params_t *hwparams;
433 + char pcm_name[128];
435 + card = get_config_int(uconvert_ascii("sound", tmp1),
436 + uconvert_ascii("alsa_card", tmp2),
439 + device = get_config_int(uconvert_ascii("sound", tmp1),
440 + uconvert_ascii("alsa_pcmdevice", tmp2),
444 + sprintf(pcm_name,"plughw:%d,%d",card,device);
445 + snd_pcm_hw_params_alloca(&hwparams);
447 + if (!(snd_pcm_open(&handle, pcm_name, SND_PCM_STREAM_PLAYBACK , 0) < 0)) {
448 + if (!(snd_pcm_hw_params_any(handle, hwparams) < 0)) {
451 + snd_pcm_close(handle);
460 + * ALSA9 init routine.
462 +static int alsa9_init(int input, int voices)
465 + int format, bps; //, fragsize, numfrags;
466 + char tmp1[128], tmp2[128];
470 + snd_pcm_hw_params_t *hwparams;
471 + char pcm_name[128];
474 + ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Input is not supported"));
479 + card = get_config_int(uconvert_ascii("sound", tmp1),
480 + uconvert_ascii("alsadigi_card", tmp2),
481 + 0); //snd_defaults_card());
483 + device = get_config_int(uconvert_ascii("sound", tmp1),
484 + uconvert_ascii("alsadigi_pcmdevice", tmp2),
485 + 0); //snd_defaults_pcm_device());
487 + periodsize = get_config_int(uconvert_ascii("sound", tmp1),
488 + uconvert_ascii("alsa_fragsize", tmp2),
489 + ALSA9_DEFAULT_FRAGSIZE);
491 + periods = get_config_int(uconvert_ascii("sound", tmp1),
492 + uconvert_ascii("alsa_numfrags", tmp2),
493 + ALSA9_DEFAULT_NUMFRAGS);
495 + sprintf(pcm_name,"plughw:%d,%d",card,device);
496 + snd_pcm_hw_params_alloca(&hwparams);
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"));
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"));
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"));
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;
520 + format = ((alsa9_bits == 16) ? SND_PCM_FORMAT_S16_NE : SND_PCM_FORMAT_S8);
523 + bps = alsa9_rate * (alsa9_stereo ? 2 : 1);
525 + case SND_PCM_FORMAT_S8:
527 + case SND_PCM_FORMAT_U8:
530 + case SND_PCM_FORMAT_S16_NE:
532 + case SND_PCM_FORMAT_U16_NE:
535 + if (sizeof(short) != 2) {
536 + ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
541 + ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
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"));
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);
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"));
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"));
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"));
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"));
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"));
590 + alsa9_bufdata = malloc(alsa9_bufsize);
592 + if (!alsa9_bufdata) {
593 + ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not allocate audio buffer"));
597 + /* Initialise mixer. */
598 + digi_alsa9.voices = voices;
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"));
607 + _mix_some_samples((unsigned long) alsa9_bufdata, 0, alsa9_signed);
609 + /* Add audio interrupt. */
610 + _unix_bg_man->register_func(alsa9_update);
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),
617 + uconvert_ascii((alsa9_stereo ? "stereo" : "mono"), tmp2));
619 + digi_driver->desc = alsa9_desc;
625 + snd_pcm_close(pcm_handle);
635 + * Shutdown ALSA9 driver.
637 +static void alsa9_exit(int input)
643 + _unix_bg_man->unregister_func(alsa9_update);
645 + free(alsa9_bufdata);
646 + alsa9_bufdata = NULL;
650 + snd_pcm_close(pcm_handle);
655 +/* alsa9_mixer_volume:
656 + * Set mixer volume (0-255)
658 +static int alsa9_mixer_volume(int volume)
662 + snd_mixer_t *handle;
665 + if (snd_mixer_open(&handle, card, device) == 0) {
666 + /* do something special */
667 + snd_mixer_close(handle);
679 +#ifdef ALLEGRO_MODULE
682 + * Called when loaded as a dynamically linked module.
684 +void _module_init(int system_driver)
686 + _unix_register_digi_driver(DIGI_ALSA9, &digi_alsa9, TRUE, TRUE);
693 diff -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
698 + * /\ _ \ /\_ \ /\_ \
699 + * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
700 + * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
701 + * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
702 + * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
703 + * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
707 + * ALSA 0.9 RawMIDI Sound driver.
709 + * By Grzegorz Godlewski based on 0.5 version
711 + * See readme.txt for copyright information.
714 +#include "allegro.h"
716 +#if (defined MIDI_ALSA9) && ((!defined ALLEGRO_WITH_MODULES) || (defined ALLEGRO_MODULE))
718 +#include "allegro/internal/aintern.h"
720 +#include "allegro/platform/aintqnx.h"
722 +#include "allegro/platform/aintunix.h"
726 + #include <stdlib.h>
728 + #include <string.h>
730 + #include <sys/asoundlib.h>
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);
739 +static char alsa9_rawmidi_desc[256];
741 +static snd_rawmidi_t *rawmidi_handle = NULL;
743 +MIDI_DRIVER midi_alsa9 =
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 */
765 +/* alsa9_rawmidi_detect:
766 + * ALSA9 RawMIDI detection.
768 +static int alsa9_rawmidi_detect(int input)
772 + int ret = FALSE, err;
773 + char tmp1[128], tmp2[128], temp[256];
774 + snd_rawmidi_t *handle = NULL;
775 + char pcm_name[128];
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());
783 + device = get_config_int(uconvert_ascii("sound", tmp1),
784 + uconvert_ascii("alsa_rawmidi_input_device", tmp2),
785 + 0); // snd_defaults_rawmidi_device());
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));
794 + snd_rawmidi_close(handle);
801 + card = get_config_int(uconvert_ascii("sound", tmp1),
802 + uconvert_ascii("alsa_rawmidi_card", tmp2),
803 + 0); // snd_defaults_rawmidi_card());
805 + device = get_config_int(uconvert_ascii("sound", tmp1),
806 + uconvert_ascii("alsa_rawmidi_device", tmp2),
807 + 0); // snd_defaults_rawmidi_device());
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));
817 + snd_rawmidi_close(handle);
825 +/* alsa9_rawmidi_init:
826 + * Setup the ALSA RawMIDI interface.
828 +static int alsa9_rawmidi_init(int input, int voices)
833 + char tmp1[128], tmp2[128], temp[256];
834 +// snd_rawmidi_info_t info;
835 + char pcm_name[128];
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());
843 + device = get_config_int(uconvert_ascii("sound", tmp1),
844 + uconvert_ascii("alsa_rawmidi_input_device", tmp2),
845 + 0); // snd_defaults_rawmidi_device());
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));
859 + card = get_config_int(uconvert_ascii("sound", tmp1),
860 + uconvert_ascii("alsa_rawmidi_card", tmp2),
861 + 0); // snd_defaults_rawmidi_card());
863 + device = get_config_int(uconvert_ascii("sound", tmp1),
864 + uconvert_ascii("alsa_rawmidi_device", tmp2),
865 + 0); // snd_defaults_rawmidi_device());
867 + sprintf(pcm_name,"plughw:%d,%d",card,device);
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));
879 + if(rawmidi_handle) {
880 + snd_rawmidi_block_mode(rawmidi_handle, 1);
881 +// snd_rawmidi_info(rawmidi_handle, &info);
883 +// strcpy(alsa9_rawmidi_desc, info.name);
884 +// midi_alsa9.desc = alsa9_rawmidi_desc;
886 + LOCK_VARIABLE(alsa9_rawmidi_desc);
887 + LOCK_VARIABLE(rawmidi_handle);
888 + LOCK_VARIABLE(midi_alsa9);
889 + LOCK_FUNCTION(alsa9_rawmidi_output);
895 +/* alsa9_rawmidi_exit:
898 +static void alsa9_rawmidi_exit(int input)
900 + if(rawmidi_handle) {
901 + snd_rawmidi_output_drain(rawmidi_handle);
902 + snd_rawmidi_close(rawmidi_handle);
905 + rawmidi_handle = NULL;
908 +/* alsa9_rawmidi_output:
909 + * Outputs MIDI data.
911 +static void alsa9_rawmidi_output(int data)
915 + err = snd_rawmidi_write(rawmidi_handle, &data, sizeof(char));
918 +END_OF_STATIC_FUNCTION(alsa9_rawmidi_output);
920 +/* alsa9_rawmidi_input:
923 +static INLINE int alsa9_rawmidi_input(void)
927 + if(snd_rawmidi_read(rawmidi_handle, &data, sizeof(char)) > 0)
934 +#ifdef ALLEGRO_MODULE
937 + * Called when loaded as a dynamically linked module.
939 +void _module_init(int system_driver)
941 + _unix_register_midi_driver(MIDI_ALSA9, &midi_alsa9, TRUE, TRUE);
944 +#endif /* ALLEGRO_MODULE */
946 +#endif /* MIDI_ALSA9 */