From alsa-devel-owner@alsa.jcu.cz  Sun Feb 21 01:06:11 1999
Received: from medelec.uia.ac.be (fnet@medelec.uia.ac.be [143.169.17.1])
	by marvin.jcu.cz (8.9.1a/8.9.1) with ESMTP id BAA24451
	for <alsa-devel@alsa.jcu.cz>; Sun, 21 Feb 1999 01:06:06 +0100
Received: (from fnet@localhost)
	by medelec.uia.ac.be (8.8.8/8.8.8) id BAA11659
	for alsa-devel@alsa.jcu.cz; Sun, 21 Feb 1999 01:06:05 +0100
To: alsa-devel@alsa.jcu.cz
From: "O/T-Track+ 2.66b" <"O/T-Track+=202.66b"@f854.n292.z2.fidonet.org>
Date: Sat, 20 Feb 99 22:30:43 +0100
Subject: Message *bounced*
Message-ID: <3655839413@f854.n292.z2.ftn>
In-Reply-To: <392457495@havoc.gtf.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

************************************************************************
***  WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING  ***
************************************************************************
*
*      The e-mail-message appended below is list- or mailserver-related
*
*   That type of mail will by definition not be processed on this system.
*
*    If you have reason to believe your message was removed without due
*     reason then kindly inform 'postmaster@f854.n292.z2.fidonet.org'.
*
************************************************************************

    From:  Data @2:292/875
    To:    Michael Putijewsky @2:244/3311.2
    Subj.: Re: Mixing
    Dated: 15 Feb 99  00:38:59
    [processed here:  20 Feb 99 22:30:43]

@TOPT 2
@INTL 2:244/3311 2:292/875
@MSGID: havoc.gtf.org 17646d17
@REPLY: screech.cs.alfred.edu 20a17e68
@REPLYADDR: alsa-devel@alsa.jcu.cz
@REPLYTO: 2:292/875@fidonet UUCP
@CHRS: LATIN-1 2
@RFC-Received: (from fnet@localhost) by infomag.infomag.iguana.be
(8.6.12/8.6.10) id VAA03500 for
Michael.Putijewsky@p2.f3311.n244.z2.fidonet.org;
Thu, 18 Feb 1999 21:08:42 +0100
@RFC-Received: from cimmeria.iguana.be (qmailr@cimmeria.iguana.be [194.7.8.7])
	by medelec.uia.ac.be (8.8.8/8.8.8) with SMTP id BAA25141 	for
<Michael_Putijewsky@p2.f3311.n244.z2.fidonet.org>; Mon, 15 Feb 1999 01:42:42
+0100
@RFC-Received: (qmail 6593 invoked from network); 15 Feb 1999 00:42:40 -0000
@RFC-Received: from mx5.gmx.net (195.63.104.85)   by cimmeria.iguana.be with
SMTP; 15 Feb 1999 00:42:40 -0000
@RFC-Received: (qmail 28149 invoked by alias); 15 Feb 1999 00:42:38 -0000
@RFC-Received: (qmail 28133 invoked by uid 0); 15 Feb 1999 00:42:37 -0000
@RFC-Received: from marvin.jcu.cz (160.217.1.3)   by mx5.gmx.net with SMTP; 15
Feb 1999 00:42:37 -0000
@RFC-Received: (from petidomo@localhost) 	by marvin.jcu.cz (8.9.1a/8.9.1) id
AAA30556; 	Mon, 15 Feb 1999 00:39:03 +0100
@RFC-Received: from havoc.gtf.org (IDENT:data@panic.ohr.gatech.edu
[130.207.47.194]) 	by marvin.jcu.cz (8.9.1a/8.9.1) with ESMTP id AAA30553 	for
<alsa-devel@alsa.jcu.cz>; Mon, 15 Feb 1999 00:39:02 +0100
@RFC-Received: (from data@localhost) 	by havoc.gtf.org (8.8.7/8.8.7) id
SAA09588 	for alsa-devel@alsa.jcu.cz; Sun, 14 Feb 1999 18:39:00 -0500
@RFC-Message-ID: <199902142339.SAA09588@havoc.gtf.org>
@RFC-In-Reply-To:
<Pine.LNX.4.05.9902140125140.3906-100000@screech.cs.alfred.edu> from
"Christopher T. Lansdown" at Feb 14, 99 01:27:36 am
@RFC-Delivered-To: GMX delivery to t0mcat@gmx.de
@RFC-Sender: alsa-devel-owner@alsa.jcu.cz
@RFC-Precedence: list
@RFC-X-Resent-By: Global Message Exchange <forwarder@gmx.net>
@RFC-X-Resent-For: t0mcat@gmx.de
@RFC-X-Resent-To: tomcat@main-kinzig.de,
Michael_Putijewsky@p2.f3311.n244.z2.fidonet.org
To: alsa-devel@alsa.jcu.cz
From: Data <data@havoc.gtf.org>
Reply-To: alsa-devel@alsa.jcu.cz
> 
> Hello,
> 	I'm in the process of writing a music library, targeted at games.
> On of it's functions will be mixing different sounds (PCM streams).  What
> is the right way to mix PCM streams?  Adding the samples, averaging them,
> or something else?  Assume identicle sample rate and stereo.

For the highest quality you should attenuate them then add them.  Mixing in 
the analog domain is simple addition, and that's what you should do digitally.
Generally analog mixers attenuate (== reduce the volume of) the signal before 
combining, since it often happens that simple addition will drive the 
amplitude out of range.
  A quick way to do this for games & such is by bit-shifting & then adding.  
For example -

short mixemquick(short sample1, short sample2)
{
    return (sample1>>1 + sample2>>1);
}

This attenuates each sample by 6 dB.  For more attenuation, shift over more. 
Alternatively you can ensure that the soundclips & such you're using are 
_already_ attenuated so you can add them without fear.  Of course active 
envelope control is another topic entirely .. bear in mind also that you 
may not need to do this at all; it's probably worthwhile to try simple 
addition first - if it sounds OK, keep it.  There are ways to achieve 
finer control, of course, but I won't bore you with those unless you ask :)
  If you decide to enforce clipping you'll need to manipulate your samples as 
longs; otherwise you won't be able to tell when they go out of range.  If you 
do it in assembly, on the other hand, you can do it 16-bit & check the 
overflow flag.  (not real real portable unfortunately.)
  For games I'd say there's no reason whatever to use floating-point 
arithmetic.  It's slower and takes more memory, and lends very little 
benefit to this kind of work (lower roundoff error - big whoop).  I'd 
actually take the trouble to ensure that integer arithmetic was always 
being used, with casts and the like.

cheers
Michael Ashton

------
To unsubscribe from <alsa-devel@alsa.jcu.cz> mailing list send message
'unsubscribe' in the body of message to <alsa-devel-request@alsa.jcu.cz>.

@Via ifmail 2:292/875@fidonet, Mon Feb 15 1999 at 01:43 (2.10-tx8.3)
@Via ifmail 2:292/862@fidonet, Thu Feb 18 1999 at 21:10 (2.10-tx8.3)

@Via D'Bridge 1.58 2:292/854  02/20 21:48


