Skip to content

fix(audio): restore bit-perfect USB exclusive playback and prevent crash on read-only buffers - #351

Open
ajisth69 wants to merge 9 commits into
mainfrom
fix/usb-bitperfect-dac-crashes
Open

ajisth69 wants to merge 9 commits into
mainfrom
fix/usb-bitperfect-dac-crashes

Conversation

@ajisth69

@ajisth69 ajisth69 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Overview

Resolves Bit-Perfect audio regressions, crossfade audio focus pause locks, redesigns the Output Detector dialog into a Poweramp-style 5-stage pipeline flow, and adds YouTube Music Cookie Login (matching the desktop app).

Summary of Changes

  1. YouTube Music Cookie Login (Matching Desktop):

    • Added \CookieNormalizer.kt\ (direct port of Desktop \InnerTubeMusicApi.normalizeCookies): supports raw \Cookie\ headers, Netscape \cookies.txt\ format (tab-separated, #HttpOnly\ flags), JSON exports from browser extensions (Cookie-Editor, EditThisCookie), and multiline text.
    • Enforces presence of the \SAPISID\ family (__Secure-3PAPISID, \SAPISID, or \APISID) required for InnerTube authenticated authorization tokens.
    • Added \CookieLoginDialog.kt\ with clipboard paste helper, real-time validation error alerts, and seamless connection.
    • Integrated Cookie Login into both \YouTubeLoginScreen.kt\ (header key button and bottom action bar) and \SettingsScreen.kt\ (direct action card under YouTube Music).
    • Wrote \CookieNormalizerTest.kt\ verifying raw headers, Netscape formats, JSON exports, and validation failures.
  2. Fix Crossfade Audio Focus Pause Loop:

    • In \handOffCrossfade(), standby was previously called with \standby.setAudioAttributes(standby.audioAttributes, true), activating ExoPlayer's internal \AudioFocusManager.
    • This caused ExoPlayer to fight LastWave's manual
      equestMediaAudioFocus(), triggering an immediate \AUDIOFOCUS_LOSS (-1)\ / \PausePermanently\ callback 40ms into crossfading. Forced resumes repeatedly paused within milliseconds.
    • Fixed by keeping \handleAudioFocus = false\ on the standby player so crossfade volume mixing and app-level audio focus proceed seamlessly without platform focus collision.
  3. Poweramp Bit-Perfect Definition Alignment:

    • Updated \SignalPath.kt\ so digital volume scaling / software gain override does not disqualify bit-perfect mode when source format, sample rate, and bit depth match the DAC wire format (matching Poweramp's behavior).
    • Exposed \�ctiveWireBits()\ on \ExclusiveUsbOutput\ to accurately compare source depth against the hardware wire transport slot.
  4. Poweramp-Style Signal Path / Output Detector Redesign:

    • Reorganized the Output Detector dialog into Poweramp's 5-stage top-to-bottom pipeline flow: Source $\to$ DSP $\to$ Volume Control $\to$ Output $\to$ Output Device.
    • Added directional track flow lines (\↓), clickable underline titles, rotary knob dial icon for volume control, and technical device flags (\DIRECT, \OFFLOAD, \EXCL, \USB_AUDIO, etc.).
    • Integrated Poweramp's bottom dual status cards: Fidelity (100% / bit-perfect indicators) and DSP indicator.
  5. Hardware & Direct USB DAC Stability:

    • Reverted \orceSoftwareVolume\ default to \alse\ to preserve UAC hardware volume controls on external DACs.
    • Prevented \ReadOnlyBufferException\ crashes on read-only MediaCodec direct byte buffers.
    • Safe software PCM scaling on isolated chunks and zero-volume latch reset on track transitions.

…ash on read-only buffers

- Revert default of forceSoftwareVolume to false to restore hardware UAC volume control
- Guard scalePcmInPlace against read-only buffers to permanently avoid ReadOnlyBufferException
- Isolate software PCM scaling in ExclusiveUsbOutput to newly allocated write chunks
- Reset pendingVolume to 1.0f across track transitions to eliminate zero-volume traps
- Fallback to 24-bit container alt setting if initial alt setting fails on UAC2 DACs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant