LibWeb: Clamp AudioParam's value between min and max

The spec isn't _super_ clear on how this is meant to be done, but the
way I understand this is that we should simply clamp the returned
'current value' between 'min' and 'max'.

Firefox does not appear to do this clamping, but Chrome does.
This commit is contained in:
Shannon Booth 2024-05-02 00:39:06 +12:00 committed by Andreas Kling
parent e2b5ff2450
commit 94354ea7fb
Notes: sideshowbarker 2024-07-17 02:39:10 +09:00
3 changed files with 10 additions and 1 deletions

View File

@ -10,3 +10,5 @@ Error: 'InvalidStateError: Oscillator node type cannot be set to 'custom'', type
oscillator node type: 'triangle'
[object AudioParam] current: 440, default: 440, min: -22050, max: 22050, rate: a-rate
[object AudioParam] current: -52, default: 440, min: -22050, max: 22050, rate: a-rate
[object AudioParam] current: 22050, default: 440, min: -22050, max: 22050, rate: a-rate
[object AudioParam] current: -22050, default: 440, min: -22050, max: 22050, rate: a-rate

View File

@ -42,5 +42,9 @@
dumpAudioParam(frequency);
frequency.value = -52;
dumpAudioParam(frequency);
frequency.value = 100_000;
dumpAudioParam(frequency);
frequency.value = -22051;
dumpAudioParam(frequency);
});
</script>

View File

@ -31,9 +31,12 @@ JS::NonnullGCPtr<AudioParam> AudioParam::create(JS::Realm& realm, float default_
AudioParam::~AudioParam() = default;
// https://webaudio.github.io/web-audio-api/#dom-audioparam-value
// https://webaudio.github.io/web-audio-api/#simple-nominal-range
float AudioParam::value() const
{
return m_current_value;
// Each AudioParam includes minValue and maxValue attributes that together form the simple nominal range
// for the parameter. In effect, value of the parameter is clamped to the range [minValue, maxValue].
return clamp(m_current_value, min_value(), max_value());
}
// https://webaudio.github.io/web-audio-api/#dom-audioparam-value