bbx_file

Audio file I/O for the bbx_audio workspace.

Overview

bbx_file provides:

  • WAV file reading via wavers
  • WAV file writing via hound
  • Integration with bbx_dsp blocks

Installation

[dependencies]
bbx_file = "0.1"
bbx_dsp = "0.1"

Supported Formats

FormatReadWrite
WAVYesYes

Features

FeatureDescription
WAV ReaderLoad WAV files
WAV WriterCreate WAV files

Quick Example

Reading

#![allow(unused)]
fn main() {
use bbx_file::readers::wav::WavFileReader;

let reader = WavFileReader::<f32>::from_path("audio.wav")?;

println!("Sample rate: {}", reader.sample_rate());
println!("Channels: {}", reader.num_channels());
println!("Duration: {:.2}s", reader.duration_seconds());

let left_channel = reader.read_channel(0);
}

Writing

#![allow(unused)]
fn main() {
use bbx_file::writers::wav::WavFileWriter;

let mut writer = WavFileWriter::<f32>::new("output.wav", 44100.0, 2)?;

writer.write_channel(0, &left_samples)?;
writer.write_channel(1, &right_samples)?;

writer.finalize()?;
}

With bbx_dsp

#![allow(unused)]
fn main() {
use bbx_dsp::{blocks::{FileInputBlock, GainBlock}, graph::GraphBuilder};
use bbx_file::readers::wav::WavFileReader;

let reader = WavFileReader::<f32>::from_path("input.wav")?;
let mut builder = GraphBuilder::<f32>::new(44100.0, 512, 2);

let file_in = builder.add(FileInputBlock::new(Box::new(reader)));
let gain = builder.add(GainBlock::new(-6.0, None));

builder.connect(file_in, 0, gain, 0);

let graph = builder.build();
}