Skip to contentSkip to conversation

Most simple use of sequencer in ALSA

DISCUSSION Guenther Sohler 3 participants 6 messages Feb 15, 2002 – Feb 16, 2002 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

I have simplified the seq.c in the alsa-driver-test direcory for me to also understand.

The program is now quite short and outputs a note and quits

here is it
-----------

#include <stdio.h>
#include "alsa/asoundlib.h"

int main(int argc, char *argv[])

{
        snd_seq_t *handle;
        snd_seq_event_t ev;

        snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
        snd_seq_alloc_queue(handle);
        
        bzero(&ev, sizeof(ev));
        ev.dest.client=65;
        ev.dest.port=0;
        ev.type = SND_SEQ_EVENT_NOTEON;
        ev.data.note.channel = 0;
        ev.data.note.note = 64 ;
        ev.data.note.velocity = 127;
        snd_seq_event_output_direct(handle, &ev);
        sleep(1);
        ev.type = SND_SEQ_EVENT_NOTEOFF;
        snd_seq_event_output_direct(handle, &ev);
        snd_seq_drain_output(handle);
        return 0;
}

There are two questions ?

Why doesn't it work if I allocate no queue ? There is no need for a queue as i directly output events
What does "hw" mean ? what are the other possibilities ?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#2 lore raw

At Fri, 15 Feb 2002 07:21:24 +0100 (MET),

Quoted 36 lines · Guenther Sohler

I have simplified the seq.c in the alsa-driver-test direcory for me to also understand.

The program is now quite short and outputs a note and quits

here is it
-----------

#include <stdio.h>
#include "alsa/asoundlib.h"

int main(int argc, char *argv[])

{
        snd_seq_t *handle;
        snd_seq_event_t ev;

        snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
        snd_seq_alloc_queue(handle);
        
        bzero(&ev, sizeof(ev));
        ev.dest.client=65;
        ev.dest.port=0;
        ev.type = SND_SEQ_EVENT_NOTEON;
        ev.data.note.channel = 0;
        ev.data.note.note = 64 ;
        ev.data.note.velocity = 127;
        snd_seq_event_output_direct(handle, &ev);
        sleep(1);
        ev.type = SND_SEQ_EVENT_NOTEOFF;
        snd_seq_event_output_direct(handle, &ev);
        snd_seq_drain_output(handle);
        return 0;
}
Quoted 4 lines

There are two questions ?

Why doesn't it work if I allocate no queue ? There is no need for a queue as i directly output events

No, you don't need to allocate a queue if you schedule by yourself. your program lack the schedule of events, i.e.

	snd_seq_ev_set_direct(&ev);

before output the event packet. this is equivalent with

	ev.queue = SND_SEQ_QUEUE_DIRECT;

if this is specified, the event is sent immediately to the destination, so you don't need any queue.
as default, the event is scheduled using a specified queue, and as default, the queue is #0. that's why you had to allocate a queue.

one more note: you don't need to call snd_seq_drain_output() when you send events via snd_seq_event_output_direct(). the drain_output() is necessary for buffered outputs via normal snd_seq_event_output() functions.

Quoted 1 line

What does "hw" mean ? what are the other possibilities ?

originally it means "hardware".
in future it can be other ones, such like "network:foo", etc. (well, we can dream :)

ciao,

Takashi

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#3 lore raw

Yeah mate - I like it when you dream ....
Do you dream in mosaics of computer screens and code ?

Quoted 78 lines · Takashi Iwai

At Fri, 15 Feb 2002 07:21:24 +0100 (MET),

Quoted 36 lines · Guenther Sohler

I have simplified the seq.c in the alsa-driver-test direcory for me to also understand.

The program is now quite short and outputs a note and quits

here is it
-----------

#include <stdio.h>
#include "alsa/asoundlib.h"

int main(int argc, char *argv[])

{
        snd_seq_t *handle;
        snd_seq_event_t ev;

        snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
        snd_seq_alloc_queue(handle);
        
        bzero(&ev, sizeof(ev));
        ev.dest.client=65;
        ev.dest.port=0;
        ev.type = SND_SEQ_EVENT_NOTEON;
        ev.data.note.channel = 0;
        ev.data.note.note = 64 ;
        ev.data.note.velocity = 127;
        snd_seq_event_output_direct(handle, &ev);
        sleep(1);
        ev.type = SND_SEQ_EVENT_NOTEOFF;
        snd_seq_event_output_direct(handle, &ev);
        snd_seq_drain_output(handle);
        return 0;
}
Quoted 4 lines

There are two questions ?

Why doesn't it work if I allocate no queue ? There is no need for a queue as i directly output events

No, you don't need to allocate a queue if you schedule by yourself. your program lack the schedule of events, i.e.

	snd_seq_ev_set_direct(&ev);

before output the event packet. this is equivalent with

	ev.queue = SND_SEQ_QUEUE_DIRECT;

if this is specified, the event is sent immediately to the destination, so you don't need any queue.
as default, the event is scheduled using a specified queue, and as default, the queue is #0. that's why you had to allocate a queue.

one more note: you don't need to call snd_seq_drain_output() when you send events via snd_seq_event_output_direct(). the drain_output() is necessary for buffered outputs via normal snd_seq_event_output() functions.

