Allow Bluetooth DAC estimate settling during silent clock calibration

This commit is contained in:
firestar5683
2026-09-20 11:34:40 -07:00
parent f0950133f6
commit eeffb8ed62
2 changed files with 9 additions and 1 deletions
+3 -1
View File
@@ -25,7 +25,9 @@ class StreamClockBridge:
if (not all(type(value) in (int,float) and math.isfinite(value) for value in (wall,current,dac))
or current<=0 or dac<=0 or not -.02<=dac-current<=5):
raise ValueError('Invalid callback clock sample')
if previous is not None and (wall<previous[0] or current<previous[1] or dac<=previous[2]):
# DAC timestamps are device-delay estimates and may move a few ms during
# Bluetooth queue priming. The offset uses the advancing current clock.
if previous is not None and (wall<previous[0] or current<previous[1]):
raise ValueError('Output callback clock did not advance')
previous=(wall,current,dac)
offsets.append(wall-current)
@@ -53,5 +53,11 @@ class StreamClockBridgeTests(unittest.TestCase):
self.assertAlmostEqual(bridge.offset,-400.)
self.assertAlmostEqual(bridge.dac_wall(501.),101.)
def test_bluetooth_dac_estimate_can_adjust_during_silent_priming(self):
samples=[(100.+i*.015,500.+i*.015,500.+i*.015+.06) for i in range(8)]
samples[4]=(samples[4][0],samples[4][1],samples[3][2]-.002235)
bridge=StreamClockBridge.from_callbacks(samples)
self.assertAlmostEqual(bridge.offset,-400.)
if __name__=='__main__':unittest.main()