MCPcopy Create free account
hub / github.com/BillyDM/Firewheel / main

Function main

examples/play_sample/src/main.rs:18–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16}
17
18fn main() {
19 tracing::subscriber::set_global_default(
20 tracing_subscriber::FmtSubscriber::builder()
21 .with_max_level(tracing::Level::DEBUG)
22 .finish(),
23 )
24 .unwrap();
25
26 let args = Cli::parse();
27
28 // --- Start the context and get the sample rate of the audio stream. ----------------
29
30 let mut cx = FirewheelContext::new(Default::default());
31 let mut stream = CpalStream::new(&mut cx, Default::default()).unwrap();
32
33 let sample_rate = cx.stream_info().unwrap().sample_rate;
34
35 // --- Create a sampler state, and add it as a node in the audio graph. --------------
36
37 let mut sampler_node = SamplerNode::default();
38
39 let sampler_id = cx
40 .add_node(sampler_node, None)
41 .expect("Sampler node should construct without error");
42
43 let graph_out_id = cx.graph_out_node_id();
44
45 cx.connect(sampler_id, graph_out_id, &[(0, 0), (1, 1)], false)
46 .unwrap();
47
48 // --- Load a sample into memory, and tell the node to use it and play it. -----------
49
50 let probed = symphonium::probe_from_file(
51 args.path, None, // Custom container probe
52 )
53 .unwrap();
54 let sample = firewheel::dyn_symphonium_resource(
55 symphonium::decode(
56 probed,
57 &symphonium::DecodeConfig::default(),
58 Some(sample_rate), // target sample rate
59 None, // An optional cache
60 None, // Custom codec registry
61 )
62 .unwrap(),
63 );
64
65 cx.queue_event_for(sampler_id, SamplerNode::set_dyn_sample_event(sample));
66
67 sampler_node.start_or_restart();
68 cx.queue_event_for(sampler_id, sampler_node.sync_play_event());
69
70 // Get the playback ID after calling `start_or_restart()` to detect when
71 // this specific playback sequence has finished playing.
72 //
73 // Note, this ID becomes invalidated once the sampler node receives a
74 // new "play" event.
75 let playback_id = sampler_node.playback_id();

Callers

nothing calls this directly

Calls 13

dyn_symphonium_resourceFunction · 0.85
queue_event_forMethod · 0.80
sync_play_eventMethod · 0.80
playback_idMethod · 0.80
playback_finishedMethod · 0.80
all_streams_okMethod · 0.80
stream_infoMethod · 0.45
add_nodeMethod · 0.45
graph_out_node_idMethod · 0.45
connectMethod · 0.45
start_or_restartMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected