Skip to content

Commit

Permalink
Rustup
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Aug 3, 2024
1 parent 97a15e2 commit 490e3e6
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/source/linear_ramp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct LinearGainRamp<I> {
start_gain: f32,
end_gain: f32,
clamp_end: bool,
sample_idx: u64
sample_idx: u64,
}

impl<I> LinearGainRamp<I>
Expand Down Expand Up @@ -85,17 +85,15 @@ where
}
} else {
self.sample_idx += 1;

let p = self.elapsed_ns / self.total_ns;
factor = self.start_gain * (1.0f32 - p) + self.end_gain * p;
factor = self.start_gain * (1.0f32 - p) + self.end_gain * p;
}

if self.sample_idx % (self.channels() as u64) == 0 {
self.elapsed_ns +=
1000000000.0 / (self.input.sample_rate() as f32);
self.elapsed_ns += 1000000000.0 / (self.input.sample_rate() as f32);
}


self.input.next().map(|value| value.amplify(factor))
}

Expand Down Expand Up @@ -157,9 +155,7 @@ mod tests {
#[test]
fn test_linearramp() {
let source1 = dummysource(10);
let mut faded = linear_gain_ramp(source1,
Duration::from_secs(4),
0.0, 1.0, true);
let mut faded = linear_gain_ramp(source1, Duration::from_secs(4), 0.0, 1.0, true);

assert_eq!(faded.next(), Some(0.0));
assert_eq!(faded.next(), Some(0.5));
Expand All @@ -177,9 +173,7 @@ mod tests {
#[test]
fn test_linearramp_clamped() {
let source1 = dummysource(10);
let mut faded = linear_gain_ramp(source1,
Duration::from_secs(4),
0.0, 0.5, true);
let mut faded = linear_gain_ramp(source1, Duration::from_secs(4), 0.0, 0.5, true);

assert_eq!(faded.next(), Some(0.0));
assert_eq!(faded.next(), Some(0.25));
Expand Down

0 comments on commit 490e3e6

Please sign in to comment.