All of lore.kernel.org
 help / color / mirror / Atom feed
* Asynchronous ALSA - callback and latency questions
@ 2014-09-08 16:03 Bram Bos
  2014-09-09  8:24 ` Clemens Ladisch
  0 siblings, 1 reply; 6+ messages in thread
From: Bram Bos @ 2014-09-08 16:03 UTC (permalink / raw)
  To: alsa-devel

Hello all,

I’m using ALSA for building a performance musical instrument, so I’m after
 low-latency audio output.
I have some questions (since I'm fairly new to ALSA and to Linux they may  be a
big n00by, so please bear with me)…

1. I’m using asynchronous audio output (i.e. using a callback). Sometimes the
system simply stops calling the callback function without giving an error. In
case of an xrun I would expect there to be an underrun message (which I
sometimes also get) so I can handle it properly. So I guess something else is
causing the issue? Any pointers?

2. What does “File descriptor is in a bad state” mean, when it is returned by
snd_pcm_writei? I notice that I can often avoid getting it by increasing the
size of my buffer but the message doesn't make sense to me.

3. Occasionally my application grinds to a halt with a “I/O is possible” message
– presumably this is triggered by the ALSA callback mechanism?

4. My last question is a bit more conceptual: what determines the playback
latency of my audio stream? The period size? The total ring buffer size? I
assume it should be the difference between the hardware playback pointer and the
software write pointer, but I can’t figure out how they are determined.

Thanks for any help.



System info: Raspberry Pi B+ (non-overclocked), Raspbian Wheezy, USB PnP CM108
audio device
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Asynchronous ALSA - callback and latency questions
  2014-09-08 16:03 Asynchronous ALSA - callback and latency questions Bram Bos
@ 2014-09-09  8:24 ` Clemens Ladisch
  2014-09-09  8:44   ` Bram Bos
  0 siblings, 1 reply; 6+ messages in thread
From: Clemens Ladisch @ 2014-09-09  8:24 UTC (permalink / raw)
  To: Bram Bos, alsa-devel

Bram Bos wrote:
> I’m using ALSA for building a performance musical instrument, so I’m after
>  low-latency audio output.
>
> 1. I’m using asynchronous audio output (i.e. using a callback).

Don't.  Many devices do not support this, and asynchronous callbacks run
in a signal handler, where you must use only signal-safe functions.

> 2. What does “File descriptor is in a bad state” mean, when it is returned by
> snd_pcm_writei?

That the device is neither running, nor in an underrun state.

> 4. what determines the playback latency of my audio stream?

The buffer size.  When you fill the buffer completely, the last sample
must wait for all previous samples to be played.


Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Asynchronous ALSA - callback and latency questions
  2014-09-09  8:24 ` Clemens Ladisch
@ 2014-09-09  8:44   ` Bram Bos
  2014-09-09  8:53     ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Bram Bos @ 2014-09-09  8:44 UTC (permalink / raw)
  To: alsa-devel


> > I’m using ALSA for building a performance musical instrument, so I’m after
> > low-latency audio output.
> >
> > 1. I’m using asynchronous audio output (i.e. using a callback).
>
> Don't.

That's an interesting insight. I reckoned using a callback was the most elegant
solution since that's what I'm used to for DirectSound, iOS, OSX, WMME, ASIO
etc.

So what would be the most bulletproof way of dealing with streaming audio
instead? Can I do polling in a non-blocking state? I think blocking-state audio
is out of the question since I do need to handle MIDI I/O and UI events at the
same time.

Thanks
Bram
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Asynchronous ALSA - callback and latency questions
  2014-09-09  8:44   ` Bram Bos
@ 2014-09-09  8:53     ` Takashi Iwai
  2014-09-09 10:50       ` Bram Bos
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2014-09-09  8:53 UTC (permalink / raw)
  To: Bram Bos; +Cc: alsa-devel

At Tue, 9 Sep 2014 10:44:01 +0200 (CEST),
Bram Bos wrote:
> 
> 
> > > I’m using ALSA for building a performance musical instrument, so I’m after
> > > low-latency audio output.
> > >
> > > 1. I’m using asynchronous audio output (i.e. using a callback).
> >
> > Don't.
> 
> That's an interesting insight. I reckoned using a callback was the most elegant
> solution since that's what I'm used to for DirectSound, iOS, OSX, WMME, ASIO
> etc.
 
If you want to go in that direction, just use JACK.  All you needed
are found there.


Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Asynchronous ALSA - callback and latency questions
  2014-09-09  8:53     ` Takashi Iwai
@ 2014-09-09 10:50       ` Bram Bos
  2014-09-09 11:23         ` Clemens Ladisch
  0 siblings, 1 reply; 6+ messages in thread
From: Bram Bos @ 2014-09-09 10:50 UTC (permalink / raw)
  To: alsa-devel

> > > > I’m using ALSA for building a performance musical instrument, so I’m
> > > > after
> > > > low-latency audio output.
> > > >
> > > > 1. I’m using asynchronous audio output (i.e. using a callback).
> > >
> > > Don't.
> >
> > That's an interesting insight. I reckoned using a callback was the most
> > elegant
> > solution since that's what I'm used to for DirectSound, iOS, OSX, WMME, ASIO
> > etc.
>
> If you want to go in that direction, just use JACK.

And the next best alternative would be blocked-mode/polling through ALSA, then?

I'd prefer to have as few software interface layer dependencies as comfortably
possible, so if I can get away with using only ALSA without requiring JACK that
would be a plus for me.

Thanks
Bram
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Asynchronous ALSA - callback and latency questions
  2014-09-09 10:50       ` Bram Bos
@ 2014-09-09 11:23         ` Clemens Ladisch
  0 siblings, 0 replies; 6+ messages in thread
From: Clemens Ladisch @ 2014-09-09 11:23 UTC (permalink / raw)
  To: alsa-devel

Bram Bos wrote:
>>>>> I’m using ALSA for building a performance musical instrument, so I’m
>>>>> after
>>>>> low-latency audio output.
>>>>>
>>>>> 1. I’m using asynchronous audio output (i.e. using a callback).
>>>>
>>>> Don't.
>>>
>>> That's an interesting insight. I reckoned using a callback was the most elegant
>>> solution since that's what I'm used to for DirectSound, iOS, OSX, WMME, ASIO etc.
>>
>> If you want to go in that direction, just use JACK.
>
> And the next best alternative would be blocked-mode/polling through ALSA, then?

Yes.  (That's what Jack uses; with full duplex, you already need to handle
multiple devices.)


Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-09 11:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-08 16:03 Asynchronous ALSA - callback and latency questions Bram Bos
2014-09-09  8:24 ` Clemens Ladisch
2014-09-09  8:44   ` Bram Bos
2014-09-09  8:53     ` Takashi Iwai
2014-09-09 10:50       ` Bram Bos
2014-09-09 11:23         ` Clemens Ladisch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.