1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! What the DAC has actually played, as opposed to what the decoder has produced.
//!
//! On the direct-USB path the decoder runs ahead of the speakers by everything
//! sitting between them: the PCM ring and the isochronous transfers already
//! submitted to the bus. The decoder-side position therefore reads ahead of
//! what is audible by that much, and the lead grows with the buffer.
//!
//! This module is the accounting, kept apart from libusb so it can be tested on
//! the host. Frames here are ring frames (one sample per channel; for native DSD
//! one byte per channel), the unit `consumer_frames` and the ring itself use.
//!
//! "Music" frames are frames taken from the ring. Wire silence sent while the
//! stream is held (pause, or the wait for a flushed ring to refill) and padding
//! added when the ring ran dry are not music, and neither are frames the DAC did
//! not take (`iso_transport_loss`).
/// Music frames of one completed transfer that the DAC actually took.
///
/// `frames` is everything queued in the transfer, `music_frames` the part of it
/// that came from the ring, and `lost_frames` what the DAC did not take. Padding
/// sits at the end of a transfer, and loss does too (a timed-out URB cancels its
/// tail, a short packet loses the end of the packet), so lost frames are charged
/// to the padding first and only the remainder to music.
pub
/// Running count of music frames the DAC has taken since the stream started or
/// the ring was last flushed.
///
/// Owned by the output thread. A flush is noticed through the epoch the ring
/// carries: a transfer filled before the flush still completes afterwards, but
/// it holds audio from before the seek and is not counted in the new epoch.
pub
/// Music frames submitted to the bus and not yet completed, for transfers filled
/// in `current_epoch`. Each item is `(epoch, music_frames)` of one in-flight
/// transfer.
pub
/// Frames between the decoder and the DAC: music in the ring plus music
/// submitted and not yet completed.
pub