mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Implement verification of 'nominal' audio options
The spec doesn't tell us the exact value to use, but a minumum & maximum range of supported values. Just to be consistent with another browser, we follow the values that firefox appears to support from testing the interface on my machine. This function will be used in the AudioBuffer constructor, but is defined in the spec as part of BaseAudioContext.
This commit is contained in:
parent
46ec3681a4
commit
5cb6d495bb
Notes:
sideshowbarker
2024-07-16 23:17:55 +09:00
Author: https://github.com/shannonbooth
Commit: 5cb6d495bb
Pull-request: https://github.com/SerenityOS/serenity/pull/24108
Reviewed-by: https://github.com/trflynn89
2 changed files with 36 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,6 +9,7 @@
|
|||
|
||||
#include <LibWeb/Bindings/BaseAudioContextPrototype.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
||||
namespace Web::WebAudio {
|
||||
|
||||
|
@ -18,6 +20,17 @@ class BaseAudioContext : public DOM::EventTarget {
|
|||
public:
|
||||
virtual ~BaseAudioContext() override;
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer-numberofchannels
|
||||
// > An implementation MUST support at least 32 channels.
|
||||
// Other browsers appear to only allow 32 channels - so let's limit ourselves to that too.
|
||||
static constexpr WebIDL::UnsignedLong MAX_NUMBER_OF_CHANNELS { 32 };
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer-samplerate
|
||||
// > An implementation MUST support sample rates in at least the range 8000 to 96000.
|
||||
// This doesn't seem consistent between browsers. We use what firefox accepts from testing BaseAudioContext.createAudioBuffer.
|
||||
static constexpr float MIN_SAMPLE_RATE { 8000 };
|
||||
static constexpr float MAX_SAMPLE_RATE { 192000 };
|
||||
|
||||
float sample_rate() const { return m_sample_rate; }
|
||||
double current_time() const { return m_current_time; }
|
||||
Bindings::AudioContextState state() const { return m_control_thread_state; }
|
||||
|
@ -29,6 +42,8 @@ public:
|
|||
void set_control_state(Bindings::AudioContextState state) { m_control_thread_state = state; }
|
||||
void set_rendering_state(Bindings::AudioContextState state) { m_rendering_thread_state = state; }
|
||||
|
||||
static WebIDL::ExceptionOr<void> verify_audio_options_inside_nominal_range(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
|
||||
|
||||
protected:
|
||||
explicit BaseAudioContext(JS::Realm&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue