PolyluteDocs polylute.app

Concepts

The USB transport

How the samples travel from Polylute to your DAC, why there is a short silence at the start, and who sets the pace.

On this page

In short

  • On USB Direct, Polylute cuts the samples into tiny packets and sends them to the DAC on a steady beat, many thousands of times a second.
  • A ring of small buffers keeps the DAC fed even if the phone is busy for a moment, so one late wake-up does not become a dropout.
  • The DAC sets the pace, not the phone. It tells Polylute how many samples it wants next.
  • Every start begins with a short silence, and pauses and skips fade. That is deliberate, and it is why those moments are not sample-for-sample copies of the file.

How it works

The USB ring and the feedbackDecoded samples wait in a queue. A high-priority thread feeds a ring of small USB buffers. The phone's USB controller sends them to the DAC. The DAC answers with a feedback value saying how many samples it needs next, and the thread uses it. Decoded samples wait in a queue A high-priority thread feeds the ring The USB ring many small buffers in flight The phone’s USB controller sends them Your DAC plays them feedback
From queue to DAC. Amber marks the ring. The dashed line is the DAC talking back.

In words

Decoded samples wait in a queue. A high-priority thread feeds them into a ring of small USB buffers. The phone’s USB controller sends the buffers to the DAC, which plays them. Along the way, the DAC sends back a feedback value that says how many samples it needs next, and the thread uses it to decide how much to put in the next buffer.

Why the DAC sets the pace

A DAC has its own clock. The phone has another one. Two clocks that are supposed to agree never agree exactly, and if the phone simply sent samples at its own pace, the DAC would slowly run short or overflow. Many USB DACs solve this by telling the phone how many samples they want in the next moment. Polylute follows that answer. When a DAC’s answer stops making sense, Polylute stops following it: see When a DAC misbehaves.

What happens at the start, at a pause and at a resume

A start, a pause and a resumeA new song starts with a stretch of silence, a short fade in, and then music. A pause fades out, keeps a quiet stream going for a while, and then goes idle. Playing again after a long pause starts with a short stretch of silence and then music. A new song silence fade music Pause music fade quiet idle Play again after a long pause silence music Dashed: digital silence. Solid amber: music.
Three moments. Dashed is digital silence. Solid amber is music.

In words

A new song starts with a stretch of silence, then a very short fade in, then music. A pause fades out, then Polylute keeps sending quiet for a little while before it calls the output idle. Playing again after a long pause starts with a shorter stretch of silence, then music.

The silence is not an accident. It gives the DAC time to lock its clock without cutting off the first note, and it gives the ring a head start. The fades at cuts stop clicks when you pause, seek or skip.

Why we built it this way

A deep ring. Android is not a real-time system. Our thread runs at a raised priority, but the phone can still make it wait. During development we saw it wait nearly a tenth of a second once, and the DAC went without data for a moment. So the ring holds about a tenth of a second of audio, enough to ride out a stall like that. It costs a little: a pause, seek or skip is heard a fraction of a second later, and a new stream starts with a short silence. We think that is a fair price for not dropping out.

A queue measured in time. The queue of waiting samples is limited by duration, not by the number of buffers. A buffer holds a fixed number of samples, so counting buffers would give far less headroom at high sample rates, exactly where the data rate is highest. A duration gives the same safety margin at every rate.

Fades where the music is cut. A hard cut in a waveform clicks. So pause, seek and skip fade over a few milliseconds. The cost is that those moments are not copies of the file, which is why they are outside what we measured in What “bit-perfect” means here.

Only USB Audio Class 2. Polylute drives DACs that follow the USB Audio Class 2 standard, because it needs the DAC’s clock and its isochronous output to be described in a way it can read. A DAC that follows the older Class 1 standard is not claimed by Polylute and stays with Android. We do not promise every Class 2 DAC will work: only the ones in Supported hardware and what we tested were tested.

For the curious

For the curiousThe numbers behind the transport
  • USB packets for a high-speed DAC are 125 µs apart. Eight of them make one transfer (a URB) of 1 ms.
  • The ring holds 128 transfers, so 128 ms of audio on the wire.
  • The queue of waiting samples is limited to about 1.44 s (the writer is told to wait) and a hard cap of about 11.9 s.
  • A new stream starts with about 128 ms of zeros. After a long pause, resuming starts with about 50 ms. After a skip or a seek, the output keeps about 110 ms of silence in front until the first new buffer is ready.
  • After a pause fades out (8 ms), Polylute keeps sending silence for 2 seconds before it calls the output idle. A first sound after a cut fades in over 15 ms.
  • The 128 ms ring survives a pause in the writer of about 100 ms with room to spare. The price is the extra latency on a pause, a seek or a skip, and some memory for the buffers.
For the curiousHow the feedback comes back

The feedback is a small number from the DAC, in a fixed-point format (16.16), once per interval. It says how many samples per interval the DAC wants. Polylute keeps a running average of readings it trusts, so that it has a healthy value to fall back on when the DAC gives a reading it should not follow.

Tested on HONOR LGN-NX3 with SNOWSKY Melody