notes
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -1,6 +1,4 @@
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustysynth::MidiFile;
|
|
||||||
use rustysynth::MidiFileSequencer;
|
|
||||||
use rustysynth::SoundFont;
|
use rustysynth::SoundFont;
|
||||||
use rustysynth::Synthesizer;
|
use rustysynth::Synthesizer;
|
||||||
use rustysynth::SynthesizerSettings;
|
use rustysynth::SynthesizerSettings;
|
||||||
@@ -24,20 +22,18 @@ fn main() {
|
|||||||
let settings = SynthesizerSettings::new(params.sample_rate as i32);
|
let settings = SynthesizerSettings::new(params.sample_rate as i32);
|
||||||
let mut synthesizer = Synthesizer::new(&sound_font, &settings).unwrap();
|
let mut synthesizer = Synthesizer::new(&sound_font, &settings).unwrap();
|
||||||
|
|
||||||
// Play some notes (middle C, E, G).
|
// 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
|
||||||
synthesizer.note_on(0, 60, 100);
|
|
||||||
synthesizer.note_on(0, 64, 100);
|
synthesizer.note_on(0, 64, 100);
|
||||||
synthesizer.note_on(0, 67, 100);
|
//synthesizer.render(&mut left[..], &mut right[..]); // puts in a state of rendering the first loop of these notes
|
||||||
|
|
||||||
// The output buffer
|
// The recycled output buffer per-loop, could be in lamba but that'd be wasteful
|
||||||
let sample_count = (params.channel_sample_count) as usize;
|
let sample_count = (params.channel_sample_count) as usize;
|
||||||
let mut left: Vec<f32> = vec![0_f32; sample_count];
|
let mut left: Vec<f32> = vec![0_f32; sample_count];
|
||||||
let mut right: 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.
|
||||||
// Start the audio output.
|
|
||||||
let _device = run_output_device(params, {
|
let _device = run_output_device(params, {
|
||||||
move |data| {
|
move |data| {
|
||||||
synthesizer.render(&mut left[..], &mut right[..]);
|
synthesizer.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() {
|
for (i, value) in left.iter().interleave(right.iter()).enumerate() {
|
||||||
data[i] = *value;
|
data[i] = *value;
|
||||||
}
|
}
|
||||||
@@ -45,7 +41,7 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Wait for 10 seconds.
|
// Let it ride
|
||||||
std::thread::sleep(std::time::Duration::from_secs(10));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user