refactor of panning calculations
This commit is contained in:
parent
3bd25b2067
commit
febe3310aa
17
src/audio.c
17
src/audio.c
@ -192,22 +192,19 @@ static void audio_sample_and_mixin_channel(struct audio_channel *channel,
|
|||||||
|
|
||||||
/* panning and mixing */
|
/* 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
|
#if AUDIO_N_CHANNELS == 2
|
||||||
|
|
||||||
for (int s = 0; s < samples_per_channel * ctx.audio_stream_channel_count; s += 2) {
|
for (int s = 0; s < samples_per_channel * ctx.audio_stream_channel_count; s += 2) {
|
||||||
/* left channel */
|
/* left channel */
|
||||||
{
|
sstream[i + s] += (int16_t)(((int16_t *)buffer)[s] *
|
||||||
const float panning = fminf(fabsf(channel->args.panning - 1.0f), 1.0f);
|
channel->args.volume * left_panning);
|
||||||
const float volume = channel->args.volume * panning;
|
|
||||||
sstream[i + s] += (int16_t)(((int16_t *)buffer)[s] * volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* right channel */
|
/* right channel */
|
||||||
{
|
sstream[i + s + 1] += (int16_t)(((int16_t *)buffer)[s + 1] *
|
||||||
const float panning = fminf(fabsf(channel->args.panning + 1.0f), 1.0f);
|
channel->args.volume * right_panning);
|
||||||
const float volume = channel->args.volume * panning;
|
|
||||||
sstream[i + s + 1] += (int16_t)(((int16_t *)buffer)[s + 1] * volume);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#error "Unimplemented channel count"
|
#error "Unimplemented channel count"
|
||||||
|
Loading…
Reference in New Issue
Block a user