#sfx #audio #gamedev #sound #procedural

usfx

Realtime procedurally generated sound effects

4 releases

0.1.3 Apr 13, 2020
0.1.2 Apr 5, 2020
0.1.1 Apr 4, 2020
0.1.0 Apr 3, 2020

#169 in Audio

Download history 427/week @ 2021-06-29 454/week @ 2021-07-06 440/week @ 2021-07-13 267/week @ 2021-07-20 10/week @ 2021-07-27 7/week @ 2021-08-03 3/week @ 2021-08-10 5/week @ 2021-08-17 4/week @ 2021-08-24 3/week @ 2021-09-07 4/week @ 2021-09-14 1/week @ 2021-09-21 4/week @ 2021-09-28 1/week @ 2021-10-05 15/week @ 2021-10-12

973 downloads per month

AGPL-3.0-or-later

30KB
382 lines

μsfx

Generate sound effects for your game in realtime.

CI Version Rust Documentation License

Example

// Create a simple blip sound
let mut sample = usfx::Sample::default();
sample.volume(0.5);

// Use a sine wave oscillator at 500 hz
sample.osc_type(usfx::OscillatorType::Sine);
sample.osc_frequency(500);

// Set the envelope
sample.env_attack(0.02);
sample.env_decay(0.05);
sample.env_sustain(0.2);
sample.env_release(0.5);

// Add some distortion
sample.dis_crunch(0.5);
sample.dis_drive(0.9);

// Create a mixer so we can play the sound
let mut mixer = usfx::Mixer::default();

// Play our sample
mixer.play(sample);

// Plug our mixer into the audio device loop
// ...
mixer.generate(&mut audio_device_buffer);

The cpal & sdl examples illustrate how to use it with different audio libraries. The music example shows how to create procedurally generated music with it (don't expect a masterpiece though, it's obvious I'm not a musician).

CPAL Example

To build the cpal & music examples on Linux you will need to have the alsa development libraries:

sudo apt install libasound2-dev

SDL Example

To build the sdl you will need the SDL2 development libraries, on Linux:

sudo apt install libsdl2-dev

Special Thanks

Dependencies