Crate kira[−][src]
Kira
Kira is an audio library designed to help create expressive audio for games. Besides the common features you’d expect from an audio library, it provides interfaces for scripting audio events, seamlessly looping complex pieces of music, smoothly changing parameters, and more.
Usage
To use Kira, first create an AudioManager
:
let mut audio_manager = AudioManager::new(AudioManagerSettings::default())?;
All audio-related actions go through the AudioManager
.
Loading and playing a sound
let mut sound_handle = audio_manager.load_sound("sound.ogg", SoundSettings::default())?; sound_handle.play(InstanceSettings::default())?;
Looping a song while preserving trailing sounds
let sound_handle = audio_manager.load_sound( "loop.ogg", SoundSettings::new().semantic_duration(Tempo(128.0).beats_to_seconds(8.0)), )?; let mut arrangement_handle = audio_manager.add_arrangement(Arrangement::new_loop( &sound_handle, LoopArrangementSettings::default(), ))?; arrangement_handle.play(InstanceSettings::default())?;
Scripting audio sequences
This example will play a kick drum sound every 4 beats and emit an event each time:
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] enum CustomEvent { Kick, } let kick_sound_handle = audio_manager.load_sound("kick.wav", SoundSettings::default())?; let mut metronome_handle = audio_manager.add_metronome(MetronomeSettings::new().tempo(Tempo(150.0)))?; audio_manager.start_sequence( { let mut sequence = Sequence::new(SequenceSettings::default()); sequence.start_loop(); sequence.play(&kick_sound_handle, InstanceSettings::default()); sequence.emit(CustomEvent::Kick); sequence.wait(kira::Duration::Beats(1.0)); sequence }, SequenceInstanceSettings::new().metronome(&metronome_handle), )?; metronome_handle.start()?;
Modules
arrangement | Combines individual sounds into larger pieces. |
audio_stream | A stream of arbitrary audio. |
group | Control multiple instances and sequences at a time. |
instance | Individual occurrences of |
manager | Bridges the main thread and the audio thread. |
metronome | Keeps time with steady pulses. |
mixer | Organizes and applies effects to audio. |
parameter | Tweenable values that can be used by many other objects. |
sequence | Scripts audio events with precise timing. |
sound | A chunk of audio data. |
Structs
CachedValue | A wrapper around |
Frame | An audio sample with a left and right channel. |
Tempo | A tempo, or speed, of some music (in beats per minute). |
Enums
CommandError | Something that can go wrong when sending a command to the audio thread. |
Duration | A duration of time. |
PlayableId | An unique identifier for something you can play multiple instances of. |
Value | A value that something can be set to. |