Skip to content

Commit 81e23f6

Browse files
committed
feat: add bits_per_sample method to Microphone source
1 parent 5474b22 commit 81e23f6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/microphone.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
use core::fmt;
102102
use std::sync::atomic::{AtomicBool, Ordering};
103103
use std::sync::Arc;
104+
use std::{f32, f64};
104105
use std::{thread, time::Duration};
105106

106107
use crate::common::assert_error_traits;
@@ -198,6 +199,21 @@ impl Source for Microphone {
198199
fn total_duration(&self) -> Option<std::time::Duration> {
199200
None
200201
}
202+
203+
fn bits_per_sample(&self) -> Option<u32> {
204+
let bits = match self.config.sample_format {
205+
cpal::SampleFormat::I8 | cpal::SampleFormat::U8 => 8,
206+
cpal::SampleFormat::I16 | cpal::SampleFormat::U16 => 16,
207+
cpal::SampleFormat::I24 => 24,
208+
cpal::SampleFormat::I32 | cpal::SampleFormat::U32 => 32,
209+
cpal::SampleFormat::I64 | cpal::SampleFormat::U64 => 64,
210+
cpal::SampleFormat::F32 => f32::MANTISSA_DIGITS,
211+
cpal::SampleFormat::F64 => f64::MANTISSA_DIGITS,
212+
_ => return None,
213+
};
214+
215+
Some(bits)
216+
}
201217
}
202218

203219
impl Iterator for Microphone {

0 commit comments

Comments
 (0)