Quoted 1 line

What does "hw" mean ? what are the other possibilities ?

originally it means "hardware".
in future it can be other ones, such like "network:foo", etc. (well, we can dream :)

ciao,

Takashi

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Signature · 13 lines
Matt

For electronic musicians ...
Vector Bass          : http://mffmvectorbass.sourceforge.net/
For developers ...
TimeScale Audio Mod  : http://mffmtimescale.sourceforge.net/
Multimedia Time Code : http://mffmtimecode.sourceforge.net/
3D Audio Library     : http://mffm3daudiolib.sourceforge.net/

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
#4 lore raw
In reply to Takashi Iwai

thank you for your info.

now i know that my procedure was almost correct.
Until now i had good success in porting my app to alsa. it will be completed soon.

rds guenther

Quoted 71 lines · On 15-Feb-02 Takashi Iwai wrote:

At Fri, 15 Feb 2002 07:21:24 +0100 (MET),

Quoted 36 lines · Guenther Sohler

I have simplified the seq.c in the alsa-driver-test direcory for me to also understand.

The program is now quite short and outputs a note and quits

here is it
-----------

#include <stdio.h>
#include "alsa/asoundlib.h"

int main(int argc, char *argv[])

{
        snd_seq_t *handle;
        snd_seq_event_t ev;

        snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
        snd_seq_alloc_queue(handle);
        
        bzero(&ev, sizeof(ev));
        ev.dest.client=65;
        ev.dest.port=0;
        ev.type = SND_SEQ_EVENT_NOTEON;
        ev.data.note.channel = 0;
        ev.data.note.note = 64 ;
        ev.data.note.velocity = 127;
        snd_seq_event_output_direct(handle, &ev);
        sleep(1);
        ev.type = SND_SEQ_EVENT_NOTEOFF;
        snd_seq_event_output_direct(handle, &ev);
        snd_seq_drain_output(handle);
        return 0;
}
Quoted 5 lines

There are two questions ?

Why doesn't it work if I allocate no queue ? There is no need for a queue as i
directly output events

No, you don't need to allocate a queue if you schedule by yourself. your program lack the schedule of events, i.e.

      snd_seq_ev_set_direct(&ev);

before output the event packet. this is equivalent with

      ev.queue = SND_SEQ_QUEUE_DIRECT;

if this is specified, the event is sent immediately to the destination, so you don't need any queue.
as default, the event is scheduled using a specified queue, and as default, the queue is #0. that's why you had to allocate a queue.

one more note: you don't need to call snd_seq_drain_output() when you send events via snd_seq_event_output_direct(). the drain_output() is necessary for buffered outputs via normal snd_seq_event_output() functions.

Quoted 1 line

What does "hw" mean ? what are the other possibilities ?

originally it means "hardware".
in future it can be other ones, such like "network:foo", etc. (well, we can dream :)

Quoted 8 lines

ciao,

Takashi

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Guenther Sohler

NewLogic Technologies AG
Millennium Park 6
A-6890 Lustenau

                                           Phone: +43-5577-62000-507

E-Mail: [email protected] Fax: +43-5577-62000-988

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#5 lore raw

mixer problem with creative audixy - was most simple alsa seq application

In reply to Takashi Iwai

Thank you very much for the advice.
I dont need thr queue any more
Now almost all midi works again in my application - but now for alsa(instead of oss)
But there is another problem now. I use an audixy card in my pc connected to an external amplifier.
Even the amplifier is set to the maximal volume, midi synth is quite silent whereas pcm is very loud.

Obviously the problem is in the mixer

alsmixer shows me a lot of volumes to adjust, but actually just the volume of "music" show en effect. maximum volume on music makes me hear a silent tune. but "master" and all other volumes do not show(sound) a change in the volume.

In my application i can now select where the output goes to

64:0 is the external midi and 65:0-3 is the awe synth
64:0 does not work all the time. but directly piping midi date to the respective /dev/snd/midixxxx always works(i hear a tune on the external keyboard).
whats the problem here ?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#6 lore raw
In reply to a message not in the archive

I have simplified the seq.c in the alsa-driver-test direcory for me to also understand.

The program is now quite short and outputs a note and quits

here is it
-----------

#include <stdio.h>
#include "alsa/asoundlib.h"

int main(int argc, char *argv[])

{
        snd_seq_t *handle;
        snd_seq_event_t ev;

        snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
        snd_seq_alloc_queue(handle);
        
        bzero(&ev, sizeof(ev));
        ev.dest.client=65;
        ev.dest.port=0;
        ev.type = SND_SEQ_EVENT_NOTEON;
        ev.data.note.channel = 0;
        ev.data.note.note = 64 ;
        ev.data.note.velocity = 127;
        snd_seq_event_output_direct(handle, &ev);
        sleep(1);
        ev.type = SND_SEQ_EVENT_NOTEOFF;
        snd_seq_event_output_direct(handle, &ev);
        snd_seq_drain_output(handle);
        return 0;
}

There are two questions ?

Why doesn't it work if I allocate no queue ? There is no need for a queue as i directly output events
What does "hw" mean ? what are the other possibilities ?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel