14QWasmAudioDevice::QWasmAudioDevice(
const char *device,
17 QAudioDevice::Mode mode)
18 : QAudioDevicePrivate(device, mode, QString::fromUtf8(desc))
21 minimumChannelCount = 1;
22 maximumChannelCount = 2;
23 minimumSampleRate = 8000;
24 maximumSampleRate = 96000;
27 supportedSampleFormats.append(QAudioFormat::UInt8);
28 supportedSampleFormats.append(QAudioFormat::Int16);
31 if (alIsExtensionPresent(
"AL_EXT_float32"))
32 supportedSampleFormats.append(QAudioFormat::Float);
34 preferredFormat.setChannelCount(2);
39 emscripten::val audioContext = emscripten::val::global(
"window")[
"AudioContext"].new_();
40 if (audioContext == emscripten::val::undefined())
41 audioContext = emscripten::val::global(
"window")[
"webkitAudioContext"].new_();
43 if (audioContext != emscripten::val::undefined()) {
44 audioContext.call<
void>(
"resume");
45 int sRate = audioContext[
"sampleRate"].as<
int>();
46 audioContext.call<
void>(
"close");
47 preferredFormat.setSampleRate(sRate);
50 auto f = QAudioFormat::Float;
52 if (!supportedSampleFormats.contains(f))
53 f = QAudioFormat::Int16;
54 preferredFormat.setSampleFormat(f);