From 76fc9fe33dd58926e552b6bd3b79d798b452c6ed Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 17 Apr 2025 21:31:24 -0400 Subject: Fix user volume fade and relative seek below 0 - Fix sync issue in sink. - Update deps and android build. Signed-off-by: Andrew Opalach --- src/buffer/volume.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/buffer') diff --git a/src/buffer/volume.h b/src/buffer/volume.h index 87b1945..7d10e6d 100644 --- a/src/buffer/volume.h +++ b/src/buffer/volume.h @@ -1,10 +1,10 @@ #include "../codec/codec.h" -static inline f32 apply_volume_f32(f32 *data, size_t sample_count, s32 channel_count, f32 volume, f32 user, f32 step) +static inline f32 apply_volume_f32(f32 *data, size_t sample_count, s32 channel_count, f32 volume, f32 limit, f32 step) { for (u32 i = 0; i < sample_count; i++) { if (step != 0.f && i % channel_count == 0) { - volume = CLAMP(volume + step, 0.f, user); + volume = CLAMP(volume + step, 0.f, limit); } f64 sample = (f64)data[i]; sample *= volume; @@ -13,11 +13,11 @@ static inline f32 apply_volume_f32(f32 *data, size_t sample_count, s32 channel_c return volume; } -static inline f32 apply_volume_s32(s32 *data, size_t sample_count, s32 channel_count, f32 volume, f32 user, f32 step) +static inline f32 apply_volume_s32(s32 *data, size_t sample_count, s32 channel_count, f32 volume, f32 limit, f32 step) { for (u32 i = 0; i < sample_count; i++) { if (step != 0.f && i % channel_count == 0) { - volume = CLAMP(volume + step, 0.f, user); + volume = CLAMP(volume + step, 0.f, limit); } f64 sample = (f64)data[i]; sample *= volume; @@ -26,11 +26,11 @@ static inline f32 apply_volume_s32(s32 *data, size_t sample_count, s32 channel_c return volume; } -static inline f32 apply_volume_s16(s16 *data, size_t sample_count, s32 channel_count, f32 volume, f32 user, f32 step) +static inline f32 apply_volume_s16(s16 *data, size_t sample_count, s32 channel_count, f32 volume, f32 limit, f32 step) { for (u32 i = 0; i < sample_count; i++) { if (step != 0.f && i % channel_count == 0) { - volume = CLAMP(volume + step, 0.f, user); + volume = CLAMP(volume + step, 0.f, limit); } f64 sample = (f64)data[i]; sample *= volume; @@ -42,19 +42,20 @@ static inline f32 apply_volume_s16(s16 *data, size_t sample_count, s32 channel_c static inline f32 apply_volume(u8 *data, size_t size, struct camu_audio_format *fmt, f32 volume, f32 user, f32 step) { size_t sample_count; + f32 limit = MAX(user, volume); switch (camu_audio_format_bytes_per_sample(fmt)) { case 4: sample_count = size / 4; if (fmt->format == CAMU_SAMPLE_FORMAT_S32) { - return apply_volume_s32((s32 *)data, sample_count, fmt->channel_count, volume, user, step); + return apply_volume_s32((s32 *)data, sample_count, fmt->channel_count, volume, limit, step); } else if (fmt->format == CAMU_SAMPLE_FORMAT_FLT) { - return apply_volume_f32((f32 *)data, sample_count, fmt->channel_count, volume, user, step); + return apply_volume_f32((f32 *)data, sample_count, fmt->channel_count, volume, limit, step); } break; case 2: sample_count = size / 2; if (fmt->format == CAMU_SAMPLE_FORMAT_S16) { - return apply_volume_s16((s16 *)data, sample_count, fmt->channel_count, volume, user, step); + return apply_volume_s16((s16 *)data, sample_count, fmt->channel_count, volume, limit, step); } break; } -- cgit v1.2.3-101-g0448