|
69 | 69 | assert bleep.flags.c_contiguous |
70 | 70 | bleeplist.append(bleep) |
71 | 71 |
|
| 72 | +actionlist = [] |
72 | 73 | with rtmixer.Mixer(device=device, channels=channels, blocksize=blocksize, |
73 | 74 | samplerate=samplerate, latency=latency, qsize=qsize) as m: |
74 | 75 | start_time = m.time |
75 | | - for bleep in bleeplist: |
| 76 | + actionlist = [ |
76 | 77 | m.play_buffer(bleep, |
77 | 78 | channels=[r.randint(channels) + 1], |
78 | | - start=start_time + r.uniform(start_min, start_max)) |
| 79 | + start=start_time + r.uniform(start_min, start_max), |
| 80 | + allow_belated=False) |
| 81 | + for bleep in bleeplist |
| 82 | + ] |
79 | 83 | while m.actions: |
80 | 84 | sd.sleep(100) |
81 | | - # TODO: get list of actions and check if all were started on time? |
82 | 85 | print('{0} buffer underflows in {1} processed audio blocks'.format( |
83 | 86 | m.stats.output_underflows, m.stats.blocks)) |
| 87 | + |
| 88 | +belated = 0 |
| 89 | +min_delay = np.inf |
| 90 | +max_delay = -np.inf |
| 91 | +for action in actionlist: |
| 92 | + assert action.type == rtmixer.PLAY_BUFFER |
| 93 | + # NB: action.allow_belated might have been invalidated |
| 94 | + assert action.requested_time != 0 |
| 95 | + if not action.actual_time: |
| 96 | + belated += 1 |
| 97 | + assert action.done_frames == 0 |
| 98 | + continue |
| 99 | + assert action.done_frames == action.total_frames |
| 100 | + delay = action.actual_time - action.requested_time |
| 101 | + if delay > max_delay: |
| 102 | + max_delay = delay |
| 103 | + if delay < min_delay: |
| 104 | + min_delay = delay |
| 105 | + |
| 106 | +print('total number of bleeps:', len(actionlist)) |
| 107 | +print('belated bleeps (not played):', belated) |
| 108 | +print('maxiumum delay (in usec):', max_delay * 1000 * 1000) |
| 109 | +print('maxiumum negative delay: ', -min_delay * 1000 * 1000) |
| 110 | +print('half sampling period: ', 0.5 * 1000 * 1000 / samplerate) |
0 commit comments