From a2bf8877008489529b73aed36df727a63351536d Mon Sep 17 00:00:00 2001 From: tuxmain Date: Tue, 23 Aug 2022 17:02:13 +0200 Subject: [PATCH] Audio using HexoDSP --- Cargo.lock | 551 ++++++++++++++++++++++++++++--------------- Cargo.toml | 11 +- README.md | 8 +- assets/init.hxy | 1 + src/audio.rs | 150 ++++++++++++ src/game.rs | 47 ++-- src/levels.rs | 3 + src/levels/level0.rs | 4 + src/levels/level1.rs | 4 + src/main.rs | 15 +- 10 files changed, 571 insertions(+), 223 deletions(-) create mode 100644 assets/init.hxy create mode 100644 src/audio.rs diff --git a/Cargo.lock b/Cargo.lock index f831094..b2fd78d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ab_glyph" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24606928a235e73cdef55a0c909719cadd72fce573e5713d58cb2952d8f5794c" +checksum = "846ffacb9d0c8b879ef9e565b59e18fb76d6a61013e5bd24ecc659864e6b1a1f" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8" +checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" [[package]] name = "approx" @@ -188,15 +188,6 @@ version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" -[[package]] -name = "atomic" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" -dependencies = [ - "autocfg", -] - [[package]] name = "atomic_refcell" version = "0.1.8" @@ -436,17 +427,6 @@ dependencies = [ "encase_derive_impl", ] -[[package]] -name = "bevy_fundsp" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a6e13dc15f060f68e5742139d63d31e472df1b271f0a5f854499e3c9c067e20" -dependencies = [ - "atomic", - "bevy", - "fundsp", -] - [[package]] name = "bevy_gilrs" version = "0.8.0" @@ -491,9 +471,9 @@ dependencies = [ [[package]] name = "bevy_hanabi" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe35e3c7a5c8b9c26093b62551929581ada6da514e8c8e1ad01c939565916d1a" +checksum = "371c5bd9edcf42721cd4e769354c221f3c4090e7a1dba0eb0bd6ca29e7828142" dependencies = [ "anyhow", "bevy", @@ -615,9 +595,9 @@ dependencies = [ [[package]] name = "bevy_pbr" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9a81bbd02f5e0a57899a41aec37d9cb14965e1e4d510547f3f680323d05c0f" +checksum = "176073021a4caeb8b448f24ce790fb57fde74b114f345064a8b102d2f7bed905" dependencies = [ "bevy_app", "bevy_asset", @@ -642,9 +622,9 @@ checksum = "d92d5679e89602a18682a37846573dcd1979410179e14204280460ba9fb8713a" [[package]] name = "bevy_rapier2d" -version = "0.16.0" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e941caacdd45fcfc0fe0be661d5aaca0392dabfa6595a96ef7f18716587195f" +checksum = "e94ea9324a836efedf4b3673a3c5e2011490fa440478d244fe6b1783557ab4fd" dependencies = [ "bevy", "bitflags", @@ -764,9 +744,9 @@ dependencies = [ [[package]] name = "bevy_sprite" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f83dfe8897d6c0d9d5ce3818d49a13e58ae2b9b9ecf4f4bb85aa31bb0678f68" +checksum = "69c419f3db09d7ac1f4d45e0874d349d5d6f47f48bc10d55cd0da36413e2331e" dependencies = [ "bevy_app", "bevy_asset", @@ -854,9 +834,9 @@ dependencies = [ [[package]] name = "bevy_ui" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac181a7b637da61fad72981ff9d2e5b899283ca7d54b2b7ea49c431121331c53" +checksum = "062ce086de1a4a470e5df48cb5c16a1dc97ab610e635cafabdef26c4a1ef5756" dependencies = [ "bevy_app", "bevy_asset", @@ -896,16 +876,16 @@ dependencies = [ [[package]] name = "bevy_window" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3bdc3a220a9bb2fad9bd30d5f44c6645725398fe1bc588fc87abf09f092696e" +checksum = "707dbbebfac72b1e63e874e7a11a345feab8c440355c0bd71e6dff26709fba9a" dependencies = [ "bevy_app", "bevy_ecs", "bevy_input", "bevy_math", "bevy_utils", - "raw-window-handle", + "raw-window-handle 0.4.3", "web-sys", ] @@ -923,7 +903,7 @@ dependencies = [ "bevy_utils", "bevy_window", "crossbeam-channel", - "raw-window-handle", + "raw-window-handle 0.4.3", "wasm-bindgen", "web-sys", "winit", @@ -935,9 +915,12 @@ version = "0.1.0" dependencies = [ "bevy", "bevy-inspector-egui", - "bevy_fundsp", "bevy_hanabi", "bevy_rapier2d", + "cpal 0.14.0", + "crossbeam-channel", + "hexodsp", + "ticktock", ] [[package]] @@ -988,9 +971,9 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytemuck" @@ -1309,6 +1292,146 @@ dependencies = [ "winapi", ] +[[package]] +name = "cpal" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d466b47cf0ea4100186a7c12d7d0166813dda7cf648553554c9c39c6324841b" +dependencies = [ + "alsa", + "core-foundation-sys 0.8.3", + "coreaudio-rs", + "jni", + "js-sys", + "libc", + "mach", + "ndk 0.7.0", + "ndk-context", + "nix 0.23.1", + "oboe", + "once_cell", + "parking_lot 0.12.1", + "stdweb", + "thiserror", + "web-sys", + "windows", +] + +[[package]] +name = "cranelift" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd96bba738454eb373087df6d6891b18009361123fef90930def4978e3837448" +dependencies = [ + "cranelift-codegen", + "cranelift-frontend", +] + +[[package]] +name = "cranelift-bforest" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "529ffacce2249ac60edba2941672dfedf3d96558b415d0d8083cd007456e0f55" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427d105f617efc8cb55f8d036a7fded2e227892d8780b4985e5551f8d27c4a92" +dependencies = [ + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity", + "cranelift-isle", + "gimli", + "log", + "regalloc2", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "551674bed85b838d45358e3eab4f0ffaa6790c70dc08184204b9a54b41cdb7d1" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b3a63ae57498c3eb495360944a33571754241e15e47e3bcae6082f40fec5866" + +[[package]] +name = "cranelift-entity" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11aa8aa624c72cc1c94ea3d0739fa61248260b5b14d3646f51593a88d67f3e6e" + +[[package]] +name = "cranelift-frontend" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "544ee8f4d1c9559c9aa6d46e7aaeac4a13856d620561094f35527356c7d21bd0" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed16b14363d929b8c37e3c557d0a7396791b383ecc302141643c054343170aad" + +[[package]] +name = "cranelift-jit" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0308e7418208639fb96c1a3dc04955fa41c4bc92dfce9106635185f71d5caf46" +dependencies = [ + "anyhow", + "cranelift-codegen", + "cranelift-entity", + "cranelift-module", + "cranelift-native", + "libc", + "log", + "region", + "target-lexicon", + "windows-sys", +] + +[[package]] +name = "cranelift-module" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979aac10dbcf0c222cd5902565bc93597ac30bbe9d879a2aa5f2402d1561f2" +dependencies = [ + "anyhow", + "cranelift-codegen", +] + +[[package]] +name = "cranelift-native" +version = "0.86.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51617cf8744634f2ed3c989c3c40cd6444f63377c6d994adab0d85807f3eb682" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + [[package]] name = "crc32fast" version = "1.3.2" @@ -1470,16 +1593,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" -[[package]] -name = "duplicate" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0a4be4cd710e92098de6ad258e6e7c24af11c29c5142f3c6f2a545652480ff8" -dependencies = [ - "heck", - "proc-macro-error", -] - [[package]] name = "egui" version = "0.18.1" @@ -1493,9 +1606,9 @@ dependencies = [ [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "emath" @@ -1664,33 +1777,17 @@ dependencies = [ "libc", ] -[[package]] -name = "fundsp" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c82c389e6a1394463627e5df8777a9350968e8828e8074d629bc65a0d54165e" -dependencies = [ - "duplicate", - "generic-array", - "lazy_static", - "num-complex", - "numeric-array", - "rsor", - "rustfft", - "tinyvec", -] - [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "d2acedae88d38235936c3922476b10fced7b2b68136f5e3c03c2d5be348a1115" [[package]] name = "futures-io" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "93a66fc6d035a26a3ae255a6d2bca35eda63ae4c5512bef54449113f7a1228e5" [[package]] name = "futures-lite" @@ -1716,16 +1813,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "gethostname" version = "0.2.3" @@ -1783,6 +1870,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +dependencies = [ + "indexmap", +] + [[package]] name = "glam" version = "0.21.3" @@ -1936,12 +2032,6 @@ dependencies = [ "serde", ] -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - [[package]] name = "hermit-abi" version = "0.1.19" @@ -1973,6 +2063,21 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "hexodsp" +version = "0.2.0" +source = "git+https://github.com/WeirdConstructor/HexoDSP#be4e9232cc05b96588b156d1c9f995f7eda41ec0" +dependencies = [ + "hound", + "lazy_static", + "ringbuf", + "serde", + "serde_json", + "synfx-dsp", + "synfx-dsp-jit", + "triple_buffer", +] + [[package]] name = "hound" version = "3.4.0" @@ -2197,9 +2302,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.131" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "libloading" @@ -2439,6 +2544,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "ndk" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys 0.4.0", + "num_enum", + "raw-window-handle 0.5.0", + "thiserror", +] + [[package]] name = "ndk-context" version = "0.1.1" @@ -2504,6 +2623,15 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ndk-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21d83ec9c63ec5bf950200a8e508bdad6659972187b625469f58ef8c08e29046" +dependencies = [ + "jni-sys", +] + [[package]] name = "nix" version = "0.22.3" @@ -2679,16 +2807,6 @@ dependencies = [ "syn", ] -[[package]] -name = "numeric-array" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c59a9b227913a685ed84aa0de5ded58274e8bcfa55760faae07bc82aee64ccf" -dependencies = [ - "generic-array", - "num-traits", -] - [[package]] name = "objc" version = "0.2.7" @@ -2762,9 +2880,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] name = "optional" @@ -2941,15 +3059,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d" -[[package]] -name = "primal-check" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b264861209b0641a9b7571695029f516698bd3f2bf46eb61fca408675630b8c" -dependencies = [ - "num-integer", -] - [[package]] name = "proc-macro-crate" version = "1.2.1" @@ -2961,30 +3070,6 @@ dependencies = [ "toml", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.43" @@ -3089,6 +3174,15 @@ dependencies = [ "cty", ] +[[package]] +name = "raw-window-handle" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" +dependencies = [ + "cty", +] + [[package]] name = "rawpointer" version = "0.2.1" @@ -3110,6 +3204,18 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regalloc2" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" +dependencies = [ + "fxhash", + "log", + "slice-group-by", + "smallvec", +] + [[package]] name = "regex" version = "1.6.0" @@ -3136,12 +3242,33 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "region" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" +dependencies = [ + "bitflags", + "libc", + "mach", + "winapi", +] + [[package]] name = "renderdoc-sys" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" +[[package]] +name = "ringbuf" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f65af18d50f789e74aaf23bbb3f65dcd22a3cb6e029b5bced149f6bd57c5c2a2" +dependencies = [ + "cache-padded", +] + [[package]] name = "robust" version = "0.2.3" @@ -3154,8 +3281,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0939e9f626e6c6f1989adb6226a039c855ca483053f0ee7c98b90e41cf731e" dependencies = [ - "cpal", - "hound", + "cpal 0.13.5", "lewton", ] @@ -3170,32 +3296,12 @@ dependencies = [ "serde", ] -[[package]] -name = "rsor" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b57e3964dc31a38416366d2e8f7675755402a10832d5cf4e4112d66ac77cdda" - [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustfft" -version = "6.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d089e5c57521629a59f5f39bca7434849ff89bd6873b521afe389c1c602543" -dependencies = [ - "num-complex", - "num-integer", - "num-traits", - "primal-check", - "strength_reduce", - "transpose", -] - [[package]] name = "rusty-xinput" version = "1.2.0" @@ -3245,18 +3351,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.143" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.143" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" +checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" dependencies = [ "proc-macro2", "quote", @@ -3265,9 +3371,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -3311,6 +3417,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slice-group-by" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" + [[package]] name = "slotmap" version = "1.0.6" @@ -3363,12 +3475,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" -[[package]] -name = "strength_reduce" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3ff2f71c82567c565ba4b3009a9350a96a7269eaa4001ebedae926230bc2254" - [[package]] name = "strsim" version = "0.10.0" @@ -3392,6 +3498,29 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synfx-dsp" +version = "0.5.3" +source = "git+https://github.com/WeirdConstructor/synfx-dsp#3334a91ee48c009707c0147434a3fc14a929c079" +dependencies = [ + "num-traits", +] + +[[package]] +name = "synfx-dsp-jit" +version = "0.5.3" +source = "git+https://github.com/WeirdConstructor/synfx-dsp-jit#f199ec697292ed59e92976d7404d6988e0a8d6b0" +dependencies = [ + "anyhow", + "cranelift", + "cranelift-codegen", + "cranelift-jit", + "cranelift-module", + "cranelift-native", + "ringbuf", + "synfx-dsp", +] + [[package]] name = "taffy" version = "0.1.0" @@ -3405,6 +3534,12 @@ dependencies = [ "typenum", ] +[[package]] +name = "target-lexicon" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" + [[package]] name = "termcolor" version = "1.1.3" @@ -3443,6 +3578,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "ticktock" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d226b8341a5d130e3446024468efab6d150ba656e086b793ac37a3d17669e626" + [[package]] name = "tiff" version = "0.6.1" @@ -3552,13 +3693,12 @@ dependencies = [ ] [[package]] -name = "transpose" -version = "0.2.1" +name = "triple_buffer" +version = "5.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95f9c900aa98b6ea43aee227fd680550cdec726526aab8ac801549eadb25e39f" +checksum = "803966e5a8397a70d3d8111afa1597ba8381346d7de4720e9f539471d371a1a3" dependencies = [ - "num-integer", - "strength_reduce", + "cache-padded", ] [[package]] @@ -3776,7 +3916,7 @@ dependencies = [ "log", "naga", "parking_lot 0.12.1", - "raw-window-handle", + "raw-window-handle 0.4.3", "smallvec", "wasm-bindgen", "wasm-bindgen-futures", @@ -3803,7 +3943,7 @@ dependencies = [ "naga", "parking_lot 0.12.1", "profiling", - "raw-window-handle", + "raw-window-handle 0.4.3", "smallvec", "thiserror", "web-sys", @@ -3841,7 +3981,7 @@ dependencies = [ "parking_lot 0.12.1", "profiling", "range-alloc", - "raw-window-handle", + "raw-window-handle 0.4.3", "renderdoc-sys", "thiserror", "wasm-bindgen", @@ -3915,17 +4055,30 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" +dependencies = [ + "windows_aarch64_msvc 0.37.0", + "windows_i686_gnu 0.37.0", + "windows_i686_msvc 0.37.0", + "windows_x86_64_gnu 0.37.0", + "windows_x86_64_msvc 0.37.0", +] + [[package]] name = "windows-sys" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] @@ -3934,30 +4087,60 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" + [[package]] name = "winit" version = "0.26.1" @@ -3981,7 +4164,7 @@ dependencies = [ "objc", "parking_lot 0.11.2", "percent-encoding", - "raw-window-handle", + "raw-window-handle 0.4.3", "wasm-bindgen", "web-sys", "winapi", diff --git a/Cargo.toml b/Cargo.toml index 9d23b54..5d6e75a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,10 +7,13 @@ edition = "2021" [dependencies] bevy = "0.8.0" -bevy_fundsp = "0.1.0" -bevy_hanabi = "0.3.0" +bevy_hanabi = "0.3.1" bevy-inspector-egui = "0.12.1" -bevy_rapier2d = "0.16.0" +bevy_rapier2d = "0.16.2" +cpal = "0.14.0" +crossbeam-channel = "0.5.6" +hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP" } +ticktock = "0.8.0" [profile.dev.package."*"] -opt-level = 3 \ No newline at end of file +opt-level = 3 diff --git a/README.md b/README.md index c511357..fe29ac0 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ ## TODO * name -* stream audio (with HexoSynthDSP) * color filters * level design * (?) can jump only from a surface (no mid-air jump) * (?) multiplayer * make WASM build work again (replace hanabi) * level reset +* more audio ## Build @@ -37,6 +37,12 @@ sh build-wasm.sh python3 -m http.server ``` +## Audio + +This game uses [HexoDSP](https://github.com/WeirdConstructor/HexoDSP) for audio synthesis. + +The synthetizer matrix can be edited using [HexoSynth](https://github.com/WeirdConstructor/HexoSynth) visual editor. + ## License GNU AGPL v3, CopyLeft 2022 Pascal Engélibert diff --git a/assets/init.hxy b/assets/init.hxy new file mode 100644 index 0000000..8ba0f92 --- /dev/null +++ b/assets/init.hxy @@ -0,0 +1 @@ +{"VERSION":2,"atoms":[["tseq",0,"cmode",["i",0]],["sfilter",0,"ftype",["i",8]],["delay",0,"mode",["i",0]],["delay",1,"mode",["i",0]],["out",0,"mono",["i",0]],["ad",0,"mult",["i",0]],["amp",0,"neg_att",["i",1]],["amp",1,"neg_att",["i",1]],["bosc",0,"wtype",["i",3]]],"cells":[["sin",1,1,2,[-1,-1,-1],[-1,"sig",-1]],["sin",0,1,3,[-1,-1,-1],["sig",-1,-1]],["sin",2,2,2,[-1,-1,-1],[-1,-1,"sig"]],["mix3",0,2,3,["ch3","ch2","ch1"],[-1,"sig",-1]],["ad",0,3,3,[-1,"inp",-1],[-1,"sig","sig"]],["amp",0,3,4,["inp",-1,-1],[-1,"sig",-1]],["amp",1,4,4,[-1,"inp",-1],[-1,-1,"sig"]],["out",0,4,5,["ch2","ch1",-1],[-1,-1,-1]]],"params":[["ad",0,"ashp",0.8149999976158142],["ad",0,"atk",15.0],["amp",0,"att",1.0],["amp",1,"att",1.0],["mix3",0,"ch1",0.0],["out",0,"ch1",0.0],["mix3",0,"ch2",0.0],["out",0,"ch2",0.0],["mix3",0,"ch3",0.0],["tseq",0,"clock",0.0],["ad",0,"dcy",1000.0],["sin",0,"det",0.0],["sin",1,"det",4.0],["sin",2,"det",7.0],["bosc",0,"det",0.0],["ad",0,"dshp",0.19500002264976501],["delay",0,"fb",0.6499999761581421],["delay",1,"fb",0.5999999642372131],["sin",0,"freq",440.0,0.0],["sin",1,"freq",440.0],["sin",2,"freq",440.0],["bosc",0,"freq",440.0],["sfilter",0,"freq",1900.0001220703125],["amp",0,"gain",0.9999999403953552],["amp",1,"gain",0.9999999403953552],["out",0,"gain",0.08999998867511749],["mix3",0,"gain1",0.9999999403953552],["mix3",0,"gain2",0.9999999403953552],["mix3",0,"gain3",0.9999999403953552],["amp",0,"inp",0.0],["amp",1,"inp",0.0],["ad",0,"inp",1.0],["delay",0,"inp",0.0],["delay",1,"inp",0.0],["sfilter",0,"inp",0.0],["delay",0,"mix",0.5],["delay",1,"mix",0.5],["mix3",0,"ogain",0.9999999403953552],["bosc",0,"pw",0.5,-0.25999999046325684],["sfilter",0,"res",0.5],["tslfo",0,"rev",0.5],["tslfo",1,"rev",0.5],["tslfo",2,"rev",0.5],["tslfo",3,"rev",0.5],["tslfo",0,"time",1699.99951171875],["tslfo",1,"time",22999.99609375],["tslfo",2,"time",19999.994140625],["tslfo",3,"time",499.99993896484375],["delay",0,"time",256.70001220703125,0.009999999776482582],["delay",1,"time",249.99998474121094,-0.007999999448657036],["tseq",0,"trig",0.0],["ad",0,"trig",0.0],["tslfo",0,"trig",0.0],["tslfo",1,"trig",0.0],["tslfo",2,"trig",0.0],["tslfo",3,"trig",0.0],["delay",0,"trig",0.0],["delay",1,"trig",0.0]],"patterns":[{"col_types":[1,3,0,0,0,0],"cursor_col":2,"cursor_row":2,"data":[[60,4071,-1,-1,-1,-1],[64,4071,-1,-1,-1,-1],[69,4071,-1,-1,-1,-1],[-1,4071,-1,-1,-1,-1],[72,4071,-1,-1,-1,-1],[76,4071,-1,-1,-1,-1],[84,4071,-1,-1,-1,-1],[-1,4071,-1,-1,-1,-1],[60,4071,-1,-1,-1,-1],[64,4071,-1,-1,-1,-1],[79,4071,-1,-1,-1,-1],[-1,4071,-1,-1,-1,-1],[72,4071,-1,-1,-1,-1],[76,4071,-1,-1,-1,-1],[65,4071,-1,-1,-1,-1],[-1,4071,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-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1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1]],"edit_step":4,"rows":16},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"props":[]} diff --git a/src/audio.rs b/src/audio.rs new file mode 100644 index 0000000..32e1e5b --- /dev/null +++ b/src/audio.rs @@ -0,0 +1,150 @@ +// https://github.com/WeirdConstructor/HexoDSP/blob/master/examples/cpal_demo_node_api.rs + +use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; +use crossbeam_channel::Receiver; +use hexodsp::{matrix_repr::MatrixRepr, *}; +use std::io::Read; +use ticktock::Clock; + +pub enum AudioMsg { + Color([f32; 3]), + Jump, +} + +pub fn setup(event_channel: Receiver) { + let mut buf = String::new(); + std::fs::File::open("assets/init.hxy") + .unwrap() + .read_to_string(&mut buf) + .unwrap(); + let matrix_repr: MatrixRepr = MatrixRepr::deserialize(&buf).unwrap(); + + let (node_conf, node_exec) = new_node_engine(); + + let mut matrix = Matrix::new(node_conf, 64, 64); + matrix.from_repr(&matrix_repr).unwrap(); + + start_backend(node_exec, move || { + let color_mix = NodeId::Mix3(0); + let color_mix_r_gain = color_mix.inp_param("gain1").unwrap(); + let color_mix_g_gain = color_mix.inp_param("gain2").unwrap(); + let color_mix_b_gain = color_mix.inp_param("gain3").unwrap(); + let jump_ad = NodeId::Ad(0); + let jump_ad_trig = jump_ad.inp_param("trig").unwrap(); + + for (_tick, _now) in Clock::framerate(10.0).iter() { + matrix.set_param(jump_ad_trig, (0.0).into()); + + if let Ok(msg) = event_channel.try_recv() { + match msg { + AudioMsg::Color([r, g, b]) => { + matrix.set_param(color_mix_r_gain, r.into()); + matrix.set_param(color_mix_g_gain, g.into()); + matrix.set_param(color_mix_b_gain, b.into()); + } + AudioMsg::Jump => matrix.set_param(jump_ad_trig, (1.0).into()), + } + } + } + }); +} + +pub fn run( + device: &cpal::Device, + config: &cpal::StreamConfig, + mut node_exec: NodeExecutor, + mut frontend_loop: F, +) where + T: cpal::Sample, +{ + let sample_rate = config.sample_rate.0 as f32; + let channels = config.channels as usize; + + node_exec.set_sample_rate(sample_rate); + + let input_bufs = [[0.0; hexodsp::dsp::MAX_BLOCK_SIZE]; 2]; + let mut outputbufs = [[0.0; hexodsp::dsp::MAX_BLOCK_SIZE]; 2]; + + let err_fn = |err| eprintln!("an error occurred on stream: {}", err); + let stream = device + .build_output_stream( + config, + move |data: &mut [T], _: &cpal::OutputCallbackInfo| { + let mut frames_left = data.len() / channels; + + let mut out_iter = data.chunks_mut(channels); + + node_exec.process_graph_updates(); + + while frames_left > 0 { + let cur_nframes = if frames_left >= hexodsp::dsp::MAX_BLOCK_SIZE { + hexodsp::dsp::MAX_BLOCK_SIZE + } else { + frames_left + }; + + let input = &[ + &input_bufs[0][0..cur_nframes], + &input_bufs[1][0..cur_nframes], + ]; + + let split = outputbufs.split_at_mut(1); + + let mut output = [ + &mut ((split.0[0])[0..cur_nframes]), + &mut ((split.1[0])[0..cur_nframes]), + ]; + + let mut context = Context { + nframes: cur_nframes, + output: &mut output[..], + input, + }; + + context.output[0].fill(0.0); + context.output[1].fill(0.0); + + node_exec.process(&mut context); + + for i in 0..cur_nframes { + if let Some(frame) = out_iter.next() { + let mut ctx_chan = 0; + for sample in frame.iter_mut() { + let value: T = + cpal::Sample::from::(&context.output[ctx_chan][i]); + *sample = value; + + ctx_chan += 1; + if ctx_chan > context.output.len() { + ctx_chan = context.output.len() - 1; + } + } + } + } + + frames_left -= cur_nframes; + } + }, + err_fn, + ) + .unwrap(); + stream.play().unwrap(); + + frontend_loop(); +} + +fn start_backend(node_exec: NodeExecutor, frontend_loop: F) { + let host = cpal::default_host(); + let device = host + .default_output_device() + .expect("Finding useable audio device"); + let config = device + .default_output_config() + .expect("A workable output config"); + + match config.sample_format() { + cpal::SampleFormat::F32 => run::(&device, &config.into(), node_exec, frontend_loop), + cpal::SampleFormat::I16 => run::(&device, &config.into(), node_exec, frontend_loop), + cpal::SampleFormat::U16 => run::(&device, &config.into(), node_exec, frontend_loop), + }; +} diff --git a/src/game.rs b/src/game.rs index b85a065..7b170c1 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,6 +1,8 @@ #![allow(clippy::precedence)] #![allow(clippy::too_many_arguments)] +pub use crate::audio::AudioMsg; + use crate::AppState; use bevy::{ @@ -8,7 +10,6 @@ use bevy::{ prelude::{shape::Quad, *}, sprite::Mesh2dHandle, }; -use bevy_fundsp::prelude::*; use bevy_hanabi::*; use bevy_rapier2d::prelude::*; use std::collections::BTreeSet; @@ -104,6 +105,7 @@ pub fn spawn_character( materials: &mut ResMut>, selected_character_id: &mut Mut, character_id_list: &mut Mut, + audio: &Res>, transform: Transform, color: Color, ) { @@ -187,6 +189,9 @@ pub fn spawn_character( // If no character is selected, then select this one if selected_character_id.0.is_none() { selected_character_id.0 = Some(character_id); + audio + .send(AudioMsg::Color([color.r(), color.g(), color.b()])) + .ok(); } } @@ -199,6 +204,7 @@ fn collision_event_system( character_query: Query<(&CharacterId, &CharacterColor, &Transform)>, mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>, mut app_state: ResMut>, + audio: Res>, ) { for collision_event in collision_events.iter() { if let CollisionEvent::Started(e1, e2, flags) = collision_event { @@ -233,6 +239,7 @@ fn collision_event_system( &mut materials, &mut selected_character_id, &mut character_id_list, + &audio, *c1_transform, new_color.into(), ); @@ -244,27 +251,18 @@ fn collision_event_system( fn keyboard_input_system( keyboard_input: Res>, - mut characters: Query<( - &CharacterId, - &mut Velocity, - &mut ExternalImpulse, - &mut ExternalForce, - &Children, - )>, + mut characters: Query<(&CharacterId, &mut Velocity, &CharacterColor, &Children)>, mut level_query: Query<(&mut SelectedCharacterId, &CharacterIdList)>, mut effect: Query<&mut ParticleEffect>, - dsp_assets: Res, - audio: Res