Skip to content

Commit

Permalink
LibWeb: Initialize AnalyserNode previous block at construction time
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 authored and Lubrsi committed Feb 13, 2025
1 parent c9cd795 commit 4bb22c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Libraries/LibWeb/WebAudio/AnalyserNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ WebIDL::ExceptionOr<void> AnalyserNode::get_byte_time_domain_data(GC::Root<WebID
// https://webaudio.github.io/web-audio-api/#dom-analysernode-fftsize
WebIDL::ExceptionOr<void> AnalyserNode::set_fft_size(unsigned long fft_size)
{
if (fft_size < 32 || fft_size > 32768 || (fft_size & (fft_size - 1)) != 0)
if (fft_size < 32 || fft_size > 32768 || !is_power_of_two(fft_size))
return WebIDL::IndexSizeError::create(realm(), "Analyser node fftSize not a power of 2 between 32 and 32768"_string);

// reset previous block to 0s
Expand Down Expand Up @@ -304,9 +304,6 @@ WebIDL::ExceptionOr<void> AnalyserNode::set_smoothing_time_constant(double smoot

WebIDL::ExceptionOr<GC::Ref<AnalyserNode>> AnalyserNode::construct_impl(JS::Realm& realm, GC::Ref<BaseAudioContext> context, AnalyserOptions const& options)
{
if (options.fft_size < 32 || options.fft_size > 32768 || !is_power_of_two(options.fft_size))
return WebIDL::IndexSizeError::create(realm, "Analyser node fftSize not a power of 2 between 32 and 32768"_string);

if (options.min_decibels >= options.max_decibels)
return WebIDL::IndexSizeError::create(realm, "Analyser node minDecibels greater than maxDecibels"_string);

Expand All @@ -317,6 +314,7 @@ WebIDL::ExceptionOr<GC::Ref<AnalyserNode>> AnalyserNode::construct_impl(JS::Real
// MUST initialize the AudioNode this, with context and options as arguments.

auto node = realm.create<AnalyserNode>(realm, context, options);
TRY(node->set_fft_size(options.fft_size));

// Default options for channel count and interpretation
// https://webaudio.github.io/web-audio-api/#AnalyserNode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<script>
const context = new OfflineAudioContext(1, 1, 44100)
const analyser = context.createAnalyser()
const dataArray = new Float32Array(analyser.frequencyBinCount)
analyser.getFloatFrequencyData(dataArray);
</script>

0 comments on commit 4bb22c5

Please sign in to comment.