Skip to content

Commit

Permalink
LibWeb: Add BaseAudioContext.createStereoPanner() factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 committed Jan 17, 2025
1 parent 33e8c10 commit f025379
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Libraries/LibWeb/WebAudio/BaseAudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ WebIDL::ExceptionOr<GC::Ref<PeriodicWave>> BaseAudioContext::create_periodic_wav
return PeriodicWave::construct_impl(realm(), *this, options);
}

// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createstereopanner
WebIDL::ExceptionOr<GC::Ref<StereoPannerNode>> BaseAudioContext::create_stereo_panner()
{
// Factory method for a StereoPannerNode.
return StereoPannerNode::create(realm(), *this);
}

WebIDL::ExceptionOr<void> BaseAudioContext::verify_audio_options_inside_nominal_range(JS::Realm& realm, float sample_rate)
{
if (sample_rate < MIN_SAMPLE_RATE || sample_rate > MAX_SAMPLE_RATE)
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibWeb/WebAudio/BaseAudioContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <LibWeb/WebAudio/ConstantSourceNode.h>
#include <LibWeb/WebAudio/DelayNode.h>
#include <LibWeb/WebAudio/PeriodicWave.h>
#include <LibWeb/WebAudio/StereoPannerNode.h>
#include <LibWeb/WebIDL/Types.h>

namespace Web::WebAudio {
Expand Down Expand Up @@ -74,6 +75,7 @@ class BaseAudioContext : public DOM::EventTarget {
WebIDL::ExceptionOr<GC::Ref<GainNode>> create_gain();
WebIDL::ExceptionOr<GC::Ref<PannerNode>> create_panner();
WebIDL::ExceptionOr<GC::Ref<PeriodicWave>> create_periodic_wave(Vector<float> const& real, Vector<float> const& imag, Optional<PeriodicWaveConstraints> const& constraints = {});
WebIDL::ExceptionOr<GC::Ref<StereoPannerNode>> create_stereo_panner();

GC::Ref<WebIDL::Promise> decode_audio_data(GC::Root<WebIDL::BufferSource>, GC::Ptr<WebIDL::CallbackType>, GC::Ptr<WebIDL::CallbackType>);

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/WebAudio/BaseAudioContext.idl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface BaseAudioContext : EventTarget {
PannerNode createPanner();
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 ();
StereoPannerNode createStereoPanner ();
[FIXME] WaveShaperNode createWaveShaper ();

Promise<AudioBuffer> decodeAudioData (ArrayBuffer audioData, optional DecodeSuccessCallback? successCallback, optional DecodeErrorCallback? errorCallback);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Harness status: OK

Found 306 tests
Found 317 tests

297 Pass
9 Fail
309 Pass
8 Fail
Pass # AUDIT TASK RUNNER STARTED.
Pass Executing "initialize"
Pass Executing "Offline createGain"
Pass Executing "Offline createDelay"
Pass Executing "Offline createBufferSource"
Fail Executing "Offline createStereoPanner"
Pass Executing "Offline createStereoPanner"
Pass Executing "Offline createDynamicsCompressor"
Pass Executing "Offline createBiquadFilter"
Pass Executing "Offline createOscillator"
Expand Down Expand Up @@ -71,6 +71,17 @@ Pass AudioBufferSourceNode.detune.maxValue is read-only is equal to true.
Pass Nominal ranges for AudioParam(s) of AudioBufferSourceNode are correct
Pass < [Offline createBufferSource] All assertions passed. (total 13 assertions)
Pass > [Offline createStereoPanner]
Pass StereoPannerNode.pan.minValue is equal to -1.
Pass StereoPannerNode.pan.maxValue is equal to 1.
Pass StereoPannerNode.pan.minValue = 42 is not equal to 42.
Pass StereoPannerNode.pan.minValue is read-only is equal to true.
Pass StereoPannerNode.pan.maxValue = 42 is not equal to 42.
Pass StereoPannerNode.pan.maxValue is read-only is equal to true.
Pass Set StereoPannerNode.pan.value = -3 is equal to -1.
Pass Set StereoPannerNode.pan.value = 3 is equal to 1.
Pass StereoPannerNode.pan was clipped to lie within the nominal range is equal to true.
Pass Nominal ranges for AudioParam(s) of StereoPannerNode are correct
Pass < [Offline createStereoPanner] All assertions passed. (total 10 assertions)
Pass > [Offline createDynamicsCompressor]
Pass DynamicsCompressorNode.threshold.minValue is equal to -100.
Pass DynamicsCompressorNode.threshold.maxValue is equal to 0.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Harness status: OK

Found 15 tests

15 Pass
Pass # AUDIT TASK RUNNER STARTED.
Pass Executing "test"
Pass Audit report
Pass > [test] Attributes and basic functionality of StereoPannerNode
Pass panner.numberOfInputs is equal to 1.
Pass panner.numberOfOutputs is equal to 1.
Pass panner.pan.defaultValue is equal to 0.
Pass panner.pan.value = 1.0 did not throw an exception.
Pass panner.pan.value is equal to 1.
Pass panner.channelCount = 1 did not throw an exception.
Pass panner.channelCount = 3 threw NotSupportedError: "StereoPannerNode does not support channel count greater than 2".
Pass panner.channelCountMode = "explicit" did not throw an exception.
Pass panner.channelCountMode = "max" threw NotSupportedError: "StereoPannerNode does not support 'max' as channelCountMode.".
Pass < [test] All assertions passed. (total 9 assertions)
Pass # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>
stereopannernode-basic.html
</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../resources/audit-util.js"></script>
<script src="../../resources/audit.js"></script>
</head>
<body>
<script id="layout-test-code">
let audit = Audit.createTaskRunner();

audit.define(
{
label: 'test',
description:
'Attributes and basic functionality of StereoPannerNode'
},
(task, should) => {

let context = new AudioContext();
let panner = context.createStereoPanner();

should(panner.numberOfInputs, 'panner.numberOfInputs').beEqualTo(1);
should(panner.numberOfOutputs, 'panner.numberOfOutputs')
.beEqualTo(1);
should(panner.pan.defaultValue, 'panner.pan.defaultValue')
.beEqualTo(0.0);
should(() => panner.pan.value = 1.0, 'panner.pan.value = 1.0')
.notThrow();
should(panner.pan.value, 'panner.pan.value').beEqualTo(1.0);

should(() => panner.channelCount = 1, 'panner.channelCount = 1')
.notThrow();
should(() => panner.channelCount = 3, 'panner.channelCount = 3')
.throw();
should(
() => panner.channelCountMode = 'explicit',
'panner.channelCountMode = "explicit"')
.notThrow();
should(
() => panner.channelCountMode = 'max',
'panner.channelCountMode = "max"')
.throw();

task.done();
});
audit.run();
</script>
</body>
</html>

0 comments on commit f025379

Please sign in to comment.