From 819972f0c08b1aed74426396bf6759a07b313820 Mon Sep 17 00:00:00 2001 From: Ivan Bushchik Date: Mon, 29 Jan 2024 19:58:20 +0300 Subject: [PATCH] 0.1.6: add "WAR" mode Signed-off-by: Ivan Bushchik --- Cargo.toml | 2 +- README.md | 2 +- src/main.rs | 35 +++++++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 88c7677..93000e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lonelyradio" description = "TCP radio for singles" -version = "0.1.5" +version = "0.1.6" edition = "2021" license = "MIT" authors = [ "Ivan Bushchik " ] diff --git a/README.md b/README.md index e755bcd..e17d6e9 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ cargo build -r ## Run ``` -lonelyradio [-a ] [-p] +lonelyradio [-a ] [-p] [-w] ``` All files (recursively) will be shuffled and played back. Public log will be displayed to stderr, private to stdout. diff --git a/src/main.rs b/src/main.rs index a3def7e..e6a6700 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ +use std::path::PathBuf; + use chrono::Local; use clap::Parser; use rand::prelude::*; use rand::seq::SliceRandom; use samplerate::ConverterType; -use std::path::PathBuf; use symphonia::core::audio::SampleBuffer; use symphonia::core::codecs::CODEC_TYPE_NULL; use symphonia::core::formats::FormatOptions; @@ -22,6 +23,9 @@ struct Args { #[arg(short, long)] public_log: bool, + + #[arg(short, long)] + war: bool, } #[tokio::main] @@ -63,19 +67,29 @@ async fn stream(mut s: TcpStream) { 'track: loop { let track = pick_track(&tracklist); println!( - "[{}] {} to {}:{}", + "[{}] {} to {}:{}{}", Local::now().to_rfc3339(), track.to_str().unwrap(), s.peer_addr().unwrap().ip(), - s.peer_addr().unwrap().port() + s.peer_addr().unwrap().port(), + if args.war { + " with WAR.rs" + } else { + "" + } ); if args.public_log { eprintln!( - "[{}] {} to {}", + "[{}] {} to {}{}", Local::now().to_rfc3339(), track.to_str().unwrap(), - s.peer_addr().unwrap().port() + s.peer_addr().unwrap().port(), + if args.war { + " with WAR.rs" + } else { + "" + } ); } @@ -134,7 +148,16 @@ async fn stream(mut s: TcpStream) { ) .unwrap(); for sample in samples { - let result = s.write(&((sample * 32768_f32) as i16).to_le_bytes()).await; + let result = s + .write( + &(if args.war { + sample.signum() as i16 * 32767 + } else { + (sample * 32768_f32) as i16 + }) + .to_le_bytes(), + ) + .await; if result.is_err() { // Socket error -> stop return;