AUDIO
Source snapshot · 11 November 2026

Executable tutorial fixtures

examples/tutorials/tests/walkthroughs.rs · 134 source lines

Read the chapters in source order. Select a numbered source line to expand its explanation; the line numbers and code match this snapshot exactly.

cargo test -p ravet-examples --test walkthroughs --no-default-features --locked
Chapters
  1. Isolate executable output files lines 1–63
  2. Test the rendered synth clip lines 64–96
  3. Test the actual effect WAV lines 97–119
  4. Test printed MPE and MIDI 2.0 traces lines 120–134

Isolate executable output files

A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

1use ravet_audio_file::{WaveEncoding, WaveReader};

Bring these module/type names into scope for “Isolate executable output files”; the surrounding chapter explains their responsibilities.

Link to line 1
2use std::{

Bring these module/type names into scope for “Isolate executable output files”; the surrounding chapter explains their responsibilities.

Link to line 2
3 fs::File,

Define or initialize fs with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 3
4 path::PathBuf,

Define or initialize path with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 4
5 process::Command,

Define or initialize process with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 5
6 sync::atomic::{AtomicUsize, Ordering},

Define or initialize sync with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 6
7};

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 7
8

Blank line separating the surrounding statements.

Link to line 8
9struct Scratch(PathBuf);

Declare the state/type or implementation used by this chapter. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 9
10impl Scratch {

Declare the state/type or implementation used by this chapter. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 10
11 fn new() -> Self {

Define new. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 11
12 static NEXT: AtomicUsize = AtomicUsize::new(0);

Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.

Link to line 12
13 let path = std::env::temp_dir().join(format!(

Bind path to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 13
14 "ravet-examples-{}-{}",

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.

Link to line 14
15 std::process::id(),

Define or initialize std with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 15
16 NEXT.fetch_add(1, Ordering::Relaxed)

Atomically increment this counter and retain the requested synchronization ordering.

Link to line 16
17 ));

Close the current expression or scope; no additional processing operation occurs on this line.

Link to line 17
18 std::fs::create_dir(&path).unwrap();

Define or initialize std with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 18
19 Self(path)

Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.

Link to line 19
20 }

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 20
21}

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 21
22impl Drop for Scratch {

Declare the state/type or implementation used by this chapter. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 22
23 fn drop(&mut self) {

Define drop. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 23
24 std::fs::remove_dir_all(&self.0).unwrap();

Define or initialize std with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 24
25 }

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 25
26}

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 26
27

Blank line separating the surrounding statements.

Link to line 27
28fn run(binary: &str, path: Option<&std::path::Path>) -> String {

Define run. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 28
29 let mut command = Command::new(binary);

Bind mutable command to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 29
30 if let Some(path) = path {

Evaluate this condition or visit this range in source order. The statements in the following scope implement “Isolate executable output files”.

Link to line 30
31 command.arg("--render").arg(path);

Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.

Link to line 31
32 } else {

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.

Link to line 32
33 command.arg("--offline");

Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.

Link to line 33
34 }

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 34
35 let output = command.output().unwrap();

Bind output to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 35
36 assert!(

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 36
37 output.status.success(),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.

Link to line 37
38 "{}",

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.

Link to line 38
39 String::from_utf8_lossy(&output.stderr)

Define or initialize String with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 39
40 );

Close the current expression or scope; no additional processing operation occurs on this line.

Link to line 40
41 String::from_utf8(output.stdout).unwrap()

Define or initialize String with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.

Link to line 41
42}

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 42
43

Blank line separating the surrounding statements.

Link to line 43
44fn read(path: &std::path::Path, frames: usize) -> Vec<f32> {

Define read. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.

Link to line 44
45 let mut reader = WaveReader::new(File::open(path).unwrap(), 256).unwrap();

Bind mutable reader to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 45
46 assert_eq!(reader.format().channels, 2);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 46
47 assert_eq!(reader.format().sample_rate, 48_000);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 47
48 assert_eq!(reader.format().encoding, WaveEncoding::Pcm16);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 48
49 assert_eq!(reader.frames(), frames as u64);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 49
50 let mut audio = Vec::new();

Bind mutable audio to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 50
51 let mut block = [0.; 512];

Bind mutable block to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 51
52 loop {

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.

Link to line 52
53 let count = reader.read_frames(&mut block).unwrap();

Bind count to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 53
54 if count == 0 {

Evaluate this condition or visit this range in source order. The statements in the following scope implement “Isolate executable output files”.

Link to line 54
55 break;

End the nearest loop when its bounded work or input condition is complete.

Link to line 55
56 }

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 56
57 audio.extend_from_slice(&block[..2 * count]);

Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.

Link to line 57
58 }

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 58
59 assert_eq!(audio.len(), frames * 2);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 59
60 audio

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.

Link to line 60
61}

