-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix audio crashes and leaks; add stress tests
- Loading branch information
Avaer Kazmer
committed
Aug 5, 2018
1 parent
419d7e5
commit ff32e78
Showing
5 changed files
with
180 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<html> | ||
<head> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/94/three.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
const ctx = THREE.AudioContext.getContext(); | ||
const buffers = []; | ||
let numLoads = 0; | ||
let booted = false; | ||
const numBuffers = 3; | ||
const _load = () => { | ||
numLoads++; | ||
new THREE.AudioLoader().load('talknerdytome.ogg', buffer => { | ||
buffers.push(buffer); | ||
while (buffers.length > numBuffers) { | ||
buffers.splice(Math.floor(Math.random() * buffers.length), 1); | ||
} | ||
|
||
numLoads--; | ||
|
||
if (buffers.length >= numBuffers && !booted) { | ||
_boot(); | ||
booted = true; | ||
} | ||
}); | ||
}; | ||
for (let i = 0; i < numBuffers; i++) { | ||
_load(); | ||
} | ||
|
||
const _boot = () => { | ||
for (let i = 0; i < 4; i++) { | ||
_recurse(); | ||
} | ||
}; | ||
let ids = 0; | ||
const _recurse = () => { | ||
const id = ids++; | ||
const absn = ctx.createBufferSource(); | ||
absn.buffer = buffers[Math.floor(Math.random() * buffers.length)]; | ||
absn.connect(ctx.destination); | ||
absn.start(); | ||
console.log('started ' + id); | ||
absn.onended = () => { | ||
console.log('ended ' + id); | ||
}; | ||
|
||
const _timeout = fn => { | ||
setTimeout(fn, Math.floor(Math.random() * 20)); | ||
}; | ||
_timeout(() => { | ||
_timeout(() => { | ||
absn.stop(); | ||
_timeout(() => { | ||
absn.disconnect(); | ||
}); | ||
}); | ||
|
||
if (numLoads < numBuffers) { | ||
_load(); | ||
} | ||
|
||
_recurse(); | ||
}); | ||
}; | ||
|
||
/* setInterval(() => { | ||
while (Math.random() >= 0.000001) {} | ||
}); */ | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<html> | ||
<head> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/94/three.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
const ctx = THREE.AudioContext.getContext(); | ||
const buffers = []; | ||
let numLoads = 0; | ||
let booted = false; | ||
const numBuffers = 3; | ||
const _load = () => { | ||
numLoads++; | ||
new THREE.AudioLoader().load('talknerdytome.ogg', buffer => { | ||
buffers.push(buffer); | ||
while (buffers.length > numBuffers) { | ||
buffers.splice(Math.floor(Math.random() * buffers.length), 1); | ||
} | ||
|
||
numLoads--; | ||
|
||
if (buffers.length >= numBuffers && !booted) { | ||
_boot(); | ||
booted = true; | ||
} | ||
}); | ||
}; | ||
for (let i = 0; i < numBuffers; i++) { | ||
_load(); | ||
} | ||
|
||
const _boot = () => { | ||
for (let i = 0; i < 4; i++) { | ||
_recurse(); | ||
} | ||
}; | ||
let ids = 0; | ||
const _recurse = () => { | ||
const id = ids++; | ||
|
||
const absn = ctx.createBufferSource(); | ||
absn.buffer = buffers[Math.floor(Math.random() * buffers.length)]; | ||
absn.connect(ctx.destination); | ||
absn.start(); | ||
console.log('started ' + id); | ||
absn.onended = () => { | ||
console.log('onended ' + id); | ||
}; | ||
|
||
const _timeout = fn => { | ||
setTimeout(fn, Math.floor(Math.random() * 2000)); | ||
}; | ||
_timeout(() => { | ||
_timeout(() => { | ||
absn.stop(); | ||
_timeout(() => { | ||
absn.disconnect(); | ||
}); | ||
}); | ||
|
||
if (numLoads < numBuffers) { | ||
_load(); | ||
} | ||
|
||
_recurse(); | ||
}); | ||
}; | ||
|
||
/* setInterval(() => { | ||
while (Math.random() >= 0.000001) {} | ||
}); */ | ||
</script> | ||
</body> | ||
</html> |
Binary file not shown.