How WaveMix works. 1. Mixing Sounds The low-level multimedia wave out put function (waveOutWrite) does not support multiple simultaneous channels of output. So in order to accomplish this we must fake out the output device. This is done by premixing the wave output and then sending this new wave to the wave output device. The core concept which wavemix uses to mix files at run time is very simple. What it does is take a small slice off of each input wave file (each input is referred to as an "channel"), mix them together into an extra buffer which is the same length of the slice and then submit this wave buffer to the multimedia function waveOutWrite. /| _______________ __ / | |-----------| | | | | | | Wave 1 |----| |-------waveOutWrite()---| | | |-----------| | | | | | | | | | | |-----------| | | |__| | | Wave 2 |----| WaveMixer | \ | |-----------| | | \| ... | | |-----------| | | | Wave n |----| | |-----------| |--------------| A digital wave is essentially an array of wave samples. At 11Khz 8bit Mono (which is used by the Wave Mixer) a wave array (or buffer) will contain 11025 byte elements per sec. of the wave duration. (i.e. a one second wave will contain 11025 data samples, a 1 minute data wave will contain 60*11025=661500 samples). To mix the waves in real time the input waves are summed together into another destination buffer. The destination buffer is typically a small size so that we can achieve real time results. A typical length is 1/8 th of a second = 11025/8=1378 samples. Waves are added as vectors. eg. D[i] = w1[i]+w2[i]+w3[i]+...+wn[i] e.g. Assuming that we have 4 waves playing and the slice length = 1378 samples. we could call a mixing routine: mixit(lpDest,rgpCDdata,4,1378); void mixit(LPSAMPLE lpDest, LPSAMPLE rgWaveSrc[], int iNumWaves, WORD wLen) { int i,iSum; WORD ctr; ctr = 0; while (wLen) { iSum=128; /* 128 is the "normal" value (silence) for 8 bit 11KHz */ for (i=0;i