From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Audio recording and mixing Date: Wed, 11 Feb 1998 19:13:22 +0000 Organization: None Distribution: world Message-ID: References: <19980211051301 DOT AAA21851 AT ladder02 DOT news DOT aol DOT com> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 56 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Myknees writes: >I read a short tutorial on digital audio mixing that basically said >that one must program the mixing routines in assembly. Do you think >that has any truth to it? I don't see why. Sample mixing is exactly the same as any other programming task: you can use whatever language you like. The Allegro mixing code is regular C. >Also, I have accidentally caused mixing to occur with this loop (based on >ex17.c): > do { > if (key[KEY_Q]){ > play_sample(the_sample, 255, pan, pitch, FALSE); > rest(50); > } > else if(key[KEY_W]){ > play_sample(the_sample, 255, pan, pitch*2, FALSE); > rest(50); > } > } while ((!key[KEY_ESC]) && (!key[KEY_SPACE])); > >It makes reverb. Where is the mixing occurring? I presume you only get the overlapping samples if you press the Q and W keys in rapid succession? Allegro can mix up to 32 simultaneous samples (the exact number depending on the config file and how many voices you reserve when setting up the sound module). The code for this is in the mixer.c file. >Are you two talking about unsigned data? That doesn't matter. The signedness of an audio waveform is just a matter of where the center point is located, and doesn't make any difference to how you can manipulate it. >I thought that adding was the only way to go. Averaging only seems like >it would be necessary in an unsigned-data situation. Adding and averaging are really the same thing, the only difference is the level of the output. When you add two 8 bit waveforms, you get a 9 bit result, which will overflow the fixed range of a digital computer. So you have a choice either to halve this value, in order to scale it back down to 8 bits (this is averaging, and loses some volume and clarity), or to clamp at the limits of the 8 bit range (keeping maximum precision, but introducing nasty distortion when it overflows). Most people use a compromise somewhere in between these two, either scaling down by less than the 'correct' value and then clamping any remaining overflow, or sometimes using more complicated curves to concentrate the maximum precision in the middle of the range (I don't do that in Allegro because I think it makes things sound worse, but some people like it). -- Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ "Pigs use it for a tambourine" - Frank Zappa