A wav encoding and decoding library in Rust https://github.com/ruuda/hound
Find a file
Ruud van Asseldonk b5b6fbdd4c Document Ambisonic subtypes
Also correct the name, one was missing an E.
2024-02-21 19:21:01 +01:00
examples Add example based on into_header_for_infinite_file 2019-09-12 22:28:07 +03:00
fuzz Bump version to v3.4.0 2018-04-07 21:45:43 +02:00
src Document Ambisonic subtypes 2024-02-21 19:21:01 +01:00
testsamples Work around for 0 valid bits 2021-02-19 13:11:06 -08:00
.gitignore Gitignore append test output 2018-04-07 20:59:39 +02:00
Cargo.lock Document Ambisonic subtypes 2024-02-21 19:21:01 +01:00
Cargo.toml Delete references to Travis CI 2022-09-09 23:42:02 +02:00
changelog.md Link GitHub pull requests in changelog 2023-09-25 22:44:20 +02:00
contributing.md Update code of conduct 2018-04-07 15:39:50 +02:00
license change licence to Apache 2.0 2015-07-21 15:13:40 +02:00
readme.md Delete references to Travis CI 2022-09-09 23:42:02 +02:00

Hound

A wav encoding and decoding library in Rust.

Crates.io version Changelog Documentation

Hound can read and write the WAVE audio format, an ubiquitous format for raw, uncompressed audio. The main motivation to write it was to test Claxon, a FLAC decoding library written in Rust.

Examples

The following example renders a 440 Hz sine wave, and stores it as a mono wav file with a sample rate of 44.1 kHz and 16 bits per sample.

use std::f32::consts::PI;
use std::i16;
use hound;

let spec = hound::WavSpec {
    channels: 1,
    sample_rate: 44100,
    bits_per_sample: 16,
    sample_format: hound::SampleFormat::Int,
};
let mut writer = hound::WavWriter::create("sine.wav", spec).unwrap();
for t in (0 .. 44100).map(|x| x as f32 / 44100.0) {
    let sample = (t * 440.0 * 2.0 * PI).sin();
    let amplitude = i16::MAX as f32;
    writer.write_sample((sample * amplitude) as i16).unwrap();
}

The file is finalized implicitly when the writer is dropped, call writer.finalize() to observe errors.

The following example computes the root mean square (RMS) of an audio file with at most 16 bits per sample.

use hound;

let mut reader = hound::WavReader::open("testsamples/pop.wav").unwrap();
let sqr_sum = reader.samples::<i16>()
                    .fold(0.0, |sqr_sum, s| {
    let sample = s.unwrap() as f64;
    sqr_sum + sample * sample
});
println!("RMS is {}", (sqr_sum / reader.len() as f64).sqrt());

Features

Read Write
Format PCMWAVEFORMAT, WAVEFORMATEX, WAVEFORMATEXTENSIBLE PCMWAVEFORMAT, WAVEFORMATEXTENSIBLE
Encoding Integer PCM, IEEE Float Integer PCM, IEEE Float
Bits per sample 8, 16, 24, 32 (integer), 32 (float) 8, 16, 24, 32 (integer), 32 (float)

Contributing

Contributions in the form of bug reports, feature requests, or pull requests are welcome. See contributing.md.

License

Hound is licensed under the Apache 2.0 license. It may be used in free software as well as closed-source applications, both for commercial and non-commercial use under the conditions given in the license. If you want to use Hound in your GPLv2-licensed software, you can add an exception to your copyright notice. Please do not open an issue if you disagree with the choice of license.