General Guidelines? (MIDI)
Are there any documented guidelines on how to make use of ALSA (especially MIDI) functions? They seem to be designed with attention to nomenclature, but I don't have a clear idea of when they're needed.
For example, when using ALSA data type foo, the standard seems to be to call snd_seq_alloc_foo, manipulate foo as desired, then call snd_seq_free_foo. This is easy enough, but sometimes (as in the case of queue), there is also a create function; how does this differ from alloc, and is it necessary?
Also, what is the relationship between buffers and queues? Is a queue needed prior to buffering output? Or do they serve completely different functions?
Thanks in advance to anyone who can clear these things up for me.
Signature · 7 lines
Brian ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com
Quoted 2 lines · Brian Victor
Are there any documented guidelines on how to make use of ALSA (especially MIDI) functions?
This is one of the parts still missing from the documentation.
Well, there are example programs ...
Quoted 5 lines
For example, when using ALSA data type foo, the standard seems to be to call
snd_seq_alloc_foo, manipulate foo as desired, then callsnd_seq_free_foo. This is easy enough, but sometimes (as in the case of queue), there is also a create function; how does this differ from alloc, and is it necessary?
The data type holds properties of the object, but it's only used to communicate between the application and the ALSA library. The create function creates the actual object in the kernel.
Quoted 1 line
Also, what is the relationship between buffers and queues?
Buffers are used to send or receive events to/from the kernel sequencer, which is responsible for routing them to/from other clients. It's an internal optimization; usually, you don't have to care about them.
Queues are used to connect two ports and to schedule events to be sent at a specific time. This can be used to play MIDI files (see alsa-lib/test/playmidi1).
HTH
Clemens
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
At Mon, 13 Jan 2003 10:25:55 +0100 (MET),
Quoted 8 lines · Clemens Ladisch
Quoted 2 lines · Brian Victor
Are there any documented guidelines on how to make use of ALSA (especially MIDI) functions?
This is one of the parts still missing from the documentation.
Well, there are example programs ...
for understanding the concept of ALSA sequencer, the old ALSA-lib document would help, too:
http://www.alsa-project.org/alsa-doc/alsa-lib-old/
except for functions API, the basic idea and the event record are identical in both ALSA 0.5.x and 0.9.0.
of course, it would be much nicer if someone helps to port this document to DocBook...
Takashi
-------------------------------------------------------
This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
Quoted 3 lines · Takashi Iwai
Quoted 1 line · Clemens Ladisch
Well, there are example programs ...
[snips]
Thanks to both of you for your responses. The old documentation was especially helpful, and I feel I have a better, if still imperfect grasp of things.
I've been following the miniArp.c sample code from Matthias Nagorni's HOWTO, and trying to break it up into functions for a C++ wrapper I'm writing. I'm having the following issues:
* On first run, the test program will only play the note on tick 0, and nothing beyond that.
* On subsequent runs, the test program doesn't even play that. I would chalk it up to poor garbage collection (I'm doing a ^C to stop the program), but miniArp will still run fine after that, and then my test program performs as the first run again.
My NoteOn code looks like this (tick is the tick at which the event should be sent):
void wxMidiQueue::NoteOn(const wxMidiOutput& port, int key,
int velocity, int tick, int channel)
{
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_noteon(&ev, channel, key, velocity); snd_seq_ev_set_source(&ev, port.GetAlsaPort()); snd_seq_ev_set_subs(&ev); snd_seq_ev_schedule_tick(&ev, m_queue, 0, tick); snd_seq_event_output_direct(m_drv.GetAlsaSeq(), &ev);
}
It's being called like this:
queue->NoteOn(*out, 60, 80, 0);
queue->NoteOn(*out, 64, 80, 1);
queue->NoteOn(*out, 67, 80, 2);
After this the queue is started. My remaining questions are:
* Above I use output_direct. Should I just be using output for events that should occur in the future?
* Does the output pool need to be big enough to accomodate any data my program will have in the queue at once? Or just big enough to allow for some buffering?
* Am I doing something absurdly wrong that you can see? I've already opened the sequencer, opened a port, allocated a queue, and set the tempo
Sorry this email was so long. But if you can provide any insight, I would really appreciate it. Thanks!
Signature · 8 lines
Brian ------------------------------------------------------- This SF.NET email is sponsored by: Take your first step towards giving your online business a competitive advantage. Test-drive a Thawte SSL certificate - our easy online guide will show you how. Click here to get started: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0027en
Quoted 7 lines · Brian Victor
* On first run, the test program will only play the note on tick 0, and nothing beyond that.
* On subsequent runs, the test program doesn't even play that. I would chalk it up to poor garbage collection (I'm doing a ^C to stop the program), but miniArp will still run fine after that, and then my test program performs as the first run again.
Running queues are visible in /proc/asound/seq/timers IIRC. And in theory, ALSA should properly free queues/timers when doing ^C.
Quoted 2 lines
* Above I use
output_direct. Should I just be using output for events that should occur in the future?
Yes. output_direct send the event directly to the destination port, without going through a queue.
Quoted 3 lines
* Does the output pool need to be big enough to accomodate any data my program will have in the queue at once? Or just big enough to allow for some buffering?
No. Yes.
HTH
Clemens
-------------------------------------------------------
This SF.NET email is sponsored by: Take your first step towards giving your online business a competitive advantage. Test-drive a Thawte SSL certificate - our easy online guide will show you how. Click here to get
started: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0027en
Quoted 2 lines · Clemens Ladisch
Running queues are visible in
/proc/asound/seq/timersIIRC. And in theory, ALSA should properly free queues/timers when doing ^C.
Thanks once more. I feel like I'm getting closer, but I'm still struggling. This is my NoteOn code:
void wxMidiQueue::NoteOn(const wxMidiOutput& port, int key,
int velocity, int tick, int channel)
{
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_note(&ev, channel, key, velocity, 10); snd_seq_ev_schedule_tick(&ev, m_queue, 0, tick); snd_seq_ev_set_source(&ev, port.GetAlsaPort()); snd_seq_ev_set_subs(&ev); snd_seq_event_output_direct(m_drv.GetAlsaSeq(), &ev);
}
For testing, I placed this in a for loop:
for (x=0; x<400; ++x) queue->NoteOn(*out, x, 127, x, 0);
Monitoring /proc/asound/seq/queues shows the events being queued, but as soon as the queue starts, all 400 notes leave the queue instantly; none are played. miniArp, from which this code is extracted nearly verbatim, will show the "queued tick events" rising and falling as notes are played and requeued. The output of /proc/asound/seq/timer when running miniArp and my test program are identical.
Clearly I'm doing something blatantly wrong, but I've compared my code to the sample's with a fine-tooth comb, and I can't for the life of me figure out what. Can you see where the problem is?
Thank you once again for your patience.
Signature · 8 lines
Brian ------------------------------------------------------- This SF.NET email is sponsored by: A Thawte Code Signing Certificate is essential in establishing user confidence by providing assurance of authenticity and code integrity. Download our Free Code Signing guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0028en
Quoted 5 lines · Brian Victor
Monitoring
/proc/asound/seq/queuesshows the events being queued, but as soon as the queue starts, all 400 notes leave the queue instantly; none are played.snd_seq_ev_schedule_tick(&ev, m_queue, 0, tick);
What is the queue's tempo? 400 ticks may not be much.
Quoted 1 line
snd_seq_ev_set_subs(&ev);
This will send the note events to the subscribers of your program's port. Are there any?
HTH
Clemens
-------------------------------------------------------
This SF.NET email is sponsored by: A Thawte Code Signing Certificate is essential in establishing user confidence by providing assurance of authenticity and code integrity. Download our Free Code Signing guide:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0028en
Quoted 7 lines · Clemens Ladisch
Quoted 5 lines · Brian Victor
Monitoring
/proc/asound/seq/queuesshows the events being queued, but as soon as the queue starts, all 400 notes leave the queue instantly; none are played.snd_seq_ev_schedule_tick(&ev, m_queue, 0, tick);What is the queue's tempo? 400 ticks may not be much.
[before starting]
owned by client : 128
lock status : Locked
queued time events : 0
queued tick events : 400
timer state : Stopped
timer PPQ : 128
current tempo : 12000000
current BPM : 5
current time : 0.000000000 s
current tick : 0
[after starting]
queue 0: [Queue-0]
owned by client : 128
lock status : Locked
queued time events : 0
queued tick events : 0
timer state : Running
timer PPQ : 128
current tempo : 12000000
current BPM : 5
current time : 1.140000000 s
current tick : 12
(Which begs another question: what does PPQ stand for? Something per quarter?)
Quoted 3 lines
Quoted 1 line
snd_seq_ev_set_subs(&ev);This will send the note events to the subscribers of your program's port. Are there any?
Yes. I have a sleep in my program that allows me to run from another
terminal: aconnect 64:0 128:1; aconnect 128:0 64:0 (Yes, there's an input port, too.)
Signature · 8 lines
Brian ------------------------------------------------------- This SF.NET email is sponsored by: Thawte.com Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en
Quoted 5 lines · Brian Victor
Quoted 4 lines · Clemens Ladisch
Quoted 3 lines · Brian Victor
Monitoring
/proc/asound/seq/queuesshows the events being queued, but as soon as the queue starts, all 400 notes leave the queue instantly; none are played.
afaik, you should use snd_seq_event_output() instead of snd_seq_event_output_direct() -- the latter is supposed to by-pass the queue for instant transmission.
you may want to look at alsa-lib/test/playmidi1.c for another reference.
Quoted 2 lines
(Which begs another question: what does PPQ stand for? Something per quarter?)
ticks/quarter (aka 'parts per quarter').
hth, tim
-------------------------------------------------------
This SF.NET email is sponsored by: Thawte.com
Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache
Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en
Quoted 3 lines · Tim Goetze
afaik, you should use
snd_seq_event_output()instead ofsnd_seq_event_output_direct()-- the latter is supposed to by-pass the queue for instant transmission.
I've tried both, actually. output() does not show any queued events in /proc/asound/seq/queues; output_direct() does. miniArp.c uses output_direct, and seems to work. Neither produces any output in my test program.
I've removed all attachments to wxWindows, so anyone should be able to compile my test program. So I don't have to keep sending snippits out of context, the code is here:
http://www.personal.psu.edu/users/b/h/bhv1/nowx.cc or
http://www.personal.psu.edu/users/b/h/bhv1/nowx.cc.html (syntax colored) (g++ nowx.cc -o nowx -lasound)
Quoted 2 lines
you may want to look at
alsa-lib/test/playmidi1.cfor another reference.
That could be useful, but at a glance I don't see anything important in there that I'm not doing. This is really perplexing me.
Quoted 3 lines
Quoted 2 lines
(Which begs another question: what does PPQ stand for? Something per quarter?)
ticks/quarter (aka 'parts per quarter').
I figured it was something like that. Thanks.
Signature · 8 lines
Brian ------------------------------------------------------- This SF.NET email is sponsored by: Thawte.com Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en
At Thu, 16 Jan 2003 16:32:05 +0100 (CET),
Quoted 4 lines · Tim Goetze
Quoted 1 line · Brian Victor
On Thu, Jan 16, 2003 at 08:39:23AM +0100, Clemens Ladisch wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines · Brian Victor
Monitoring
/proc/asound/seq/queuesshows the events being queued, but as soon as the queue starts, all 400 notes leave the queue instantly; none are played.afaik, you should use
snd_seq_event_output()instead ofsnd_seq_event_output_direct()-- the latter is supposed to by-pass the queue for instant transmission.
well, this is not exact: snd_seq_event_output_direct() sends the event without "output buffer" on the user-space.
if the event record has a proper queue value (i.e. event.queue != SND_SEQ_QUEUE_DIRECT), it is scheduled on the specified queue.
for by-passing the scheduling on the queue, you need to mark the queue via snd_seq_ev_set_direct().
snd_seq_event_output() will put the event onto the output buffer. the buffered events won't be sent and stay on the buffer until either the buffer becomes full or snd_seq_drain_output() is called explicitly.
this i/o-buffer was introduced to reduce the amounts of read/write, ioctls. this could be implemented more sofisticatedly as a high-level library...
Takashi
-------------------------------------------------------
This SF.NET email is sponsored by: Thawte.com
Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache
Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en