Crate kira_loaders

Source
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::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§

Enums§

  • Errors that can occur when loading or streaming an audio file.

Functions§