#[cfg(feature = "apm")]
use mediaway_common::Bytes;
#[allow(
clippy::redundant_pub_crate,
reason = "pub(crate) here satisfies rustc's unreachable_pub; clippy's \
redundant_pub_crate and unreachable_pub disagree on the fix"
)]
pub(crate) fn bytes_to_f32(data: &[u8]) -> Vec<f32> {
data.chunks_exact(4)
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
.collect()
}
#[cfg(feature = "apm")]
#[allow(
clippy::redundant_pub_crate,
reason = "pub(crate) here satisfies rustc's unreachable_pub; clippy's \
redundant_pub_crate and unreachable_pub disagree on the fix"
)]
pub(crate) fn f32_to_bytes(samples: &[f32]) -> Bytes {
let mut buf = Vec::with_capacity(samples.len() * 4);
for &sample in samples {
buf.extend_from_slice(&sample.to_le_bytes());
}
Bytes::from(buf)
}