Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Audio WASM support #54

Open
Bombfuse opened this issue May 1, 2021 · 2 comments
Open

Audio WASM support #54

Bombfuse opened this issue May 1, 2021 · 2 comments
Labels
portability A key bug/enhancement for porting to a platform

Comments

@Bombfuse
Copy link
Owner

Bombfuse commented May 1, 2021

Alternatively, make Kira compatible with WASM emerald.

@Bombfuse Bombfuse added the portability A key bug/enhancement for porting to a platform label Jul 10, 2021
@Bombfuse
Copy link
Owner Author

Exact instructions for audio with Kira on WASM by @iliakonnov:

Build for wasm as usual:
cargo build --example audio --target wasm32-unknown-unknown

A bit of patching in your target directory with audio.wasm:

wasm-bindgen ./audio.wasm --out-dir ./audio --target web
sed -i "s/import \* as __wbg_star0 from 'env';//" audio/audio.js
sed -i "s/let wasm;/let wasm; export const set_wasm = (w) => wasm = w;/" audio/audio.js
sed -i "s/imports\['env'\] = __wbg_star0;/return imports.wbg\;/" audio/audio.js

Then it could be run using miniquad's html:

<canvas id="glcanvas" tabindex='1'></canvas>
<!-- Minified and statically hosted version of https://github.com/not-fl3/macroquad/blob/master/js/mq_js_bundle.js -->
<script src="https://not-fl3.github.io/miniquad-samples/mq_js_bundle.js"></script>
<script type="module">
   import init, { set_wasm } from "./audio/audio.js";
    
    async function run() {
        let wbg = await init();

        miniquad_add_plugin({
            register_plugin: (a) => (a.wbg = wbg),
            on_init: () => set_wasm(wasm_exports),
            version: "0.0.1",
            name: "wbg",
        });

        load("./audio/audio_bg.wasm");
    }

    run();
</script>

@Bombfuse Bombfuse changed the title Use quad-snd for WASM audio backend Audio WASM support Jul 11, 2021
@Bombfuse
Copy link
Owner Author

Audio now works in Emerald on WASM, you just need to follow the guide here, and replace "emerald.js" with the latest "gl.js" from miniquad. I'm going to keep this issue open until building for WASM with audio is as simple as calling a single command.

This might lead to an emerald cli that makes building things simpler.

https://github.com/smokku/gwg-bindgen

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
portability A key bug/enhancement for porting to a platform
Projects
None yet
Development

No branches or pull requests

1 participant