作品Works / Leo HiFi
Engineering log · Oct 2026工程记录 · 2026 年 10 月

A 2015 phone, rebuilt into a single-purpose HiFi player. 一台 2015 年的手机,被改造成只做一件事的 HiFi 播放器。

The Mi Note Pro shipped with an ESS ES9018K2M DAC and an OPA1612 headphone stage — then spent a decade routing music around them. This project rewrote its audio path so streaming music reaches that DAC at its native 44.1 kHz, untouched, and proved it with measurements rather than adjectives. 小米 Note Pro 出厂就带有 ESS ES9018K2M DAC 和 OPA1612 耳放,但十年来音乐大多绕开了它们。这个项目重写了它的音频通路,让流媒体音乐以原生 44.1 kHz、不经任何改动地送进这颗 DAC,并且用测量数据而不是形容词来证明这一点。

440,040frames checked, all bit-exact (app → HAL)帧逐位比对,全部一致(应用 → HAL)
44,101frames/s measured clock (target 44,100)帧/秒 实测时钟(目标 44,100)
0unsafe states across 7 fault scenarios7 类异常场景中的不安全状态
267host-test scenarios, also under ASan/UBSan项主机测试,含 ASan/UBSan

The signal chain信号链

Every stage the music crosses, and how much of it is actually proven. Green is measured on the device; amber is inferred from configuration. 音乐经过的每一级,以及其中多少是真正被证明过的。绿色为实机测量,琥珀色为根据配置推断。

The bit-exact span starts where an app hands samples to Android (AudioTrack) and ends at the driver's PCM write. Spotify's own decoder is outside it: its sample-altering options (normalization, Automix) are switched off, which is checked in its settings, not measured. SRC = sample-rate conversion · FX = audio effects · guard = refuses the ordinary headphone path while hardware volume is in charge, so faults go silent instead of loud. "逐位一致"这一段,从应用把样本交给 Android(AudioTrack)开始,到驱动写入 PCM 为止。Spotify 自己的解码器不在这一段里:它会改动样本的选项(音量均衡、Automix)已经关闭,这一点是在设置里核对的,没有测量。SRC = 采样率转换;FX = 音效;保护 = 硬件音量接管期间拒绝普通耳机通道,出错时只会静音,不会变响。

How it was built怎么做出来的

Five driver candidates, each built against a locked source manifest, gated by host tests and a static ABI check, deployed with a verified backup and a one-command rollback. 五个驱动候选版本。每一个都基于锁定的源码清单构建,先过主机测试和静态 ABI 门禁,再带着已校验的备份部署,并且一条命令就能回滚。

01

Route to the real DAC接到真正的 DAC

A new HiFi headphone device sends music over the QUAT I2S bus to the ES9018K2M instead of the stock codec amplifier, behind an evidence-gated state machine.新增 HiFi 耳机设备,让音乐经 QUAT I2S 总线送到 ES9018K2M,不再走原厂编解码器的耳放;整个过程由一个带证据门禁的状态机控制。

A

Shared-backend correctness共享后端的正确性

Concurrent streams no longer rewrite the backend mid-song or report a playing stream as idle.多个音频流同时存在时,不再在歌曲中途改写后端,也不会把正在播放的流误报为空闲。

B

Native 44.1 kHz原生 44.1 kHz

The mixer and the I2S backend run at the music's own rate. The clock never changes while audio is active.混音器和 I2S 后端都按音乐本身的采样率运行;有音频在播放时,时钟从不改变。

C

Hardware volume, fail-silent硬件音量,出错即静音

Volume keys drive the DAC's own attenuator (−60 to −9 dB) while Android's digital gain stays at 0 dB. Any unordered exit is silent by construction.音量键直接调 DAC 自身的衰减器(−60 到 −9 dB),Android 的数字增益始终保持 0 dB。任何不按顺序的退出,在设计上都只会静音。

D

Hardening and a measurement tap加固,以及一个测量用的抓取点

Restores the DAC filter after driver resets, larger audio periods, a crash fix for truncated diagnostics, and a capture tap that made the bit-exactness test possible.驱动重置后恢复 DAC 滤波器设置;加大音频缓冲周期;修复诊断输出被截断时的崩溃;新增一个抓取点,逐位比对测试正是靠它才得以进行。

Evidence, not adjectives用证据说话

The claim "this device plays HiFi" was attacked from every direction a phone allows. Results below; the measurement tools are in the repository, so every row can be reproduced. "这台设备是 HiFi 的"这个结论,在手机能做到的每一个方向上都接受了攻击。结果如下。测量工具都在源码仓库里,每一行结果都可以复现。

