diff --git a/src/audio.c b/src/audio.c index 4c65621..d2883fb 100644 --- a/src/audio.c +++ b/src/audio.c @@ -192,22 +192,19 @@ static void audio_sample_and_mixin_channel(struct audio_channel *channel, /* panning and mixing */ + const float left_panning = fminf(fabsf(channel->args.panning - 1.0f), 1.0f); + const float right_panning = fminf(fabsf(channel->args.panning + 1.0f), 1.0f); + #if AUDIO_N_CHANNELS == 2 for (int s = 0; s < samples_per_channel * ctx.audio_stream_channel_count; s += 2) { /* left channel */ - { - const float panning = fminf(fabsf(channel->args.panning - 1.0f), 1.0f); - const float volume = channel->args.volume * panning; - sstream[i + s] += (int16_t)(((int16_t *)buffer)[s] * volume); - } + sstream[i + s] += (int16_t)(((int16_t *)buffer)[s] * + channel->args.volume * left_panning); /* right channel */ - { - const float panning = fminf(fabsf(channel->args.panning + 1.0f), 1.0f); - const float volume = channel->args.volume * panning; - sstream[i + s + 1] += (int16_t)(((int16_t *)buffer)[s + 1] * volume); - } + sstream[i + s + 1] += (int16_t)(((int16_t *)buffer)[s + 1] * + channel->args.volume * right_panning); } #else #error "Unimplemented channel count"