PolyluteDocs polylute.app

Concepts

How audio reaches your DAC

Two roads lead from the file to the sound. Here is who owns each one, and how Polylute picks between them.

On this page

In short

  • There are two roads to a USB DAC. On the Android route the sound goes through Android’s own audio system. On USB Direct Polylute talks to the DAC itself.
  • Only the last stretch is Polylute’s own. Opening the file, decoding it, the queue and the clock are the same on both roads.
  • Polylute picks the road for you, song by song, and shows which one it used.
  • We built it this way so that nothing sits between the file and the DAC that you did not choose.

How it works

Every song starts the same way: the player opens the file and decodes it into plain samples. What happens next depends on the road.

The Android routeThe player decodes the file, Polylute's effects may change the samples, Android's audio system mixes the sound, and it leaves through the speaker, Bluetooth or USB through Android. Android route The player decodes the file Polylute’s effects EQ, ReplayGain, peak limiter Android’s audio system mixes the sound Speaker, Bluetooth, or USB through Android USB DirectThe player decodes the file, Polylute's effects may change the samples when Resonance is on, Polylute's own USB output packs the samples for USB, and the DAC plays them. USB Direct The player decodes the file Polylute’s effects only with Resonance Polylute’s USB output packs the samples for USB Your DAC plays them
The two roads. Amber marks the part Polylute owns: its own USB output.

In words

Android route: the player decodes the file, Polylute’s effects (EQ, ReplayGain, an optional peak limiter) may change the samples, Android’s audio system mixes the sound, and it leaves through the speaker, Bluetooth, or USB through Android.

USB Direct: the player decodes the file, Polylute’s effects change the samples only when Resonance is on, and Polylute’s own USB output packs the samples and sends them to the DAC, which plays them.

What is the same on both roads

Polylute uses Media3, Google’s open-source player library for Android, for everything except the final output. That covers opening files, decoding them (FLAC with the reference FLAC library), the queue, the position and the clock, and the media notification. A song is decoded the same way whichever road it takes.

What is Polylute’s own

Only the output. On USB Direct, Polylute replaces the player’s audio output with its own. That output asks the DAC to switch to the file’s sample rate, packs the samples, sends them over USB and watches over the DAC’s volume. The next pages tell the rest: The USB transport, Keeping volume safe and When a DAC misbehaves.

How Polylute picks the road

Polylute asks a short list of questions, always in the same order, and the first answer that says “Android” wins. If none does, the road is USB Direct.

How Polylute picks the roadSix questions in order. Crossfade, an Android effect or a speed other than 1.0 times sends the sound through Android. So does having no DAC or no USB permission, a file the DAC cannot take or a failed Direct attempt, an unsafe moment to switch, or a DAC that is shared with other apps. If none apply, the road is USB Direct: Resonance if Polylute has to change the samples, Purity if not. Crossfade, an Android effect, or a speed other than 1.0×? yes Android route no No DAC, or no USB permission for it? yes Android route no The DAC can’t take this file, or Direct failed? yes Android route no Not a safe moment yet to switch? yes Android, for now no Is the DAC shared with other apps right now? yes Android route no Must Polylute change the samples? EQ, ReplayGain, volume yes Resonance (Direct) no USB Direct, Purity
Choosing the road. Amber marks the usual result with a DAC: USB Direct with the samples untouched.

In words

  1. Is crossfade, an Android sound effect, or a speed other than 1.0× in use? Then the sound goes through the Android route.
  2. Is there no DAC, or no USB permission for it? Android route.
  3. Can the DAC not take this file, or did Direct just fail for it? Android route.
  4. Is it not a safe moment to switch yet? Android route, for now.
  5. Is the DAC shared with other apps right now? Android route.
  6. Otherwise it is USB Direct. If Polylute has to change the samples (EQ, ReplayGain or digital volume), that is Resonance. If not, it is Purity.

With Purity on and a DAC connected, crossfade, sound effects and speed are frozen, so the first question never sends the sound to Android. That is the point of Purity: see Purity and Resonance: two promises.

The Track details page for a 96 kHz, 24-bit FLAC file. In the Output section the route reads USB Direct, Purity, the output rate is 96 kHz, and the equalizer is bypassed.
You can always see which road was used. The Route line in Track details says it.

Why we built it this way

Android’s audio system is made to mix many apps together. That is useful for most people, but it means the system is allowed to change the signal on the way: mix it, change its volume, convert its rate. Polylute cannot see or control what it does. So to hand a DAC the file’s own samples, Polylute has to go around it.

That has a cost. Once the app talks to the DAC itself, it also has to handle the conversation Android would normally handle: the DAC’s clock, its volume, giving it back to other apps, and recovering when a DAC misbehaves. We think that is worth it, but it is real work and real risk, which is why the rest of the Concepts section exists. It also only works with DACs that follow the USB Audio Class 2 standard. For everything else (the phone speaker, Bluetooth, other DACs) the Android route is there and works as it does in any music app.

We chose to replace only the output, not the whole player. A second player of our own would be a second place for bugs in queues, seeking and decoding. Keeping one decoding path means a song decodes the same way on either road.

For the curious

For the curiousThe full order of the questions

The real order has two more rows than the diagram. After the three “Android sound” questions (crossfade, effect, speed), a diagnostic override in Maintenance can force the Android route, or hold Direct off. Those exist for testing, not for listening. Before the safe-moment question, Polylute also checks whether a previous attempt at Direct already failed for this DAC and this sample rate. If it did, it does not try again on every song change.

The question about changing the samples only counts EQ, ReplayGain and digital volume. Crossfade and sound effects are not about the samples at all: they are reasons Direct cannot be used, and they come first.

For the curiousWhy Polylute pauses instead of using the speaker

When Polylute has just given the DAC back to Android, Android takes a moment to register the USB output again. In that gap, playing would mean the speaker or a dead route. Polylute holds playback for a short wait, resumes if the USB output appears in time, and otherwise leaves you paused.

Tested on HONOR LGN-NX3 with SNOWSKY Melody