Skip to content

Commit 27dbee7

Browse files
committed
It's a proper library now!
1 parent 2a54e1f commit 27dbee7

File tree

8 files changed

+700
-394
lines changed

8 files changed

+700
-394
lines changed

Cargo.lock

Lines changed: 60 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
[package]
2-
name = "sqa-ng"
2+
name = "sqa-engine"
33
version = "0.0.1"
44
authors = ["eeeeeta <eeeeeta@users.noreply.github.com>"]
55

66
[dependencies]
7-
sqa-jack = "0.1"
7+
sqa-jack = "0.3"
88
bounded-spsc-queue = { git = "https://github.com/eeeeeta/bounded-spsc-queue", rev = "542e581" }
99
time = "0.1"
1010
arrayvec = "0.3"
1111
hound = "3.0"
12+
error-chain = "0.7"
13+
parking_lot = "0.3"
14+
uuid = { version = "0.3", features = ["v4"] }

examples/wav.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#![feature(step_by)]
2+
3+
extern crate hound;
4+
extern crate sqa_engine;
5+
use std::thread;
6+
use std::io::{self, Read};
7+
use sqa_engine::{EngineContext, jack, Sender};
8+
fn main() {
9+
let mut ec = EngineContext::new(None).unwrap();
10+
let mut reader = hound::WavReader::open("test.wav").unwrap();
11+
let mut chans = vec![];
12+
let mut ctls = vec![];
13+
for ch in 0..reader.spec().channels*16 {
14+
let st = format!("channel {}", ch);
15+
let p = ec.new_channel(&st).unwrap();
16+
let mut send = ec.new_sender(reader.spec().sample_rate as u64);
17+
send.set_output_patch(p);
18+
ctls.push(send.make_plain());
19+
chans.push((p, send));
20+
}
21+
for (i, port) in ec.conn.get_ports(None, None, Some(jack::PORT_IS_INPUT | jack::PORT_IS_PHYSICAL)).unwrap().into_iter().enumerate() {
22+
if i % 2 == 0 {
23+
for ch in (0..chans.len()).step_by(2) {
24+
ec.conn.connect_ports(&ec.chans[chans[ch].0], &port).unwrap();
25+
}
26+
}
27+
else {
28+
for ch in (1..chans.len()).step_by(2) {
29+
ec.conn.connect_ports(&ec.chans[chans[ch].0], &port).unwrap();
30+
}
31+
}
32+
33+
}
34+
let _ = thread::spawn(move || {
35+
let mut idx = 0;
36+
let mut cnt = 0;
37+
for samp in reader.samples::<f32>() {
38+
let samp = samp.unwrap();
39+
for ch in (idx..chans.len()).step_by(2) {
40+
chans[ch].1.buf.push(samp * 0.1);
41+
}
42+
idx += 1;
43+
cnt += 1;
44+
if cnt == 500_000 {
45+
println!("Haha, random buffering fail for 5 seconds!!!");
46+
::std::thread::sleep(::std::time::Duration::new(5, 0));
47+
println!("Alright, panic over.");
48+
}
49+
if idx >= 2 {
50+
idx = 0;
51+
}
52+
}
53+
});
54+
println!("*** Press Enter to begin playback!");
55+
io::stdin().read(&mut [0u8]).unwrap();
56+
let time = Sender::<()>::precise_time_ns();
57+
for ch in ctls.iter_mut() {
58+
ch.set_start_time(time);
59+
ch.set_active(true);
60+
}
61+
let mut secs = 0;
62+
loop {
63+
thread::sleep(::std::time::Duration::new(1, 0));
64+
secs += 1;
65+
println!("{}: {} samples - vol {}", ctls[0].position(), ctls[0].position_samples(), ctls[0].volume());
66+
if secs == 20 {
67+
println!("Haha, some sadist set ch0's active to false for 5 seconds!!!");
68+
ctls[0].set_active(false);
69+
}
70+
if secs == 25 {
71+
ctls[0].set_active(true);
72+
println!("Alright, panic over.");
73+
}
74+
if secs > 25 && secs < 36 {
75+
ctls[0].set_volume((secs - 25) as f32 * 0.1);
76+
}
77+
if secs > 60 {
78+
break;
79+
}
80+
}
81+
}

src/errors.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use sqa_jack;
2+
error_chain! {
3+
types {
4+
Error, ErrorKind, ChainErr, EngineResult;
5+
}
6+
links {
7+
Jack(sqa_jack::errors::Error, sqa_jack::errors::ErrorKind);
8+
}
9+
errors {
10+
LimitExceeded {
11+
description("You have exceeded the channel or sender limit.")
12+
display("Engine channel or sender limit exceeded")
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)