From 60ad12033aab2712682bfbd8f48538394cc3c04b Mon Sep 17 00:00:00 2001 From: badaix Date: Thu, 27 Oct 2016 09:56:56 +0200 Subject: [PATCH 1/3] added stdout-backend --- .travis.yml | 1 + Cargo.toml | 1 + src/audio_backend/mod.rs | 7 +++++++ src/audio_backend/stdout.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 src/audio_backend/stdout.rs diff --git a/.travis.yml b/.travis.yml index 8051fceb..1ed471c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ script: - cargo build --no-default-features --features "with-syntex facebook" - cargo build --no-default-features --features "with-syntex portaudio-backend" - cargo build --no-default-features --features "with-syntex pulseaudio-backend" + - cargo build --no-default-features --features "with-syntex stdout-backend" - cargo build --no-default-features --features "with-syntex alsa-backend" - cargo build --no-default-features --features "with-syntex" --target armv7-unknown-linux-gnueabihf diff --git a/Cargo.toml b/Cargo.toml index 7006bc99..31f1f3c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ nightly = ["serde_macros"] with-tremor = ["tremor"] facebook = ["hyper/ssl", "openssl"] +stdout-backend = [] alsa-backend = ["alsa"] portaudio-backend = ["portaudio"] pulseaudio-backend= ["libpulse-sys"] diff --git a/src/audio_backend/mod.rs b/src/audio_backend/mod.rs index 4dc85124..3cf00925 100644 --- a/src/audio_backend/mod.rs +++ b/src/audio_backend/mod.rs @@ -54,6 +54,11 @@ fn mk_sink(device: Option<&str>) -> Box { Box::new(S::open(device)) } +#[cfg(feature = "stdout-backend")] +mod stdout; +#[cfg(feature = "stdout-backend")] +use self::stdout::StdoutSink; + #[cfg(feature = "alsa-backend")] mod alsa; #[cfg(feature = "alsa-backend")] @@ -75,6 +80,8 @@ declare_backends! { (&'static str, &'static (Fn(Option<&str>) -> Box + Sync + Send + 'static)) ] = &[ + #[cfg(feature = "stdout-backend")] + ("stdout", &mk_sink::), #[cfg(feature = "alsa-backend")] ("alsa", &mk_sink::), #[cfg(feature = "portaudio-backend")] diff --git a/src/audio_backend/stdout.rs b/src/audio_backend/stdout.rs new file mode 100644 index 00000000..25847316 --- /dev/null +++ b/src/audio_backend/stdout.rs @@ -0,0 +1,33 @@ +use super::{Open, Sink}; +use std::io::{self, Write}; +use std::slice; +use std::mem; + + +pub struct StdoutSink;//Option, String); + +impl Open for StdoutSink { + fn open(_: Option<&str>) -> StdoutSink { + StdoutSink + } +} + +impl Sink for StdoutSink { + fn start(&mut self) -> io::Result<()> { + Ok(()) + } + + fn stop(&mut self) -> io::Result<()> { + Ok(()) + } + + fn write(&mut self, data: &[i16]) -> io::Result<()> { +// http://stackoverflow.com/questions/30838358/writing-vecu16-to-a-file + let slice_u8: &[u8] = unsafe { slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * mem::size_of::()) }; + try!(io::stdout().write_all(slice_u8)); + try!(io::stdout().flush()); + + Ok(()) + } +} + From 6b82a765b137408a34a0dcda7bf44ccac61e6391 Mon Sep 17 00:00:00 2001 From: badaix Date: Thu, 27 Oct 2016 09:56:56 +0200 Subject: [PATCH 2/3] added stdout-backend --- .travis.yml | 1 + Cargo.toml | 1 + src/audio_backend/mod.rs | 7 +++++++ src/audio_backend/stdout.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 src/audio_backend/stdout.rs diff --git a/.travis.yml b/.travis.yml index 8051fceb..1ed471c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ script: - cargo build --no-default-features --features "with-syntex facebook" - cargo build --no-default-features --features "with-syntex portaudio-backend" - cargo build --no-default-features --features "with-syntex pulseaudio-backend" + - cargo build --no-default-features --features "with-syntex stdout-backend" - cargo build --no-default-features --features "with-syntex alsa-backend" - cargo build --no-default-features --features "with-syntex" --target armv7-unknown-linux-gnueabihf diff --git a/Cargo.toml b/Cargo.toml index df5b2781..65bfd2ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ nightly = ["serde_macros"] with-tremor = ["tremor"] facebook = ["hyper/ssl", "openssl"] +stdout-backend = [] alsa-backend = ["alsa"] portaudio-backend = ["portaudio"] pulseaudio-backend= ["libpulse-sys"] diff --git a/src/audio_backend/mod.rs b/src/audio_backend/mod.rs index 4dc85124..3cf00925 100644 --- a/src/audio_backend/mod.rs +++ b/src/audio_backend/mod.rs @@ -54,6 +54,11 @@ fn mk_sink(device: Option<&str>) -> Box { Box::new(S::open(device)) } +#[cfg(feature = "stdout-backend")] +mod stdout; +#[cfg(feature = "stdout-backend")] +use self::stdout::StdoutSink; + #[cfg(feature = "alsa-backend")] mod alsa; #[cfg(feature = "alsa-backend")] @@ -75,6 +80,8 @@ declare_backends! { (&'static str, &'static (Fn(Option<&str>) -> Box + Sync + Send + 'static)) ] = &[ + #[cfg(feature = "stdout-backend")] + ("stdout", &mk_sink::), #[cfg(feature = "alsa-backend")] ("alsa", &mk_sink::), #[cfg(feature = "portaudio-backend")] diff --git a/src/audio_backend/stdout.rs b/src/audio_backend/stdout.rs new file mode 100644 index 00000000..25847316 --- /dev/null +++ b/src/audio_backend/stdout.rs @@ -0,0 +1,33 @@ +use super::{Open, Sink}; +use std::io::{self, Write}; +use std::slice; +use std::mem; + + +pub struct StdoutSink;//Option, String); + +impl Open for StdoutSink { + fn open(_: Option<&str>) -> StdoutSink { + StdoutSink + } +} + +impl Sink for StdoutSink { + fn start(&mut self) -> io::Result<()> { + Ok(()) + } + + fn stop(&mut self) -> io::Result<()> { + Ok(()) + } + + fn write(&mut self, data: &[i16]) -> io::Result<()> { +// http://stackoverflow.com/questions/30838358/writing-vecu16-to-a-file + let slice_u8: &[u8] = unsafe { slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * mem::size_of::()) }; + try!(io::stdout().write_all(slice_u8)); + try!(io::stdout().flush()); + + Ok(()) + } +} + From 383e0e9ae806cf881f5bf3c0ab280e01d3e47da3 Mon Sep 17 00:00:00 2001 From: badaix Date: Thu, 27 Oct 2016 09:56:56 +0200 Subject: [PATCH 3/3] added stdout-backend --- .travis.yml | 1 + Cargo.toml | 1 + src/audio_backend/mod.rs | 7 +++++++ src/audio_backend/stdout.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 src/audio_backend/stdout.rs diff --git a/.travis.yml b/.travis.yml index 8051fceb..1ed471c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ script: - cargo build --no-default-features --features "with-syntex facebook" - cargo build --no-default-features --features "with-syntex portaudio-backend" - cargo build --no-default-features --features "with-syntex pulseaudio-backend" + - cargo build --no-default-features --features "with-syntex stdout-backend" - cargo build --no-default-features --features "with-syntex alsa-backend" - cargo build --no-default-features --features "with-syntex" --target armv7-unknown-linux-gnueabihf diff --git a/Cargo.toml b/Cargo.toml index df5b2781..65bfd2ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ nightly = ["serde_macros"] with-tremor = ["tremor"] facebook = ["hyper/ssl", "openssl"] +stdout-backend = [] alsa-backend = ["alsa"] portaudio-backend = ["portaudio"] pulseaudio-backend= ["libpulse-sys"] diff --git a/src/audio_backend/mod.rs b/src/audio_backend/mod.rs index 4dc85124..3cf00925 100644 --- a/src/audio_backend/mod.rs +++ b/src/audio_backend/mod.rs @@ -54,6 +54,11 @@ fn mk_sink(device: Option<&str>) -> Box { Box::new(S::open(device)) } +#[cfg(feature = "stdout-backend")] +mod stdout; +#[cfg(feature = "stdout-backend")] +use self::stdout::StdoutSink; + #[cfg(feature = "alsa-backend")] mod alsa; #[cfg(feature = "alsa-backend")] @@ -75,6 +80,8 @@ declare_backends! { (&'static str, &'static (Fn(Option<&str>) -> Box + Sync + Send + 'static)) ] = &[ + #[cfg(feature = "stdout-backend")] + ("stdout", &mk_sink::), #[cfg(feature = "alsa-backend")] ("alsa", &mk_sink::), #[cfg(feature = "portaudio-backend")] diff --git a/src/audio_backend/stdout.rs b/src/audio_backend/stdout.rs new file mode 100644 index 00000000..25847316 --- /dev/null +++ b/src/audio_backend/stdout.rs @@ -0,0 +1,33 @@ +use super::{Open, Sink}; +use std::io::{self, Write}; +use std::slice; +use std::mem; + + +pub struct StdoutSink;//Option, String); + +impl Open for StdoutSink { + fn open(_: Option<&str>) -> StdoutSink { + StdoutSink + } +} + +impl Sink for StdoutSink { + fn start(&mut self) -> io::Result<()> { + Ok(()) + } + + fn stop(&mut self) -> io::Result<()> { + Ok(()) + } + + fn write(&mut self, data: &[i16]) -> io::Result<()> { +// http://stackoverflow.com/questions/30838358/writing-vecu16-to-a-file + let slice_u8: &[u8] = unsafe { slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * mem::size_of::()) }; + try!(io::stdout().write_all(slice_u8)); + try!(io::stdout().flush()); + + Ok(()) + } +} +