Compare commits
2 Commits
c470f7ae40
...
2cdfcb72ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cdfcb72ee | ||
|
|
90b202f0df |
29
src/main.rs
29
src/main.rs
@@ -1,5 +1,4 @@
|
||||
use itertools::Itertools;
|
||||
use tinyaudio::prelude::*;
|
||||
|
||||
mod flags;
|
||||
mod syn;
|
||||
@@ -12,25 +11,26 @@ fn main() {
|
||||
flags.sound_font,
|
||||
flags.sample_rate,
|
||||
);
|
||||
|
||||
let params = OutputDeviceParameters {
|
||||
channels_count: 2,
|
||||
sample_rate: flags.sample_rate,
|
||||
channel_sample_count: flags.sample_rate / flags.bpm * 60 / flags.smallest_note,
|
||||
};
|
||||
|
||||
// Play some notes (middle C, E, G). // 16 channels actually // 60=c 64=e 67=g //up to 128velocity though dont go below 50 tbh // 12 notes per octave
|
||||
syn.note_on(0, 64 + 12, 127);
|
||||
//syn.render(&mut left[..], &mut right[..]); // puts in a state of rendering the first loop of these notes
|
||||
|
||||
// The recycled output buffer per-loop, could be in lamba but that'd be wasteful
|
||||
play(syn, flags.sample_rate, flags.bpm, flags.smallest_note);
|
||||
}
|
||||
|
||||
fn play(mut s: syn::Syn, sample_rate: usize, bpm: usize, smallest_note: usize) {
|
||||
let params = tinyaudio::prelude::OutputDeviceParameters {
|
||||
channels_count: 2,
|
||||
sample_rate: sample_rate,
|
||||
channel_sample_count: sample_rate / bpm * 60 / smallest_note,
|
||||
};
|
||||
|
||||
let sample_count = (params.channel_sample_count) as usize;
|
||||
let mut left: Vec<f32> = vec![0_f32; sample_count];
|
||||
let mut right: Vec<f32> = vec![0_f32; sample_count];
|
||||
// Start the audio output. Executes channel_sample_count per loop, sample_rate/channel_sample_count per second forever.
|
||||
let _device = run_output_device(params, {
|
||||
|
||||
let _device = tinyaudio::prelude::run_output_device(params, {
|
||||
move |data| {
|
||||
syn.render(&mut left[..], &mut right[..]); // put in a state of rendering the next loop of these notes
|
||||
s.render(&mut left[..], &mut right[..]); // put in a state of rendering the next loop of these notes
|
||||
for (i, value) in left.iter().interleave(right.iter()).enumerate() {
|
||||
data[i] = *value;
|
||||
}
|
||||
@@ -38,7 +38,6 @@ fn main() {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
// Let it ride
|
||||
// Wait it out
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user