Close the surrounding scope, value or argument list in “Isolate executable output files”.

Link to line 61
62

Blank line separating the surrounding statements.

Link to line 62
63#[test]

Apply this Rust attribute to the following item. cfg selects which target/feature/test build contains it; derive generates the named trait implementations.

Link to line 63

Test the rendered synth clip

Launch the synth executable, verify silence before scheduled notes and note/pedal/release behavior, and confirm the complete output frame count. This exercises the actual executable/helper path, not just a mock processor call.

64fn synth_renders_timed_notes_pedal_hold_and_complete_release() {

Define synth_renders_timed_notes_pedal_hold_and_complete_release. Launch the synth executable, verify silence before scheduled notes and note/pedal/release behavior, and confirm the complete output frame count. This exercises the actual executable/helper path, not just a mock processor call.

Link to line 64
65 let scratch = Scratch::new();

Bind scratch to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 65
66 let path = scratch.0.join("nested/synth.wav");

Bind path to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 66
67 run(env!("CARGO_BIN_EXE_midi-synth"), Some(&path));

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 67
68 let audio = read(&path, 72_000);

Bind audio to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 68
69 assert!(

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 69
70 audio

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the rendered synth clip” explanation above.

Link to line 70
71 .as_chunks::<2>()

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the rendered synth clip” explanation above.

Link to line 71
72 .0

Supply this literal numeric entry to the array or argument list being constructed. Its units/addressing follow the containing fixture or configuration.

Link to line 72
73 .iter()

Borrow collection entries for iteration without moving or copying the whole collection.

Link to line 73
74 .all(|frame| frame[0] == frame[1])

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 74
75 );

Close the current expression or scope; no additional processing operation occurs on this line.

Link to line 75
76 assert!(audio[..2 * 2_400].iter().all(|v| *v == 0.));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 76
77 for (start, end) in [(3_000, 11_000), (17_000, 27_000), (47_000, 59_000)] {

Evaluate this condition or visit this range in source order. The statements in the following scope implement “Test the rendered synth clip”.

Link to line 77
78 assert!(audio[2 * start..2 * end].iter().any(|v| v.abs() > 0.04));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 78
79 }

Close the surrounding scope, value or argument list in “Test the rendered synth clip”.

Link to line 79
80 for (start, end) in [(14_500, 16_000), (30_500, 32_000), (62_500, 72_000)] {

Evaluate this condition or visit this range in source order. The statements in the following scope implement “Test the rendered synth clip”.

Link to line 80
81 assert!(audio[2 * start..2 * end].iter().all(|v| *v == 0.));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 81
82 }

Close the surrounding scope, value or argument list in “Test the rendered synth clip”.

Link to line 82
83 let original = std::fs::read(&path).unwrap();

Bind original to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 83
84 assert!(

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 84
85 !Command::new(env!("CARGO_BIN_EXE_midi-synth"))

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 85
86 .arg("--render")

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 86
87 .arg(&path)

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 87
88 .output()

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 88
89 .unwrap()

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 89
90 .status

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the rendered synth clip” explanation above.

Link to line 90
91 .success()

Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.

Link to line 91
92 );

Close the current expression or scope; no additional processing operation occurs on this line.

Link to line 92
93 assert_eq!(std::fs::read(&path).unwrap(), original);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 93
94}

Close the surrounding scope, value or argument list in “Test the rendered synth clip”.

Link to line 94
95

Blank line separating the surrounding statements.

Link to line 95
96#[test]

Apply this Rust attribute to the following item. cfg selects which target/feature/test build contains it; derive generates the named trait implementations.

Link to line 96

Test the actual effect WAV

Launch the delay fixture and check cross-channel impulse timing, feedback decay and the exact sample-timed bypass result. A reader error or missing file fails the fixture.

