Minor code improvements and crates bump

This commit is contained in:
Roderick van Domburg 2021-03-27 21:13:14 +01:00
parent 74b2fea338
commit bfca1ec15e
5 changed files with 31 additions and 30 deletions

16
Cargo.lock generated
View file

@ -795,9 +795,9 @@ dependencies = [
[[package]]
name = "gstreamer"
version = "0.16.5"
version = "0.16.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d50f822055923f1cbede233aa5dfd4ee957cf328fb3076e330886094e11d6cf"
checksum = "9ff5d0f7ff308ae37e6eb47b6ded17785bdea06e438a708cd09e0288c1862f33"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
@ -1061,9 +1061,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "jack"
version = "0.6.5"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c1871c91fa65aa328f3bedbaa54a6e5d1de009264684c153eb708ba933aa6f5"
checksum = "2deb4974bd7e6b2fb7784f27fa13d819d11292b3b004dce0185ec08163cf686a"
dependencies = [
"bitflags",
"jack-sys",
@ -1073,9 +1073,9 @@ dependencies = [
[[package]]
name = "jack-sys"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1d6ab7ada402b6a27912a2b86504be62a48c58313c886fe72a059127acb4d7"
checksum = "57983f0d72dfecf2b719ed39bc9cacd85194e1a94cb3f9146009eff9856fef41"
dependencies = [
"lazy_static",
"libc",
@ -1161,9 +1161,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.90"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7"
[[package]]
name = "libloading"

View file

@ -24,8 +24,8 @@ num-traits = "0.2"
tempfile = "3.1"
zerocopy = "0.3"
librespot-tremor = { version = "0.2.0", optional = true }
vorbis = { version ="0.0.14", optional = true }
librespot-tremor = { version = "0.2", optional = true }
vorbis = { version ="0.0", optional = true }
[features]
with-tremor = ["librespot-tremor"]

View file

@ -25,8 +25,8 @@ shell-words = "1.0.0"
alsa = { version = "0.5", optional = true }
portaudio-rs = { version = "0.3", optional = true }
libpulse-binding = { version = "2.13", optional = true, default-features = false }
libpulse-simple-binding = { version = "2.13", optional = true, default-features = false }
libpulse-binding = { version = "2", optional = true, default-features = false }
libpulse-simple-binding = { version = "2", optional = true, default-features = false }
jack = { version = "0.6", optional = true }
libc = { version = "0.2", optional = true }
rodio = { version = "0.13", optional = true, default-features = false }

View file

@ -98,7 +98,7 @@ impl<'a> Open for PortAudioSink<'a> {
impl<'a> Sink for PortAudioSink<'a> {
fn start(&mut self) -> io::Result<()> {
macro_rules! start_sink {
($stream: ident, $parameters: ident) => {{
(ref mut $stream: ident, ref $parameters: ident) => {{
if $stream.is_none() {
*$stream = Some(
Stream::open(
@ -115,10 +115,11 @@ impl<'a> Sink for PortAudioSink<'a> {
$stream.as_mut().unwrap().start().unwrap()
}};
}
match self {
Self::F32(stream, parameters) => start_sink!(stream, parameters),
Self::S32(stream, parameters) => start_sink!(stream, parameters),
Self::S16(stream, parameters) => start_sink!(stream, parameters),
Self::F32(stream, parameters) => start_sink!(ref mut stream, ref parameters),
Self::S32(stream, parameters) => start_sink!(ref mut stream, ref parameters),
Self::S16(stream, parameters) => start_sink!(ref mut stream, ref parameters),
};
Ok(())
@ -126,15 +127,15 @@ impl<'a> Sink for PortAudioSink<'a> {
fn stop(&mut self) -> io::Result<()> {
macro_rules! stop_sink {
($stream: expr) => {{
(ref mut $stream: ident) => {{
$stream.as_mut().unwrap().stop().unwrap();
*$stream = None;
}};
}
match self {
Self::F32(stream, _parameters) => stop_sink!(stream),
Self::S32(stream, _parameters) => stop_sink!(stream),
Self::S16(stream, _parameters) => stop_sink!(stream),
Self::F32(stream, _parameters) => stop_sink!(ref mut stream),
Self::S32(stream, _parameters) => stop_sink!(ref mut stream),
Self::S16(stream, _parameters) => stop_sink!(ref mut stream),
};
Ok(())
@ -142,7 +143,7 @@ impl<'a> Sink for PortAudioSink<'a> {
fn write(&mut self, packet: &AudioPacket) -> io::Result<()> {
macro_rules! write_sink {
($stream: expr, $samples: expr) => {
(ref mut $stream: expr, $samples: expr) => {
$stream.as_mut().unwrap().write($samples)
};
}
@ -150,15 +151,15 @@ impl<'a> Sink for PortAudioSink<'a> {
let samples = packet.samples();
let result = match self {
Self::F32(stream, _parameters) => {
write_sink!(stream, samples)
write_sink!(ref mut stream, samples)
}
Self::S32(stream, _parameters) => {
let samples_s32: &[i32] = &SamplesConverter::to_s32(samples);
write_sink!(stream, samples_s32)
write_sink!(ref mut stream, samples_s32)
}
Self::S16(stream, _parameters) => {
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
write_sink!(stream, samples_s16)
write_sink!(ref mut stream, samples_s16)
}
};
match result {

View file

@ -27,14 +27,14 @@ macro_rules! rodio_sink {
match self.format {
AudioFormat::F32 => {
let source = rodio::buffer::SamplesBuffer::new(NUM_CHANNELS as u16, SAMPLE_RATE, samples);
self.rodio_sink.append(source)
self.rodio_sink.append(source);
},
AudioFormat::S16 => {
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
let source = rodio::buffer::SamplesBuffer::new(NUM_CHANNELS as u16, SAMPLE_RATE, samples_s16);
self.rodio_sink.append(source)
self.rodio_sink.append(source);
},
_ => unimplemented!(),
_ => unreachable!(),
};
// Chunk sizes seem to be about 256 to 3000 ish items long.
@ -64,15 +64,15 @@ macro_rules! rodio_sink {
let rodio_device = match_device(&host, device);
debug!("Using cpal device");
let stream = rodio::OutputStream::try_from_device(&rodio_device)
let (stream, stream_handle) = rodio::OutputStream::try_from_device(&rodio_device)
.expect("couldn't open output stream.");
debug!("Using Rodio stream");
let sink = rodio::Sink::try_new(&stream.1).expect("couldn't create output sink.");
let sink = rodio::Sink::try_new(&stream_handle).expect("couldn't create output sink.");
debug!("Using Rodio sink");
Self {
rodio_sink: sink,
stream: stream.0,
stream: stream,
format: format,
}
}