refactor of panning calculations

This commit is contained in:
veclavtalica 2024-07-08 09:57:29 +03:00
parent 3bd25b2067
commit febe3310aa

View File

@ -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"