-
Hello. I was implementing a part where characters make sounds when they speak (such as Animal Crossing), which is used a lot in other games. From too complicated cpal to roadio or rubato... and I found a library called kira and tried it, and it's been successful to some extent. However, if you play a sound file imported into the reqwest library, AudioManager's num_sounds() will continue to build up, and if it is approximately 20 to 30, the browser will experience severe lag. And this num_sounds() doesn't seem to shrink at all, so the StaticSoundData you created doesn't seem to be released from memory. So the temporary measures I have adopted are as follows. pub fn play(&self) -> Result<(), Box<dyn Error>> {
let sound = self.base_sound.clone();
let sound = sound.playback_rate(self.speed);
let sound = sound.volume(self.volum);
let sound = sound.reverse(self.is_rev);
// let track = AUDIO_MANAGER.write().add_sub_track({
// let mut builder = TrackBuilder::new();
// if self.reverb != 0. {
// builder.add_effect(ReverbBuilder::new().damping(self.reverb));
// }
// // builder.add_effect(LfoBuilder::new().frequency(self.pitch));
// // builder.add_effect(CompressorBuilder::new().ratio(self.speed));
// // builder.add_effect();
// builder
// })?;
info!("{}", AUDIO_MANAGER.write().num_sounds()); // AUDIO_MANAGER is static value (GlobalSignal<AudioManager>) for dioxus system
let num_sound = AUDIO_MANAGER.write().num_sounds();
let num_cap = AUDIO_MANAGER.write().sound_capacity() - 1;
if num_sound >= num_cap {
*AUDIO_MANAGER.write() = {
let mut settings = AudioManagerSettings::default();
let mut capercities = Capacities::default();
capercities.sound_capacity = CAPS;
info!("사운드 캐퍼시티 {}", capercities.sound_capacity);
settings.capacities = capercities;
let manager: AudioManager<DefaultBackend> = AudioManager::new(settings).unwrap();
manager
};
}
(*AUDIO_MANAGER.write()).play(sound)?;
Ok(())
} When AudioManager's maximum acceptable sound is full (CAPS is temporarily set to 16), replace it with a new AudioManager, and this method has been quite successful... But I think this is a temporary way, and if the sound should run once every 10 ms, there is also a problem that some sounds don't play, so I want to improve it. Is there a way to remove StaticSound Data loaded on AudioManager? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Each time you play a sound, previously played sounds that are now finished are supposed to be unloaded. So I'm wondering if this is some kind of Kira wasm bug. I have a couple questions:
|
Beta Was this translation helpful? Give feedback.
-
Can you post a simple example that I can run? Without being able to run the code it's hard to tell what's wrong. |
Beta Was this translation helpful? Give feedback.
-
OK, I found the bug. It's not a wasm-specific bug, but one that happens if you play a static sound backwards. It's fixed now in v0.9.4. Thank you for helping me catch it! |
Beta Was this translation helpful? Give feedback.
OK, I found the bug. It's not a wasm-specific bug, but one that happens if you play a static sound backwards. It's fixed now in v0.9.4. Thank you for helping me catch it!