[−][src]Crate kira
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 an interface for scripting audio events to happen at certain times, like the tick of a metronome.
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 sound_id = audio_manager.add_sound(Sound::from_file("loop.ogg", SoundSettings::default())?)?; audio_manager.play_sound(sound_id, InstanceSettings::default())?;
Looping a piece of music
let sound_id = audio_manager.add_sound(Sound::from_file( "loop.ogg", SoundSettings { metadata: SoundMetadata { semantic_duration: Some(Tempo(128.0).beats_to_seconds(16.0)), }, ..Default::default() }, )?)?; // when the sound loops, start the loop 4 beats in let loop_start = Tempo(128.0).beats_to_seconds(4.0); audio_manager.play_sound(sound_id, InstanceSettings::new().loop_region(loop_start..))?;
Scripting audio sequences
This example will play a kick drum sound every 4 beats and emit an event each time:
let mut sequence = Sequence::new(); sequence.start_loop(); sequence.wait_for_interval(4.0); sequence.play_sound(kick_drum_sound_id, InstanceSettings::default()); sequence.emit_custom_event(CustomEvent::KickDrum); audio_manager.start_sequence(sequence)?; // start the metronome so the sequence will have a pulse to listen for audio_manager.start_metronome()?;
Modules
instance | Provides an interface to control "instances", or individual occurrences, of a sound. |
manager | Provides a bridge between the main thread and the audio thread. |
mixer | Provides an interface for organizing and applying effects to sounds. |
parameter | Provides an interface for smoothly changing values over time. |
sequence | Provides an interface to script timed audio events. |
sound | Provides an interface to work with pieces of audio. |
Structs
CachedValue | A wrapper around |
MetronomeSettings | Settings for the metronome. |
StereoSample | Represents an audio sample with a left and right channel. |
Tempo | Represents a tempo, or speed, of some music (in beats per minute). |
Enums
AudioError | |
Duration | Represents a duration of time. |
Event | An audio-related event that can be observed on the main thread. |
Value | A number that something can be set to. |
Type Definitions
AudioResult |