Expand description
§kira-loaders
Provides support for loading and streaming sounds from audio files in Kira.
§Examples
§Loading a sound into memory all at once
use kira::{
manager::{backend::MockBackend, AudioManager, AudioManagerSettings},
sound::static_sound::StaticSoundSettings,
};
const SAMPLE_RATE: u32 = 48_000;
let mut manager = AudioManager::new(
MockBackend::new(SAMPLE_RATE),
AudioManagerSettings::default(),
)
.unwrap();
manager.play(kira_loaders::load(
"sound.ogg",
StaticSoundSettings::default(),
)?)?;
§Streaming a sound from disk
use kira::manager::{backend::MockBackend, AudioManager, AudioManagerSettings};
use kira_loaders::StreamingSoundSettings;
const SAMPLE_RATE: u32 = 48_000;
let mut manager = AudioManager::new(
MockBackend::new(SAMPLE_RATE),
AudioManagerSettings::default(),
)
.unwrap();
manager.play(kira_loaders::stream(
"sound.ogg",
StreamingSoundSettings::default(),
)?)?;
§Static vs. streaming sounds
kira-loaders
can load entire sounds into memory, but it can also
stream them from the disk in real-time. This reduces the amount of
memory needed to play large audio files.
The stream
function takes a StreamingSoundSettings
argument,
which is almost the same as StaticSoundSettings
. Similarly,
StreamingSoundHandle
s are very similar to
StaticSoundHandle
s.
Streaming sounds have some disadvantages compared to static sounds:
- Streaming sounds require more CPU power.
- There may be a longer delay between when you call
AudioManager::play
and when the sound actually starts playing. - Seeking the sound may also have a longer delay.
- If the file cannot be read from the disk fast enough, there will be hiccups in the sound playback. (This will not affect other sounds, though.)
- Backwards playback is not supported.
StreamingSoundData
cannot be cloned.
Structs§
- A streaming sound that is not playing yet.
- Controls a streaming sound.
- Settings for a streaming sound.
Enums§
- Errors that can occur when loading or streaming an audio file.
Functions§
- Loads an audio file into a
StaticSoundData
. - Loads a cursor wrapping audio file data into a
StaticSoundData
. - Creates a
StreamingSoundData
for an audio file. - Creates a
StreamingSoundData
for a cursor wrapping audio file data.