CHX7R6AMVYVLZJ7DSE6E3B4TCJPRWS2V7ZEJIU2UQ3SSLRKYMJWQC
FIO72ZSANLC3OS5IKSZ4PUAIBFAAHZA6EFGHMHP6YVFGTOJ7PPKQC
7FTW5AQKOO4W5AIHYZSAKLQR6LGVTXH7SKMSTA4ER4C4HP54VE4QC
7SXAXY6J4QHPDUUHCKZDEZOZ2IUMSBWODICOMIZH2KA2BGV3F54QC
ASIORORAPGGVNLR42J6PZRTG7JKK34GYXBYSKSTJFXSFW6YXBJJQC
KZU3YXA22IYIPZICQTMZ4XILKCWOI5O6W4H72PDXDUTZDFVMVGVQC
3PEU6H5YDCRN2O7IIORFPJRKDE6FOJVMBOXSAGU7CJWOHULYNEAQC
ZW67OU7OPHAITCJS3GHQYFBRY5YGOIGRD7B4CKULAXAEXHM42KYQC
ZJ2DSL63RVPSNXIGTAZNPV6HLHOKLWC5RSK5EAAM3HIYUJ5Y3ISQC
5DFOVYVHNSGK7MPEEY3YZXIRXK6UNLVDVUQZ3SXGCXAU7C2CMJPAC
MKB2A5XCWBZO2E6QFE6PD36LF3IGMJCGJB5TGMRAPSKCKHS75ISAC
DBHCCY3W2DG4WYMXBZ2UCNYVGZ5PS5UUUNWCXVYJ4TMXQDIZT6GAC
5Y32O2B2GTH2UHFA3NO4ZY673XNHT3W4DQADFMK4LMKLSXMZKHGQC
CAN3DHITMPDA2DJC63QMMPMIC63FMWCUAI4ZLKPLEHIYG2EWIAHAC
//! emulation of sfxr using fundsp
use crate::fundsp_kira::Machine;
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
utils::BoxedFuture,
};
use fundsp::hacker32::*;
pub struct SfxrPlugin;
impl Plugin for SfxrPlugin {
fn build(&self, app: &mut App) {
app.init_asset_loader::<SfxrLoader>();
}
}
#[derive(serde::Deserialize)]
struct Sfxr {
amp: Option<f32>,
f: f32,
}
#[derive(Default)]
struct SfxrLoader;
#[non_exhaustive]
#[derive(thiserror::Error, Debug)]
enum SfxrLoaderError {
/// An [IO](std::io) Error
#[error("Could not load asset: {0}")]
Io(#[from] std::io::Error),
/// A [RON](ron) Error
#[error("Could not parse RON: {0}")]
RonSpannedError(#[from] ron::error::SpannedError),
}
impl AssetLoader for SfxrLoader {
type Asset = Machine;
type Settings = ();
type Error = SfxrLoaderError;
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a Self::Settings,
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let sfxr = ron::de::from_bytes::<Sfxr>(&bytes)?;
Ok(Machine::new(
pink() * sfxr.amp.unwrap_or(1.0) * envelope(move |t| exp(-sfxr.f * t)),
))
})
}
fn extensions(&self) -> &[&str] {
&["sfxr.ron"]
}
}
fn test_audio_loop(
audio: Res<Audio>,
audio_load_test: Res<AudioLoadTest>,
// mut fundsp_output: NonSendMut<fundsp_kira::FundspAudioOutput>,
// mut track: ResMut<fundsp_kira::MainTrack>,
) {
fn test_audio_loop(audio: Res<Audio>, audio_load_test: Res<AudioLoadTest>) {
use fundsp::hacker32::*;
let noisy_handle = machines.add(fundsp_kira::Machine::new(
pink() * envelope(|t| exp(-5.0 * t)),
// pink() * 0.2,
));
// use fundsp::hacker32::*;
// let noisy_handle = machines.add(fundsp_kira::Machine::new(
// pink() * envelope(|t| exp(-5.0 * t)),
// // pink() * 0.2,
// ));
let noisy_handle = asset_server.load("debug.sfxr.ron");
(
amp: Some(0.2),
f: 0.1,
)