Skip to content

Commit a2fc272

Browse files
dvdskroderickvd
authored andcommitted
adds mic docs & example + fixes mic yielding zeros
1 parent d9818ce commit a2fc272

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/microphone.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@ impl Source for Microphone {
181181
self.config.sample_rate
182182
}
183183

184+
// TODO: use cpal::SampleFormat::bits_per_sample() when cpal v0.17 is released
185+
fn bits_per_sample(&self) -> Option<u32> {
186+
let bits = match self.config.sample_format {
187+
cpal::SampleFormat::I8 | cpal::SampleFormat::U8 => 8,
188+
cpal::SampleFormat::I16 | cpal::SampleFormat::U16 => 16,
189+
cpal::SampleFormat::I24 => 24,
190+
cpal::SampleFormat::I32 | cpal::SampleFormat::U32 | cpal::SampleFormat::F32 => 32,
191+
cpal::SampleFormat::I64 | cpal::SampleFormat::U64 | cpal::SampleFormat::F64 => 64,
192+
_ => return None,
193+
};
194+
195+
Some(bits)
196+
}
197+
184198
fn total_duration(&self) -> Option<std::time::Duration> {
185199
None
186200
}

0 commit comments

Comments
 (0)