Skip to content

Commit cdd00d8

Browse files
committed
Use .stats attribute in examples and other example updates
1 parent d335cf5 commit cdd00d8

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

examples/bleeperoo.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
#!/usr/bin/env python3
2+
"""Play some random bleeps.
3+
4+
This example shows the feature of playing a buffer at a given absolute time.
5+
Since all play_buffer() invocations are (deliberately) done at once, this puts
6+
some strain on the "action queue".
7+
The "qsize" has to be increased in order to handle this.
8+
9+
This example also shows that NumPy arrays can be used, as long as they are
10+
C-contiguous and use the 'float32' data type.
11+
12+
"""
213

314
from __future__ import division # Only needed for Python 2.x
415
import numpy as np
@@ -13,6 +24,7 @@
1324
samplerate = 44100
1425

1526
bleeps = 300
27+
qsize = 512 # Must be a power of 2
1628

1729
attack = 0.005
1830
release = 0.1
@@ -58,12 +70,13 @@
5870
bleeplist.append(bleep)
5971

6072
with rtmixer.Mixer(device=device, channels=channels, blocksize=blocksize,
61-
samplerate=samplerate, latency=latency, qsize=512) as m:
73+
samplerate=samplerate, latency=latency, qsize=qsize) as m:
6274
start_time = m.time
6375
for bleep in bleeplist:
6476
m.play_buffer(bleep,
6577
channels=[r.randint(channels) + 1],
6678
start=start_time + r.uniform(start_min, start_max))
6779
while m.actions:
6880
sd.sleep(100)
69-
# TODO: check for xruns
81+
print('{0} buffer underflows in {1} processed audio blocks'.format(
82+
m.stats.output_underflows, m.stats.blocks))

examples/delay.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
print('press Return to quit')
2828
print('#' * 80)
2929
input()
30-
# TODO: check xruns
30+
print('input underflows:', stream.stats.input_underflows)
31+
print('input overflows:', stream.stats.input_overflows)
32+
print('output underflows:', stream.stats.output_underflows)

examples/play_file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@
3838
if written < size:
3939
break
4040
m.wait(action)
41-
# TODO: check for xruns and ringbuffer errors
41+
# TODO: check for ringbuffer errors
42+
if action.stats.output_underflows:
43+
print('output underflows:', action.stats.output_underflows)

examples/plot_input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ def update_plot(frame):
7676
q = rtmixer.RingBuffer(elementsize, stepsize * qsize)
7777
action = stream.record_ringbuffer(q)
7878
plt.show()
79+
# TODO: check for ringbuffer errors?
7980
print('Input overflows:', action.stats.input_overflows)

0 commit comments

Comments
 (0)