mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-13 18:36:38 +02:00
Previously we were inconsistent by generating code for enum definitions but not generating code for dictionaries. With future changes to the IDL generator to expose helpers to convert to and from IDL values this produced circular depdendencies. To solve this problem, also generate the dictionary definitions in bindings headers.
61 lines
2.5 KiB
C++
61 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Vector.h>
|
|
#include <LibJS/Forward.h>
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
#include <LibWeb/WebIDL/Buffers.h>
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
|
#include <LibWeb/WebIDL/Types.h>
|
|
|
|
namespace Web::WebAudio {
|
|
|
|
// https://webaudio.github.io/web-audio-api/#AudioBuffer
|
|
class AudioBuffer final : public Bindings::PlatformObject {
|
|
WEB_PLATFORM_OBJECT(AudioBuffer, Bindings::PlatformObject);
|
|
GC_DECLARE_ALLOCATOR(AudioBuffer);
|
|
|
|
public:
|
|
static WebIDL::ExceptionOr<GC::Ref<AudioBuffer>> create(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);
|
|
static WebIDL::ExceptionOr<GC::Ref<AudioBuffer>> construct_impl(JS::Realm&, Bindings::AudioBufferOptions const&);
|
|
|
|
virtual ~AudioBuffer() override;
|
|
|
|
float sample_rate() const;
|
|
WebIDL::UnsignedLong length() const;
|
|
double duration() const;
|
|
WebIDL::UnsignedLong number_of_channels() const;
|
|
WebIDL::ExceptionOr<GC::Ref<JS::Float32Array>> get_channel_data(WebIDL::UnsignedLong channel) const;
|
|
WebIDL::ExceptionOr<void> copy_from_channel(GC::Root<JS::Float32Array> const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0) const;
|
|
WebIDL::ExceptionOr<void> copy_to_channel(GC::Root<JS::Float32Array> const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0);
|
|
|
|
private:
|
|
explicit AudioBuffer(JS::Realm&, Bindings::AudioBufferOptions const&);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
virtual size_t external_memory_size() const override;
|
|
|
|
// https://webaudio.github.io/web-audio-api/#dom-audiobuffer-number-of-channels-slot
|
|
// The number of audio channels for this AudioBuffer, which is an unsigned long.
|
|
//
|
|
// https://webaudio.github.io/web-audio-api/#dom-audiobuffer-internal-data-slot
|
|
// A data block holding the audio sample data.
|
|
Vector<GC::Ref<JS::Float32Array>> m_channels; // [[internal data]] / [[number_of_channels]]
|
|
|
|
// https://webaudio.github.io/web-audio-api/#dom-audiobuffer-length-slot
|
|
// The length of each channel of this AudioBuffer, which is an unsigned long.
|
|
WebIDL::UnsignedLong m_length {}; // [[length]]
|
|
|
|
// https://webaudio.github.io/web-audio-api/#dom-audiobuffer-sample-rate-slot
|
|
// The sample-rate, in Hz, of this AudioBuffer, a float.
|
|
float m_sample_rate {}; // [[sample rate]]
|
|
};
|
|
|
|
}
|