-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
next
module for new data-oriented API design
- Loading branch information
1 parent
00dfee3
commit 8c2d45a
Showing
11 changed files
with
781 additions
and
94 deletions.
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, Frame}; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
fn main() { | ||
// Define waveform | ||
const RAMP: Wave = Wave::sig(440.0).ramp(Wave::MIN); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
let mut synth = Synth::new(RAMP); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "ease.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
fn main() { | ||
// Define waveform | ||
const RAMP: Wave = Wave::sig(440.0).ramp(Wave::MAX); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
let mut synth = Synth::new(RAMP); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "ramp.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
fn main() { | ||
// Define waveform | ||
const RECT: Wave = Wave::sig(440.0).rect(&Wave::sig(0.5)); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
let mut synth = Synth::new(RECT); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "rectangle.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::osc::Sawtooth; | ||
use twang::Synth; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
// State of the synthesizer. | ||
struct Processors { | ||
saw: Sawtooth, | ||
} | ||
|
||
fn main() { | ||
// Initialize audio | ||
// Define waveform | ||
const SAW: Wave = Wave::sig(440.0).saw(); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
// Create audio processors | ||
let proc = Processors { | ||
saw: Sawtooth::new(), | ||
}; | ||
// Build synthesis algorithm | ||
let mut synth = Synth::new(proc, |proc, frame: Frame<_, 2>| { | ||
// Calculate the next sample for each processor | ||
let saw = proc.saw.step(440.0); | ||
// Pan the generated audio center | ||
frame.pan(saw, 0.0) | ||
}); | ||
let mut synth = Synth::new(SAW); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink()); | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "sawtooth.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::osc::Sine; | ||
use twang::Synth; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
// State of the synthesizer. | ||
struct Processors { | ||
sine: Sine, | ||
} | ||
|
||
fn main() { | ||
// Initialize audio | ||
// Define waveform | ||
const SINE: Wave = Wave::sig(440.0).sine(); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
// Create audio processors | ||
let proc = Processors { sine: Sine::new() }; | ||
// Build synthesis algorithm | ||
let mut synth = Synth::new(proc, |proc, frame: Frame<_, 2>| { | ||
// Calculate the next sample for each processor | ||
let sine = proc.sine.step(440.0); | ||
// Pan the generated audio center | ||
frame.pan(sine, 0.0) | ||
}); | ||
let mut synth = Synth::new(SINE); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink()); | ||
// Plot synthesized audio | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Plot synthesized audio, and write to a WAV file | ||
// plot::write(&audio); | ||
// Write synthesized audio to WAV file | ||
wav::write(audio, "sine.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::osc::Pulse; | ||
use twang::Synth; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
// State of the synthesizer. | ||
struct Processors { | ||
pulse: Pulse, | ||
} | ||
|
||
fn main() { | ||
// Initialize audio | ||
// Define waveform | ||
const SQUARE: Wave = Wave::sig(440.0).sq(); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
// Create audio processors | ||
let proc = Processors { | ||
pulse: Pulse::new(), | ||
}; | ||
// Build synthesis algorithm | ||
let mut synth = Synth::new(proc, |proc, frame: Frame<_, 2>| { | ||
// Calculate the next sample for each processor | ||
let square = proc.pulse.step(440.0, Default::default()); | ||
// Pan the generated audio center | ||
frame.pan(square, 0.0) | ||
}); | ||
let mut synth = Synth::new(SQUARE); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink()); | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "square.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
fn main() { | ||
// Define waveform | ||
const TRAP: Wave = Wave::sig(440.0).trap(&Wave::sig(0.5), Wave::ZERO); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
let mut synth = Synth::new(TRAP); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "trap.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
use fon::{chan::Ch16, Audio, Frame}; | ||
use twang::osc::Triangle; | ||
use twang::Synth; | ||
use twang::next::{Synth, Wave}; | ||
|
||
mod wav; | ||
|
||
// State of the synthesizer. | ||
struct Processors { | ||
triangle: Triangle, | ||
} | ||
|
||
fn main() { | ||
// Initialize audio | ||
// Define waveform | ||
const TRIANGLE: Wave = Wave::sig(440.0).trap(Wave::ZERO, Wave::MAX); | ||
|
||
// Initialize audio, and create synthesizer | ||
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5); | ||
// Create audio processors | ||
let proc = Processors { | ||
triangle: Triangle::new(), | ||
}; | ||
// Build synthesis algorithm | ||
let mut synth = Synth::new(proc, |proc, frame: Frame<_, 2>| { | ||
// Calculate the next sample for each processor | ||
let triangle = proc.triangle.step(440.0); | ||
// Pan the generated audio center | ||
frame.pan(triangle, 0.0) | ||
}); | ||
let mut synth = Synth::new(TRIANGLE); | ||
|
||
// Synthesize 5 seconds of audio | ||
synth.stream(audio.sink()); | ||
synth.stream(audio.sink(), &[]); | ||
|
||
// Write synthesized audio to WAV file | ||
wav::write(audio, "triangle.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
Oops, something went wrong.