From ae5c4aad9b112bbb9b70e53122e0d73486da99c9 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 1 Feb 2024 23:21:12 +0100 Subject: [PATCH] add xrun handling to the examples it's very primitive, but it shows adequately what can happen and what to do about it minimally (that is, complain and move on). --- isine.py | 3 ++- playbacktest.py | 3 ++- playwav.py | 3 ++- recordtest.py | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/isine.py b/isine.py index c792818..3cc764d 100644 --- a/isine.py +++ b/isine.py @@ -84,7 +84,8 @@ class SinePlayer(Thread): except Empty: pass if buffer: - self.device.write(buffer) + if self.device.write(buffer) < 0: + print("Playback buffer underrun! Continuing nonetheless ...") isine = SinePlayer() diff --git a/playbacktest.py b/playbacktest.py index 74232ca..8551fe8 100755 --- a/playbacktest.py +++ b/playbacktest.py @@ -47,7 +47,8 @@ if __name__ == '__main__': # Read data from stdin data = f.read(320) while data: - out.write(data) + if out.write(data) < 0: + print("Playback buffer underrun! Continuing nonetheless ...") data = f.read(320) out.close() diff --git a/playwav.py b/playwav.py index bb7f30d..b91c600 100755 --- a/playwav.py +++ b/playwav.py @@ -39,7 +39,8 @@ def play(device, f): data = f.readframes(periodsize) while data: # Read data from stdin - device.write(data) + if device.write(data) < 0: + print("Playback buffer underrun! Continuing nonetheless ...") data = f.readframes(periodsize) diff --git a/recordtest.py b/recordtest.py index 62d13ff..f84865d 100755 --- a/recordtest.py +++ b/recordtest.py @@ -59,6 +59,8 @@ if __name__ == '__main__': # Read data from device l, data = inp.read() - if l: + if l < 0: + print("Capture buffer overrun! Continuing nonetheless ...") + elif l: f.write(data) time.sleep(.001)