Generate sound effects for your game in realtime.
```rust // Create a simple blip sound let mut sample = usfx::Sample::default(); sample.volume(0.5);
// Use a sine wave oscillator at 500 hz sample.osctype(usfx::OscillatorType::Sine); sample.oscfrequency(500);
// Set the envelope sample.envattack(0.02); sample.envdecay(0.05); sample.envsustain(0.2); sample.envrelease(0.5);
// Add some distortion sample.discrunch(0.5); sample.disdrive(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 audiodevicebuffer); ```
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).
To build the cpal
& music
examples on Linux you will need to have the alsa development libraries:
bash
sudo apt install libasound2-dev
To build the sdl
you will need the SDL2 development libraries, on Linux:
bash
sudo apt install libsdl2-dev