blob: 39dda67567928c7f13b389c9f2dee0d8de9dc549 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
use ::Filter;
use std::str::FromStr;
grammar;
pub Main: Filter = {
<preamp: Preamp> <eq: Eq> => {
let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64).sqrt()).collect();
// TODO: add decibel_to_ratio conversion function
let preamp = 10f64.powf(preamp / 10f64);
Filter { preamp, frequencies: eq.0, coefficients }
}
}
Preamp: f64 = {
"Preamp:" <Decibel>
}
Eq: (Vec<u32>, Vec<f64>) = {
"GraphicEQ:" <values:(<(Integer Float)> ";")+> <end:(Integer Float)> => {
let mut values = values;
values.push(end);
values.into_iter().unzip()
}
}
Decibel: f64 = {
<Float> "dB"
}
Float: f64 = {
<RawFloat>,
<SignedInteger> => <> as f64,
<Integer> => <> as f64,
}
RawFloat: f64 = r"-?[0-9]*\.[0-9]+" => f64::from_str(<>).unwrap();
SignedInteger: i32 = r"-[0-9]+" => i32::from_str(<>).unwrap();
Integer: u32 = r"[0-9]+"=> u32::from_str(<>).unwrap();
// vim: ft=rust
|