-
Notifications
You must be signed in to change notification settings - Fork 9
/
telecoms.rs
71 lines (65 loc) · 1.83 KB
/
telecoms.rs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
extern crate synthrs;
use synthrs::synthesizer::{make_samples, quantize_samples};
use synthrs::wave::sine_wave;
use synthrs::writer::write_wav_file;
fn main() {
write_wav_file(
"out/dialtone.wav",
44_100,
&quantize_samples::<i16>(&make_samples(15.0, 44_100, |t: f64| -> f64 {
0.5 * (sine_wave(350.0)(t) + sine_wave(440.0)(t))
})),
)
.expect("failed");
write_wav_file(
"out/busysignal.wav",
44_100,
&quantize_samples::<i16>(&make_samples(8.0, 44_100, |t: f64| -> f64 {
if t % 1.0 < 0.5 {
0.5 * (sine_wave(480.0)(t) + sine_wave(620.0)(t))
} else {
0.0
}
})),
)
.expect("failed");
write_wav_file(
"out/fastbusysignal.wav",
44_100,
&quantize_samples::<i16>(&make_samples(15.0, 44_100, |t: f64| -> f64 {
if t % 0.5 < 0.25 {
0.5 * (sine_wave(480.0)(t) + sine_wave(620.0)(t))
} else {
0.0
}
})),
)
.expect("failed");
write_wav_file(
"out/offhook.wav",
44_100,
&quantize_samples::<i16>(&make_samples(15.0, 44_100, |t: f64| -> f64 {
if t % 0.2 < 0.1 {
0.25 * (sine_wave(1400.0)(t)
+ sine_wave(2060.0)(t)
+ sine_wave(2450.0)(t)
+ sine_wave(2600.0)(t))
} else {
0.0
}
})),
)
.expect("failed");
write_wav_file(
"out/ring.wav",
44_100,
&quantize_samples::<i16>(&make_samples(15.0, 44_100, |t: f64| -> f64 {
if t % 6.0 < 2.0 {
0.50 * (sine_wave(440.0)(t) + sine_wave(480.0)(t))
} else {
0.0
}
})),
)
.expect("failed");
}