97fn effect_renders_ping_pong_repeats_and_sample_timed_bypass() {

Define effect_renders_ping_pong_repeats_and_sample_timed_bypass. Launch the delay fixture and check cross-channel impulse timing, feedback decay and the exact sample-timed bypass result. A reader error or missing file fails the fixture.

Link to line 97
98 let scratch = Scratch::new();

Bind scratch to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 98
99 let path = scratch.0.join("effect.wav");

Bind path to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 99
100 run(env!("CARGO_BIN_EXE_effect"), Some(&path));

Call the displayed operation with these arguments as the next step in “Test the actual effect WAV”. The chapter describes its role and validation.

Link to line 100
101 let audio = read(&path, 96_000);

Bind audio to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 101
102 for (frame, channel, value) in [

Evaluate this condition or visit this range in source order. The statements in the following scope implement “Test the actual effect WAV”.

Link to line 102
103 (12000, 0, 0.5),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 103
104 (14400, 1, 0.25),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 104
105 (24000, 1, 0.25),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 105
106 (26400, 0, 0.125),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 106
107 (36000, 0, 0.125),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 107
108 (38400, 1, 0.0625),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 108
109 (48000, 1, 0.0625),

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 109
110 ] {

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.

Link to line 110
111 assert!((audio[2 * frame + channel] - value).abs() < 0.00004);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 111
112 assert_eq!(audio[2 * frame + 1 - channel], 0.);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 112
113 }

Close the surrounding scope, value or argument list in “Test the actual effect WAV”.

Link to line 113
114 assert!(audio[2 * 72007..2 * 73600].iter().all(|s| *s == 0.));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 114
115 assert!((audio[2 * 73600] - 0.125).abs() < 0.00004);

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 115
116 assert!(audio[2 * 73600 + 1..].iter().all(|s| *s == 0.));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 116
117}

Close the surrounding scope, value or argument list in “Test the actual effect WAV”.

Link to line 117
118

Blank line separating the surrounding statements.

Link to line 118
119#[test]

Apply this Rust attribute to the following item. cfg selects which target/feature/test build contains it; derive generates the named trait implementations.

Link to line 119

Test printed MPE and MIDI 2.0 traces

Run both explicit offline inspectors and assert their reports contain independent member/master expression and exact full-resolution MIDI 2.0 fields. These tests open neither a device nor a window.

120fn expression_walkthroughs_report_independent_mpe_and_lossless_midi2() {

Define expression_walkthroughs_report_independent_mpe_and_lossless_midi2. Run both explicit offline inspectors and assert their reports contain independent member/master expression and exact full-resolution MIDI 2.0 fields. These tests open neither a device nor a window.

Link to line 120
121 let mpe = run(env!("CARGO_BIN_EXE_mpe"), None);

Bind mpe to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 121
122 assert!(mpe.contains(

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 122
123 "channel=1 key=60 Held: member_bend=12.0 master_bend=-2.0 pressure=0.787 timbre=0.504"

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test printed MPE and MIDI 2.0 traces” explanation above.

Link to line 123
124 ));

Close the current expression or scope; no additional processing operation occurs on this line.

Link to line 124
125 assert!(mpe.contains(

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 125
126 "channel=2 key=64 Held: member_bend=0.0 master_bend=-2.0 pressure=0.000 timbre=0.000"

Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test printed MPE and MIDI 2.0 traces” explanation above.

Link to line 126
127 ));

Close the current expression or scope; no additional processing operation occurs on this line.

Link to line 127
128 assert!(mpe.contains("channel=1 key=60 Released: member_bend=12.0 master_bend=0.0"));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 128
129 let midi2 = run(env!("CARGO_BIN_EXE_midi2"), None);

Bind midi2 to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.

Link to line 129
130 assert!(midi2.contains("frame=0 group=1 channel=2 words=[41923c00, abcd0000]"));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 130
131 assert!(midi2.contains("frame=17 group=1 channel=2 words=[41623c00, 91234567]"));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 131
132 assert!(midi2.contains("frame=17 group=1 channel=2 words=[41a23c00, deadbeef]"));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 132
133 assert!(midi2.contains("frame=48 group=1 channel=2 words=[41823c00, 12340000]"));

Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.

Link to line 133
134}

Close the surrounding scope, value or argument list in “Test printed MPE and MIDI 2.0 traces”.

Link to line 134

Source SHA-256: e7db9833ad6181da35f1b497966b2a2b8f0119e434d3c7f7f3486e067dc656c7

API: ravet_audio_file

All tutorial walkthroughs