use rodio::{OutputStream, Sink, Source}; use crate::io::Audio; use crate::audio::SAMPLE_RATE; use std::time::Duration; pub struct RodioAudio { _stream: OutputStream, _sink: Sink, } struct RodioWave(W); impl Iterator for RodioWave where ::Item: rodio::Sample { type Item = W::Item; fn next(&mut self) -> Option { self.0.next() } } impl Source for RodioWave where ::Item: rodio::Sample { fn current_frame_len(&self) -> Option { None } fn channels(&self) -> u16 { 1 } fn sample_rate(&self) -> u32 { SAMPLE_RATE } fn total_duration(&self) -> Option { None } } impl Audio for RodioAudio { fn new + Send + 'static>(wave: S) -> Self { let (stream, stream_handle) = OutputStream::try_default().unwrap(); let sink = Sink::try_new(&stream_handle).unwrap(); sink.append(RodioWave(wave)); RodioAudio { _stream: stream, _sink: sink, } } }