From: brodskye at cae.wisc.edu Newsgroups: alt.sb.programmer Subject: Re: best way to mix? 8 bit 16 bit same time? Date: 5 Apr 1997 19:37:27 GMT Lines: 46 Message-ID: <5i69ln$3v2i@news.doit.wisc.edu> References: <334622C0.40AF@ix.netcom.com> In article <334622C0.40AF@ix.netcom.com>, Kris wrote: >1. Is it possible to play 8bit and 16bit digital sound at the same time? I'm not sure, but I think it should work. The sections of SB16 hardware that handle 8 and 16-bit sound are separated enough that you can record and play simultaneously, so it stands to reason that you can play sound on both channels simultaneously. The only limitation is that you need to play them same sampling rate. >2. What is the best way to mix samples on the fly? If you're using the normal double-buffering method, you mix one block of data for each interrupt. If you mix into the block when you get an interrupt signaling that it just finished playing, there is a one block delay, but there are no interruptions. For the actual mixing, there are several methods. The _bad_ method is to average the samples, adding them up and then dividing by the number of channels. This results in reducing the total amplitude and reducing the bit depth per channel but doesn't cause any peak clipping distortion. Even though it's bad, it still has some uses, which I'll get into later. The _good_ method is to add up all the channels, then clip it to the range (-128..127 for 8-bit). This doesn't affect the amplitude at all, doesn't reduce the bit depth, but can introduce a bit of peak clipping distortion. The distortion really isn't too noticable, as constructive interference resulting in severe distortion doesn't happen too often, especially if you don't play all your sounds at max amplitude. The only problem with this is that it's difficult to implement with 16-bit sound. I like to use a lookup table for the clipping, but can't allocate 64k*channels just for clipping. If you choose to use this method for 16-bit sound, you'll have to add the channels up into a 32-bit variable, then use a compare of conditional jumps for the clipping. In SMIX, I just used the add-and-divide method (it actually turns into add-and-multiply, as you're dividing by a number less than one) for 16-bit sound, as the SB16 tends to have loud output in the first place (negating the mixing losses) and has enough bit depth to mix 256 channels without any loss of precision. Ethan Brodsky -- ----