[utils] add various crossfading things

main
annieversary 2021-09-16 15:26:41 +02:00
parent b53fa00e86
commit 37e9626b24
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/// Linear crossfade
/// x is the crossfading param, [0, 1]
/// Returns (fade_in, fade_out)
pub fn lin_crossfade(x: f32) -> (f32, f32) {
(x, 1.0 - x)
}
// next two are from https://signalsmith-audio.co.uk/writing/2021/cheap-energy-crossfade/
/// Amplitude preserving crossfade
/// x is the crossfading param, [0, 1]
/// Returns (fade_in, fade_out)
pub fn ap_crossfade(x: f32) -> (f32, f32) {
let fin = x * x * (3.0 - 2.0 * x);
(fin, 1.0 - fin)
}
/// Energy preserving crossfade
/// x is the crossfading param, [0, 1]
/// Returns (fade_in, fade_out)
pub fn ep_crossfade(x: f32) -> (f32, f32) {
let x2 = 1.0 - x;
let a = x * x2;
let b = a * (1.0 + 1.4186 * a);
let c = b + x;
let d = b + x2;
(c * c, d * d)
}

View File

@ -1,4 +1,5 @@
pub mod buffers;
pub mod crossfade;
pub mod delay;
pub mod envelope;
pub mod logs;