LibWeb/WebAudio: Implement BaseAudioContext#createPanner
Required by Unity Web games.
This commit is contained in:
parent
4f691c2410
commit
3063be11a9
Notes:
github-actions[bot]
2024-12-17 12:39:24 +00:00
Author: https://github.com/Lubrsi Commit: https://github.com/LadybirdBrowser/ladybird/commit/3063be11a91 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2942 Reviewed-by: https://github.com/gmta ✅
5 changed files with 156 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
|||
#include <LibWeb/WebAudio/DynamicsCompressorNode.h>
|
||||
#include <LibWeb/WebAudio/GainNode.h>
|
||||
#include <LibWeb/WebAudio/OscillatorNode.h>
|
||||
#include <LibWeb/WebAudio/PannerNode.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/Promise.h>
|
||||
|
||||
|
@ -111,6 +112,13 @@ WebIDL::ExceptionOr<GC::Ref<GainNode>> BaseAudioContext::create_gain()
|
|||
return GainNode::create(realm(), *this);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createpanner
|
||||
WebIDL::ExceptionOr<GC::Ref<PannerNode>> BaseAudioContext::create_panner()
|
||||
{
|
||||
// Factory method for a PannerNode.
|
||||
return PannerNode::create(realm(), *this);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer
|
||||
WebIDL::ExceptionOr<void> BaseAudioContext::verify_audio_options_inside_nominal_range(JS::Realm& realm, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate)
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
WebIDL::ExceptionOr<GC::Ref<OscillatorNode>> create_oscillator();
|
||||
WebIDL::ExceptionOr<GC::Ref<DynamicsCompressorNode>> create_dynamics_compressor();
|
||||
WebIDL::ExceptionOr<GC::Ref<GainNode>> create_gain();
|
||||
WebIDL::ExceptionOr<GC::Ref<PannerNode>> create_panner();
|
||||
|
||||
GC::Ref<WebIDL::Promise> decode_audio_data(GC::Root<WebIDL::BufferSource>, GC::Ptr<WebIDL::CallbackType>, GC::Ptr<WebIDL::CallbackType>);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#import <WebAudio/DynamicsCompressorNode.idl>
|
||||
#import <WebAudio/GainNode.idl>
|
||||
#import <WebAudio/OscillatorNode.idl>
|
||||
#import <WebAudio/PannerNode.idl>
|
||||
#import <WebIDL/DOMException.idl>
|
||||
|
||||
// https://www.w3.org/TR/webaudio/#enumdef-audiocontextstate
|
||||
|
@ -42,7 +43,7 @@ interface BaseAudioContext : EventTarget {
|
|||
GainNode createGain();
|
||||
[FIXME] IIRFilterNode createIIRFilter (sequence<double> feedforward, sequence<double> feedback);
|
||||
OscillatorNode createOscillator();
|
||||
[FIXME] PannerNode createPanner ();
|
||||
PannerNode createPanner();
|
||||
[FIXME] PeriodicWave createPeriodicWave (sequence<float> real, sequence<float> imag, optional PeriodicWaveConstraints constraints = {});
|
||||
[FIXME] ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);
|
||||
[FIXME] StereoPannerNode createStereoPanner ();
|
||||
|
|
46
Tests/LibWeb/Text/expected/WebAudio/PannerNode.txt
Normal file
46
Tests/LibWeb/Text/expected/WebAudio/PannerNode.txt
Normal file
|
@ -0,0 +1,46 @@
|
|||
PannerNode
|
||||
AudioNode
|
||||
EventTarget
|
||||
Object
|
||||
[object AudioParam] current: 0, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -52, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 100000, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -22051, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 0, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -52, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 100000, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -22051, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 0, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -52, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 100000, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -22051, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 1, default: 1, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -52, default: 1, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 100000, default: 1, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -22051, default: 1, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 0, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -52, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 100000, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -22051, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 0, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -52, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: 100000, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
[object AudioParam] current: -22051, default: 0, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate
|
||||
default panningModel: equalpower
|
||||
default distanceModel: inverse
|
||||
default refDistance: 1
|
||||
default maxDistance: 10000
|
||||
default rolloffFactor: 1
|
||||
default coneInnerAngle: 360
|
||||
default coneOuterAngle: 360
|
||||
default coneOuterGain: 0
|
||||
Did throw RangeError: refDistance cannot be negative
|
||||
Did throw RangeError: rolloffFactor cannot be negative
|
||||
Did throw RangeError: maxDistance cannot be negative
|
||||
Did throw InvalidStateError: coneOuterGain must be in the range of [0, 1]
|
||||
Did throw InvalidStateError: coneOuterGain must be in the range of [0, 1]
|
||||
Did throw RangeError: refDistance cannot be negative
|
||||
Did throw RangeError: rolloffFactor cannot be negative
|
||||
Did throw RangeError: maxDistance cannot be negative
|
||||
Did throw InvalidStateError: coneOuterGain must be in the range of [0, 1]
|
||||
Did throw InvalidStateError: coneOuterGain must be in the range of [0, 1]
|
99
Tests/LibWeb/Text/input/WebAudio/PannerNode.html
Normal file
99
Tests/LibWeb/Text/input/WebAudio/PannerNode.html
Normal file
|
@ -0,0 +1,99 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function dumpAudioParam(param) {
|
||||
println(`${param} current: ${param.value}, default: ${param.defaultValue}, min: ${param.minValue}, max: ${param.maxValue}, rate: ${param.automationRate}`);
|
||||
}
|
||||
|
||||
function checkThrows(func) {
|
||||
try {
|
||||
func();
|
||||
println("FAIL: Did not throw!");
|
||||
} catch (e) {
|
||||
println(`Did throw ${e.name}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
test(() => {
|
||||
const audioContext = new OfflineAudioContext(1, 5000, 44100);
|
||||
|
||||
const panner = audioContext.createPanner();
|
||||
|
||||
// Check prototype
|
||||
let prototype = Object.getPrototypeOf(panner);
|
||||
|
||||
while (prototype) {
|
||||
println(prototype.constructor.name);
|
||||
prototype = Object.getPrototypeOf(prototype);
|
||||
}
|
||||
|
||||
// Audio Params
|
||||
const audioParams = [
|
||||
panner.positionX,
|
||||
panner.positionY,
|
||||
panner.positionZ,
|
||||
panner.orientationX,
|
||||
panner.orientationY,
|
||||
panner.orientationZ,
|
||||
];
|
||||
|
||||
for (const audioParam of audioParams) {
|
||||
dumpAudioParam(audioParam);
|
||||
audioParam.value = -52;
|
||||
dumpAudioParam(audioParam);
|
||||
audioParam.value = 100_000;
|
||||
dumpAudioParam(audioParam);
|
||||
audioParam.value = -22051;
|
||||
dumpAudioParam(audioParam);
|
||||
}
|
||||
|
||||
// Default values
|
||||
println(`default panningModel: ${panner.panningModel}`);
|
||||
println(`default distanceModel: ${panner.distanceModel}`);
|
||||
println(`default refDistance: ${panner.refDistance}`);
|
||||
println(`default maxDistance: ${panner.maxDistance}`);
|
||||
println(`default rolloffFactor: ${panner.rolloffFactor}`);
|
||||
println(`default coneInnerAngle: ${panner.coneInnerAngle}`);
|
||||
println(`default coneOuterAngle: ${panner.coneOuterAngle}`);
|
||||
println(`default coneOuterGain: ${panner.coneOuterGain}`);
|
||||
|
||||
checkThrows(() => {
|
||||
panner.refDistance = -1;
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
panner.rolloffFactor = -1;
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
panner.maxDistance = -1;
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
panner.coneOuterGain = -1;
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
panner.coneOuterGain = 1.23;
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
new PannerNode(audioContext, { refDistance: -1 });
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
new PannerNode(audioContext, { rolloffFactor: -1 });
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
new PannerNode(audioContext, { maxDistance: -1 });
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
new PannerNode(audioContext, { coneOuterGain: -1 });
|
||||
});
|
||||
|
||||
checkThrows(() => {
|
||||
new PannerNode(audioContext, { coneOuterGain: 1.23 });
|
||||
});
|
||||
});
|
||||
</script>
|
Loading…
Add table
Reference in a new issue