Skip to content

Commit d0e1b2e

Browse files
committed
Examples: rename "q" to "rb"
... in oder to avoid confusion with the built-in queue.Queue and becauase PortAudio also calls it "ring buffer" and not "queue".
1 parent b2b64d2 commit d0e1b2e

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

examples/delay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
samplerate = 48000
1111
safety = 0.1 # Shouldn't be less than the duration of an audio block
1212

13-
qsize = 2**math.ceil(math.log2((delay + safety) * samplerate))
13+
rb_size = 2**math.ceil(math.log2((delay + safety) * samplerate))
1414

1515
stream = rtmixer.MixerAndRecorder(
1616
channels=channels, blocksize=blocksize, samplerate=samplerate,
1717
latency=latency)
1818
with stream:
1919
samplesize = 4
2020
assert {samplesize} == set(stream.samplesize)
21-
q = rtmixer.RingBuffer(samplesize * channels, qsize)
21+
rb = rtmixer.RingBuffer(samplesize * channels, rb_size)
2222
start = stream.time + safety
23-
stream.record_ringbuffer(q, start=start, allow_belated=False)
24-
stream.play_ringbuffer(q, start=start + delay, allow_belated=False)
23+
stream.record_ringbuffer(rb, start=start, allow_belated=False)
24+
stream.play_ringbuffer(rb, start=start + delay, allow_belated=False)
2525
# TODO: check if start was successful
2626
print('#' * 80)
2727
print('press Return to quit')

examples/play_file.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@
1111
playback_blocksize = 256
1212
latency = 0
1313
reading_blocksize = 1024
14-
reading_qsize = 16 # Number of blocks, has to be power of two
14+
rb_size = 16 # Number of blocks, has to be power of two
1515

1616
with sf.SoundFile(filename) as f:
1717
with rtmixer.Mixer(channels=f.channels,
1818
blocksize=playback_blocksize,
1919
samplerate=f.samplerate, latency=latency) as m:
2020
elementsize = f.channels * m.samplesize
21-
q = rtmixer.RingBuffer(elementsize, reading_blocksize * reading_qsize)
21+
rb = rtmixer.RingBuffer(elementsize, reading_blocksize * rb_size)
2222
# Pre-fill ringbuffer:
23-
_, buf, _ = q.get_write_buffers(reading_blocksize * reading_qsize)
23+
_, buf, _ = rb.get_write_buffers(reading_blocksize * rb_size)
2424
written = f.buffer_read_into(buf, dtype='float32')
25-
q.advance_write_index(written)
26-
action = m.play_ringbuffer(q)
25+
rb.advance_write_index(written)
26+
action = m.play_ringbuffer(rb)
2727
while True:
28-
while q.write_available < reading_blocksize:
28+
while rb.write_available < reading_blocksize:
2929
if action not in m.actions:
3030
break
3131
sd.sleep(int(1000 * reading_blocksize / f.samplerate))
3232
if action not in m.actions:
3333
break
34-
size, buf1, buf2 = q.get_write_buffers(reading_blocksize)
34+
size, buf1, buf2 = rb.get_write_buffers(reading_blocksize)
3535
assert not buf2
3636
written = f.buffer_read_into(buf1, dtype='float32')
37-
q.advance_write_index(written)
37+
rb.advance_write_index(written)
3838
if written < size:
3939
break
4040
m.wait(action)

0 commit comments

Comments
 (0)