shorepine / amy

AMY - the Additive Music synthesizer librarY

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tests: Discontinuity in PWM

dpwe opened this issue · comments

Looking at tests/ref/TestPWM.wav, there's a big discontinuity in the DC offset at t=0.325 sec.

This looks a lot like similar problems we had at one point in the SAW waveforms resulting from the per-block offset calculation.

Digging in to this, it comes from the jumps in PWM phase as it's modulated. So in one 256 sample block, the delay of the negative-going pulse is a constant, say, 78 samples. Then it's the next block, the duty has been modulated by 0.035 of a cycle, and now the negative pulse is being read from the lookup table with a skip of 4.7 samples before the sample point of the last sample written in the previous block. If we're in the middle of the high-amplitude part of the impulse waveform, we significantly mess up the energy. But that's relatively rare for the highly concentrated impulse waveforms, so much of the time it looks like it's working.

Fixed in 8a3d209 by adding slight frequency modulation to the negative-going edges to ensure the phase exactly hits the projected final value at the end of the block. Involves a one-block delay in PWM (mediated by new field msynth[osc].last_duty).