mirror of
https://github.com/haileys/bark
synced 2024-11-28 14:20:23 +00:00
add bark_core::audio with Sample, Frame types and conversion fns
This commit is contained in:
parent
81da1b7079
commit
69eb04d6a9
4 changed files with 34 additions and 3 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -235,9 +235,9 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
|||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.13.1"
|
||||
version = "1.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
|
||||
checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6"
|
||||
dependencies = [
|
||||
"bytemuck_derive",
|
||||
]
|
||||
|
|
|
@ -11,7 +11,7 @@ bark-core = { path = "bark-core" }
|
|||
bark-protocol = { path = "bark-protocol" }
|
||||
|
||||
bitflags = { version = "2.4", features = ["bytemuck"] }
|
||||
bytemuck = { version = "1.13", features = ["derive"] }
|
||||
bytemuck = { version = "1.14", features = ["derive", "must_cast"] }
|
||||
derive_more = { version = "0.99" }
|
||||
heapless = "0.7"
|
||||
log = "0.4"
|
||||
|
|
30
bark-core/src/audio.rs
Normal file
30
bark-core/src/audio.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use bark_protocol::CHANNELS;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
|
||||
pub type Sample = f32;
|
||||
|
||||
#[derive(Pod, Zeroable, Copy, Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct Frame(pub Sample, pub Sample);
|
||||
|
||||
pub fn from_interleaved(samples: &[Sample]) -> &[Frame] {
|
||||
// ensure samples contains whole frames only
|
||||
assert_eq!(0, samples.len() % usize::from(CHANNELS));
|
||||
|
||||
bytemuck::cast_slice(samples)
|
||||
}
|
||||
|
||||
pub fn from_interleaved_mut(samples: &mut [Sample]) -> &mut [Frame] {
|
||||
// ensure samples contains whole frames only
|
||||
assert_eq!(0, samples.len() % usize::from(CHANNELS));
|
||||
|
||||
bytemuck::cast_slice_mut(samples)
|
||||
}
|
||||
|
||||
pub fn to_interleaved(frames: &[Frame]) -> &[Sample] {
|
||||
bytemuck::must_cast_slice(frames)
|
||||
}
|
||||
|
||||
pub fn to_interleaved_mut(frames: &mut [Frame]) -> &mut [Sample] {
|
||||
bytemuck::must_cast_slice_mut(frames)
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod audio;
|
||||
pub mod consts;
|
||||
pub mod decode;
|
||||
pub mod encode;
|
||||
|
|
Loading…
Reference in a new issue