vst3_host_test/
vst3_host_test.rs1use std::path::Path;
7
8use mkaudiolibrary::host::{load, scan_vst3};
9use mkaudiolibrary::processor::AudioIO;
10
11fn main() {
12 let dir = Path::new("/Library/Audio/Plug-Ins/VST3");
13 let found = scan_vst3(dir);
14 println!("Found {} VST3 classes in {}", found.len(), dir.display());
15 for d in found.iter().take(8) {
16 println!(" [{}] {} - {}", d.format, d.vendor, d.name);
17 }
18
19 let descriptor = found
20 .first()
21 .expect("no VST3 plugins found to test against");
22 println!("\nLoading: {} - {}", descriptor.vendor, descriptor.name);
23
24 let mut plugin = load(descriptor).expect("failed to load VST3 plugin");
25 println!(
26 "Loaded '{}' by '{}': {} in / {} out, {} parameters",
27 plugin.name(),
28 plugin.vendor(),
29 plugin.num_inputs(),
30 plugin.num_outputs(),
31 plugin.num_parameters()
32 );
33
34 plugin.prepare(48000, 512).expect("prepare failed");
35 plugin.set_active(true).expect("set_active failed");
36
37 for i in 0..plugin.num_parameters().min(5) {
38 println!(
39 " param[{}] '{}' = {:.4}",
40 i,
41 plugin.parameter_name(i),
42 plugin.get_parameter(i)
43 );
44 }
45
46 let in_channels = plugin.num_inputs().max(1);
47 let out_channels = plugin.num_outputs().max(1);
48
49 let mut input_storage = vec![vec![0.0f32; 512]; in_channels];
52 let mut output_storage = vec![vec![0.0f32; 512]; out_channels];
53
54 for channel in &mut input_storage {
55 for (i, sample) in channel.iter_mut().enumerate() {
56 *sample = (i as f32 / 48000.0 * 440.0 * std::f32::consts::TAU).sin() * 0.25;
57 }
58 }
59
60 let input: Vec<&[f32]> = input_storage.iter().map(Vec::as_slice).collect();
61 let mut output: Vec<&mut [f32]> = output_storage.iter_mut().map(Vec::as_mut_slice).collect();
62 let mut audio = AudioIO::new(Some(&input), &mut output, None, None);
63
64 plugin.process(&mut audio);
65
66 let mut peak = 0.0f32;
67 let mut nonzero = false;
68 for channel in &output_storage {
69 for &s in channel.iter() {
70 if s != 0.0 {
71 nonzero = true;
72 }
73 peak = peak.max(s.abs());
74 }
75 }
76
77 println!("\nOutput peak: {:.6}, nonzero: {}", peak, nonzero);
78 println!(
79 "OK: VST3 host rendered a real block of audio through '{}'.",
80 plugin.name()
81 );
82}