Direct2D Part 3

Yeah, there’s some discussion to do with confusion around the implementation here:

I’m wondering what might be a good way to fix it in line with the discussion in these threads.
The code looks a little different than it did at the time that thread was written, but I think the hotspot is still the same, the logic of the pushSample() method:

void pushSample (float newSample) noexcept
{
    if (--subSample <= 0)
    {
        if (++nextSample == levels.size())
            nextSample = 0;

        levels.getReference (nextSample) = value;
        subSample = owner.getSamplesPerBlock();
        value = Range<float> (newSample, newSample);
    }
    else
    {
        value = value.getUnionWith (newSample);
    }
}

One easy improvement is replacing

value = Range (newSample, newSample);

with

value.setStart(newSample);
value.setEnd(newSample);

to avoid calling the Range constructor once every buffer.

Beyond that, I’m guessing it might be necessary to rebuffer and display a range of samples slightly later to ensure constant availability of the samples to be added next to the drawing routine. It’s interesting though that the scrolling is totally smooth on Linux and macOS but not on Windows though.

As an aside, in other recent work, I noticed Windows Audio having inconsistency wrt latency reported using the same AudioLatencyDemo, and this is not observed on the same machine running macOS or Linux. You could run the same latency test again and again and get slightly different results each time, with a skew of about 5 samples.