Skip to content

Commit b7a82e6

Browse files
committed
Add example of sample playback
1 parent 2abca63 commit b7a82e6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

caw/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ caw_interactive = { version = "0.3", path = "../interactive", optional = true }
3838
anyhow = "1.0"
3939
rand = "0.8"
4040
env_logger = "0.11"
41+
clap = { version = "4", features = ["derive"] }
4142

4243
[[example]]
4344
name = "electric_organ_menu"
@@ -58,3 +59,7 @@ required-features = [ "interactive" ]
5859
[[example]]
5960
name = "simple"
6061
required-features = [ "interactive" ]
62+
63+
[[example]]
64+
name = "audio_file_playback"
65+
required-features = [ "interactive", "audio_file" ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use caw::prelude::*;
2+
use clap::Parser;
3+
4+
fn sig(
5+
_input: Input,
6+
audio_file_buf: Vec<f32>,
7+
_channel: Channel,
8+
) -> Sig<impl SigT<Item = f32>> {
9+
sample_playback(audio_file_buf).build()
10+
}
11+
12+
#[derive(Parser, Debug)]
13+
struct Args {
14+
wav_path: String,
15+
}
16+
17+
fn main() -> anyhow::Result<()> {
18+
env_logger::init();
19+
let args = Args::parse();
20+
let window = Window::builder()
21+
.sane_default()
22+
.visualization(Visualization::StereoOscillographics)
23+
.line_width(2)
24+
.stride(4)
25+
.fade(true)
26+
.build();
27+
let input = window.input();
28+
let audio_file_buf = read_wav_stereo(args.wav_path)?;
29+
window.play_stereo(
30+
Stereo::new(
31+
sig(input.clone(), audio_file_buf.left, Channel::Left),
32+
sig(input.clone(), audio_file_buf.right, Channel::Right),
33+
),
34+
Default::default(),
35+
)
36+
}

0 commit comments

Comments
 (0)