Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Henning Thielemann <alsa@henning-thielemann.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: how to handle buffer underrun in a softsynth
Date: Mon, 28 Nov 2011 21:16:28 +0100	[thread overview]
Message-ID: <4ED3EC1C.70100@ladisch.de> (raw)
In-Reply-To: <alpine.DEB.2.00.1111281636560.13399@anubis.informatik.uni-halle.de>

Henning Thielemann wrote:
> I have written a software synthesizer in Haskell that fetches MIDI events
> from ALSA sequencer and plays the rendered signal via ALSA pcm. However it
> cannot cope correctly with buffer underruns.
> ...
>   Now when I detect a buffer underrun on writing a block to an ALSA pcm
> sink, I like to know the time gap in order to adjust the timestamps of the
> incoming MIDI events.

The sample clock is usually not synchronized with any other clock, so
you won't be able to get a very exact measurement.

However, there is a different way to approach this problem: just disable
underruns.  :)  Set the stop_threshold to the same value as the boundary,
and ALSA will no longer stop the device when an underrun happens.¹  This
means that you'll have to write some data more quickly than normally to
catch up², but the overall timing of the samples will not be affected.

¹ The device will still stop on fatal errors such as an unplugged USB
  device.
² Or, if you detect this case, just use snd_pcm_forward(); the samples
  that are 'too late' won't be played anyway.


Regards,
Clemens

  reply	other threads:[~2011-11-28 20:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28 16:06 how to handle buffer underrun in a softsynth Henning Thielemann
2011-11-28 20:16 ` Clemens Ladisch [this message]
2011-11-29  8:39   ` Henning Thielemann
2011-11-29 10:46     ` Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ED3EC1C.70100@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=alsa@henning-thielemann.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox