X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=snd_mix.c;h=05abc83a5fc95dbdaf803d97bfa9dc698152ab74;hb=e0d72a97bea6a4f2af3bf0fffefe428650bac8b4;hp=ec3de1b7b6961351e2d6c039d1ac32cd356fc294;hpb=98b08b42c82e591dc0259003be04c7aefa2a1fda;p=xonotic%2Fdarkplaces.git diff --git a/snd_mix.c b/snd_mix.c index ec3de1b7..05abc83a 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -183,23 +183,13 @@ CHANNEL MIXING static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint, unsigned int count) { - int snd_vol, vol[SND_LISTENERS]; + int vol[SND_LISTENERS]; const snd_buffer_t *sb; unsigned int i, sb_offset; - // If this channel manages its own volume - if (ch->flags & CHANNELFLAG_FULLVOLUME) - snd_vol = 256; - else - snd_vol = (int)(volume.value * 256); - - // calculate mixing volumes based on channel volumes and volume cvar - // also limit the volumes to values that won't clip + // move to the stack (do we need to?) for (i = 0;i < SND_LISTENERS;i++) - { - vol[i] = ch->listener_volume[i] * snd_vol; - vol[i] = bound(0, vol[i], 65536); - } + vol[i] = ch->listener_volume[i]; // if volumes are all zero, just return for (i = 0;i < SND_LISTENERS;i++) @@ -267,6 +257,15 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint, samples += 2; } } + else if (vol[0] + vol[1] > 0 && ch->prologic_invert == -1) + { + for (i = 0;i < count;i++) + { + paint[i].sample[0] += (samples[0] * vol[0]) >> 8; + paint[i].sample[1] -= (samples[1] * vol[1]) >> 8; + samples += 2; + } + } else if (vol[0] + vol[1] > 0) { for (i = 0;i < count;i++) @@ -318,6 +317,15 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint, samples += 1; } } + else if (vol[0] + vol[1] > 0 && ch->prologic_invert == -1) + { + for (i = 0;i < count;i++) + { + paint[i].sample[0] += (samples[0] * vol[0]) >> 8; + paint[i].sample[1] -= (samples[0] * vol[1]) >> 8; + samples += 1; + } + } else if (vol[0] + vol[1] > 0) { for (i = 0;i < count;i++) @@ -377,6 +385,15 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint, samples += 2; } } + else if (vol[0] + vol[1] > 0 && ch->prologic_invert == -1) + { + for (i = 0;i < count;i++) + { + paint[i].sample[0] += (samples[0] * vol[0]) >> 16; + paint[i].sample[1] -= (samples[1] * vol[1]) >> 16; + samples += 2; + } + } else if (vol[0] + vol[1] > 0) { for (i = 0;i < count;i++) @@ -428,6 +445,15 @@ static qboolean SND_PaintChannel (channel_t *ch, portable_sampleframe_t *paint, samples += 1; } } + else if (vol[0] + vol[1] > 0 && ch->prologic_invert == -1) + { + for (i = 0;i < count;i++) + { + paint[i].sample[0] += (samples[0] * vol[0]) >> 16; + paint[i].sample[1] -= (samples[0] * vol[1]) >> 16; + samples += 1; + } + } else if (vol[0] + vol[1] > 0) { for (i = 0;i < count;i++) @@ -467,8 +493,8 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) for (i = 0; i < total_channels ; i++, ch++) { sfx_t *sfx; - unsigned int ltime; - unsigned int count; + int ltime; + int count; sfx = ch->sfx; if (sfx == NULL) @@ -477,21 +503,23 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) continue; if (ch->flags & CHANNELFLAG_PAUSED) continue; + if (!sfx->total_length) + continue; ltime = 0; if (ch->pos < 0) { count = -ch->pos; - count = min(count, frames - ltime); + count = min(count, (int)frames - ltime); ch->pos += count; ltime += count; } - while (ltime < frames) + while (ltime < (int)frames) { // paint up to end of buffer or of input, whichever is lower count = sfx->total_length - ch->pos; - count = bound(0, count, frames - ltime); + count = bound(0, count, (int)frames - ltime); if (count) { SND_PaintChannel (ch, paintbuffer + ltime, count);