diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2022-06-10 11:42:16 +1000 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-06 22:50:42 +0000 |
commit | edfac528c8381f510ca83a8edb94db9a3e3e10f7 (patch) | |
tree | 5e96b3a4598a7d15019d73f738f62451bd7d5693 | |
parent | 48413bf92e7efddf4d104febcb193ac26918f2aa (diff) |
wasm: update and fix qwasmaudiodevice
- set min and max sample rates according to AudioContext docs
- remove use of EM_ASM to allow better use of multithreading
- ensure feature thread is used
Fixes: QTBUG-104045
Change-Id: Id0bf8905c68f4364abc6f3a9029f75cc5275ff0b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@gmail.com>
(cherry picked from commit 731e6b6f510b01e496860a208d304789aa72fca3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/multimedia/wasm/qwasmaudiodevice.cpp | 26 |
2 files changed, 22 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 033d02ec5..96b2f8cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,5 +21,10 @@ if(NOT TARGET Qt::Network) message(NOTICE "Skipping the build as the condition \"TARGET Qt::Network\" is not met.") return() endif() +if(NOT QT_FEATURE_thread) + message(NOTICE "Skipping the build as the QT_FEATURE_thread is not met.") + return() +endif() + qt_build_repo() diff --git a/src/multimedia/wasm/qwasmaudiodevice.cpp b/src/multimedia/wasm/qwasmaudiodevice.cpp index 18eb9e967..b8f3532b5 100644 --- a/src/multimedia/wasm/qwasmaudiodevice.cpp +++ b/src/multimedia/wasm/qwasmaudiodevice.cpp @@ -3,6 +3,9 @@ #include "qwasmaudiodevice_p.h" #include <emscripten.h> +#include <emscripten/val.h> +#include <emscripten/bind.h> + #include <AL/al.h> #include <AL/alc.h> @@ -16,8 +19,8 @@ QWasmAudioDevice::QWasmAudioDevice(const char *device, const char *desc, bool is minimumChannelCount = 1; maximumChannelCount = 2; - minimumSampleRate = 1; - maximumSampleRate = 192'000; + minimumSampleRate = 8000; + maximumSampleRate = 96000; // js AudioContext max according to docs // native openAL formats supportedSampleFormats.append(QAudioFormat::UInt8); @@ -29,13 +32,18 @@ QWasmAudioDevice::QWasmAudioDevice(const char *device, const char *desc, bool is preferredFormat.setChannelCount(2); - preferredFormat.setSampleRate(EM_ASM_INT({ - var AudioContext = window.AudioContext || window.webkitAudioContext; - var ctx = new AudioContext(); - var sr = ctx.sampleRate; - ctx.close(); - return sr; - })); + // FIXME: firefox + // An AudioContext was prevented from starting automatically. + // It must be created or resumed after a user gesture on the page. + emscripten::val audioContext = emscripten::val::global("window")["AudioContext"].new_(); + if (audioContext == emscripten::val::undefined()) + audioContext = emscripten::val::global("window")["webkitAudioContext"].new_(); + + if (audioContext != emscripten::val::undefined()) { + int sRate = audioContext["sampleRate"].as<int>(); + audioContext.call<void>("close"); + preferredFormat.setSampleRate(sRate); + } auto f = QAudioFormat::Float; |