All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Joerg-Cyril.Hoehle@t-systems.com
Cc: alsa-devel@alsa-project.org
Subject: Re: How to pair Wine with ALSA? part2: buffer&period size / blocking / mmap (long)
Date: Tue, 16 Aug 2011 09:16:14 +0200	[thread overview]
Message-ID: <4E4A193E.9030601@ladisch.de> (raw)
In-Reply-To: <8E4C156DA5797D418DBFADFD8CE655A41392BAD31D@HE113481.emea1.cds.t-internal.com>

Joerg-Cyril.Hoehle@t-systems.com wrote:
> Clemens Ladisch wrote:
> >This was designed for hardware that is reprogrammed after each buffer
> >anyway (ISA DMA) or that allows dynamic buffers (e.g. ICH AC'97, which
> >was designed for WinMM).
> 
> You mean that HW can be told: "play N1 frames at address X1, to be
> followed without glitch with N2 frames at address X2"?  And
> afterwards, "after you'll be done with X2, play N3 at address X3"?

Yes.

> >Can't you hand out a pointer to ALSA's buffer?
> 
> I am not aware of any way outside snd_pcm_mmap_begin to obtain a
> pointer from ALSA.

Well, you could hand out that pointer.

>>What exactly gets optimized with mmap?  Please note that snd_pcm_write*
>>copies the data from the supplied buffer into ALSA's buffer; if your
>>code does the same, it is not the slightest bit faster.
> 
> I'm not sure I understand what you mean.

In practice, almost every program ends up with a function like this:

my_pcm_write(buffer, count)
{
	snd_pcm_mmap_begin();
	memcpy(mmap_buffer, buffer, count);
	/* and handle wraparound */
	snd_pcm_mmap_commit();
}

This would be no optimization over snd_pcm_writei().

> What's expected to happen in Wine without mmap is:
> 1. app copies/writes data into Wine-managed GetBuffer pool
> 1.b because of ring-buffer management, there's even a little
>     more copying in case of wrap-around.
> 2. ALSA pcm_write* copies from Wine's pool into HW buffer.
> 
> The optimization is:
> 0. app gets pointer from Wine's GetBuffer, which
>    in turn gets it from ALSA's snd_pcm_mmap_begin.
> 1. app copies/writes data into ALSA's HW buffer.

That would indeed be an optimization.

> I'm not sure PA or dmix support mmap.

There are devices that don't have 'real' memory.  However, the default
device then uses the "plug" plugin that supports mmap emulation (with
a timer that then writes data with the normal write call).

>  - How is waveOutGetPosition defined in the presence of huge
>    latencies, i.e. is it implicitly based on a ~0 latency assumption?
>  - When are buffers submitted to waveOutWrite returned to the app?
>    a) After the front-end processed them (sent them to the next stage)?
>    b) After the back-end (speaker) played the last sample in it?
>    The difference matters only as non-zero latencies are introduced into
>    the audio chain, i.e. with networking, USB or simply PA's 2s buffers.

In the bad old times, there was not software processing, buffers were
returned immediately after the hardware was finished with them, and
there was no significant latency.

> >You can call nonblock(0) immediately after open.
> >But if your code never actually blocks, why bother to set it?
> 
> Somebody reported and I've verified that snd_pcm_drain would always
> fail (with -11 IIRC) in non-blocking mode.

Well, if you do want to block, you indeed need blocking mode.  :)


Regards,
Clemens

      reply	other threads:[~2011-08-16  7:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-12 12:24 How to pair Wine with ALSA? part2: buffer&period size / blocking / mmap (long) Joerg-Cyril.Hoehle
2011-08-14 12:23 ` Clemens Ladisch
2011-08-15 15:57   ` Joerg-Cyril.Hoehle
2011-08-16  7:16     ` Clemens Ladisch [this message]

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=4E4A193E.9030601@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=Joerg-Cyril.Hoehle@t-systems.com \
    --cc=alsa-devel@alsa-project.org \
    /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.