MCPcopy Create free account
hub / github.com/PerroEngine/Perro / new

Method new

perro_source/audio_stack/perro_pawdio/src/controller.rs:43–213  ·  view source on GitHub ↗
(static_audio_lookup: Option<fn(u64) -> &'static [u8]>)

Source from the content-addressed store, hash-verified

41 tx: Sender<AudioCommand>,
42 next_playback_id: Arc<AtomicU64>,
43 source_pool: Mutex<HashMap<u64, Arc<str>>>,
44 loaded: Arc<Mutex<AudioLoadedState>>,
45}
46
47#[derive(Default)]
48struct AudioLoadedState {
49 sources: HashSet<Arc<str>>,
50 soundfonts: HashSet<perro_ids::SoundFontID>,
51}
52
53#[derive(Clone)]
54pub struct AudioSourceHandle {
55 source: Arc<str>,
56}
57
58impl AudioSourceHandle {
59 #[must_use]
60 pub fn as_str(&self) -> &str {
61 &self.source
62 }
63}
64
65fn run_audio_worker<F>(
66 static_audio_lookup: Option<fn(u64) -> &'static [u8]>,
67 player_factory: F,
68 commands: &Receiver<AudioCommand>,
69 startup: &Sender<Result<(), String>>,
70 loaded: &Mutex<AudioLoadedState>,
71) where
72 F: FnOnce(Option<fn(u64) -> &'static [u8]>) -> Result<BarkPlayer, String>,
73{
74 let player = match player_factory(static_audio_lookup) {
75 Ok(player) => player,
76 Err(err) => {
77 let _ = startup.send(Err(err));
78 return;
79 }
80 };
81 if startup.send(Ok(())).is_err() {
82 return;
83 }
84
85 while let Ok(command) = commands.recv() {
86 process_audio_command(&player, command, loaded);
87 }
88}
89
90fn set_source_loaded(loaded: &Mutex<AudioLoadedState>, source: &Arc<str>, value: bool) {
91 let Ok(mut loaded) = loaded.lock() else {
92 return;
93 };
94 if value {
95 loaded.sources.insert(Arc::clone(source));
96 } else {
97 loaded.sources.remove(source);
98 }
99}
100

Callers

nothing calls this directly

Calls 15

audio_disabled_by_envFunction · 0.85
drop_source_assetMethod · 0.80
sendMethod · 0.80
load_soundfont_bytesMethod · 0.80
as_requestMethod · 0.80
release_midiMethod · 0.80
nameMethod · 0.45
load_sourceMethod · 0.45
insertMethod · 0.45
removeMethod · 0.45
load_source_bytesMethod · 0.45
play_sourceMethod · 0.45

Tested by

no test coverage detected