switch to fork for cpal

This commit is contained in:
dskleingeld 2021-01-27 00:12:23 +01:00 committed by dvdsk
parent 023e833b01
commit 204a3f89c9
No known key found for this signature in database
GPG key ID: 6CF9D20C5709A836
3 changed files with 56 additions and 42 deletions

View file

@ -15,7 +15,7 @@ claxon = { version = "0.4.2", optional = true }
hound = { version = "3.3.1", optional = true } hound = { version = "3.3.1", optional = true }
lewton = { version = "0.10", optional = true } lewton = { version = "0.10", optional = true }
# minimp3_fixed = { version = "0.5.4", optional = true} # minimp3_fixed = { version = "0.5.4", optional = true}
minimp3 = { git = "https://github.com/dskleingeld/minimp3-rs.git", optional = true } minimp3_fixed = { package = "minimp3", git = "https://github.com/dvdsk/minimp3-rs.git", optional = true }
symphonia = { version = "0.5.2", optional = true, default-features = false } symphonia = { version = "0.5.2", optional = true, default-features = false }
crossbeam-channel = { version = "0.5.8", optional = true } crossbeam-channel = { version = "0.5.8", optional = true }

View file

@ -373,15 +373,17 @@ where
R: Read + Seek, R: Read + Seek,
{ {
fn request_pos(&mut self, pos: f32) -> bool { fn request_pos(&mut self, pos: f32) -> bool {
match self.0 { match &mut self.0 {
#[cfg(feature = "wav")] #[cfg(all(feature = "wav", not(feature = "symphonia-wav")))]
DecoderImpl::Wav(ref source) => false, DecoderImpl::Wav(_) => false,
#[cfg(feature = "vorbis")] #[cfg(all(feature = "vorbis", not(feature = "symphonia-vorbis")))]
DecoderImpl::Vorbis(ref source) => false, DecoderImpl::Vorbis(_) => false,
#[cfg(feature = "flac")] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(ref source) => false, DecoderImpl::Flac(_) => false,
#[cfg(feature = "mp3")] #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))]
DecoderImpl::Mp3(ref mut source) => source.request_pos(pos), DecoderImpl::Mp3(source) => source.request_pos(pos),
#[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(_) => false,
DecoderImpl::None(_) => false, DecoderImpl::None(_) => false,
} }
} }
@ -392,18 +394,19 @@ where
R: Read + Seek, R: Read + Seek,
{ {
fn request_pos(&mut self, pos: f32) -> bool { fn request_pos(&mut self, pos: f32) -> bool {
match self.0 { match &mut self.0 {
#[cfg(feature = "wav")] #[cfg(all(feature = "wav", not(feature = "symphonia-wav")))]
DecoderImpl::Wav(ref source) => false, DecoderImpl::Wav(_) => false,
#[cfg(feature = "vorbis")] #[cfg(all(feature = "vorbis", not(feature = "symphonia-vorbis")))]
DecoderImpl::Vorbis(ref source) => false, DecoderImpl::Vorbis(_) => false,
#[cfg(feature = "flac")] #[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(ref source) => false, DecoderImpl::Flac(_) => false,
#[cfg(feature = "mp3")] #[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))]
DecoderImpl::Mp3(ref mut source) => {source.request_pos(pos)}, DecoderImpl::Mp3(source) => source.request_pos(pos),
#[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(_) => false,
DecoderImpl::None(_) => false, DecoderImpl::None(_) => false,
} }
// todo!();
} }
} }

View file

@ -29,13 +29,9 @@ struct Controls {
pause: AtomicBool, pause: AtomicBool,
volume: Mutex<f32>, volume: Mutex<f32>,
stopped: AtomicBool, stopped: AtomicBool,
<<<<<<< HEAD
speed: Mutex<f32>, speed: Mutex<f32>,
to_clear: Mutex<u32>, to_clear: Mutex<u32>,
||||||| parent of 2cb7526 (seek implemented through SourceExt trait)
=======
set_pos: Mutex<Option<f32>>, set_pos: Mutex<Option<f32>>,
>>>>>>> 2cb7526 (seek implemented through SourceExt trait)
} }
impl Sink { impl Sink {
@ -59,13 +55,9 @@ impl Sink {
pause: AtomicBool::new(false), pause: AtomicBool::new(false),
volume: Mutex::new(1.0), volume: Mutex::new(1.0),
stopped: AtomicBool::new(false), stopped: AtomicBool::new(false),
<<<<<<< HEAD
speed: Mutex::new(1.0), speed: Mutex::new(1.0),
to_clear: Mutex::new(0), to_clear: Mutex::new(0),
||||||| parent of 2cb7526 (seek implemented through SourceExt trait)
=======
set_pos: Mutex::new(None), set_pos: Mutex::new(None),
>>>>>>> 2cb7526 (seek implemented through SourceExt trait)
}), }),
sound_count: Arc::new(AtomicUsize::new(0)), sound_count: Arc::new(AtomicUsize::new(0)),
detached: false, detached: false,
@ -129,32 +121,51 @@ impl Sink {
#[inline] #[inline]
pub fn append_seekable<S>(&self, source: S) pub fn append_seekable<S>(&self, source: S)
where where
S: Source + Send + 'static, S: Source + SourceExt + Send + 'static,
S: SourceExt + Send + 'static, f32: FromSample<S::Item>,
S::Item: Sample, S::Item: Sample + Send,
S::Item: Send,
{ {
// Wait for queue to flush then resume stopped playback
if self.controls.stopped.load(Ordering::SeqCst) {
if self.sound_count.load(Ordering::SeqCst) > 0 {
self.sleep_until_end();
}
self.controls.stopped.store(false, Ordering::SeqCst);
}
let controls = self.controls.clone(); let controls = self.controls.clone();
let start_played = AtomicBool::new(false);
let source = source let source = source
.speed(1.0)
.pausable(false) .pausable(false)
.amplify(1.0) .amplify(1.0)
.skippable()
.stoppable() .stoppable()
.periodic_access(Duration::from_millis(5), move |src| { .periodic_access(Duration::from_millis(5), move |src| {
if controls.stopped.load(Ordering::SeqCst) { if controls.stopped.load(Ordering::SeqCst) {
src.stop(); src.stop();
} else { }
src.inner_mut().set_factor(*controls.volume.lock().unwrap()); {
src.inner_mut() let mut to_clear = controls.to_clear.lock().unwrap();
.inner_mut() if *to_clear > 0 {
.set_paused(controls.pause.load(Ordering::SeqCst)); let _ = src.inner_mut().skip();
if let Some(pos) = controls.set_pos.lock().unwrap().take() { *to_clear -= 1;
src.inner_mut()
.inner_mut()
.inner_mut()
.request_pos(pos);
} }
} }
let amp = src.inner_mut().inner_mut();
amp.set_factor(*controls.volume.lock().unwrap());
amp.inner_mut()
.set_paused(controls.pause.load(Ordering::SeqCst));
amp.inner_mut()
.inner_mut()
.set_factor(*controls.speed.lock().unwrap());
let seekable = amp.inner_mut().inner_mut().inner_mut();
if let Some(pos) = controls.set_pos.lock().unwrap().take() {
seekable.request_pos(pos);
}
start_played.store(true, Ordering::SeqCst);
}) })
.convert_samples(); .convert_samples();
self.sound_count.fetch_add(1, Ordering::Relaxed); self.sound_count.fetch_add(1, Ordering::Relaxed);