pub struct Bank<R: Read> { /* private fields */ }Expand description
An FMOD sound bank.
The FMOD sound bank is a container format that can contain multiple streams/songs.
All streams have the same AudioFormat.
Decoding and encoding is performed lazily.
Examples
Reading from a slice of bytes:
use fsbex::Bank;
use std::error::Error;
fn read_from_slice(bytes: &[u8]) -> Result<Bank<&[u8]>, Box<dyn Error>> {
let bank = Bank::new(bytes)?;
Ok(bank)
}Reading from a File using a Path:
use fsbex::Bank;
use std::{error::Error, fs::File, io::BufReader, path::Path};
fn read_from_file<P: AsRef<Path>>(path: P) -> Result<Bank<BufReader<File>>, Box<dyn Error>> {
let file = File::open(path)?;
let reader = BufReader::new(file);
let bank = Bank::new(reader)?;
Ok(bank)
}Implementations§
source§impl<R: Read> Bank<R>
impl<R: Read> Bank<R>
sourcepub fn new(source: R) -> Result<Self, DecodeError>
pub fn new(source: R) -> Result<Self, DecodeError>
Creates a new Bank<R> by parsing from an I/O stream.
Contents are parsed directly from the stream without being buffered in memory.
When reading from a source where small, repeated read calls are inefficient, such as a File,
buffering with something like BufReader is recommended.
Errors
This function returns an error if parsing of the sound bank’s file header failed.
See DecodeError for more information.
sourcepub fn format(&self) -> AudioFormat
pub fn format(&self) -> AudioFormat
Returns the audio format of streams in the sound bank.
See AudioFormat for the list of known formats.
sourcepub fn num_streams(&self) -> NonZeroU32
pub fn num_streams(&self) -> NonZeroU32
Returns the number of streams in the sound bank.
sourcepub fn read_streams<F, E>(self, f: F) -> Result<(), LazyStreamError<E>>where
F: Fn(LazyStream<'_, R>) -> Result<(), E>,
pub fn read_streams<F, E>(self, f: F) -> Result<(), LazyStreamError<E>>where F: Fn(LazyStream<'_, R>) -> Result<(), E>,
Sequentially reads streams from the sound bank, consuming this Bank<R>.
Streams can be accessed within the function f as they are read.
See LazyStream for more information.
Errors
This function returns an error if:
- an error was returned from
f - the underlying reader failed to advance to the next stream
See LazyStreamError for more information.