use std::{
fmt::{Display, Error, Formatter},
future::Future,
marker::PhantomData,
pin::Pin,
task::{Context, Poll},
};
use fon::{chan::Ch32, Frame, Stream};
use super::{AudioDevice, SoundDevice};
pub(crate) struct Microphone();
impl SoundDevice for Microphone {
const INPUT: bool = true;
}
impl Display for Microphone {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
f.write_str("Default")
}
}
impl Default for Microphone {
fn default() -> Self {
Microphone()
}
}
impl Microphone {
pub(crate) fn record<F: Frame<Chan = Ch32>>(
&mut self,
) -> MicrophoneStream<'_, F> {
MicrophoneStream(PhantomData)
}
pub(crate) fn channels(&self) -> u8 {
1
}
}
impl Future for Microphone {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Pending
}
}
impl From<AudioDevice> for Microphone {
fn from(this: AudioDevice) -> Self {
Self::default()
}
}
pub(crate) struct MicrophoneStream<'a, F: Frame<Chan = Ch32>>(
PhantomData<&'a F>,
);
impl<F: Frame<Chan = Ch32>> Iterator for MicrophoneStream<'_, F> {
type Item = F;
fn next(&mut self) -> Option<Self::Item> {
None
}
}
impl<F: Frame<Chan = Ch32>> Stream<F> for MicrophoneStream<'_, F> {
fn sample_rate(&self) -> Option<f64> {
Some(crate::consts::SAMPLE_RATE.into())
}
fn len(&self) -> Option<usize> {
Some(crate::consts::PERIOD.into())
}
}