sim_lib_audio_dsp/
runtime.rs1use sim_kernel::{Cx, Lib, LibManifest, Linker, LoadCx, Result, Symbol};
2use sim_lib_core::{SurfaceField, SurfacePackLib, SurfacePackSpec, SurfaceValueSpec, install_once};
3
4const AUDIO_DSP_LIB_ID: &str = "audio-dsp";
5
6pub struct AudioDspLib;
9
10impl Lib for AudioDspLib {
11 fn manifest(&self) -> LibManifest {
12 audio_dsp_pack().manifest()
13 }
14
15 fn load(&self, cx: &mut LoadCx, linker: &mut Linker<'_>) -> Result<()> {
16 audio_dsp_pack().load(cx, linker)
17 }
18}
19
20pub fn install_audio_dsp_lib(cx: &mut Cx) -> Result<()> {
22 install_once(cx, &AudioDspLib)?;
23 Ok(())
24}
25
26pub fn audio_dsp_symbols() -> Vec<Symbol> {
28 [
29 "SmoothValue",
30 "SmoothedGain",
31 "Gain",
32 "Pan",
33 "DcBlocker",
34 "OnePoleFilter",
35 "BiquadFilter",
36 "StateVariableFilter",
37 "DelayProcessor",
38 "FractionalDelay",
39 "CombFilter",
40 "AllPassFilter",
41 "Chorus",
42 "Flanger",
43 "Vibrato",
44 "Waveshaper",
45 "SoftClipper",
46 "Compressor",
47 "Limiter",
48 "Gate",
49 "OversamplingWrapper",
50 ]
51 .into_iter()
52 .map(|name| Symbol::qualified(AUDIO_DSP_LIB_ID, name))
53 .collect()
54}
55
56fn audio_dsp_pack() -> SurfacePackLib {
57 SurfacePackLib {
58 spec: SurfacePackSpec {
59 lib_id: Symbol::new(AUDIO_DSP_LIB_ID),
60 values: audio_dsp_symbols()
61 .into_iter()
62 .map(|symbol| SurfaceValueSpec {
63 symbol: symbol.clone(),
64 fields: vec![
65 (Symbol::new("symbol"), SurfaceField::Symbol(symbol)),
66 (
67 Symbol::new("layer"),
68 SurfaceField::Str(AUDIO_DSP_LIB_ID.to_owned()),
69 ),
70 (
71 Symbol::new("kind"),
72 SurfaceField::Str("audio-graph-processor".to_owned()),
73 ),
74 (
75 Symbol::new("role"),
76 SurfaceField::Str(
77 "reusable pure Rust DSP processor descriptor".to_owned(),
78 ),
79 ),
80 (
81 Symbol::new("contract"),
82 SurfaceField::Str("Processor".to_owned()),
83 ),
84 ],
85 })
86 .collect(),
87 },
88 }
89}