diff --git a/alsa-lib-git-fixes.diff b/alsa-lib-git-fixes.diff
index ed4678b..f6181a2 100644
--- a/alsa-lib-git-fixes.diff
+++ b/alsa-lib-git-fixes.diff
@@ -1,3 +1,19 @@
+diff --git a/configure.in b/configure.in
+index 4e5e757..cb2877b 100644
+--- a/configure.in
++++ b/configure.in
+@@ -594,8 +594,9 @@ AC_OUTPUT(Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg \
+ src/conf/cards/Makefile \
+ src/conf/pcm/Makefile \
+ modules/Makefile modules/mixer/Makefile modules/mixer/simple/Makefile \
+- alsalisp/Makefile aserver/Makefile test/Makefile utils/Makefile \
+- utils/alsa-lib.spec utils/alsa.pc)
++ alsalisp/Makefile aserver/Makefile \
++ test/Makefile test/lsb/Makefile \
++ utils/Makefile utils/alsa-lib.spec utils/alsa.pc)
+
+ dnl Create asoundlib.h dynamically according to configure options
+ echo "Creating asoundlib.h..."
diff --git a/include/control.h b/include/control.h
index 2361dc3..29ea397 100644
--- a/include/control.h
@@ -388,7 +404,7 @@ index b4d0a41..ab40f50 100644
"\t" XSUB " %%edx, %%ecx\n"
"2:"
diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c
-index 826685f..2fbee73 100644
+index 826685f..3a99d55 100644
--- a/src/pcm/pcm_hooks.c
+++ b/src/pcm/pcm_hooks.c
@@ -43,12 +43,39 @@ struct _snd_pcm_hook {
@@ -431,19 +447,18 @@ index 826685f..2fbee73 100644
static int snd_pcm_hooks_close(snd_pcm_t *pcm)
{
snd_pcm_hooks_t *h = pcm->private_data;
-@@ -71,6 +98,11 @@ static int snd_pcm_hooks_close(snd_pcm_t *pcm)
+@@ -71,6 +98,10 @@ static int snd_pcm_hooks_close(snd_pcm_t *pcm)
snd_pcm_hook_remove(hook);
}
}
+ while (!list_empty(&h->dllist)) {
-+ struct snd_pcm_hook_dllist *dl;
+ pos = h->dllist.next;
+ hook_remove_dlobj(list_entry(pos, struct snd_pcm_hook_dllist, list));
+ }
err = snd_pcm_generic_close(pcm);
if (err < 0)
res = err;
-@@ -193,6 +225,7 @@ int snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
+@@ -193,6 +224,7 @@ int snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
for (k = 0; k <= SND_PCM_HOOK_TYPE_LAST; ++k) {
INIT_LIST_HEAD(&h->hooks[k]);
}
@@ -451,16 +466,15 @@ index 826685f..2fbee73 100644
err = snd_pcm_new(&pcm, SND_PCM_TYPE_HOOKS, name, slave->stream, slave->mode);
if (err < 0) {
free(h);
-@@ -312,6 +345,8 @@ static int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *root, snd_config_
+@@ -312,6 +344,7 @@ static int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *root, snd_config_
snd_config_iterator_t i, next;
int (*install_func)(snd_pcm_t *pcm, snd_config_t *args) = NULL;
void *h = NULL;
-+ struct snd_pcm_hook_dllist *dl;
+
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid hook definition");
return -EINVAL;
-@@ -402,20 +437,26 @@ static int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *root, snd_config_
+@@ -402,20 +435,26 @@ static int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *root, snd_config_
_err:
if (type)
snd_config_delete(type);
@@ -638,10 +652,336 @@ index 20e119b..8b2d2d0 100644
if (! rate)
return -ENOMEM;
diff --git a/src/seq/seq_midi_event.c b/src/seq/seq_midi_event.c
-index b5caa1b..53d0572 100644
+index b5caa1b..ddaac5a 100644
--- a/src/seq/seq_midi_event.c
+++ b/src/seq/seq_midi_event.c
-@@ -442,6 +442,7 @@ long snd_midi_event_decode(snd_midi_event_t *dev, unsigned char *buf, long count
+@@ -129,12 +129,23 @@ static const struct extra_event_list_t {
+ #endif /* DOC_HIDDEN */
+
+ /**
+- * \brief Initialize MIDI event parser
+- * \param bufsize buffer size for MIDI message
+- * \param rdev allocated MIDI event parser
+- * \return 0 on success otherwise a negative error code
++ * \brief Creates a MIDI event parser.
++ * \param[in] bufsize Size of the buffer used for encoding; this should be
++ * large enough to hold the largest MIDI message to be
++ * encoded.
++ * \param[out] rdev The new MIDI event parser.
++ * \return Zero on success, otherwise a negative error code.
+ *
+- * Allocates and initializes MIDI event parser.
++ * This function creates and initializes a MIDI parser object that can be used
++ * to convert a MIDI byte stream to sequencer events (encoding) and/or to
++ * convert sequencer events to a MIDI byte stream (decoding).
++ *
++ * \par Errors:
++ *
++ * - -ENOMEM
- Out of memory.
++ *
++ * \par Conforming to:
++ * LSB 3.2
+ */
+ int snd_midi_event_new(size_t bufsize, snd_midi_event_t **rdev)
+ {
+@@ -159,11 +170,13 @@ int snd_midi_event_new(size_t bufsize, snd_midi_event_t **rdev)
+ }
+
+ /**
+- * \brief Free MIDI event parser
+- * \param dev MIDI event parser
+- * \return 0 on success otherwise a negative error code
++ * \brief Frees a MIDI event parser.
++ * \param dev MIDI event parser.
+ *
+- * Frees MIDI event parser.
++ * Frees a MIDI event parser.
++ *
++ * \par Conforming to:
++ * LSB 3.2
+ */
+ void snd_midi_event_free(snd_midi_event_t *dev)
+ {
+@@ -174,11 +187,15 @@ void snd_midi_event_free(snd_midi_event_t *dev)
+ }
+
+ /**
+- * \brief Enable/disable MIDI command merging
+- * \param dev MIDI event parser
+- * \param on 0 - enable MIDI command merging, 1 - always pass the command
++ * \brief Enables/disables MIDI command merging.
++ * \param dev MIDI event parser.
++ * \param on 0 to enable MIDI command merging,
++ * 1 to always write the command byte.
++ *
++ * This function enables or disables MIDI command merging (running status).
+ *
+- * Enable/disable MIDI command merging
++ * When MIDI command merging is not disabled, #snd_midi_event_decode is allowed
++ * to omit any status byte that is identical to the previous status byte.
+ */
+ void snd_midi_event_no_status(snd_midi_event_t *dev, int on)
+ {
+@@ -196,11 +213,15 @@ inline static void reset_encode(snd_midi_event_t *dev)
+ }
+
+ /**
+- * \brief Reset MIDI encode parser
+- * \param dev MIDI event parser
+- * \return 0 on success otherwise a negative error code
++ * \brief Resets MIDI encode parser.
++ * \param dev MIDI event parser.
+ *
+- * Resets MIDI encode parser
++ * This function resets the MIDI encoder of the parser \a dev.
++ * Any partially encoded MIDI message is dropped,
++ * and running status state is cleared.
++ *
++ * \par Conforming to:
++ * LSB 3.2
+ */
+ void snd_midi_event_reset_encode(snd_midi_event_t *dev)
+ {
+@@ -208,11 +229,15 @@ void snd_midi_event_reset_encode(snd_midi_event_t *dev)
+ }
+
+ /**
+- * \brief Reset MIDI decode parser
+- * \param dev MIDI event parser
+- * \return 0 on success otherwise a negative error code
++ * \brief Resets MIDI decode parser.
++ * \param dev MIDI event parser.
++ *
++ * This function resets the MIDI decoder of the parser \a dev.
++ * The next decoded message does not use running status from before the call to
++ * \a snd_midi_event_reset_decode.
+ *
+- * Resets MIDI decode parser
++ * \par Conforming to:
++ * LSB 3.2
+ */
+ void snd_midi_event_reset_decode(snd_midi_event_t *dev)
+ {
+@@ -220,11 +245,14 @@ void snd_midi_event_reset_decode(snd_midi_event_t *dev)
+ }
+
+ /**
+- * \brief Initializes MIDI parsers
+- * \param dev MIDI event parser
+- * \return 0 on success otherwise a negative error code
++ * \brief Resets MIDI encode/decode parsers.
++ * \param dev MIDI event parser.
++ *
++ * This function resets both encoder and decoder of the MIDI event parser.
++ * \sa snd_midi_event_reset_encode, snd_midi_event_reset_decode
+ *
+- * Initializes MIDI parsers (both encode and decode)
++ * \par Conforming to:
++ * LSB 3.2
+ */
+ void snd_midi_event_init(snd_midi_event_t *dev)
+ {
+@@ -233,12 +261,21 @@ void snd_midi_event_init(snd_midi_event_t *dev)
+ }
+
+ /**
+- * \brief Resize MIDI message (event) buffer
+- * \param dev MIDI event parser
+- * \param bufsize new requested buffer size
+- * \return 0 on success otherwise a negative error code
++ * \brief Resizes the MIDI message encoding buffer.
++ * \param dev MIDI event parser.
++ * \param bufsize The new buffer size.
++ * \return Zero on success, otherwise a negative error code.
+ *
+- * Resizes MIDI message (event) buffer.
++ * This function resizes the buffer that is used to hold partially encoded MIDI
++ * messages.
++ *
++ * If there is a partially encoded message in the buffer, it is dropped.
++ *
++ * \par Errors:
++ *
++ * - -ENOMEM
- Out of memory.
++ *
++ * \sa snd_midi_event_encode, snd_midi_event_reset_encode
+ */
+ int snd_midi_event_resize_buffer(snd_midi_event_t *dev, size_t bufsize)
+ {
+@@ -258,16 +295,67 @@ int snd_midi_event_resize_buffer(snd_midi_event_t *dev, size_t bufsize)
+ }
+
+ /**
+- * \brief Read bytes and encode to sequencer event if finished
+- * \param dev MIDI event parser
+- * \param buf MIDI byte stream
+- * \param count count of bytes of MIDI byte stream to encode
+- * \param ev Result - sequencer event
+- * \return count of encoded bytes otherwise a negative error code
+- *
+- * Read bytes and encode to sequencer event if finished.
+- * If complete sequencer event is available, ev->type is not
+- * equal to #SND_SEQ_EVENT_NONE.
++ * \brief Encodes bytes to sequencer event.
++ * \param[in] dev MIDI event parser.
++ * \param[in] buf Buffer containing bytes of a raw MIDI stream.
++ * \param[in] count Number of bytes in \a buf.
++ * \param[out] ev Sequencer event.
++ * \return The number of bytes consumed, or a negative error code.
++ *
++ * This function tries to use up to \a count bytes from the beginning of the
++ * buffer to encode a sequencer event. If a complete MIDI message has been
++ * encoded, the sequencer event is written to \a ev; otherwise, \a ev->type is
++ * set to #SND_SEQ_EVENT_NONE, and further bytes are required to complete
++ * a message.
++ *
++ * The buffer in \a dev is used to hold any bytes of a not-yet-complete MIDI
++ * message. If a System Exclusive message is larger than the buffer, the
++ * message is split into multiple parts, and a sequencer event is returned at
++ * the end of each part.
++ *
++ * Any bytes that are not part of a valid MIDI message are silently ignored,
++ * i.e., they are consumed without signaling an error.
++ *
++ * When this function returns a system exclusive sequencer event (\a ev->type
++ * is #SND_SEQ_EVENT_SYSEX), the data pointer (\a ev->data.ext.ptr) points into
++ * the MIDI event parser's buffer. Therefore, the sequencer event can only be
++ * used as long as that buffer remains valid, i.e., until the next call to
++ * #snd_midi_event_encode, #snd_midi_event_encode_byte,
++ * #snd_midi_event_resize_buffer, #snd_midi_event_init,
++ * #snd_midi_event_reset_encode, or #snd_midi_event_free for that MIDI event
++ * parser.
++ *
++ * This function can generate any sequencer event that corresponds to a MIDI
++ * message, i.e.:
++ * - #SND_SEQ_EVENT_NOTEOFF
++ * - #SND_SEQ_EVENT_NOTEON
++ * - #SND_SEQ_EVENT_KEYPRESS
++ * - #SND_SEQ_EVENT_CONTROLLER
++ * - #SND_SEQ_EVENT_PGMCHANGE
++ * - #SND_SEQ_EVENT_CHANPRESS
++ * - #SND_SEQ_EVENT_PITCHBEND
++ * - #SND_SEQ_EVENT_SYSEX
++ * - #SND_SEQ_EVENT_QFRAME
++ * - #SND_SEQ_EVENT_SONGPOS
++ * - #SND_SEQ_EVENT_SONGSEL
++ * - #SND_SEQ_EVENT_TUNE_REQUEST
++ * - #SND_SEQ_EVENT_CLOCK
++ * - #SND_SEQ_EVENT_START
++ * - #SND_SEQ_EVENT_CONTINUE
++ * - #SND_SEQ_EVENT_STOP
++ * - #SND_SEQ_EVENT_SENSING
++ * - #SND_SEQ_EVENT_RESET
++ * .
++ * Some implementations may also be able to generate the following events
++ * for a sequence of controller change messages:
++ * - #SND_SEQ_EVENT_CONTROL14
++ * - #SND_SEQ_EVENT_NONREGPARAM
++ * - #SND_SEQ_EVENT_REGPARAM
++ *
++ * \par Conforming to:
++ * LSB 3.2
++ *
++ * \sa snd_midi_event_new, snd_midi_event_reset_encode, snd_midi_event_encode_byte
+ */
+ long snd_midi_event_encode(snd_midi_event_t *dev, const unsigned char *buf, long count, snd_seq_event_t *ev)
+ {
+@@ -289,13 +377,23 @@ long snd_midi_event_encode(snd_midi_event_t *dev, const unsigned char *buf, long
+ }
+
+ /**
+- * \brief Read one byte and encode to sequencer event if finished
+- * \param dev MIDI event parser
+- * \param c a byte of MIDI stream
+- * \param ev Result - sequencer event
+- * \return 1 - sequencer event is completed, 0 - next byte is required for completion, otherwise a negative error code
++ * \brief Encodes byte to sequencer event.
++ * \param[in] dev MIDI event parser.
++ * \param[in] c A byte of a raw MIDI stream.
++ * \param[out] ev Sequencer event.
++ * \return 1 if a sequenver event has been completed, 0 if more bytes are
++ * required to complete an event, or a negative error code.
++ *
++ * This function tries to use the byte \a c to encode a sequencer event. If
++ * a complete MIDI message has been encoded, the sequencer event is written to
++ * \a ev; otherwise, further bytes are required to complete a message.
+ *
+- * Read byte and encode to sequencer event if finished.
++ * See also the description of #snd_midi_event_encode.
++ *
++ * \par Conforming to:
++ * LSB 3.2
++ *
++ * \sa snd_midi_event_new, snd_midi_event_reset_encode, snd_midi_event_encode
+ */
+ int snd_midi_event_encode_byte(snd_midi_event_t *dev, int c, snd_seq_event_t *ev)
+ {
+@@ -405,14 +503,56 @@ static void songpos_event(snd_midi_event_t *dev, snd_seq_event_t *ev)
+ }
+
+ /**
+- * \brief Decode sequencer event to MIDI byte stream
+- * \param dev MIDI event parser
+- * \param buf Result - MIDI byte stream
+- * \param count Available bytes in MIDI byte stream
+- * \param ev Event to decode
+- * \return count of decoded bytes otherwise a negative error code
+- *
+- * Decode sequencer event to MIDI byte stream.
++ * \brief Decodes sequencer event to MIDI byte stream.
++ * \param[in] dev MIDI event parser.
++ * \param[out] buf Buffer for the resulting MIDI byte stream.
++ * \param[in] count Number of bytes in \a buf.
++ * \param[in] ev The sequencer event to decode.
++ * \return The number of bytes written to \a buf, or a negative error code.
++ *
++ * This function tries to decode the sequencer event into one or more MIDI
++ * messages, and writes the raw MIDI byte(s) into \a buf.
++ *
++ * The generated MIDI messages may use running status, unless disabled with
++ * #snd_midi_event_no_status.
++ *
++ * The required buffer size for a sequencer event it as most 12 bytes, except
++ * for System Exclusive events (\a ev->type == #SND_SEQ_EVENT_SYSEX) which can
++ * have any length (as specified by \a ev->data.ext.len).
++ *
++ * The following sequencer events correspond to MIDI messages:
++ * - #SND_SEQ_EVENT_NOTEOFF
++ * - #SND_SEQ_EVENT_NOTEON
++ * - #SND_SEQ_EVENT_KEYPRESS
++ * - #SND_SEQ_EVENT_CONTROLLER
++ * - #SND_SEQ_EVENT_PGMCHANGE
++ * - #SND_SEQ_EVENT_CHANPRESS
++ * - #SND_SEQ_EVENT_PITCHBEND
++ * - #SND_SEQ_EVENT_SYSEX
++ * - #SND_SEQ_EVENT_QFRAME
++ * - #SND_SEQ_EVENT_SONGPOS
++ * - #SND_SEQ_EVENT_SONGSEL
++ * - #SND_SEQ_EVENT_TUNE_REQUEST
++ * - #SND_SEQ_EVENT_CLOCK
++ * - #SND_SEQ_EVENT_START
++ * - #SND_SEQ_EVENT_CONTINUE
++ * - #SND_SEQ_EVENT_STOP
++ * - #SND_SEQ_EVENT_SENSING
++ * - #SND_SEQ_EVENT_RESET
++ * - #SND_SEQ_EVENT_CONTROL14
++ * - #SND_SEQ_EVENT_NONREGPARAM
++ * - #SND_SEQ_EVENT_REGPARAM
++ *
++ * \par Errors:
++ *
++ * - -EINVAL
- \a ev is not a valid sequencer event.
++ *
- -ENOENT
- The sequencer event does not correspond to one or more MIDI messages.
++ *
- -ENOMEM
- The MIDI message(s) would not fit into \a count bytes.
++ *
++ * \par Conforming to:
++ * LSB 3.2
++ *
++ * \sa snd_midi_event_reset_decode, snd_midi_event_no_status
+ */
+ long snd_midi_event_decode(snd_midi_event_t *dev, unsigned char *buf, long count, const snd_seq_event_t *ev)
+ {
+@@ -442,6 +582,7 @@ long snd_midi_event_decode(snd_midi_event_t *dev, unsigned char *buf, long count
if (cmd == MIDI_CMD_COMMON_SYSEX) {
@@ -649,7 +989,7 @@ index b5caa1b..53d0572 100644
qlen = ev->data.ext.len;
if (count < qlen)
return -ENOMEM;
-@@ -566,10 +567,10 @@ static int extra_decode_xrpn(snd_midi_event_t *dev, unsigned char *buf, int coun
+@@ -566,10 +707,10 @@ static int extra_decode_xrpn(snd_midi_event_t *dev, unsigned char *buf, int coun
if (dev->nostat && count < 12)
return -ENOMEM;
cmd = MIDI_CMD_CONTROL|(ev->data.control.channel & 0x0f);
@@ -664,3 +1004,508 @@ index b5caa1b..53d0572 100644
if (cmd != dev->lastcmd && !dev->nostat) {
if (count < 9)
return -ENOMEM;
+diff --git a/test/Makefile.am b/test/Makefile.am
+index 2d7e92b..ae524a4 100644
+--- a/test/Makefile.am
++++ b/test/Makefile.am
+@@ -1,3 +1,5 @@
++SUBDIRS=. lsb
++
+ check_PROGRAMS=control pcm pcm_min latency seq \
+ playmidi1 timer rawmidi midiloop \
+ oldapi queue_timer namehint client_event_filter
+diff --git a/test/lsb/Makefile.am b/test/lsb/Makefile.am
+new file mode 100644
+index 0000000..8d2c1bd
+--- /dev/null
++++ b/test/lsb/Makefile.am
+@@ -0,0 +1,6 @@
++TESTS = midi_event
++check_PROGRAMS = $(TESTS)
++noinst_HEADERS = test.h
++
++AM_CFLAGS = -Wall -pipe
++LDADD = ../../src/libasound.la
+diff --git a/test/lsb/midi_event.c b/test/lsb/midi_event.c
+new file mode 100644
+index 0000000..3a4d7fa
+--- /dev/null
++++ b/test/lsb/midi_event.c
+@@ -0,0 +1,362 @@
++#include
++#include
++#include
++#include
++#include "test.h"
++
++/*
++ * Checks whether the regular expression matches the entire MIDI data, printed
++ * as hex.
++ */
++static int midi_matches_regex(unsigned char *midi, int count, const char *regex)
++{
++ char *text;
++ regex_t re;
++ regmatch_t match;
++ int i;
++
++ text = malloc(2 * count + 1);
++ if (!text)
++ return 0;
++ for (i = 0; i < count; ++i)
++ sprintf(text + 2 * i, "%02x", midi[i]);
++ if (regcomp(&re, regex, REG_EXTENDED) != 0) {
++ free(text);
++ return 0;
++ }
++ i = regexec(&re, text, 1, &match, 0);
++ i = i == 0 && match.rm_so == 0 && match.rm_eo == strlen(text);
++ regfree(&re);
++ free(text);
++ return i;
++}
++
++static void test_decode(void)
++{
++ snd_midi_event_t *midi_event;
++ snd_seq_event_t ev;
++ unsigned char buf[50];
++ int count;
++
++ ALSA_CHECK(snd_midi_event_new(256 /* ? */, &midi_event));
++
++#define DECODE() snd_midi_event_decode(midi_event, buf, sizeof(buf), &ev)
++#define BUF_MATCHES(str) midi_matches_regex(buf, count, str)
++#define DECODES_TO(str) ((count = DECODE()), BUF_MATCHES(str))
++
++ snd_seq_ev_clear(&ev);
++
++ snd_seq_ev_set_fixed(&ev);
++ ev.type = SND_SEQ_EVENT_NONE;
++ TEST_CHECK(DECODE() == -ENOENT);
++
++ snd_seq_ev_set_noteoff(&ev, 1, 2, 3);
++ TEST_CHECK(DECODES_TO("810203"));
++
++ snd_seq_ev_set_noteon(&ev, 4, 5, 6);
++ TEST_CHECK(DECODES_TO("940506"));
++
++ snd_seq_ev_set_keypress(&ev, 7, 8, 9);
++ TEST_CHECK(DECODES_TO("a70809"));
++
++ snd_seq_ev_set_controller(&ev, 10, 11, 12);
++ TEST_CHECK(DECODES_TO("ba0b0c"));
++
++ snd_seq_ev_set_pgmchange(&ev, 13, 14);
++ TEST_CHECK(DECODES_TO("cd0e"));
++
++ snd_seq_ev_set_chanpress(&ev, 15, 16);
++ TEST_CHECK(DECODES_TO("df10"));
++
++ snd_seq_ev_set_pitchbend(&ev, 1, 0x222);
++ TEST_CHECK(DECODES_TO("e12244"));
++
++ snd_seq_ev_set_sysex(&ev, 6, "\xf0\x7e\x7f\x06\x01\xf7");
++ TEST_CHECK(DECODES_TO("f07e7f0601f7"));
++
++ snd_seq_ev_set_fixed(&ev);
++ ev.type = SND_SEQ_EVENT_QFRAME;
++ ev.data.control.value = 3;
++ TEST_CHECK(DECODES_TO("f103"));
++
++ ev.type = SND_SEQ_EVENT_SONGPOS;
++ ev.data.control.value = 0x444;
++ TEST_CHECK(DECODES_TO("f24408"));
++
++ ev.type = SND_SEQ_EVENT_SONGSEL;
++ ev.data.control.value = 5;
++ TEST_CHECK(DECODES_TO("f305"));
++
++ ev.type = SND_SEQ_EVENT_TUNE_REQUEST;
++ TEST_CHECK(DECODES_TO("f6"));
++
++ ev.type = SND_SEQ_EVENT_CLOCK;
++ TEST_CHECK(DECODES_TO("f8"));
++
++ ev.type = SND_SEQ_EVENT_START;
++ TEST_CHECK(DECODES_TO("fa"));
++
++ ev.type = SND_SEQ_EVENT_CONTINUE;
++ TEST_CHECK(DECODES_TO("fb"));
++
++ ev.type = SND_SEQ_EVENT_STOP;
++ TEST_CHECK(DECODES_TO("fc"));
++
++ ev.type = SND_SEQ_EVENT_SENSING;
++ TEST_CHECK(DECODES_TO("fe"));
++
++ ev.type = SND_SEQ_EVENT_RESET;
++ TEST_CHECK(DECODES_TO("ff"));
++
++ ev.type = SND_SEQ_EVENT_CONTROL14;
++ ev.data.control.channel = 6;
++ ev.data.control.param = 7;
++ ev.data.control.value = 0x888;
++ /*
++ * This regular expression catches all allowed combinations of LSB/MSB
++ * order and running status.
++ */
++ TEST_CHECK(DECODES_TO("b6(0711(b6)?2708|2708(b6)?0711)"));
++
++ ev.type = SND_SEQ_EVENT_NONREGPARAM;
++ ev.data.control.channel = 9;
++ ev.data.control.param = 0xaaa;
++ ev.data.control.value = 0xbbb;
++ TEST_CHECK(DECODES_TO("b9(622a(b9)?6315|6315(b9)?622a)(b9)?(0617(b9)?263b|263b(b9)?0617)"));
++
++ ev.type = SND_SEQ_EVENT_REGPARAM;
++ ev.data.control.channel = 12;
++ ev.data.control.param = 0xddd;
++ ev.data.control.value = 0xeee;
++ TEST_CHECK(DECODES_TO("bc(645d(bc)?651b|651b(bc)?645d)(bc)?(061d(bc)?266e|266e(bc)?061d)"));
++
++ /* no running status after SysEx */
++ snd_seq_ev_set_pgmchange(&ev, 0, 0x11);
++ TEST_CHECK(DECODES_TO("c011"));
++ snd_seq_ev_set_sysex(&ev, 6, "\xf0\x7e\x7f\x09\x02\xf7");
++ TEST_CHECK(DECODES_TO("f07e7f0902f7"));
++ snd_seq_ev_set_pgmchange(&ev, 0, 0x11);
++ TEST_CHECK(DECODES_TO("c011"));
++
++ /* no running status for non-realtime common messages */
++ ev.type = SND_SEQ_EVENT_QFRAME;
++ ev.data.control.value = 0x11;
++ TEST_CHECK(DECODES_TO("f111"));
++ TEST_CHECK(DECODES_TO("f111"));
++
++ snd_midi_event_free(midi_event);
++}
++
++static void test_reset_decode(void)
++{
++ snd_midi_event_t *midi_event;
++ snd_seq_event_t ev;
++ unsigned char buf[50];
++ int count;
++
++ ALSA_CHECK(snd_midi_event_new(256 /* ? */, &midi_event));
++
++ snd_seq_ev_clear(&ev);
++
++ snd_seq_ev_set_noteon(&ev, 1, 2, 3);
++ TEST_CHECK(DECODES_TO("910203"));
++
++ snd_midi_event_reset_decode(midi_event);
++
++ TEST_CHECK(DECODES_TO("910203"));
++
++ snd_midi_event_free(midi_event);
++}
++
++static void test_encode(void)
++{
++ snd_midi_event_t *midi_event;
++ snd_seq_event_t ev;
++
++ ALSA_CHECK(snd_midi_event_new(256, &midi_event));
++
++#define ENCODE(str) snd_midi_event_encode(midi_event, \
++ (const unsigned char *)str, \
++ sizeof(str) - 1, &ev)
++ TEST_CHECK(ENCODE("\x81\x02\x03") == 3);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NOTEOFF);
++ TEST_CHECK((ev.flags & SND_SEQ_EVENT_LENGTH_MASK) == SND_SEQ_EVENT_LENGTH_FIXED);
++ TEST_CHECK(ev.data.note.channel == 1);
++ TEST_CHECK(ev.data.note.note == 2);
++ TEST_CHECK(ev.data.note.velocity == 3);
++
++ TEST_CHECK(ENCODE("\x94\x05\x06") == 3);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NOTEON);
++ TEST_CHECK(ev.data.note.channel == 4);
++ TEST_CHECK(ev.data.note.note == 5);
++ TEST_CHECK(ev.data.note.velocity == 6);
++
++ TEST_CHECK(ENCODE("\xa7\x08\x09") == 3);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_KEYPRESS);
++ TEST_CHECK(ev.data.note.channel == 7);
++ TEST_CHECK(ev.data.note.note == 8);
++ TEST_CHECK(ev.data.note.velocity == 9);
++
++ TEST_CHECK(ENCODE("\xba\x0b\x0c") == 3);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CONTROLLER);
++ TEST_CHECK(ev.data.control.channel == 10);
++ TEST_CHECK(ev.data.control.param == 11);
++ TEST_CHECK(ev.data.control.value == 12);
++
++ TEST_CHECK(ENCODE("\xcd\x0e") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_PGMCHANGE);
++ TEST_CHECK(ev.data.control.channel == 13);
++ TEST_CHECK(ev.data.control.value == 14);
++
++ TEST_CHECK(ENCODE("\xdf\x10") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CHANPRESS);
++ TEST_CHECK(ev.data.control.channel == 15);
++ TEST_CHECK(ev.data.control.value == 16);
++
++ TEST_CHECK(ENCODE("\xe1\x22\x33") == 3);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_PITCHBEND);
++ TEST_CHECK(ev.data.control.channel == 1);
++ TEST_CHECK(ev.data.control.value == -1630);
++
++ TEST_CHECK(ENCODE("\xf0\x7f\x7f\x04\x01\x7f\x7f\xf7") == 8);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_SYSEX);
++ TEST_CHECK((ev.flags & SND_SEQ_EVENT_LENGTH_MASK) == SND_SEQ_EVENT_LENGTH_VARIABLE);
++ TEST_CHECK(ev.data.ext.len == 8);
++ TEST_CHECK(!memcmp(ev.data.ext.ptr, "\xf0\x7f\x7f\x04\x01\x7f\x7f\xf7", 8));
++
++ TEST_CHECK(ENCODE("\xf1\x04") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_QFRAME);
++ TEST_CHECK(ev.data.control.value == 4);
++
++ TEST_CHECK(ENCODE("\xf2\x55\x66") == 3);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_SONGPOS);
++ TEST_CHECK(ev.data.control.value == 13141);
++
++ TEST_CHECK(ENCODE("\xf3\x07") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_SONGSEL);
++ TEST_CHECK(ev.data.control.value == 7);
++
++ TEST_CHECK(ENCODE("\xf6") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_TUNE_REQUEST);
++
++ TEST_CHECK(ENCODE("\xf8") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CLOCK);
++
++ TEST_CHECK(ENCODE("\xfa") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_START);
++
++ TEST_CHECK(ENCODE("\xfb") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CONTINUE);
++
++ TEST_CHECK(ENCODE("\xfc") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_STOP);
++
++ TEST_CHECK(ENCODE("\xfe") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_SENSING);
++
++ TEST_CHECK(ENCODE("\xff") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_RESET);
++
++ TEST_CHECK(ENCODE("\xc1\xf8") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CLOCK);
++ TEST_CHECK(ENCODE("\x22") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_PGMCHANGE);
++ TEST_CHECK(ev.data.control.channel == 1);
++ TEST_CHECK(ev.data.control.value == 0x22);
++ TEST_CHECK(ENCODE("\xf8") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CLOCK);
++ TEST_CHECK(ENCODE("\x33") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_PGMCHANGE);
++ TEST_CHECK(ev.data.control.channel == 1);
++ TEST_CHECK(ev.data.control.value == 0x33);
++
++ TEST_CHECK(ENCODE("\xc1\xf6") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_TUNE_REQUEST);
++ TEST_CHECK(ENCODE("\x44\x44") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NONE);
++
++ snd_midi_event_free(midi_event);
++}
++
++static void test_reset_encode(void)
++{
++ snd_midi_event_t *midi_event;
++ snd_seq_event_t ev;
++
++ ALSA_CHECK(snd_midi_event_new(256, &midi_event));
++
++ TEST_CHECK(ENCODE("\x91\x02") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NONE);
++
++ snd_midi_event_reset_encode(midi_event);
++
++ TEST_CHECK(ENCODE("\x03") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NONE);
++
++ snd_midi_event_free(midi_event);
++}
++
++static void test_init(void)
++{
++ snd_midi_event_t *midi_event;
++ snd_seq_event_t ev;
++ unsigned char buf[50];
++ int count;
++
++ ALSA_CHECK(snd_midi_event_new(256, &midi_event));
++
++ snd_seq_ev_set_noteon(&ev, 1, 2, 3);
++ TEST_CHECK(DECODES_TO("910203"));
++
++ TEST_CHECK(ENCODE("\x94\x05") == 2);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NONE);
++
++ snd_midi_event_init(midi_event);
++
++ snd_seq_ev_set_noteon(&ev, 1, 2, 3);
++ TEST_CHECK(DECODES_TO("910203"));
++
++ TEST_CHECK(ENCODE("\x06") == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NONE);
++
++ snd_midi_event_free(midi_event);
++}
++
++static void test_encode_byte(void)
++{
++ snd_midi_event_t *midi_event;
++ snd_seq_event_t ev;
++
++ ALSA_CHECK(snd_midi_event_new(256, &midi_event));
++
++#define ENCODE_BYTE(c) snd_midi_event_encode_byte(midi_event, c, &ev)
++ TEST_CHECK(ENCODE_BYTE(0x81) == 0);
++ TEST_CHECK(ENCODE_BYTE(0x02) == 0);
++ TEST_CHECK(ENCODE_BYTE(0x03) == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NOTEOFF);
++ TEST_CHECK((ev.flags & SND_SEQ_EVENT_LENGTH_MASK) == SND_SEQ_EVENT_LENGTH_FIXED);
++ TEST_CHECK(ev.data.note.channel == 1);
++ TEST_CHECK(ev.data.note.note == 2);
++ TEST_CHECK(ev.data.note.velocity == 3);
++ TEST_CHECK(ENCODE_BYTE(0x04) == 0);
++ TEST_CHECK(ENCODE_BYTE(0xf8) == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_CLOCK);
++ TEST_CHECK(ENCODE_BYTE(0x05) == 1);
++ TEST_CHECK(ev.type == SND_SEQ_EVENT_NOTEOFF);
++ TEST_CHECK(ev.data.note.channel == 1);
++ TEST_CHECK(ev.data.note.note == 4);
++ TEST_CHECK(ev.data.note.velocity == 5);
++
++ snd_midi_event_free(midi_event);
++}
++
++int main(void)
++{
++ test_decode();
++ test_reset_decode();
++ test_encode();
++ test_reset_encode();
++ test_encode_byte();
++ test_init();
++ return TEST_EXIT_CODE();
++}
+diff --git a/test/lsb/test.h b/test/lsb/test.h
+new file mode 100644
+index 0000000..ff697c5
+--- /dev/null
++++ b/test/lsb/test.h
+@@ -0,0 +1,29 @@
++#ifndef TEST_H_INCLUDED
++#define TEST_H_INCLUDED
++
++#include
++#include
++
++/* XXX this variable definition does not belong in a header file */
++static int any_test_failed;
++
++#define TEST_CHECK(cond) do \
++ if (!(cond)) { \
++ fprintf(stderr, "%s:%d: test failed: %s\n", __FILE__, __LINE__, #cond); \
++ any_test_failed = 1; \
++ } \
++ while (0)
++
++#define ALSA_CHECK(fn) ({ \
++ int err = fn; \
++ if (err < 0) { \
++ fprintf(stderr, "%s:%d: ALSA function call failed (%s): %s\n", \
++ __FILE__, __LINE__, snd_strerror(err), #fn); \
++ any_test_failed = 1; \
++ } \
++ err; \
++ })
++
++#define TEST_EXIT_CODE() any_test_failed
++
++#endif
+diff --git a/test/pcm.c b/test/pcm.c
+index ee27422..abb83e4 100644
+--- a/test/pcm.c
++++ b/test/pcm.c
+@@ -34,17 +34,18 @@ static void generate_sine(const snd_pcm_channel_area_t *areas,
+ static double max_phase = 2. * M_PI;
+ double phase = *_phase;
+ double step = max_phase*freq/(double)rate;
+- double res;
+- unsigned char *samples[channels], *tmp;
++ unsigned char *samples[channels];
+ int steps[channels];
+- unsigned int chn, byte;
+- union {
+- int i;
+- unsigned char c[4];
+- } ires;
+- unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
+- int bps = snd_pcm_format_width(format) / 8; /* bytes per sample */
+-
++ unsigned int chn;
++ int format_bits = snd_pcm_format_width(format);
++ unsigned int maxval = (1 << (format_bits - 1)) - 1;
++ int bps = format_bits / 8; /* bytes per sample */
++ int phys_bps = snd_pcm_format_physical_width(format) / 8;
++ int big_endian = snd_pcm_format_big_endian(format) == 1;
++ int to_unsigned = snd_pcm_format_unsigned(format) == 1;
++ int is_float = (format == SND_PCM_FORMAT_FLOAT_LE ||
++ format == SND_PCM_FORMAT_FLOAT_BE);
++
+ /* verify and prepare the contents of areas */
+ for (chn = 0; chn < channels; chn++) {
+ if ((areas[chn].first % 8) != 0) {
+@@ -61,12 +62,27 @@ static void generate_sine(const snd_pcm_channel_area_t *areas,
+ }
+ /* fill the channel areas */
+ while (count-- > 0) {
+- res = sin(phase) * maxval;
+- ires.i = res;
+- tmp = ires.c;
++ union {
++ float f;
++ int i;
++ } fval;
++ int res, i;
++ if (is_float) {
++ fval.f = sin(phase) * maxval;
++ res = fval.i;
++ } else
++ res = sin(phase) * maxval;
++ if (to_unsigned)
++ res ^= 1U << (format_bits - 1);
+ for (chn = 0; chn < channels; chn++) {
+- for (byte = 0; byte < (unsigned int)bps; byte++)
+- *(samples[chn] + byte) = tmp[byte];
++ /* Generate data in native endian format */
++ if (big_endian) {
++ for (i = 0; i < bps; i++)
++ *(samples[chn] + phys_bps - 1 - i) = (res >> i * 8) & 0xff;
++ } else {
++ for (i = 0; i < bps; i++)
++ *(samples[chn] + i) = (res >> i * 8) & 0xff;
++ }
+ samples[chn] += steps[chn];
+ }
+ phase += step;
+@@ -827,6 +843,13 @@ int main(int argc, char *argv[])
+ }
+ if (format == SND_PCM_FORMAT_LAST)
+ format = SND_PCM_FORMAT_S16;
++ if (!snd_pcm_format_linear(format) &&
++ !(format == SND_PCM_FORMAT_FLOAT_LE ||
++ format == SND_PCM_FORMAT_FLOAT_BE)) {
++ printf("Invalid (non-linear/float) format %s\n",
++ optarg);
++ return 1;
++ }
+ break;
+ case 'v':
+ verbose = 1;
diff --git a/alsa.changes b/alsa.changes
index 236ad9d..41d37ab 100644
--- a/alsa.changes
+++ b/alsa.changes
@@ -1,3 +1,14 @@
+-------------------------------------------------------------------
+Tue Jul 7 14:57:24 CEST 2009 - tiwai@suse.de
+
+- pcm_hooks: cosmetic removal of unused variables
+- more midi_event documentation
+- add midi event tests
+- test/pcm.c: Sample generation on big endian platforms was broken.
+- test/pcm.c: Fix S24 format
+- test/pcm.c: Generic linear PCM support
+- test/pcm.c: float format support
+
-------------------------------------------------------------------
Tue Jun 30 11:22:08 CEST 2009 - tiwai@suse.de
diff --git a/alsa.spec b/alsa.spec
index fa95078..28ec280 100644
--- a/alsa.spec
+++ b/alsa.spec
@@ -34,7 +34,7 @@ Obsoletes: alsa-64bit
#
Summary: Advanced Linux Sound Architecture
Version: 1.0.20
-Release: 5
+Release: 6
Source: ftp://ftp.alsa-project.org/pub/lib/alsa-lib-%{package_version}.tar.bz2
Source8: 40-alsa.rules
Source11: alsasound