www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/13/15:07:03

From: DavMac AT iname DOT com (Davin McCall)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Mixing Sound...
Date: Fri, 13 Aug 1999 15:09:35 GMT
Organization: Monash Uni
Lines: 57
Distribution: world
Message-ID: <37b4331e.43081642@newsserver.cc.monash.edu.au>
References: <37B1ED4C DOT 25700BCB AT geocities DOT com> <7p0r0i$5mt$1 AT taliesin DOT netcom DOT net DOT uk>
NNTP-Posting-Host: damcc5.halls.monash.edu.au
X-Trace: towncrier.cc.monash.edu.au 934556908 9234 130.194.198.138 (13 Aug 1999 15:08:28 GMT)
X-Complaints-To: abuse AT monash DOT edu DOT au
NNTP-Posting-Date: 13 Aug 1999 15:08:28 GMT
X-Newsreader: Forte Free Agent 1.1/32.230
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Actually, adding is the correct way to do it. However, there are a few
things to be taken into account:

* The sample format (unsigned or signed, 8 or 16 bits [for egs] etc)

* The overflow that can occur when adding two samples. ie, the result
of adding the values is greater or lower than the greatest
representable value or lowest representable value respectively.

The usual way of dealing with 2nd is clipping, ie if:

	sample = sample_a + sample_b

yields

	sample > MAX_REPRESENTABLE_VALUE

then sample is made equal to MAX_REPRESENTABLE_VALUE. This generally
requires that sample is capable of holding values larger than MRV
(theoretically, at least twice as big).

The volume shouldn't "go through the roof" - in theory (and in
practice, if you are doing things right) the two sounds should sound
as if they are being played simultaneously.

Davin.


On Fri, 13 Aug 1999 11:11:19 +0100, "Michael Stewart"
<mike AT reggin DOT freeserve DOT co DOT uk> wrote:

>Sahab Yazdani wrote in message <37B1ED4C DOT 25700BCB AT geocities DOT com>...
>>Well I finally wrote my SoundCard Handler and its working properly.
>>
>>Now I have just one problem.
>>
>>I don't know how to mix two sounds together.
>>I tried adding them, but the volume just goes through the roof and only
>>the louder of the too is audiable.
>>
>>what I'm doing right now...
>>
>>mixingblock is a short int
>>and data is an unsigned char
>>
>>*mixingblock+=*data;
>>
>>and then _farnspokew-ing them to the actual buffer
>
>I've never done sound before but would it not be better to average the
>values rather than add them ?
>
>

__________________________________________________________
       *** davmac - sharkin'!! davmac AT iname DOT com ***
my programming page: http://yoyo.cc.monash.edu.au/~davmac/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019