forked from auracaster/pyalsaaudio
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).
This commit is contained in:
3
isine.py
3
isine.py
@@ -84,7 +84,8 @@ class SinePlayer(Thread):
|
|||||||
except Empty:
|
except Empty:
|
||||||
pass
|
pass
|
||||||
if buffer:
|
if buffer:
|
||||||
self.device.write(buffer)
|
if self.device.write(buffer) < 0:
|
||||||
|
print("Playback buffer underrun! Continuing nonetheless ...")
|
||||||
|
|
||||||
|
|
||||||
isine = SinePlayer()
|
isine = SinePlayer()
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ if __name__ == '__main__':
|
|||||||
# Read data from stdin
|
# Read data from stdin
|
||||||
data = f.read(320)
|
data = f.read(320)
|
||||||
while data:
|
while data:
|
||||||
out.write(data)
|
if out.write(data) < 0:
|
||||||
|
print("Playback buffer underrun! Continuing nonetheless ...")
|
||||||
data = f.read(320)
|
data = f.read(320)
|
||||||
out.close()
|
out.close()
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ def play(device, f):
|
|||||||
data = f.readframes(periodsize)
|
data = f.readframes(periodsize)
|
||||||
while data:
|
while data:
|
||||||
# Read data from stdin
|
# Read data from stdin
|
||||||
device.write(data)
|
if device.write(data) < 0:
|
||||||
|
print("Playback buffer underrun! Continuing nonetheless ...")
|
||||||
data = f.readframes(periodsize)
|
data = f.readframes(periodsize)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ if __name__ == '__main__':
|
|||||||
# Read data from device
|
# Read data from device
|
||||||
l, data = inp.read()
|
l, data = inp.read()
|
||||||
|
|
||||||
if l:
|
if l < 0:
|
||||||
|
print("Capture buffer overrun! Continuing nonetheless ...")
|
||||||
|
elif l:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
time.sleep(.001)
|
time.sleep(.001)
|
||||||
|
|||||||
Reference in New Issue
Block a user