-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
172 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
def persamp: sample = div (mul 440.0 (mul 2.0 pi)) 48000.0;; | ||
def main: for k : clock. ~^(k) sample = ((&^(k) s. \x. sin x :: `(!(unbox s) (add x persamp))) : sample -> ~^(k) sample) 0.0;; | ||
def persamp: sample = 2. * 3.14159 * 440. / 48000.;; | ||
let main: ~^(audio) sample = ((&^(audio) s. \x. sin x :: `(!(unbox s) (x + persamp))) : sample -> ~^(audio) sample) 0.0;; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
def main: for k : clock. ~^(k) sample = &^(k) s. 42.0 :: `!(unbox s);; | ||
let main: ~^(audio) sample = &^(audio) s. 42.0 :: `!(unbox s);; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def batch2helper: for k : clock. | ||
(~^(2k) sample -> |>^(2k) ~^(k) [sample; 2]) * | ||
(sample -> ~^(2k) sample -> ~^(k) [sample; 2]) = | ||
(&^(2k) bh. | ||
((\s0. | ||
let (x0, s1) = %s0 in | ||
`((let (b, h) = !(unbox bh) in h) x0 !s1)), | ||
(\x0. \s1. | ||
let (x1, s2) = %s1 in | ||
[x0, x1] :: (`((let (b, h) = !(unbox bh) in b) !s2)) | ||
: |>^(2k) |>^(2k) ~^(k) [sample; 2])));; | ||
|
||
def batch2: for k : clock. ~^(2k) sample -> |>^(2k) ~^(k) [sample; 2] = | ||
let (b, h) = batch2helper @(k) in b;; | ||
|
||
def sample: for k1 : clock. for k2 : clock. ~^(k1) (~^(k2) sample) -> ~^(k1) sample = | ||
&^(k1) sam. \s_out. | ||
let (s_in, s_outp) = %s_out in | ||
let (x, s_inp) = %s_in in | ||
x :: `(!(unbox sam) !s_outp);; | ||
|
||
def switch: for k : clock. ~^(k) sample -> ~^(k) (unit + ~^(k) sample) -> ~^(k) sample = | ||
&^(k) swi. \s. \e. | ||
let (maybe_switch, ep) = %e in | ||
case maybe_switch | ||
{ inl a => let (x, sp) = %s in | ||
x :: `(!(unbox swi) !sp !ep) | ||
| inr ns => let (x, nsp) = %ns in | ||
x :: `(!(unbox swi) !nsp !ep) | ||
};; | ||
|
||
def foo: for c : clock. ~^(6c) sample -> |>^(6c) ~^(3c) [sample; 2] = batch2 @(3c);; | ||
|
||
let main: ~^(audio) sample = &^(audio) s. 0. :: `(!(unbox s));; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::fs::{self, File}; | ||
use std::io::Read; | ||
#[cfg(feature = "run")] | ||
use std::io; | ||
|
||
use clocky::toplevel::{compile, TopLevel}; | ||
#[cfg(feature = "run")] | ||
use clocky::toplevel::run; | ||
#[cfg(feature = "run")] | ||
use hound::{Error::IoError, WavReader}; | ||
use typed_arena::Arena; | ||
|
||
#[test] | ||
fn test_accepts() { | ||
for test_file in fs::read_dir("tests/accept").unwrap() { | ||
let test_file_path = test_file.unwrap().path(); | ||
// yes this weird construction is necessary, `ext != Some("rs")` will not work | ||
println!("found file {:?}", &test_file_path); | ||
if !matches!(test_file_path.extension(), Some(ext) if ext == "cky") { | ||
continue; | ||
} | ||
println!("testing file {:?}", &test_file_path); | ||
let mut code = String::new(); | ||
File::open(&test_file_path).unwrap().read_to_string(&mut code).unwrap(); | ||
let arena = Arena::new(); | ||
let mut toplevel = TopLevel::new(&arena); | ||
let wasm_bytes = compile(&mut toplevel, code).unwrap(); | ||
#[cfg(feature = "run")] | ||
{ | ||
let wav_file = match WavReader::open(test_file_path.with_extension("wav")) { | ||
Ok(f) => f, | ||
Err(IoError(err)) if err.kind() == io::ErrorKind::NotFound => { | ||
println!("...no wav file, not running the compilation result"); | ||
continue; | ||
}, | ||
Err(err) => panic!("hound error: {}", err), | ||
}; | ||
let ran_samples = run(&wasm_bytes, 48000 * 2); | ||
let expected_samples = wav_file.into_samples().collect::<Result<Vec<f32>, _>>().unwrap(); | ||
assert_eq!(ran_samples, expected_samples); | ||
} | ||
drop(wasm_bytes); | ||
} | ||
} |