-
Notifications
You must be signed in to change notification settings - Fork 4
/
process.rs
129 lines (98 loc) · 3.36 KB
/
process.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#![allow(clippy::restriction)]
use std::any::type_name;
use libpd_rs::functions::{
block_size, close_patch, init, initialize_audio, open_patch,
process::{
process_double, process_float, process_raw, process_raw_double, process_raw_short,
process_short,
},
util::dsp_on,
};
fn type_of<T>(_: T) -> &'static str {
type_name::<T>()
}
#[test]
fn all_process_functions() {
let sample_rate = 44100;
let output_channels = 2;
init().unwrap();
initialize_audio(0, output_channels, sample_rate).unwrap();
dsp_on().unwrap();
let patch_handle = open_patch("tests/patches/sine.pd").unwrap();
// Float
let input_buffer = [0.0f32; 512];
let mut output_buffer = [0.0f32; 1024];
for _ in 0..(44100 / block_size() * output_channels) {
let ticks = output_buffer.len() as i32 / (block_size() * output_channels);
process_float(ticks, &input_buffer, &mut output_buffer);
}
let sum = output_buffer.iter().fold(0_f32, |mut acc, element| {
acc += element;
acc
});
assert_eq!(type_of(output_buffer[0]), "f32");
assert_ne!(sum, 0.0);
// Double
let input_buffer = [0.0f64; 512];
let mut output_buffer = [0.0f64; 1024];
for _ in 0..(44100 / block_size() * output_channels) {
let ticks = output_buffer.len() as i32 / (block_size() * output_channels);
process_double(ticks, &input_buffer, &mut output_buffer);
}
let sum = output_buffer.iter().fold(0_f64, |mut acc, element| {
acc += element;
acc
});
assert_eq!(type_of(output_buffer[0]), "f64");
assert_ne!(sum, 0.0);
// Short
let input_buffer = [0i16; 512];
let mut output_buffer = [0i16; 1024];
for _ in 0..(44100 / block_size() * output_channels) {
let ticks = output_buffer.len() as i32 / (block_size() * output_channels);
process_short(ticks, &input_buffer, &mut output_buffer);
}
let sum = output_buffer.iter().fold(0_i32, |mut acc, element| {
acc += *element as i32;
acc
});
assert_eq!(type_of(output_buffer[0]), "i16");
assert_ne!(sum, 0);
// Float Raw
let input_buffer = [0.0f32; 512];
let mut output_buffer = [0.0f32; 1024];
for _ in 0..(44100 / block_size() * output_channels) {
process_raw(&input_buffer, &mut output_buffer);
}
let sum = output_buffer.iter().fold(0_f32, |mut acc, element| {
acc += element;
acc
});
assert_eq!(type_of(output_buffer[0]), "f32");
assert_ne!(sum, 0.0);
// Double Raw
let input_buffer = [0.0f64; 512];
let mut output_buffer = [0.0f64; 1024];
for _ in 0..(44100 / block_size() * output_channels) {
process_raw_double(&input_buffer, &mut output_buffer);
}
let sum = output_buffer.iter().fold(0_f64, |mut acc, element| {
acc += element;
acc
});
assert_eq!(type_of(output_buffer[0]), "f64");
assert_ne!(sum, 0.0);
// Short Raw
let input_buffer = [0_i16; 512];
let mut output_buffer = [0_i16; 1024];
for _ in 0..(44100 / block_size() * output_channels) {
process_raw_short(&input_buffer, &mut output_buffer);
}
let sum = output_buffer.iter().fold(0_i32, |mut acc, element| {
acc += *element as i32;
acc
});
assert_eq!(type_of(output_buffer[0]), "i16");
assert_ne!(sum, 0);
close_patch(patch_handle).unwrap();
}