News for hackers. Stuff that matters.
Re:Variable duty cycle square waves with the Web Audio API by em3rgent0rdr on Monday April 07, 2025 @02:20PM (#43614359)
More precisely "pulse width" would be a time, while "duty cycle" would be a percent.

And while when going from 0% to 50% duty cycle it could be said that "a square wave with a low pulse width will sound thinner than one with a high pulse width", however, once you go past 50% duty cycle the situation reverses. So a 25% duty cycle would sound almost identical to a 75% duty cycle...the amplitudes of their Fourier transform components would be identical.

Re:Variable duty cycle square waves with the Web Audio API by hunter2_ on Monday April 07, 2025 @03:07PM (#43614775)
> almost identical ... components would be identical

I'm having a tough time reconciling how the former could be almost identical while the latter is identical. I guess the former involves a human listening through a speaker which has asymmetric imperfections (maybe the speaker moves outward more easily than it moves inward, or a DC offset in the signal leads to compression in the high-excursion side that doesn't exist on the low-excursion side, etc.) whereas the FFT readout doesn't necessarily have a speaker in the system at all.

[dead]
Re:Variable duty cycle square waves with the Web Audio API by hunter2_ on Monday April 07, 2025 @08:09PM (#43617180)
Good point. If I have 2 oscillators, and no control over their phase as they mix, then an option to choose 25% vs 75% for one of them would at least offer some variation instead of none.

As for compression, this [0] is a good intro. Most commonly it is applied to a signal deliberately to achieve a desired outcome, but I'm referring to a (generally) undesired speaker nonlinearity [1] near its maximum power handling capacity.

[0] https://en.wikipedia.org/wiki/Dynamic_range_compression

[1] https://marshallforum.com/threads/what-exactly-does-speaker-...

Re:Variable duty cycle square waves with the Web Audio API by recursive on Monday April 07, 2025 @04:18PM (#43615517)
Different linearity properties on the positive and negative side would be pretty bad for a speaker, but possible. In the case of a square wave, non-linearity would be identical to a fixed amplitude change though, possibly with a DC bias.

Based on the gameboy wiki I looked up, the phase of the 25% duty and 75% duty are such that they are inverse of each other, seemingly eliminating the possibility of combining the two for different waveforms.