summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorGraham Northup <grissess@nexusg.org>2017-09-27 00:50:06 -0400
committerGraham Northup <grissess@nexusg.org>2017-09-27 00:50:06 -0400
commit629d2fa754dcd4bbdbd1e84ea9f7598806abc840 (patch)
treeafd9e5777fe418425657fe04324d66e64aead6bf /src/main.rs
parent150d71cae770598ade7e09419150f1218e961128 (diff)
It makes networked noise! (Poorly, for now)
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index fc15e53..e06d2b1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,35 +1,29 @@
use std::io;
use std::io::*;
+use std::net::*;
extern crate synfone;
use synfone::synth::*;
use synfone::lang::*;
+use synfone::client::*;
-const FRAMES: usize = 44100 * 2;
-
-const GEN: &'static str = "add(mul(sine(param('freq', 440)), 0.5), mul(sine(param('freq2', 660)), 0.5))";
+const GEN: &'static str = "mul(sine(param('v_freq', 500)), ifelse(rel(param('v_frame'), '<', param('v_deadline')), param('v_amp'), 0.0))";
fn main() {
- let mut params = Parameters::default();
-
- let mut gen = Parser::new(Tokenizer::new(GEN.chars())).expect("Failed to get first token").parse().expect("Failed to compile generator");
+ let env = Environment::default();
+
+ let gen = Parser::new(Tokenizer::new(GEN.chars())).expect("Failed to get first token").parse().expect("Failed to compile generator");
+ let sock = UdpSocket::bind("0.0.0.0:13676").expect("Failed to bind socket");
- let mut counter = 0;
+ let mut client = Client::new(sock, vec![gen], env).expect("Failed to create client");
+ let mut buf: Vec<u8> = Vec::new();
let mut out = io::stdout();
- let mut outbuf: Vec<u8> = Vec::new();
-
- params.vars.insert("freq".to_string(), 440.0);
- params.vars.insert("freq2".to_string(), 660.0);
-
- while counter < FRAMES {
- *params.vars.get_mut("freq").unwrap() = 440.0 + 440.0 * ((counter as f32) / (FRAMES as f32));
- *params.vars.get_mut("freq2").unwrap() = 660.0 + 220.0 * ((counter as f32) / (FRAMES as f32));
- let buf = gen.eval(&params);
- let curlen = outbuf.len();
- outbuf.reserve_exact(buf.size() - curlen);
- unsafe { outbuf.set_len(buf.size()); }
- buf.bytes(&mut outbuf);
- out.write_all(&outbuf).expect("failed to write to stdout");
- counter += buf.len();
+
+ eprintln!("Starting.");
+
+ while client.pump(&mut buf) {
+ out.write_all(&buf).expect("Failed to write samples");
}
+
+ eprintln!("Exiting.");
}