The average_period_set variable can be accessed in different threads, so always lock it when reading. Furthermore when switching to averaging mode we should make sure we don't have cached buffers that aren't used in that mode. And any modeswitch will cause the latency to change, so we should post a NewLatency message