Attack攻击方向 Method方法 Result结果
Bit-exactness逐位完整 Integer pseudo-random pattern played through a test app, captured at the driver and compared frame by frame测试应用播放整数伪随机序列,在驱动处截取,逐帧比对 440,040 / 440,040PASS
Clock accuracy时钟精度 Kernel hardware-pointer timestamps over 60 s60 秒窗口内的内核硬件指针时间戳 44,101.0 ± 16 fpsPASS
Rate stability采样率稳定 Next, previous, pause/resume — backend rate read after each下一首、上一首、暂停后继续,每次之后读取后端采样率 44.1 kHz ×4PASS
Fault safety异常安全 Kill audio server, toggle accessibility, reinstall app, unplug/replug, reboot, framework crash, ordered HiFi exit — polled for "ordinary path at full gain"杀掉音频服务、开关无障碍服务、重装应用、拔插耳机、重启、框架崩溃、正常关闭 HiFi,持续轮询是否出现"普通通道 + 满增益" 0 unsafe0 次不安全PASS
Config drift配置漂移 File hashes and settings after reboots; two external overrides caught and corrected within 60 s重启后核对文件哈希和设置;两次被外部改写,都在 60 秒内被纠正 stable稳定PASS
30-min soak30 分钟长测 Screen off, scrolling, full CPU load, app switching息屏、滚动、CPU 满载、频繁切换应用 No dropouts mid-track; ~1.5 s gap at some track changes (streaming prefetch)曲目中途无断流;部分切歌处约 1.5 秒停顿(流媒体预取不及时)PARTIAL

Living with it日常使用

The whole device now exists for one app. Everything else was measured, then trimmed or kept.整台设备现在只为一个应用服务。其余的一切都先测量,再决定去掉还是保留。

Smoothness流畅
Janky frames, before卡顿帧,修复前
64%
Janky frames, after卡顿帧,修复后
~30%

Root cause: the big CPU cores had been switched off behind the scheduler's back. Both clusters are now capped at 1.25 GHz.根因:大核在调度器不知情的情况下被关掉了。现在两个 CPU 簇都限频在 1.25 GHz。

Debloat去冗余
Lock-screen redraw, before锁屏重绘,关闭前
52 fps
Lock-screen redraw, after锁屏重绘,关闭后
29 fps

Six unused system apps disabled, the music visualizer removed, the cellular modem powered down. Spotify's volume normalization and Automix turned off — the only real sample alterations left in the chain.停用了 6 个用不到的系统应用,去掉了锁屏音乐可视化,关闭了蜂窝基带。关掉了 Spotify 的音量均衡和 Automix,这是链路上仅剩的两处真实样本改动。

Power功耗
Screen-off playback息屏播放
0.95 W

Honest number: still high for a player. Larger audio buffers cut CPU busy time from 13% to 11% but did not move the watt meter, so the remaining draw lives elsewhere — the next thing to dissect.如实说:对一台播放器来说仍然偏高。加大音频缓冲后,CPU 忙碌从 13% 降到 11%,但功耗读数没有变化,说明剩下的耗电在别处——这是下一步要拆解的对象。

What this does not prove这些还没有被证明

Written down so nobody has to guess.写下来,免得任何人去猜。

  • The DSP and analog stages were not instrumented. The DSP runs without tuning data and at 0 dB, so pass-through is inferred, not measured. Noise floor, distortion and maximum output level need an external audio interface.DSP 和模拟输出两级没有接测量。DSP 在没有调校参数、0 dB 的状态下运行,所以"直通"只是推断,没有测量。底噪、失真和最大输出电平需要外接声卡才能测。
  • The source is lossy: the streaming tier available here tops out at 320 kbps Ogg Vorbis. A transparent chain cannot add back what the codec removed.音源是有损的:这里能用的串流音质最高是 320 kbps Ogg Vorbis。链路再透明,也补不回编码时丢掉的信息。
  • Gapless playback is not reliable over a slow network; downloaded playlists avoid it.网络慢的时候,无缝播放并不可靠;把歌单下载到本地可以避开这个问题。
  • Validated on exactly one phone and one firmware. The −9 dB volume cap is conservative, not measured — start quiet with sensitive headphones.只在一台手机、一个固件上验证过。−9 dB 的音量上限是保守取值,不是测量得出的;灵敏的耳机请从小音量开始。

Method方法

Measure before claiming先测量,再下结论

"By design" and "measured" are kept apart in every record. A result only changes category when there is data.每一条记录里都把"按设计"和"已测量"分开写。只有拿到数据,结论才会从前者升级为后者。

Everything reversible一切可回滚

Every change ships with a verified backup and a rollback command, logged with its timestamp and hash.每一处改动都附带已校验的备份和回滚命令,并记录时间戳和哈希。

Fail silent, never loud出错只静音,绝不变响

With hardware volume in charge, the only acceptable failure mode for headphones is silence. This was tested, not assumed.硬件音量接管期间,耳机唯一可以接受的故障方式就是静音。这一点经过了测试,而不是假定。

One variable at a time一次只改一个变量

Changes that did not help were reverted and recorded — including a full ahead-of-time compile that made cold start slower.没有效果的改动都会撤销并记录下来,包括一次让冷启动反而变慢的完整预编译。

Source源码

Driver patches, controller app, host tests and measurement tools are open source under Apache-2.0.驱动补丁、控制应用、主机测试和测量工具都以 Apache-2.0 协议开源。

github.com/leekaomin380/leo-hifi

Independent hobby project. Not affiliated with, endorsed by or sponsored by Xiaomi, Spotify, ESS Technology, Texas Instruments or Qualcomm; product names are used only to describe the hardware and software involved. Modifying system software can damage a device or produce unexpectedly loud output — protect your hearing.独立的个人爱好项目。与小米、Spotify、ESS Technology、德州仪器、高通均无关联,也未获得它们的认可或赞助;文中的产品名称仅用于说明所涉及的软硬件。修改系统软件可能损坏设备,或产生意外的大音量,请注意保护听力。