Passage Profiles: headphone correction and user profiles#
Passage Profiles is the listener's personalisation layer, applied immediately before the DAC driver. The first profile stage is AutoEq headphone correction; the profile document is designed to grow to hearing compensation, crossfeed, loudness and per-DAC settings.
It is part of the base dev.usbdac:usbdac AAR from 0.1.26. There is no
separate dependency and no new native library. The public Kotlin package is
dev.passage.profiles; the native entry points remain inside libusbdac.so.
Passage Profiles does not replace the output selector.
It wraps the PcmOutput the selector returns.
The two nouns#
| Noun | Owner | Meaning |
|---|---|---|
| Correction profile | The library catalogue | One headphone model's AutoEq bands, preamp and measurement source. It has a stable id such as oratory1990/over-ear/Sennheiser HD 650. |
| Passage profile | Your app | A versioned document with an enabled flag and one or more stages. Today the only stage is headphoneCorrection. |
The app stores the Passage profile; the library validates and applies it. The library never writes preferences, reads files or uses the network.
Add it to the app#
Use the same artifact and version as the rest of the SDK:
implementation("dev.usbdac:usbdac:0.1.26")
The catalogue is embedded: about 6,000 recommended headphone models in a 1.5 MB asset, already inside the AAR. There is no download, no first-run indexing and no licence server.
Let the listener choose a headphone#
Search by model name. An empty query returns the first page in name order.
// Call off the main thread; the catalogue is searched in native code.
val results: List<CorrectionProfileSummary> =
withContext(Dispatchers.Default) { PassageProfiles.search("hd650") }
results.forEach { result ->
// Show source and rig as well: variants can share a model name.
println("${result.name} — ${result.source} (${result.rig})")
}
A result carries the stable id, display name, source, rig, kind,
preampDb, filterCount, designRateHz and peakGainDb. Store the id, not
the display name. If the saved id is absent after a library update,
ProfileException
reports PROFILE_NOT_FOUND; ask the listener to choose again. Do not substitute
a similarly named model.
browse(offset, limit) is the page source for a list field with no query.
search and browse cap limit at 200.
Create, save and restore a profile#
A profile is a small JSON document. Start from the template, then add the chosen stage:
val profile = PassageProfiles.defaultProfile()
.withHeadphoneCorrection(
HeadphoneCorrection(
profileId = chosen.id,
bassBoostDb = 0f,
trebleBoostDb = 0f,
maxGainDb = null,
catalogVersion = PassageProfiles.catalogVersion,
),
)
.withEnabled(true)
// Your app owns persistence. Save this string in DataStore, a file, a database,
// or wherever the rest of the app's settings live.
val savedJson: String = PassageProfiles.profileToJson(profile)
Restore it through the native validator rather than parsing the fields yourself:
val profile: PassageProfile = PassageProfiles.profileFromJson(savedJson)
The document looks like this:
{
"schema": "usbdac.profiles/v1",
"id": "optional-app-id",
"name": "My HD 650",
"enabled": true,
"stages": [{
"type": "headphoneCorrection",
"profile": "oratory1990/over-ear/Sennheiser HD 650",
"catalogVersion": "autoeq-7ae0f56d5307",
"extraHeadroomDb": 0.0,
"bassBoostDb": 0.0,
"trebleBoostDb": 0.0,
"maxGainDb": null
}]
}
idandnameare app-owned and round-trip unchanged. The library does not generate ids or resolve duplicates.enabled = falsekeeps the stages. Turning a profile off is not the same as deleting it.catalogVersionis informational. If the catalogue changed, tell the listener that the correction was updated; do not silently pin old bands.- Unknown stage types are refused with
UNSUPPORTED_STAGE, never ignored.
Wrap the selected output#
Build the profile in front of the output the app writes to. The format must be the format your app passes to that output, not necessarily the negotiated USB wire format.
val selected: SelectedOutput = selector.open(context, request)
// The raw transport verdict, before the profile and before any conversion wrapper.
val transport = selected.stream?.bitPerfect ?: selected.bitPerfect
val output: ProfileOutput = PassageProfiles.wrap(
target = selected,
format = selected.format,
profile = profile,
transport = transport,
)
wrap returns a ProfileOutput that is a normal PcmOutput: use its write,
play, pause, flush, drain and counters as before. The profile adds no
buffered latency and does not change the frame rate, but it does change sample
values.
When the profile is disabled, wrap is a pass-through and the target's
bit-perfect verdict is preserved. When it is enabled, ProfileOutput.bitPerfect
is NotVerified; transportBitPerfect still carries the transport's own
verdict for the display below.
For a native DSD or DoP source, wrap the PCM target of DsdPcmOutput, never
the DSD input. A headphone correction cannot filter DSD bits directly. If the
listener has not explicitly chosen DSD-to-PCM conversion, leave the profile off
for that track.
Bass, treble and max gain#
The three AutoEq-style controls live on the HeadphoneCorrection stage:
| Field | Range | Effect |
|---|---|---|
bassBoostDb |
-12 to +12 dB | Extra low shelf at 105 Hz, Q 0.70 |
trebleBoostDb |
-12 to +12 dB | Extra high shelf at 10 kHz, Q 0.70 |
maxGainDb |
0 to 24 dB, or null | Per-band ceiling for positive gains |
extraHeadroomDb |
-24 to 0 dB | Extra attenuation on top of the profile preamp |
maxGainDb is a post-fit ceiling, not a re-optimisation. The library clamps
positive bands, recomputes the headroom and reports the result. Show the final
curve and call the result “customized”; do not present it as the untouched AutoEq
fit.
Positive boosts increase the required headroom. The processor lowers its preamp automatically, so a +6 dB bass boost does not make the output 6 dB louder; it makes the bass 6 dB louder relative to the rest of the curve, with the same peak.
Draw the graph#
The library returns the exact correction curve that is running. There is no image to download and no separate graph package.
val curve: ProfileCurve = output.curve(points = 128)
// Frequencies are already log-spaced from 20 Hz to 20 kHz.
curve.frequenciesHz
curve.magnitudeDb // filters only, preamp excluded
curve.outputDb // filters plus the effective preamp
curve.effectivePreampDb
curve.peakGainDb
Draw outputDb as the audible correction and magnitudeDb as the filter shape.
The same arrays come from PassageProfiles.curve(profile, points, sampleRateHz)
for a preview before a stream is open; pass the rate the output will use.
This is the correction response, not AutoEq's static before/after plot with the measured headphone response and target. That plot needs the measurement and target series, which are not shipped. The correction graph includes the listener's boosts and max-gain clamp, which a static image would not.
The signal path: bit-perfect is not a setting#
Do not add a “bit-perfect mode” switch. Combine the transport verdict, the profile stages and what your decoder knows into one line:
val path = PassageProfiles.describeSignalPath(
decision = selected.decision,
transport = transport.value,
stages = output.stages,
source = SourceFidelity.LOSSLESS, // your decoder knows: LOSSLESS, LOSSY or UNKNOWN
sourceLabel = "FLAC 24/96",
softwareGainDb = 0f, // the stream's own gain, if any
)
statusLine.text = path.headline
| Verdict | What it means |
|---|---|
BIT_PERFECT |
Lossless source, no profile, conversion or software gain, transport verified |
PERSONALIZED |
A profile is active; the source is unchanged, the samples are corrected |
CONVERTED |
The library changed the rate or depth |
PERSONALIZED_AND_CONVERTED |
Both |
SOFTWARE_GAIN |
Software gain changed the samples |
SOURCE_LOSSY |
The decoded stream reached the DAC untouched, but the source codec is lossy |
SOURCE_UNKNOWN |
Your app did not declare the source |
NOT_VERIFIED |
The transport could not vouch for the path; use the blocker's sentence |
BIT_PERFECT is computed, never set. A correction profile is not called
“not bit-perfect” in the headline; it is called Personalized. The listener
can see the trade: the master is untouched, the samples sent to the DAC are
adjusted for their headphones.
Settings and lifecycle#
Three listener choices belong in the app's settings, in their own words:
- Use the DAC directly — the existing
OutputPolicy.allowDirectUsbchoice. - Sound profile — Off, or a chosen headphone correction. Store the profile JSON and its id/name; the library does not persist anything.
- Convert what the DAC cannot play — the existing
OutputPolicy.allowConversionchoice.
Apply a profile change at the next track boundary: build a new ProfileOutput
and let the old one drain and close. A live toggle would need a click-free gain
ramp and coefficient swap; that is a follow-on, not part of this release.
ProfileOutput exposes live state for the screen:
output.stages // applied stages, with label and customized flag
output.effectivePreampDb
output.peakGainDb
output.bassBoostDb
output.trebleBoostDb
output.requestedMaxGainDb
output.clampedBands
output.clippedSamples
output.invalidSamples
If clippedSamples grows, lower extraHeadroomDb or reduce the boosts. The
steady-state guard prevents a full-scale tone from clipping, but intersample
peaks and transients can still exceed full scale; the processor saturates and
counts them.
Errors and actions#
| Code | When | What to do |
|---|---|---|
PROFILE_NOT_FOUND |
Saved id is absent from this catalogue | Keep the profile off; open search; never auto-substitute |
UNSUPPORTED_STAGE |
Profile contains a stage this build does not implement | Tell the listener the profile needs a newer library; do not apply the rest |
INVALID_PROFILE |
Schema, empty enabled profile, bad range | Offer “reset profile”; show the detail |
UNSUPPORTED_FORMAT |
DoP/native DSD, odd layout, below 32 kHz | Leave the profile off for the track or choose explicit DSD-to-PCM |
UNSUPPORTED_CHANNELS |
More than two channels | Leave the profile off; a headphone correction is mono/stereo only |
CATALOG_UNAVAILABLE |
Embedded catalogue is corrupt | Report a build error; fall back to no profile |
INVALID_ARGUMENT |
Closed processor or malformed call | Fix the call; do not retry blindly |
Every failure is a ProfileException with a typed ProfileErrorCode. A profile
that cannot be applied is off, and the signal path says why.
Threading and performance#
PassageProfiles.searchandbrowsetouch native code. Debounce a text field and call them off the main thread. The catalogue is about 1.5 MB; the full search scans 6,000 entries in under a millisecond in a release host build.PassageProfiles.processor/wrapbuilds coefficients and evaluates the headroom curve once. Do it off the audio thread at a track boundary.ProfileProcessor.processandProfileOutput.writeuse one writer thread, like everyPcmOutput. The DSP isf64and allocates nothing per write.- A 10-band stereo correction measured about 20 ns per frame on an Apple Silicon host in release. A phone remains far faster than realtime.
Catalogue and attribution#
- The embedded catalogue is AutoEq's recommended results at the commit shown by
PassageProfiles.catalogVersion: 6,033 models, 1.5 MB. - AutoEq is MIT; the measurements originate with oratory1990, crinacle, Rtings, Innerfidelity and others. Show the source and rig in search results, and credit AutoEq and the measurement source in the app's About screen.
- Release distribution of the derived catalogue should wait for the
measurement-data licence review in
NOTICE.
Acceptance checklist#
- [ ] Search, choose and restore a profile from app storage while offline.
- [ ] Disabled profile: output is a pass-through and the transport verdict is unchanged.
- [ ] Enabled profile: signal path says Personalized, not “not bit-perfect”.
- [ ] Lossy source through a verified transport says SOURCE_LOSSY; the app does not claim bit-perfect.
- [ ] Bass/treble/max-gain changes update the graph and the effective preamp.
- [ ] A seek/flush resets the filter and clears clipping counters.
- [ ] Drain completes only after pending processed audio is forwarded.
- [ ] Unplug pauses playback; the profile does not redirect to the speaker.
- [ ] DoP/native DSD with a profile shows
UNSUPPORTED_FORMATunless the listener explicitly chose DSD-to-PCM. - [ ] More than two channels and rates below 32 kHz leave the profile off.
- [ ] Clipped samples are visible if they occur.