From bd8e264b8fc02337e4d84579db7ac5decffa6274 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Mon, 5 Aug 2024 23:09:05 +0200 Subject: [PATCH] Apply Julian's changes to improve a1's mixing --- Sources/kinc/audio1/a1unit.c | 2 +- Sources/kinc/audio1/audio.c.h | 4 ++-- Sources/kinc/audio1/sound.c.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/kinc/audio1/a1unit.c b/Sources/kinc/audio1/a1unit.c index b3612f9fa..46b2c20d1 100644 --- a/Sources/kinc/audio1/a1unit.c +++ b/Sources/kinc/audio1/a1unit.c @@ -4,7 +4,7 @@ struct kinc_a1_channel { kinc_a1_sound_t *sound; - float position; + double position; bool loop; volatile float volume; float pitch; diff --git a/Sources/kinc/audio1/audio.c.h b/Sources/kinc/audio1/audio.c.h index 7871c8a9c..7685377c5 100644 --- a/Sources/kinc/audio1/audio.c.h +++ b/Sources/kinc/audio1/audio.c.h @@ -18,12 +18,12 @@ static kinc_a1_channel_t channels[CHANNEL_COUNT]; static kinc_a1_stream_channel_t streamchannels[CHANNEL_COUNT]; static kinc_internal_video_channel_t videos[CHANNEL_COUNT]; -static float sampleLinear(int16_t *data, float position) { +static float sampleLinear(int16_t *data, double position) { int pos1 = (int)position; int pos2 = (int)(position + 1); float sample1 = data[pos1] / 32767.0f; float sample2 = data[pos2] / 32767.0f; - float a = position - pos1; + float a = (float)(position - pos1); return sample1 * (1 - a) + sample2 * a; } diff --git a/Sources/kinc/audio1/sound.c.h b/Sources/kinc/audio1/sound.c.h index 117ee4c29..6b19a10f3 100644 --- a/Sources/kinc/audio1/sound.c.h +++ b/Sources/kinc/audio1/sound.c.h @@ -201,7 +201,7 @@ kinc_a1_sound_t *kinc_a1_sound_create(const char *filename) { kinc_affirm(false); } } - sound->sample_rate_pos = 44100 / (float)sound->samples_per_second; + sound->sample_rate_pos = kinc_a2_samples_per_second() / (float)sound->samples_per_second; free(data); return sound;