diff options
| author | 2025-04-17 21:31:24 -0400 | |
|---|---|---|
| committer | 2025-04-17 21:33:08 -0400 | |
| commit | 76fc9fe33dd58926e552b6bd3b79d798b452c6ed (patch) | |
| tree | bdbffbb532fb0da1195e34119b3f5ecb1cc200d7 /src/buffer | |
| parent | de68f3f60442edc5138fdb5320f40ec53a35b232 (diff) | |
| download | camu-76fc9fe33dd58926e552b6bd3b79d798b452c6ed.tar.gz camu-76fc9fe33dd58926e552b6bd3b79d798b452c6ed.tar.bz2 camu-76fc9fe33dd58926e552b6bd3b79d798b452c6ed.zip | |
Fix user volume fade and relative seek below 0
- Fix sync issue in sink.
- Update deps and android build.
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/buffer')
| -rw-r--r-- | src/buffer/volume.h | 19 |
1 files changed, 10 insertions, 9 deletions
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; } |