#![forbid(unsafe_code)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct DecodedAudioData {
timestamps_us: Vec<f64>,
sample_counts: Vec<u32>,
channel_counts: Vec<u32>,
samples: Vec<Vec<f32>>,
}
impl DecodedAudioData {
#[must_use]
pub const fn new(
timestamps_us: Vec<f64>,
sample_counts: Vec<u32>,
channel_counts: Vec<u32>,
samples: Vec<Vec<f32>>,
) -> Self {
Self {
timestamps_us,
sample_counts,
channel_counts,
samples,
}
}
}
#[wasm_bindgen]
impl DecodedAudioData {
#[wasm_bindgen(getter)]
#[allow(
clippy::cast_possible_truncation,
reason = "test/smoke chunk counts are tiny"
)]
#[allow(
clippy::missing_const_for_fn,
reason = "#[wasm_bindgen] does not support const fn"
)]
pub fn chunk_count(&self) -> u32 {
self.timestamps_us.len() as u32
}
pub fn timestamp_us(&self, index: u32) -> f64 {
self.timestamps_us[index as usize]
}
pub fn sample_count(&self, index: u32) -> u32 {
self.sample_counts[index as usize]
}
pub fn channel_count(&self, index: u32) -> u32 {
self.channel_counts[index as usize]
}
pub fn samples(&self, index: u32) -> Vec<f32> {
self.samples[index as usize].clone() }
}
#[cfg(test)]
#[path = "audio_frames_tests.rs"]
mod tests;