/* * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::WebAudio { struct AudioBufferOptions { WebIDL::UnsignedLong number_of_channels { 1 }; WebIDL::UnsignedLong length {}; float sample_rate {}; }; // 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> create(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, AudioBufferOptions const&); virtual ~AudioBuffer() override; float sample_rate() const; WebIDL::UnsignedLong length() const; double duration() const; WebIDL::UnsignedLong number_of_channels() const; WebIDL::ExceptionOr> get_channel_data(WebIDL::UnsignedLong channel) const; WebIDL::ExceptionOr copy_from_channel(GC::Root const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0) const; WebIDL::ExceptionOr copy_to_channel(GC::Root const&, WebIDL::UnsignedLong channel_number, WebIDL::UnsignedLong buffer_offset = 0); private: explicit AudioBuffer(JS::Realm&, AudioBufferOptions const&); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) 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> 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]] }; }