diff options
author | Silas Bartha <[email protected]> | 2024-09-09 21:14:56 -0400 |
---|---|---|
committer | Silas Bartha <[email protected]> | 2024-09-09 21:14:56 -0400 |
commit | 128573aa260644424e834e04ac08dd236736bf5d (patch) | |
tree | db0b342fde17630947a4be04aef04bf99c0e5a4d | |
parent | 40fa831b47f14d649795faeced9cb8a59916f88f (diff) |
Drop task with decoder
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/assets.rs | 9 |
2 files changed, 6 insertions, 5 deletions
@@ -1,7 +1,7 @@ [package] name = "bevy_rustysynth" description = "A plugin which adds MIDI file and soundfont audio support to the bevy engine via rustysynth." -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "0BSD OR MIT OR Apache-2.0" diff --git a/src/assets.rs b/src/assets.rs index 58a6ed3..5f0e08b 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -8,7 +8,7 @@ use bevy::{ asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}, audio::Source, prelude::*, - tasks::AsyncComputeTaskPool, + tasks::{AsyncComputeTaskPool, Task}, }; use itertools::Itertools; use rustysynth::{MidiFile, MidiFileSequencer, SoundFont, Synthesizer, SynthesizerSettings}; @@ -47,6 +47,7 @@ impl AssetLoader for MidiAssetLoader { pub struct MidiDecoder { sample_rate: usize, stream: Receiver<f32>, + _task: Task<()>, } impl MidiDecoder { @@ -58,7 +59,7 @@ impl MidiDecoder { let mut midi = Cursor::new(midi); let sample_rate = 44100_usize; let (tx, rx) = async_channel::bounded::<f32>(sample_rate * 2); - AsyncComputeTaskPool::get() + let task = AsyncComputeTaskPool::get() .spawn(async move { let midi = Arc::new(MidiFile::new(&mut midi).expect("Failed to read midi file.")); let settings = SynthesizerSettings::new(sample_rate as i32); @@ -78,9 +79,9 @@ impl MidiDecoder { } } tx.close(); - }) - .detach(); + }); Self { + _task: task, sample_rate, stream: rx, } |