Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Abramo Bagnara <abramo.bagnara@libero.it>
To: Jaroslav Kysela <perex@suse.cz>
Cc: Jaroslaw Sobierski <fycio@gucio.com>,
	"alsa-devel@lists.sourceforge.net"
	<alsa-devel@lists.sourceforge.net>
Subject: Re: Re: dmix plugin
Date: Mon, 17 Feb 2003 14:29:55 +0100	[thread overview]
Message-ID: <3E50E3D3.49AF1D55@libero.it> (raw)
In-Reply-To: Pine.LNX.4.44.0302171407290.1054-100000@pnote.perex-int.cz

Jaroslav Kysela wrote:
> 
> On Mon, 17 Feb 2003, Abramo Bagnara wrote:
> 
> > Jaroslav Kysela wrote:
> > >
> > > On Mon, 17 Feb 2003, Jaroslaw Sobierski wrote:
> > >
> > > > > > b) sum overflow: we can lower volume of samples before sum; I think that
> > > > > >    hardware works in this way, too
> > > > >
> > > > > Here I don't understand you. Suppose we have 3 samples to mix:
> > > > > a = 0x7500
> > > > > b = 0x7400
> > > > > c = 0x8300
> > > > >
> > > > > If you do a + b + c (in this order) you obtain:
> > > > > d=0
> > > > > d += a -> 7500
> > > > > d += b -> 0xe900 -> 0x7fff
> > > > > d += c -> 0x02ff
> > > > >
> > > > > while the correct result is 0x6c00. You see?
> > > >
> > > > AFAIK most hardware does not mix by reducing volume before the sum. On the
> > > > contrary, it is usually summed "as is" to a wider register, and often even so
> > > > used. For example, a sound card able to mix 16 chanels of 16 bits would have
> > > > a 16+4 bits or 24 bit register were the channels are added and no saturation
> > > > can occur. In good hardware this would not even be downscaled back to 16 bits,
> > > > but a 24 bit D/A converter would be used instead. In older times (Gravis Ultra
> > > > Sound and I think older SB AWE) this could easily be spotted by the difference
> > > > in supported "hardware" channels and "software" channels. A card with a 32 bit
> > > > sum register and 24 bit DA could support (as above) 16 hardware channels and
> > > > for example 64 software channels (mixed together in quadrouplets to the 16 hw).
> > > >
> > > > In our case, such "solution" would have to affect the whole buffer, meaning
> > > > we would need 3 (or better yet 4) bytes per sample, which would eventually get
> > > > reduced back to 2 bytes on the way out to the sound card. This seems neither
> > > > elegant nor memory efficient but would work, and also solves the "a)" problem
> > > > because we don't need to saturate so an atomic add can be performed on each
> > > > sample.
> > >
> > > Yes, this solution is good. I've though about it, too. Unfortunately, it
> > > adds additional transfers including saturation from the "sum" ring buffer
> > > to the DMA buffer of hardware.
> >
> > I remember you that the main point of dmix existence is the "direct"
> > part.
> >
> > If we'd need to use an intermediate buffer and a mixing thread, the dmix
> > approach lose our interest.
> >
> > A solution might be to have a shared parallel sw ring buffer where to
> > store the exact value:
> >
> >         xadd(sw, *src);
> >       do {
> >               v = *sw;
> >               if (v > 0x7fff)
> >                       s = 0x7fff;
> >               else if (v < -0x8000)
> >                       s = -0x8000;
> >               else
> >                       s = v;
> >               *hw = v;
> >       } while (unlikely(v != *sw));
> >
> > This should solve also the atomicity update.
> >
> > Comments?
> 
> We probably talk about same thing, but in different words. I also don't
> think that atomicity is an problem when xadd() is atomic (and it is atomic
> for i386).
> 
> Then you need to do the saturation and store to the hardware ring buffer,
> but if this operation is after xadd() then we don't care about atomicity,
> because we are 100% sure that we have a valid result.
> 
> Algorithm:
> 
>         while (count) {
>                 atomic_xadd(sum_ring_buffer[idx], local_buffer[idx]);
>                 hw_ring_buffer[idx] = saturate(sum_ring_buffer[idx]);
>         }

