diff --git a/code/client/snd_dma.c b/code/client/snd_dma.c index 28de908e..3c33c78a 100644 --- a/code/client/snd_dma.c +++ b/code/client/snd_dma.c @@ -1339,7 +1339,7 @@ void S_Update_(void) { & ~(dma.submission_chunk-1); // never mix more than the complete buffer - samps = dma.samples >> (dma.channels-1); + samps = dma.samples / dma.channels; if (endtime - s_soundtime > samps) endtime = s_soundtime + samps; diff --git a/code/client/snd_mix.c b/code/client/snd_mix.c index af0ba44a..d3b6d0d1 100644 --- a/code/client/snd_mix.c +++ b/code/client/snd_mix.c @@ -150,18 +150,16 @@ void S_TransferPaintBuffer(int endtime) { int out_idx; int count; - int out_mask; int *p; int step; int val; + int i; unsigned long *pbuf; pbuf = (unsigned long *)dma.buffer; if ( s_testsound->integer ) { - int i; - // write a fixed sine wave count = (endtime - s_paintedtime); for (i=0 ; i> 8; - p+= step; + if ( i % dma.channels >= 2 ) + { + val = 0; + } + else + { + val = *p >> 8; + p+= step; + } if (val > 0x7fff) val = 0x7fff; else if (val < -32767) /* clamp to one less than max to make division max out at -1.0f. */ val = -32767; out[out_idx] = ((float) val) / 32767.0f; - out_idx = (out_idx + 1) & out_mask; + out_idx = (out_idx + 1) % dma.samples; } } else if (dma.samplebits == 16) { short *out = (short *) pbuf; - while (count--) + for (i=0 ; i> 8; - p+= step; + if ( i % dma.channels >= 2 ) + { + val = 0; + } + else + { + val = *p >> 8; + p+= step; + } if (val > 0x7fff) val = 0x7fff; else if (val < -32768) val = -32768; out[out_idx] = val; - out_idx = (out_idx + 1) & out_mask; + out_idx = (out_idx + 1) % dma.samples; } } else if (dma.samplebits == 8) { unsigned char *out = (unsigned char *) pbuf; - while (count--) + for (i=0 ; i> 8; - p+= step; + if ( i % dma.channels >= 2 ) + { + val = 0; + } + else + { + val = *p >> 8; + p+= step; + } if (val > 0x7fff) val = 0x7fff; else if (val < -32768) val = -32768; out[out_idx] = (val>>8) + 128; - out_idx = (out_idx + 1) & out_mask; + out_idx = (out_idx + 1) % dma.samples; } } } diff --git a/code/sdl/sdl_snd.c b/code/sdl/sdl_snd.c index e37b4d38..24142c19 100644 --- a/code/sdl/sdl_snd.c +++ b/code/sdl/sdl_snd.c @@ -267,14 +267,8 @@ qboolean SNDDMA_Init(void) if (!tmp) tmp = (obtained.samples * obtained.channels) * 10; - if (tmp & (tmp - 1)) // not a power of two? Seems to confuse something. - { - int val = 1; - while (val < tmp) - val <<= 1; - - tmp = val; - } + // samples must be divisible by number of channels + tmp -= tmp % obtained.channels; dmapos = 0; dma.samplebits = SDL_AUDIO_BITSIZE(obtained.format);