Skip to content

Commit

Permalink
Implement rest of pulse synthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed May 18, 2024
1 parent 3b66f6e commit 552bbc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod wav;

fn main() {
// Define waveform
let waveform = const { Line(440.0).osc().pulse(Line(0.0), Line(0.5)) };
let waveform = const { Line(440.0).osc().pulse(Line(0.0), Line(1.0)) };
// Initialize audio, and create synthesizer
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5);
let mut synth = Synth::new(waveform);
Expand Down
14 changes: 12 additions & 2 deletions src/tree/osc/pulse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ where
{
fn synthesize(&self, elapsed: u64, interval: u64, vars: &[f32]) -> Chunk {
let chunk = self.0.synthesize(elapsed, interval, vars);
let _cycle = self.1.synthesize(elapsed, interval, vars);
let cycle = self.1.synthesize(elapsed, interval, vars);
let alias = self.2.synthesize(elapsed, interval, vars);
let clip = alias.recip();
let offset = cycle;
let pulse = chunk
.abs()
.gain(2.0)
.offset(-1.0)
.mix(offset)
.clip()
.amplify(clip)
.clip();
let scale = offset.gain(0.5).neg_abs().offset(1.0).recip();

chunk.abs().gain(2.0).offset(-1.0).amplify(clip).clip()
offset.gain(-0.5).mix(pulse).amplify(scale)
}
}

0 comments on commit 552bbc9

Please sign in to comment.