fix safari audio

This commit is contained in:
d07riv
2019-08-13 05:50:32 +03:00
parent df2154e0c5
commit 79851342bb
3 changed files with 10 additions and 4 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "diabloweb",
"version": "1.0.24",
"version": "1.0.25",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "diabloweb",
"version": "1.0.24",
"version": "1.0.25",
"private": true,
"dependencies": {
"@babel/core": "7.4.3",

View File

@@ -9,6 +9,12 @@ function no_sound() {
};
}
function decodeAudioData(context, buffer) {
return new Promise((resolve, reject) => {
context.decodeAudioData(buffer, resolve, reject);
});
}
export default function init_sound() {
const AudioContext = window.AudioContext || window.webkitAudioContext;
if (!AudioContext) {
@@ -29,7 +35,7 @@ export default function init_sound() {
}
const buffer = context.createBuffer(channels, length, rate);
for (let i = 0; i < channels; ++i) {
buffer.copyToChannel(data.subarray(i * length, i * length + length), i);
buffer.getChannelData(i).set(data.subarray(i * length, i * length + length));
}
sounds.set(id, {
buffer: Promise.resolve(buffer),
@@ -41,7 +47,7 @@ export default function init_sound() {
if (!context) {
return;
}
const buffer = context.decodeAudioData(data.buffer);
const buffer = decodeAudioData(context, data.buffer);
sounds.set(id, {
buffer,
gain: context.createGain(),