Subject: Re: /dev/sound, non-blocking IO, and select
To: Alan Post <>
From: Jared D. McNeill <>
List: tech-kern
Date: 04/07/2005 10:29:47
On Thu, 2005-04-07 at 12:59 +0000, Alan Post wrote:
> If you want to do full duplex, you should also do an AUDIO_SETFD
> between the open and the SETINFO:
>   int is_full_duplex = 1;
>   if ( -1 == ioctl( afd, AUDIO_SETFD, &is_full_duplex )) die( "ioctl" );

That seems to have helped (I'm actually getting data back on reads now).

> In my application, I don't open the device O_NONBLOCK.  Also, I set
> the blocksize in the SETINFO.  Note also that if you aren't changing
> values in the audioinfo struct, you can leave them initialized by
> AUDIO_INITINFO -- the SETINFO ioctl will recognize such values as
> "don't change" (see audiosetinfo() in audio.c).  Finally, it can be
> instructive to do a GETINFO after your SETINFO, and see what you end
> up with, as the settings you send in SETINFO are really just a
> request, and the hardware decides what it's capable of.

In this case, I know that the info I'm setting is what the chip is
capable of.

As for the O_NONBLOCK, this is because the application (originally
written to use ALSA) opens its devices with the SND_PCM_NONBLOCK flag

> Also, if you want low-latency, I recommend:
>   * Recording:  if you read as soon as data is available, the kernel
>                 buffer won't fill up
>   * Playing:  if you set:
>                 info.hiwat = 2;
>                 info.lowat = 1;
>               then writing will block after the play buffer holds
>               2*blocksize, and allow writing again after flushing
>               1*blocksize to the hardware.
> My audio device is:
>   auich0 at pci0 dev 31 function 5: i82801AA (ICH) AC-97 Audio
>   auich0: interrupting at irq 9
>   auich0: Analog Devices AD1881 codec; headphone, Analog Devices Phat Stereo
>   auich0: measured ac97 link rate at 47999 Hz, will use 48000 Hz
>   audio0 at auich0: full duplex, mmap, independent

This is also an auich, but a slightly different type:

  auich1 at pci0 dev 31 function 6: i82801DB (ICH4) AC-97 Modem
  auich1: interrupting at irq 11
  auich1: ac97: Conexant D480 MDC V.92 Modem codec; no 3D stereo
  auich1: ac97: ext mid 4001<LINE1>, secondary codec
  audio1 at auich1: full duplex, mmap, independent

(although I've tested against the standard auich audio device as well
with the same results).