-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2691f59
commit 0607d43
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fon::{chan::Ch16, Audio}; | ||
use twang::tree::{line::Line, Synth}; | ||
|
||
mod wav; | ||
//mod plot; | ||
|
||
fn main() { | ||
// Define waveform | ||
let waveform = const { Line(440.0).osc().bezier(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); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink(), &[]); | ||
// Plot synthesized audio, and write to a WAV file | ||
//plot::write(&audio); | ||
wav::write(audio, "bezier.wav").expect("Failed to write WAV file"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::tree::{Chunk, Wave}; | ||
|
||
/// Bezier wave | ||
/// | ||
/// Takes phase (-1 to 1) and curve (-1 to 1) as input | ||
#[derive(Debug)] | ||
pub struct Bezier<I, J>(pub I, pub J); | ||
|
||
impl<I, J> Wave for Bezier<I, J> | ||
where | ||
I: Wave, | ||
J: Wave, | ||
{ | ||
fn synthesize(&self, elapsed: u64, interval: u64, vars: &[f32]) -> Chunk { | ||
let mut chunk = self.0.synthesize(elapsed, interval, vars); | ||
let curve = self.1.synthesize(elapsed, interval, vars); | ||
|
||
for (src, curve) in chunk.0.iter_mut().zip(curve.0.iter()) { | ||
let sign = src.signum(); | ||
let mut output = -src.abs(); | ||
|
||
output += 1.0; | ||
output = output + output * curve * (output - 1.0) - 1.0; | ||
*src = output.copysign(sign); | ||
} | ||
|
||
chunk | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters