3 unstable releases

0.2.0 Jan 31, 2022
0.1.1 Jun 22, 2021
0.1.0 Jun 22, 2021

#939 in Audio

Download history 21/week @ 2024-07-23 15/week @ 2024-07-30 4/week @ 2024-08-06 18/week @ 2024-08-13 47/week @ 2024-08-20 33/week @ 2024-08-27 156/week @ 2024-09-03 87/week @ 2024-09-10 78/week @ 2024-09-17 163/week @ 2024-09-24 12/week @ 2024-10-01 36/week @ 2024-10-08 44/week @ 2024-10-15 68/week @ 2024-10-22 97/week @ 2024-10-29 164/week @ 2024-11-05

385 downloads per month

MIT license

45KB
946 lines

RawSample

A library for working with raw audio samples.

Most audio APIs work with buffers of bytes. To do anything with the sample values, these raw bytes must be converted to and from numeric types.

This library aims to provide the low level tools for converting most common sample formats from raw bytes to float values. Both f32 and f64 are supported, as well as both big-endian and little-endian byte order.

use rawsample::{SampleWriter, SampleReader, SampleFormat};
// create a vec of samples
let values = vec![-0.5, -0.25, -0.125, 0.0, 0.125, 0.25, 0.5];
// create a vec to store raw bytes
let mut rawbytes: Vec<u8> = Vec::new();
// write the samples as raw bytes
f64::write_samples(&values, &mut rawbytes, &SampleFormat::S32LE).unwrap();
// create another vec to store the samples after reading back 
let mut values2 = Vec::new();
let mut slice: &[u8] = &rawbytes;

// read the raw bytes back as samples into the new vec 
f64::read_all_samples(&mut slice, &mut values2, &SampleFormat::S32LE).unwrap();

Dependencies

~150KB