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,
StreamingSoundHandles are very similar to
StaticSoundHandles.
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::playand 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.
StreamingSoundDatacannot be cloned.
Structs§
- Streaming
Sound Data - A streaming sound that is not playing yet.
- Streaming
Sound Handle - Controls a streaming sound.
- Streaming
Sound Settings - Settings for a streaming sound.
Enums§
- Error
- Errors that can occur when loading or streaming an audio file.
Functions§
- load
- Loads an audio file into a
StaticSoundData. - load_
from_ cursor - Loads a cursor wrapping audio file data into a
StaticSoundData. - stream
- Creates a
StreamingSoundDatafor an audio file. - stream_
from_ cursor - Creates a
StreamingSoundDatafor a cursor wrapping audio file data.