From febe3310aa07a662c60b61d71f8700c31f9c8e39 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Mon, 8 Jul 2024 09:57:29 +0300 Subject: [PATCH] refactor of panning calculations --- src/audio.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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"