AudioThumbnail shows DC offset for silence

The AudioThumbnail rendering logic adds artificial DC offset to the 8-bit peak data representation. This happens when both min and max get rounded to zero.

In AudioThumbnail::MinMaxValue::setFloat

    if (values[0] == values[1])
    {
        if (values[1] == 127)
            values[0]--;
        else
            values[1]++;
    }

The idea here AFAIK is to avoid empty min/max ranges, and is probably reasonable, but the modification must be symmetric e.g. both values must be shifted. Currently, when the thumbnail gets vertically scaled up, all of the background noise appears to be above the center line, making it look like the audio has DC offset.

Maybe do something like:

    if (values[0] == values[1])
    {
        if (values[1] == 127)
            values[0]--;
        else
            values[1]++;
            
            // Offset the min value too
            if (values[0] > -128) {
                values[0]--;
            }
    }
1 Like