You're wrong: xadd is atomic but xadd/read/saturation/write is not.

Without the loop I've added you risk to write on hw_ring_buffer an *old*
value:

A:		B:
xadd
read
		xadd
		read
		saturate
		write
saturate
write

-- 
Abramo Bagnara                       mailto:abramo.bagnara@libero.it

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

  reply	other threads:[~2003-02-17 13:29 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-17 10:04 dmix plugin Jaroslaw Sobierski
2003-02-17 10:15 ` Jaroslav Kysela
2003-02-17 12:15   ` Abramo Bagnara
2003-02-17 13:12     ` Jaroslav Kysela
2003-02-17 13:29       ` Abramo Bagnara [this message]
2003-02-17 15:00         ` Jaroslav Kysela
2003-02-17 15:21           ` Abramo Bagnara
2003-02-17 10:32 ` tomasz motylewski
  -- strict thread matches above, loose matches on Subject: below --
2003-02-17 11:18 Jaroslaw Sobierski
2003-02-17 11:53 ` Jaroslav Kysela
2003-02-17 13:12 Jaroslaw Sobierski
2003-02-17 13:22 ` Jaroslav Kysela
2003-02-17 18:15   ` Paul Davis
2003-02-18 22:36     ` Abramo Bagnara
2003-02-17 13:24 ` Jaroslav Kysela
2003-02-17 15:32 Jaroslaw Sobierski
2003-02-17 19:45 ` Jaroslav Kysela
2003-02-17 20:44   ` tomasz motylewski
2003-02-17 20:59     ` Jaroslav Kysela
2003-02-18 10:00   ` Abramo Bagnara
2003-02-18 12:52     ` Jaroslav Kysela
2003-02-18 13:10       ` Jaroslaw Sobierski
2003-02-18 13:19         ` Jaroslav Kysela
2003-02-18 14:51       ` Paul Davis
2003-02-18 16:51         ` Jaroslav Kysela
2003-02-18 21:07     ` Jaroslav Kysela
2003-02-19 10:20       ` Abramo Bagnara
2003-02-19 11:01         ` Jaroslav Kysela
2003-02-19 11:17           ` Abramo Bagnara
2003-02-19 13:49             ` Abramo Bagnara
2003-02-19 15:45               ` Jaroslaw Sobierski
2003-02-19 20:39                 ` Abramo Bagnara
2003-02-19 18:34               ` Jaroslav Kysela
2003-02-19 21:24                 ` Jaroslav Kysela
2003-02-20  8:28                 ` Abramo Bagnara
2003-02-20  8:30                 ` Jaroslaw Sobierski
2003-02-20  8:48                   ` Abramo Bagnara
2003-02-20  8:53                 ` Abramo Bagnara
2003-02-20 16:49                   ` Jaroslav Kysela
2003-02-20 17:57                     ` Abramo Bagnara
2003-02-20 18:26                       ` Paul Davis
2003-02-20 22:14                         ` Abramo Bagnara
2003-02-20 19:55                       ` Jaroslav Kysela
2003-02-20 21:19                         ` tomasz motylewski
2003-02-20 21:27                           ` Jaroslav Kysela
2003-02-21 10:25                         ` Abramo Bagnara
2003-02-21 14:08                         ` Jaroslaw Sobierski
2003-02-19 10:33       ` Jaroslaw Sobierski
2003-02-19 11:08         ` Jaroslav Kysela
2003-02-17 16:18 Jaroslaw Sobierski
2003-02-17 22:28 Jaroslaw Sobierski

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=3E50E3D3.49AF1D55@libero.it \
    --to=abramo.bagnara@libero.it \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=fycio@gucio.com \
    --cc=perex@suse.cz \
    /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