Shine is a fixed-point MP3 encoder: it runs on devices without a floating-point unit, and it's fast everywhere else too. The last release was in 2017, and this one is a big one: shine finally has a psychoacoustic model.
What's new
- A psychoacoustic model, on by default: masking
thresholds, noise allocation, a bit reservoir, short blocks for
transients, mid/side stereo decided frame by frame, and a lowpass at low
bitrates. It's all still fixed point, with no floating point and no libm
in the library. If you want the details, the whole model is written up
in
doc/psy. - It holds up against LAME, at about three times the
speed. Scored with PEAQ's 2f model on 53 music and speech
clips, shine gets 60.7 at 64 kbps stereo and LAME (default settings)
56.6; at 96 kbps it's 78.1 against 77.5, and at 128 kbps 90.1 against
90.2. On an Apple M5, shine encodes 128 kbps stereo at 425x realtime,
LAME at 154x. The 64 kbps number uses
-r, which lets shine drop to a lower samplerate at low bitrates. It's off by default, so the stream always keeps the samplerate you give it unless you ask. - A fast mode for devices that can't afford the
model:
-Q 0is the original encoder, two to four times faster again (1630x on the same machine). - Gapless playback: shine writes the same Info frame as LAME, which FFmpeg, GStreamer and Firefox know how to read, and streams no longer get cut short at the end.
- Faster across the board, with NEON and AVX2 code picked at run time and identical output everywhere.
- Lots of fixes: invalid streams at some samplerates and bitrates, output that was 1 dB too loud, distortion on loud input, and different output on ARM and MIPS.
Speed and quality
How this was made
Most of this release was written with an AI coding assistant. The programmer set the direction and the constraints (fixed point, no libm, no floating point in the library), reviewed every change, did the listening and made the design decisions.
A clean-room spec. LAME served as the reference
model, but its code never reached the encoder. The work ran in three
passes, each reading only what the previous one wrote: first a
description of how LAME's psychoacoustic model behaves, then a spec for
shine written from that description, with MUST/SHOULD/MAY rules, named
constants and known pitfalls, and finally a fixed-point implementation
written from the spec alone. The spec lives in doc/psy and
is complete enough to rebuild the model without the code. It remains the
source of truth: every later change went into the spec first, then into
the code.
Optimization loops. Quality tuning is automated around PEAQ. A special build exposes the model's constants as knobs, candidates are screened on a few clips, and the survivors face a gate on the full 53-clip corpus: no clip may lose more than 5 points, and the mean may not drop. What passes goes into the spec, then into the code, and the release build must produce exactly the same streams as the gated one. Hundreds of candidates went through this loop, with blind listening tests as checkpoints.
CPU time got a loop of its own. We profiled each encoding step, read the assembly the compiler produced for the hot ones, and tried vectorization options: compiler flags, loop shapes, intrinsics. An option stayed only if it was faster and bit-identical to the reference, and was then written directly into the code. The result is a set of NEON and AVX2 kernels picked at run time, all matching the portable C version bit for bit.
Tooling. With an assistant, tooling is cheap to build, so we built a lot of it: a quality report and a quality gate that score any encoder against LAME and FDK AAC, a speed and memory report, per-step profiles, disassembly of the built encoder to see what the compiler vectorized, and timed test builds of each vectorization option, compared bit for bit against the reference. Add to that a reference oracle for the fixed-point model, a check that keeps floating point out of the library, golden hashes that pin the output on every architecture, diagnosis scripts for block types, bit usage and error spectra, the README charts and the blind-test page. CI covers x86, ARM, s390x (big-endian), WebAssembly and sanitizers.
Upgrading
This release breaks the API and the ABI, so you'll need to recompile.
The new header is shine/shine.h, and every name is now
prefixed (SHINE_MONO, mpeg.bitrate, ...). Your
3.x code should still build as is through shine/layer3.h;
the compiler will just point out each old name you're using. Everything
is listed in the ChangeLog.
The JavaScript package, @toots/shine.js, goes to 2.0.0:
it's now an ES module compiled to WebAssembly, and it gets the model
too.
Come listen
Those scores come from a model of human hearing, not from people. So what do your ears say? There's a blind test that puts shine 4.0 next to LAME and AAC (Fraunhofer's FDK) on 15 music and speech clips. The results update live, right next to what the model predicted: https://toots.github.io/shine/listen/
It's eight short tests, about fifteen minutes with headphones. Every answer helps, especially if your ears disagree with the scores.
- Release: https://github.com/toots/shine/releases/tag/4.0.0
- Source: https://github.com/toots/shine
- npm:
npm install @toots/shine.js