I’ve decided to add a couple of lossless audio formats in a preparation for a long-term goal of having a NihAV
-based player (the debug tool nihav-player
that I currently have can’t really count for one especially considering how it does not play pure audio files and tends to deadlock in SDL audio thread).
So I’ve added nihav-llaudio
crate with four most common formats for music I have, namely FLAC, Monkey’s Audio, TTA and WavPack. And I guess it’s time to revisit my opinion about various lossless audio formats now that I’ve (re)implemented support for some of them (I tried to summarise my views about them almost ten years ago). Let’s see what has changed since then:
- I had a closer look at MPEG-4 ALS and it turned out to be rather interesting (and probably the only lossless audio codec with P-frames) but it also has somewhat insane options (like maximum prediction order of 1023 for LPC; or coding the whole file with just one I-frame and the rest being P-frames so no seeking is possible) and RLSLMS being broken (the reference decoder can’t decode the official reference samples) and it got no popularity at all;
- TTA turned out to be very simple with a baffling rationale
The sample count in a TTA1 frame is a multiple to 576 (sound buffer granule). Based on this, the “frame time” is defined as a constant 1.04489795918367346939. Thus, the sample count in a regular TTA1 frame determined as: regular TTA1 frame length = frame time * sample rate.
I’m no mathematician so this does not form a coherent logical chain for me, I’d use something like “frame length in samples is sample rate rounded up to multiple of 576” instead of “sample rate multiplied by 256/245”. The main irritating point is that last frame contains less samples and you need to signal that it’s last frame (or merely check if you have enough bits left to decode a full frame after you decoded enough samples for the last frame). Oh, and TTA2 seems to be still in development.
- And speaking about codecs in development, I don’t see new lossless audio codecs appearing after 2010. Either I got too old and don’t spot them or the interest has finally faded out. This might be because most people don’t buy music any more but rather rent it in some online store or use some streaming service. And those who still do probably use one of the old established codecs like FLAC.
- And since I’ve mentioned it, my opinion on it has not changed and only got a bit more refined not that I have a decoder for it as well. Previously I thought FLAC is a simple format with a bad bitstream format that makes seeking hard. Now I know that FLAC is a simple format (fixed predictor or LPC up to order 32 and fixed Rice codes; the only thing that improves compression is splitting residues into partitions where optimal k for coding them can be selected) with horribly designed bitstream format.
Normally lossless audio formats either store offsets for each frame or have an easily recognizable header, but FLAC is different. It’s obvious that the author was inspired by MPEG audio header design but those actually had frame sizes coded. Here in order to find where the frame ends you need either to decode it or calculate CRC for the data you read (and in the likely case of false positives also check that the data is followed by a valid header). One could argues that there’s often a seek table in FLAC file but for e.g. in
luckynight.flac
those entries are for multiples of ten seconds positions, making seeking to a more precise position a task of skipping frames (which is fun—see above). - WavPack is still the best designed format in my opinion though it would be nicer to have some initial header with various metadata instead of having it stored in the first block. Other than that still no objections.
- And it turns out there’s lossless AAC compression that employs wavelet transform before LPC (it’s Chinese AAC though so who cares).
I remember reading somewhere (on Hydrogenaudio most likely) a brief story about development of several popular lossless audio codecs (even told by the author of one but I might be wrong). Essentially it’s not a NIH syndrome but very close: somebody develops a format, another guy finds a minor flaw the original developer refuses to address (my memory is hazy but I think there were such things mentioned as no plugin for some player or not supporting some tags) and develops another format. The amount of formats that came to existence because somebody wanted to create a format and could not keep it to himself is pretty large too.
But those days seem to be over and maybe I’ll reverse engineer some of those old codecs for documenting reasons as there’s very little risk that somebody would pick them up and make widespread now. Alternatively I can rant on newer formats sucking as well. Though why wait, let’s do it now:
- AAC sucks because of the countless extensions and attempts to bundle various coding approaches under the same name (fun fact – “xHE-AAC” is actually pronounced as “MPEG-D you-suck”);
- AV1 sucks because of the organisational structure and their decisions during (and after) the design stage;
- AV2 is not here yet but it sucks for the same reason;
- BlueTooth audio codecs suck in various ways (except SBC, it’s okay for the purpose), especially because of marketing them as high-definition and robust while in reality they rarely are;
- Chinese codecs suck for being rip-offs of better-known codecs. It’s especially gross that one of them got standardised as IEEE 1857.2 AAC;
- H.264 sucks because of countless extensions;
- H.265 inherited some from H.264 and added the licensing situation on top of that;
- MPEG-5 EVC sucks because it’s a Frankenstein monster constructed from bits from H.263-H.265;
- Opus sucks for being designed for streaming case and used elsewhere;
- Vector-based codecs suck because current tools are still not good enough to autovectorise complex shapes and recognize gradients.
Now back to doing nothing.
APE have now support for >2 channels.
For a couple of weeks even.
From a quick glance it’s the same interleaved format with post reconstruction performed on channel pairs.
I’ve also not mentioned DSD support in WavPack either because there’s little reason to care about it for a person who expects to play just CD rips (in other words—me).
Crazy to see my luckynight.flac sample referenced. It makes me wonder if my “luckynight” corpus will endure as the most comprehensive archive of lossless audio codec samples.
Why not? It might be not be as popular as
len(n)a.pnm
but considering where people usually take their corpus of exotic and less exotic samples it has good chances.[…] I’d mentioned in a previous post on lossless audio codecs, I wanted to look at some of them that are still not reverse engineered […]