Compare commits

...

2 Commits

Author SHA1 Message Date
Bel LaPointe
0f36241687 get a static sf2 to bake in and its so cute 2026-03-10 12:05:18 -06:00
Bel LaPointe
fbfb216a64 reduce mise default 2026-03-10 11:55:34 -06:00
4 changed files with 32 additions and 37 deletions

View File

@@ -1 +0,0 @@
/usr/share/soundfonts/FatBoy.sf2

View File

@@ -1,8 +1,5 @@
[tools] [tools]
rust = "latest" rust = "latest"
[tasks.setup]
run = "echo paru -S fluidsynth soundfont-fatboy"
[tasks.default] [tasks.default]
run = "if ! aconnect -o -l | grep -q FLUID; then fluidsynth --server $(find /usr/share -name \\*.sf2 | head -n 1); fi; cargo run" run = "cargo run"

View File

@@ -7,41 +7,40 @@ use std::sync::Arc;
use tinyaudio::prelude::*; use tinyaudio::prelude::*;
fn main() { fn main() {
// Load the SoundFont. // Load the SoundFont.
let mut sf2 = File::open("FatBoy.sf2").unwrap(); let mut sf2 = File::open("super_small_font.sf2").unwrap();
let sound_font = Arc::new(SoundFont::new(&mut sf2).unwrap()); let sound_font = Arc::new(SoundFont::new(&mut sf2).unwrap());
// Setup the audio output. // Setup the audio output.
let params = OutputDeviceParameters { let params = OutputDeviceParameters {
channels_count: 2, channels_count: 2,
sample_rate: 44100, sample_rate: 44100,
channel_sample_count: 4410, channel_sample_count: 4410,
}; };
// Create the synthesizer. // Create the synthesizer.
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). // 16 channels actually // 60=c 64=e 67=g //up to 128velocity though dont go below 50 tbh // 12 notes per octave // 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
synthesizer.note_on(0, 64+12, 127); synthesizer.note_on(0, 64 + 12, 127);
//synthesizer.render(&mut left[..], &mut right[..]); // puts in a state of rendering the first loop of these notes //synthesizer.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 // 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. Executes channel_sample_count per loop, sample_rate/channel_sample_count per second forever.
let _device = run_output_device(params, { let _device = run_output_device(params, {
move |data| { move |data| {
synthesizer.render(&mut left[..], &mut right[..]); // put in a state of rendering the next loop of these notes 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;
} }
} }
}) })
.unwrap(); .unwrap();
// Let it ride // Let it ride
std::thread::sleep(std::time::Duration::from_secs(2)); std::thread::sleep(std::time::Duration::from_secs(2));
} }

BIN
super_small_font.sf2 Normal file

Binary file not shown.