Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error on WebAssembly #1

Closed
markusmoenig opened this issue Jun 29, 2022 · 7 comments
Closed

Compiler error on WebAssembly #1

markusmoenig opened this issue Jun 29, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@markusmoenig
Copy link

Is this engine capable to run under wasm32 ? Right now I get a compile error.

error[E0433]: failed to resolve: could not find `StreamInner` in `platform`
   --> /Users/markusmoenig/.cargo/registry/src/github.com-1ecc6299db9ec823/audio-engine-0.2.2/src/engine.rs:135:33
    |
135 |                 cpal::platform::StreamInner::WebAudio(x) => {
    |                                 ^^^^^^^^^^^ could not find `StreamInner` in `platform`
@Rodrigodd
Copy link
Owner

Oh no, I may have published the wrong branch in crates.io. The wasm-resume branch contains a function to resume the AudioContext in Wasm, but it depends on an unpublished version of cpal (needs this commit).

I will try to yank that version and publish a new one.

But for the time being, you can patch cpal in your Cargo.toml:

[patch.crates-io]

# audio-engine 0.2.2 needs a unpublished version of cpal
cpal = { git = "https://github.com/RustAudio/cpal.git", rev = "b1457e5945cfeb136b7b04c8870b63c2ae3f2212" }

@markusmoenig
Copy link
Author

Thanks for the answer and suggestion. But if this patch applied I still get the above compiler errors.

@Rodrigodd
Copy link
Owner

I published a new version that should solve that error.

But I think that the patch also should have solved the problem. Are you sure that the patch was being applied? It only works if it is put in the Workspace root or in the Cargo.toml of the crate being build (don't work if put in a dependency). You can confirm if it is being applied by running cargo tree, cpal should contain the GitHub address.

But in any case, the new version should solve this. Can you confirm if it works now?

@markusmoenig
Copy link
Author

Yes, it compiles now. It was my error as you said, did not put the patch into the workspace.

Ok, it compiles now! However I get a crash when I try to decode my wav file.

I will try to narrow it down and also try different wav files. I embed my files use rust_embed.

[Error] panicked at 'called Result::unwrap() on an Err value: TooWide', /Users/markusmoenig/.cargo/registry/src/github.com-1ecc6299db9ec823/audio-engine-0.2.3/src/wav.rs:41:36

Stack:

@http://127.0.0.1:8080/client_standalone_web.js:331:30
wasm-stub@[wasm code]

.wasm-function[console_error_panic_hook::hook::h4d011d5e076e94ae]@[wasm code] .wasm-function[core::ops::function::Fn::call::h032de97329426c04]@[wasm code] .wasm-function[std::panicking::rust_panic_with_hook::he2a025723e105e28]@[wasm code] .wasm-function[std::panicking::begin_panic_handler::{{closure}}::hd9f8c213ec91b9d5]@[wasm code] .wasm-function[std::sys_common::backtrace::__rust_end_short_backtrace::h6efd730283875809]@[wasm code] .wasm-function[rust_begin_unwind]@[wasm code] .wasm-function[core::panicking::panic_fmt::hb02133958c1e7d35]@[wasm code] .wasm-function[core::result::unwrap_failed::h68fdaca771c68bb6]@[wasm code] .wasm-function[audio_engine::converter::SampleRateConverter::new::h4769ca637db84d56]@[wasm code] .wasm-function[audio_engine::engine::AudioEngine::new_sound::ha9f989d0b0f42578]@[wasm code] .wasm-function[ as core::future::future::Future>::poll::h1abde6f002602186]@[wasm code] .wasm-function[wasm_bindgen_futures::task::singlethread::Task::run::h639c8475153e992e]@[wasm code] .wasm-function[wasm_bindgen_futures::queue::Queue::new::{{closure}}::h358ade576eab6a3c]@[wasm code] .wasm-function[+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h94dac06645129eaa]@[wasm code]

wasm-stub@[native code]
__wbg_adapter_50@http://127.0.0.1:8080/client_standalone_web.js:223:134
real@http://127.0.0.1:8080/client_standalone_web.js:200:21
promiseReactionJob@[native code]

(anonymous function) (client_standalone_web.js:343)
wasm-stub
<?>.wasm-function[console_error_panic_hook::hook::h4d011d5e076e94ae]
<?>.wasm-function[core::ops::function::Fn::call::h032de97329426c04]
<?>.wasm-function[std::panicking::rust_panic_with_hook::he2a025723e105e28]
<?>.wasm-function[std::panicking::begin_panic_handler::{{closure}}::hd9f8c213ec91b9d5]
<?>.wasm-function[std::sys_common::backtrace::__rust_end_short_backtrace::h6efd730283875809]
<?>.wasm-function[rust_begin_unwind]
<?>.wasm-function[core::panicking::panic_fmt::hb02133958c1e7d35]
<?>.wasm-function[core::result::unwrap_failed::h68fdaca771c68bb6]
<?>.wasm-function[audio_engine::converter::SampleRateConverter<T>::new::h4769ca637db84d56]
<?>.wasm-function[audio_engine::engine::AudioEngine::new_sound::ha9f989d0b0f42578]
<?>.wasm-function[<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h1abde6f002602186]
<?>.wasm-function[wasm_bindgen_futures::task::singlethread::Task::run::h639c8475153e992e]
<?>.wasm-function[wasm_bindgen_futures::queue::Queue::new::{{closure}}::h358ade576eab6a3c]
<?>.wasm-function[<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h94dac06645129eaa]
wasm-stub
__wbg_adapter_50 (client_standalone_web.js:223:135)
real (client_standalone_web.js:200)
promiseReactionJob

@markusmoenig
Copy link
Author

I get the same error when I play natively on my Mac. Seems to be an unsupported audio sample format ?

@Rodrigodd
Copy link
Owner

Seems to be an unsupported audio sample format?

Yes, currently the wave decoder only supports decoding WAV files with a bit depth of 16 bits or lower (the entire audio engine uses i16).

But the engine should at least convert the samples to i16 (and should not panic).

I will close this issue as solved and open a new one for this.

@Rodrigodd Rodrigodd changed the title Wasm Compiler error on WebAssembly Jun 30, 2022
@Rodrigodd
Copy link
Owner

Opened #2

@Rodrigodd Rodrigodd added the bug Something isn't working label Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants