I am currently dabbeling with programming a real-time audio software and I already got a simple pipeline where notes can be played and released and each note has its own envelope so that the amplitude of each note signal begins and ends at 0 smoothly.
However, I am currently running into the problem that if 2 notes overlap not exactly, there are pop sounds appearing at the intersection points. So for example, if a note sounds from 0 to 1 s and another note from 0.5 to 1.5 s, there are pop sounds at 0.5 and 1 s.
I am not sure why there would be discontinuities there. If there is no overlap or the notes overlap exactly, there are no pop sounds.
Anyone have an idea, what could be the issue?
The samples are mixed via the arithmetic mean and the envelopes I have tried so far were with linear/quadratic fade-in/out. The underlying waves are single sinusoids.
UPDATE
I think, I found the issue. It is the arithmetic mean, I think @KnutInge alluded to that issue, the normalization factor I use is the inverse of the currently active notes, so if that changes from a frame to the next, the amplitude changes drastically.
I am not sure, how to handle this. Should I compute the interpolation factor via the envelope values? Basically something like $$\alpha = \frac{envelope_0}{envelope_0+envelope_1}$$ and then $$sample = \alpha\cdot sample_0 + (1-\alpha)\cdot sample_1$$? This generalizes to arbitrary amounts of active notes, right?