Skip to content

Commit

Permalink
Fix wavetable amplitude.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamiPerttu committed Nov 12, 2024
1 parent 801ad0a commit 89829d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
18 changes: 9 additions & 9 deletions examples/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,14 @@ impl eframe::App for State {
});
let waveform = match self.waveform {
Waveform::Sine => Net::wrap(Box::new(pitch * 2.0 >> sine() * 0.1)),
Waveform::Saw => Net::wrap(Box::new(pitch >> saw() * 0.25)),
Waveform::Square => Net::wrap(Box::new(pitch >> square() * 0.25)),
Waveform::Triangle => Net::wrap(Box::new(pitch >> triangle() * 0.25)),
Waveform::Organ => Net::wrap(Box::new(pitch >> organ() * 0.25)),
Waveform::Hammond => Net::wrap(Box::new(pitch >> hammond() * 0.25)),
Waveform::Saw => Net::wrap(Box::new(pitch >> saw() * 0.2)),
Waveform::Square => Net::wrap(Box::new(pitch >> square() * 0.2)),
Waveform::Triangle => Net::wrap(Box::new(pitch >> triangle() * 0.2)),
Waveform::Organ => Net::wrap(Box::new(pitch >> organ() * 0.2)),
Waveform::Hammond => Net::wrap(Box::new(pitch >> hammond() * 0.2)),
Waveform::Pulse => Net::wrap(Box::new(
(pitch | lfo(move |t| lerp11(0.01, 0.99, sin_hz(0.1, t))))
>> pulse() * 0.25,
>> pulse() * 0.2,
)),
Waveform::Pluck => {
Net::wrap(Box::new(zero() >> pluck(pitch_hz as f32, 0.5, 0.5) * 0.5))
Expand All @@ -485,11 +485,11 @@ impl eframe::App for State {
>> resonator()
>> shape(Adaptive::new(0.1, Atan(0.05))) * 0.5,
)),
Waveform::PolySaw => Net::wrap(Box::new(pitch >> poly_saw() * 0.06)),
Waveform::PolySquare => Net::wrap(Box::new(pitch >> poly_square() * 0.06)),
Waveform::PolySaw => Net::wrap(Box::new(pitch >> poly_saw() * 0.2)),
Waveform::PolySquare => Net::wrap(Box::new(pitch >> poly_square() * 0.2)),
Waveform::PolyPulse => Net::wrap(Box::new(
(pitch | lfo(move |t| lerp11(0.01, 0.99, sin_hz(0.1, t))))
>> poly_pulse() * 0.06,
>> poly_pulse() * 0.2,
)),
};
let filter = match self.filter {
Expand Down
3 changes: 1 addition & 2 deletions src/wavetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ where

super::fft::inverse_fft(&mut a);

let z = sqrt(length as f32);

let z = length as f32;
a.iter().map(|x| x.im * z).collect()
}

Expand Down
6 changes: 3 additions & 3 deletions tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn test_basic() {
);
check_wave(dc((110.0, 220.0)) >> declick_s(0.1) + pass() >> (saw() ^ dsf_square_r(0.9)));
check_wave(
dc((20.0, 40.0)) >> reverse() >> pass() * pass() >> (dsf_saw_r(0.999) ^ square() * 0.2),
dc((20.0, 40.0)) >> reverse() >> pass() * pass() >> (dsf_saw_r(0.999) ^ square() * 0.1),
);
check_wave(
dc((880.0, 440.0)) >> pass() - pass() >> branchf::<U2, _, _>(|f| (f - 0.5) * triangle()),
Expand All @@ -207,8 +207,8 @@ fn test_basic() {
| ((mls() | dc(880.0)) >> !bandpass_q(1.0) >> notch_q(2.0)),
);
check_wave(
dc((440.0, 880.0)) >> multisplit::<U2, U5>() >> sumi::<U10, _, _>(|_| saw() * 0.2)
| saw_hz(220.0).phase(0.5),
dc((440.0, 880.0)) >> multisplit::<U2, U5>() >> sumi::<U10, _, _>(|_| saw() * 0.1)
| saw_hz(220.0).phase(0.5) * 0.1,
);
check_wave(
dc((440.0, 880.0)) >> multisplit::<U2, U3>() >> multijoin::<U2, U3>() >> (sine() | sine()),
Expand Down

0 comments on commit 89829d3

Please sign in to comment.