WebAudio/web-audio-api

Unclearness regarding the DC-offset in PeriodicWave

dd-pardal opened this issue · 3 comments

Describe the issue

Section 1.28.3.1 states that the element of the [[real]] array at index 0 is the DC-offset but the formula for the waveform in section 1.28.4 doesn't depend on it. Is this value being purposefully ignored? If so, adding a note about it in the spec would be helpful.

Where Is It

Section 1.28.

Additional Information

Firefox and Chromium seem to ignore this value.

If I remember correctly, being able to DC-offset is intended, back when the PeriodicWave object was not really specified. We when wrote the formula, but must have made a mistake there, dropping the DC-offset part.

Chrome and Firefox currently ignore the value (specifically, set the first real and imaginary coefficient to 0 before doing the inverse Fourier transform), but could use it.

It seems somewhat useful for control signal at least (where there's no dynamic range concerns, and can go outside of [-1.0, 1.0]).

This is correctly specified in https://webaudio.github.io/web-audio-api/#PeriodicWave-constructors (step 3.), and we can't change it now. Authors can use the ConstantSourceNode to add a DC-offset, and we'll change the spec text to make it clear that this cannot produce a DC-Offset.

hoch commented

TPAC 2024:

In 1.28.3.1. Dictionary PeriodicWaveOptions Members, we can modify to clarify this point:

The real parameter represents an array of cosine terms. The first element (index 0) is the DC-offset of the periodic waveform. The second element (index 1) represents the fundmental frequency. The third represents the first overtone and so on.