-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippets.txt
46 lines (40 loc) · 1.48 KB
/
snippets.txt
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
{
let (_stream, stream_handle) = rodio::OutputStream::try_default().unwrap();
// Example: Sound from a file:
let file = std::fs::File::open("output.wav").unwrap();
let beep_sink = stream_handle.play_once(BufReader::new(file)).unwrap();
beep_sink.set_volume(0.3);
// Example: Sound from a generative source:
stream_handle.play_raw(
SineWave::new(1000.0)
.take_duration(Duration::from_secs(30))
.amplify(0.1))
.unwrap();
// Sound from the VST host:
stream_handle.play_raw(OutputSource::new(&vst, &buffer_size)).unwrap();
}
{
stream_handle.play_raw(
SineWave::new(1000.0)
.take_duration(Duration::from_millis(100)))
.unwrap()
}
{
// Example: output to a file:
use std::fs::File;
// let mut inp_file = File::open(Path::new("data/sine.wav"))?;
// let (header, data) = wav::read(&mut inp_file)?;
let wav_header = wav::Header::new(wav::WAV_FORMAT_IEEE_FLOAT, 2, 48000, 32);
let mut out_file = File::create(Path::new("output.wav")).unwrap();
// wav::write(wav_header, BitDepth::ThirtyTwoFloat &mut out_file).unwrap();
let mut pcm_data = vec![];
for _i in 1..20 {
plugin.process(&mut audio_buffer);
pcm_data.append(&mut outputs[0].to_vec());
}
let wav_data = wav::BitDepth::ThirtyTwoFloat(pcm_data.to_owned());
wav::write(wav_header, &wav_data, &mut out_file).unwrap();
drop(out_file);
}
println!("Closing host instance.");
drop(instance);