All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Davis <paul@linuxaudiosystems.com>
To: James Wright <james@jigsawdezign.com>
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: Moving from OSS to ALSA
Date: Sun, 11 Jan 2004 13:28:57 -0500	[thread overview]
Message-ID: <200401111828.i0BISvRO025390@dhin.linuxaudiosystems.com> (raw)
In-Reply-To: Your message of "Sun, 11 Jan 2004 18:13:11 GMT." <20040111181311.7726a5b5.james@jigsawdezign.com>

>   I am currently looking into rewriting our current OSS sound routines to nat
>ive ALSA, as it seems OSS will invariably be phased out now that the ALSA driv
>er is distrubuted with the Linux kernel, plus ALSA seems to have a great numbe
>r of benefits for us. 
>
>  Our current sound routines perform software sound sample mixing for use in g
>ames. All the  mixing and transfers happen in a non-blocking function called u
>pdate_jsound() which we call every 1/60th of a second in our main game loop. W
>e find the total size of the hardware ring buffer and use MMAP writes to it. W
>e effectively break the ring buffer into 1024 byte "fragments", and always kee
>p one whole fragment ahead to ensure no underruns. We do this by the follwing:

best method:
-----------
1) set the avail_min s/w parameter to the period size
2) call poll on the file descriptor(s) returned from
   snd_pcm_poll_descriptors(). when you return from poll,
   you know you have at least one period of data ready (possibly
   more, so you need to check).
3) use snd_pcm_mmap_*() to handle mmap access. ALSA
   doesn't provide simple access to mmap'ped buffers 
   because this could not work for some classes of
   ALSA devices.

survey the source of JACK (jackit.sf.net) for some ideas.

however, that probably won't work so well for you it doesn't integrate
into your "game loop". for that, use snd_pcm_delay() to find out the
gap between the application (s/w) pointer and the hardware pointer,
then use the snd_pcm_mmap_*() calls from there.

its a lot more complex under ALSA. but thats because ALSA provides a
lot of things that OSS does not, and doing everything via the simple
system call interface that OSS uses makes it impossible to provide
them "appropriately".

if you were writing software for musicians and studios rather than
games and consumer media apps, check out JACK for a different, simpler
and more powerful API (that uses ALSA internally).

--p


-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html

  reply	other threads:[~2004-01-11 18:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-11 18:13 Moving from OSS to ALSA James Wright
2004-01-11 18:28 ` Paul Davis [this message]
2004-01-11 21:39   ` James Wright
2004-01-11 22:29 ` Lorn Potter
2004-01-11 22:48   ` Måns Rullgård
2004-01-11 22:49   ` James Wright
2004-01-11 23:11   ` Kai Vehmanen
2004-01-12  1:15     ` Lorn Potter
2004-01-12  8:42       ` Jaroslav Kysela
2004-01-12 12:54         ` Paul Davis
2004-01-12 13:56           ` Takashi Iwai

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=200401111828.i0BISvRO025390@dhin.linuxaudiosystems.com \
    --to=paul@linuxaudiosystems.com \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=james@jigsawdezign.com \
    /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 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.