265 points · by jsbg · 4y ago · 237 comments
I have often wondered why other media formats don't do a similar thing, especially since changing a media file's tags (which can change the checksum of a file) or name (which makes external verification from txt file difficult) is quite common. I even wrote a utility[0] that uses ffmpeg to hash all ffmpeg compatible bitstreams, and store their hashes in a xattr (yes, with lots of other options to test and compare, etc.), but all media formats should just be as clever (and care as much) to do this natively, like FLAC.
I mean -- why not?
Background: Lenovo Thinkpad T520 laptop, random crashes and data corruption.
Diagnosis: Eventually let memtestx86+ run a bunch of times for like a week and it wasn't showing any errors. Finally about to give up I pressed some key on the keyboard and it blew errors immediately all over the screen. This suggested EC or maybe some BIOS-controlled keyboard driver was writing to memory it shouldn't have been.
Fix: I am a Linux user, the kernel has an option to reserve low memory for poorly behaving BIOS that likes to write where it shouldn't. CONFIG_X86_RESERVE_LOW should be set to at least 64kb and increased up to 640kb if this issues continue to happen. There are some other options to scan for this misbehavior but I honestly don't know how Linux currently handles it: https://lkml.org/lkml/2013/11/11/683
But I have one nitpick with FLAC in this regard: they chose MD5 as the checksum instead of something sensible like CRC32/CRC64... It makes no sense, because we're not doing cryptography here - we're doing an integrity check. Moreover it makes a parallelized FLAC encoder somewhat problematic to implement, as there's always going to be a serial bottleneck at the end for computing the MD5 hash. CRC on the other hand could easily be parallelized. But I'm afraid we'll have to live with this shortcoming forever now ¯\_(ツ)_/¯
> But I'm afraid we'll have to live with this shortcoming forever now ¯\_(ツ)_/¯
I don't believe there is a fundamental reason why a later version of FLAC couldn't/wouldn't allow different algos as I think the raw decoded bitstream is checksum-ed and is just stored as a FLAC tag[1]. So they could just version that tag.
[0]: http://underpop.online.fr/f/ffmpeg/help/hash.htm.gz [1]: Language corrected. See comment.
Sure, it's just metadata. It's just about backwards compatibility.
By the way, the checksum is calculated on the raw data fed into the encoder. It doesn't make sense to decode the data you've just encoded.
https://interviewfor.red has lots of info about that exact thing, because in some uh… very peculiar communities, sharing a lossy file passed as a lossless file is a serious offense.
You're basically looking for two things: first, an abrupt stop to frequencies above a certain point -- compression uses applies a low-pass filter to eliminate them.
Second, a bunch of rectangular-ish boxes where signal is missing. The spectrogram will look like swiss cheese in a way -- this is where the compression algorithm decides audio information can be deleted because it's "masked" by e.g. louder surrounding sounds.
(Generally speaking, the more aggressive the compression, the lower the frequency ceiling, and the more/bigger swiss cheese holes.)
On the other hand, if you run e.g. AAC compression at a very high bitrate and explicitly force no lowpass filter at all (which virtually nobody does in practice, but you can do from a command-line tool)... you won't be able to see any qualitative difference. Because you won't be able to hear any qualitative difference either. :)
I imagine low pass filtering depends a bit on which compression you're using.
None of these tricks will work for detecting GAN compressed audio, though.
http://tausoft.org/wiki/aucdtect
I wonder if there is any open source implementation of the algorithm it uses.
I'm guessing sometimes frequency cutoff is due to using less than ideal microphones, although not the extreme cutoffs (I'm fairly sure it would be gradual in that case). It also seems there is often a fair amount of noise around 20kHz that I'm guessing is from recording equipment, sometimes on tracks that otherwise look suspiciously like they are from lossy audio. Additionally, in some cases there could potentially be high frequency cutoffs in processing while otherwise being lossless, particularly stuff like electronic music where there can be a lot of processing in general. So I'm not sure if it is necessarily all that easy to tell in general, although there are certainly some from Bandcamp that seem highly likely to be conversions from lossy formats :(.
In the case of FLAC the situation is straight forward, you've got uncompressed audio and a codec that's performing lossless compression. You want to know what was encoded losslessly matches the input. It's no different from a checksum in a compressed archive.
It's less straightforward with a lossy compressed codec. Are we just checksumming the compressed bitstream? Where in the handling of the bitstream are we doing the checksum? In MOV/MP4 a media track can have arbitrary start and end times. It makes doing in/out cuts super fast. But when it comes to checksumming the track do we checksum all the samples in the track or only the samples that will play? If a file if flattened and a track has all the samples out of the playable region discarded do we now have to recalculate the checksum?
Media tracks can also have header tags that indicate stuff like display color space, displayed size, or even track level metadata. Are we checksumming the track bitstream and important track headers? A video needing to render in a particular color space will be materially affected if it's bitstream is preserved but color space tags are dropped.
If you want to hack in checksums for track bitstreams both MOV/MP4 and Matroska can accept arbitrary tags for tracks so you can just write a checksum to a track header tag if you really want to. You really need a table of rules for doing the checksum otherwise it's a wasted effort.
But I guess most people and thus file formats don't care. If your file's corrupted and you don't notice it doesn't matter. And if you do notice you don't need a checksum to tell you. I don't necessarily agree (knowing where the corruption occurred is useful), but I can see the reasoning.
Second, do any give an indication of when the error correction fails: I think CD players just fill the missing data with the last sample value (certainly this was the case for first gen CD players)- but this FLAC encoding gives a better procedure: replace the missing samples from those of a predictive model. But either way, it would be nice to know when the playback is not perfect.
> Some ROM drives are capable of reporting C2 error information along with the audio data and some ripping software can use this information to determine whether the retrieved audio data is valid or not. A standardised mechanism for ROM drives to report C2 error information is documented in the Multi-Media Command (MMC) standard
https://docs.linn.co.uk/wiki/index.php/CD_Ripping_Terminolog...
How much would audiophiles pay to have a quality indicator on their CD player? Hmm...
Edit: Sony's CXD2500BQ shows error correction information on the pins- no FPGA needed.
CXD2500BQ is used in Onkyo's DX-7310
This company claims to have a product for this (but no pictures..), follow the links for their "CD Errormonitor":
Still-- why not just output Quake on that line and subtract the error correction from the starting 100% health?
Exact Audio Copy shows it but will spend minutes re-reading the same frames: https://i.imgur.com/ZGozdhz.png (screenshot mine, unfortunately)
I want something like that for JPG, with parity.
I have no domain knowledge here, just curious
Hell, 99% of all computers are still running on non-checksummed filesystems, if not 99.99%.
For the most part, only a tiny minority of people are even aware of bit rot, let alone have anything they simultaneously care enough about to protect against, and have enough ownership of it to attempt to try.
Most such audio codecs are based to some degree on variants of fourier transforms, so this modification is done by dropping or reducing resolution of parts of the output.
CD audio is perfectly lossless - it encodes the signal that you put in by measuring a voltage 44100 times per second and recording that exactly. When you play it back you get exactly the same signal back out. The only problem is, this takes up a lot of space, roughly 10MB per minute for stereo audio.
MP3 audio is lossy in that rather than storing the exact values of a waveform, it stores a description of how short segments of the waveform change. The higher the bitrate, the better the description, and the more detailed the reproduction. A low bitrate MP3 is like trying to redraw the original waveform from a vague description with a paint roller, a high bitrate MP3 is like trying to draw it with a mapping pen from a really detailed description.
FLAC audio is lossless because it takes the precise values of the audio, and uses a technique similar to zip files to find similar-looking blocks of data. Think in terms of having a one-second silence recorded as "Zero, then 44099 more of 'em" rather than "zero zero zero zero zero..." and so on 44100 times.
Not at all! CD audio amplitude is quantized to 16 bits, and temporally sampled at 44100 Hz as you say. Certainly very high quality, but there's absolutely a loss (that nobody can really hear).
Thank you
Just like any general purpose compression: everything - flac could be used just like zip/zlib/gzip as a general purpose compressor it just wouldn’t compress as well on most data that isn’t audio.
> dropped when "LOSS" occurs?
Lossy compression generally employs some type of perceptual coding where data is reorganized such that the signal data is sorted or localized according to its perceptual importance. This does partly involve removing or reducing the density of signal in the higher frequencies but it also exploits things such as masking both in time - inability to perceive signals occurring close in time of similar frequency. And frequency masking - our inability to hear quieter signals that are close in frequency to a louder one.
You cannot do the same with MP3, AAC, OGG, Opus or any other lossy codec.
The exact frequency/amplitude relationships where masking effects come into play were studied by the telecoms early on (meaning in the 1950s-1960s era), and are still a key part of most lossy encoding models these days.
See https://en.wikipedia.org/wiki/Critical_band and https://en.wikipedia.org/wiki/Psychoacoustics as an introduction to the principles.
Cutting down the bandwidth (lowering the sample rate) wont sound as good as an actual lossy codec - otherwise we could just resample.
But IMO these are the properties of a good container file / stream format. FLAC might define its own but IMO most codecs could work well with a generic container.
Are there other, more advanced lossless encodings that do this? And if so, why didn't they catch on compared to FLAC?
For that matter, is there a lossless format that just embeds a regular lossy encoding of the audio as the approximation, and then computes+stores the residual relative to that? (I'm guessing that this wouldn't work well for some reason, but I'm not sure what that reason would be.)
(ETA: the other later lossless audio formats that I'm personally aware of — ALAC, Monkey's Audio, and WavPack — all seem to use linear prediction. Seemingly they were all designed under the presumption of the constraint that the encode step must be able to be done in hardware / with fixed-sized memory buffers; rather than allowing that you can load the whole PCM audio file into memory and do things like FFT to it. Possibly made sense in the late 90s, when a PC's RAM wasn't much larger than five minutes of uncompressed audio. Doesn't really make sense today. Maybe we're due for a new lossless audio encoding?)
I'm curious if you'd gain anything by doing an mdct and then modeling in the frequency domain and then storing the residuals... Lots of the frequency channels will usually have much lower energy, so the residuals wind up being easier to store.
That led me to other coders: DTS-HD Master Audio [2] (née DTS++) and OptimFROG DualStream [3].
OptimFROG's DualStream mode is similar to WavPack's hybrid mode, and DTS-HD MA uses DTS Coherent Acoustics (based on ADPCM), so none of these are based on a perceptual lossy codec besides MPEG-4 SLS.
(Sorry to keep replying here, I keep stumbling on interesting things after the edit window closes)
[1] https://en.wikipedia.org/wiki/MPEG-4_SLS
It's not "regular lossy", but WavPack does allow separating lossy from the residual in hybrid mode. I think this is rarely done with DCT-based stuff because there's so much potential imprecision in the decoders.
Is this just a thing with old codecs? I'd think that any codec from the last 10 years could assume a minimum level of support for certain ALU ops in even the wimpiest hardware expected to decode it; and then constrain more-powerful implementations to emulate that minimum standard, so as to get exactly the same decoded output. (I.e., define a strict "decoder abstract machine" semantics, and then explain how various real-world software/hardware impls should implement it.)
Is this why h.264 and friends are specified in terms of how it's decoded?
Wondering if FLAC already does this or if such a feature could be added?
In the 80s and 90s some people were going crazy over HiFi, only the absolute high end products were just good enough. I remmeber seeing stereo systems for 50,000$ and more. CDs were already seen as inferior to records quality-wise, and speakers had to be huge if possible.
Today Wifi speakers are all the rage. The music is downloaded (precompressed) and then sent over Wifi or Bluetooth with (sometimes very) limited bandwidth to a single speaker which has the size of a laptop.
How does the audio quality compare? Is it like day and night? Or do the new multi room systems play in the same league as the old system that were used by enthusiasts? I often have the feeling that overall sound quality does not matter anymore as long as the bass is strong enough, but as I said at the beginning, my ears are not very sensitive.
Please repeat this when people say "there's no reason to use sample rates above 44 kHz". While it's true for source material, it should be properly caveated.
"greater than 44 kSamp/s", not "<44 kSamp/s"
"ADCs" should be "DACs". While it's still correct, it isn't on-topic.
But, a lot of popular music out there isn’t mastered for that use case (high end ABX testing). On the contrary, there are tons of CDs that are extremely compressed (in the dynamic range sense) so as to sound as loud as possible on the radio [1]. If you compare one of these CDs with an earlier (or even contemporary) vinyl release which has been mastered correctly then of course the vinyl will sound better!
Unfortunately, because we’re dealing with a Wild West of media, new and old, floating around in the marketplace we don’t have the luxury of a perfect ABX comparison, and so people will continue to buy and prefer old formats. It is for that reason that we can’t dismiss them.
For example, much of the great early Bluenote jazz was recorded by RVG in the living room of his parents' home in New Jersey. [1]
Until it is resampled in the noisy OS mixer and/or lossy compressed again to be sent over Bluetooth. Very few ABX studies consider the effect of such modern "digital signal chains", especially transcoding. It's much better to start with FLAC.
But saying this without mentioning the loudness wars misses the main force behind vinyl's staying power.
This is like making an argument for transistor guitar amps. They're better on paper, but tubes produce a type of distortion that is pleasing to many listeners.
Doesn't sound very scientific to me.
> How does the audio quality compare?
Why compare with an old system from the 80s? I got to hear a friend's friend's modern audiophile setup. A dedicated room with Wilson Audio speakers (totally overpriced but amazing), high-end DAC, high-end amp... It was bliss. One of these $50K+ setup but bliss. This is nothing like a laptop, a soundbar or a Sonos.
> Or do the new multi room systems play in the same league as the old system that were used by enthusiasts?
I wouldn't be suprised they'd actually be better than these old systems. But they don't play in the same league as actual modern audiophile setups.
From my experience with them, you kind of just summed up the HiFi/audiophile core. I've spent waaay too much time with audio engineers, recording engineers, etc from edit bays to sound stages. Yes, there are now things that I can hear because they pointed it out to me, but until then, I was perfectly content with my head in the sand of not-knowing. However, while I agree there are certain things that can make a difference, the tendency for the absurd always seems to take hold.
To be fair you can have a similarly great experience on significantly more affordable setups around 10k.
DAC and amplification above a certain price range is basically good enough to become indistinguishable from one another. The largest part of your budget should go into speakers. And don't underestimate the effects of proper room treatment and correction. Solutions like Dirac Live have made this much more approachable.
Anything above that will provide very marginal gains. There's a lot of costly prestige above that threshold which doesn't always translate into real audible benefits.
What do you mean? What's the difference between an audiophile setup from the 80s GP was mentioning and one from today? Today you'd have a DAC, for a start. Maybe some DRC (Digital Room Correction software). Then amps have progressed tremendously. And so did speakers (newer materials).
As for the setup I listened to: I'm no pro, I don't remember the details. I know the speakers were Wilson Audio but I don't remember the DAC nor the amp(s) brands: all I know is it was high-end stuff costing money I'm personally not willing to put in an audio setup. But it did sound very good.
Meanwhile, mass-market audio has gotten better but not consistently. The speakers are usually the limiting factor for quality: you can have at most any two of small speakers, deep bass, or volume for a given power budget. Lots of consumer systems go for small speakers and don't have either deep bass or high volume.
Does sound quality matter? That's an individual choice. It's available to you at a much lower cost than ever before in history.
Once you do lossless -> lossy, you're "stuck", unless you accept reencoding artifacts and those do add up to eventually be bad.
I'm an audio enthusiast, have quality (but not excessive, triple digit prices) DACs, amps and everything else. I can't ABX 256kbps+ MP3s from lossless, but the above stands.
Just compare the original earbuds included with the iPod to the wired EarPods that Apple sells now.
Or compare the AirPods Pro ($249) to what the same amount (inflation adjusted) could get you 20 years ago.
Of course there’s still plenty of space on the high end, and still the higher you go the more you need to spend to achieve 1% better sound.
These absolutely still exist. What's changed, to an extent, is that they're a bit less fashionable; whereas in the 80s any self-respecting rich person needed a hifi that cost as much as a small house, today, this is largely the preserve of (rich) enthusiasts.
The vast majority of people would have had relatively low cost stereo systems which were, by and large, far worse than their modern contemporaries, tho.
My guess: >90% of music consumers don't care about quality as long as it's good enough. What they care is ease of use. Why should they have a complicated setup and try getting their records in lossless FLAC when they can just go onto Spotify / Apple Music / YouTube and press play.
I've seen lot's of people that don't even care that their audio has the intro parts when playing from youtube. So why should they care for HiFi.
Apple Music has lossless now.
Same, but at home I also play directly the FLAC files (laptop / DAC / amp / floorstanding loudspeakers). They're not that much bigger than 320 kbps mp3 files.
I convert to lossy for my car, which takes mp3 files but not FLAC.
I used to collect mp3s back in the Napster days. My HDD was maybe 40 GB back then (?), maybe not even that. Nowadays FLAC files size aren't a concern. I think a screenshot of my screen takes more room than a song FLAC encoded.
Interestingly, a study suggests that room acoustics don't negatively affect the sound of good speakers, and what that means is that for listening, acoustics don't matter as much as they do for recording.
This ain’t true - for example Bluetooth is lossy compression.
‘Digital’ doesn’t mean lossless from the source.
MP3 is more like an edited version of the original where "extra fluff" is removed from the audio in a way that you can still hear the important bits. And then compressed for further space savings.
Obviously, there is no point in converting MP3 to FLAC since when the original lossless audio track was MP3'd , it lost some of the audio information, so you'd only be changing the compression algorithm, I imagine.
I'm really confused by what you're talking about lol... especially "up"convert...??? WAV is the ultimate lossless audio on PC. It really doesn't get any better than WAV. There is no "up" from WAV. FLAC is a compression format for WAV, that does not lose any data. The output of FLAC will be identical to the WAV file, even though its compressed. MP3 is a compression format for WAV that loses data, and will not be identical to the original WAV file.
When you rip one of your CD, a good ripper shall verify that your rip is 100% bit perfect (by verifying that the hash of your rip matches an online database of hashes of CDs ripped by other people). These rippers typically do rip to FLAC.
FWIW on Linux I've had good luck with "whipper" in the past (haven't ripped any CD that recently) [1]
How can an Apple device not support FLAC? Are they really that locked down that you can't do something basic like install a codec?
You can't install a codec globally on iOS, but there are many, many player apps that support FLAC: https://www.igeeksblog.com/best-music-player-apps-for-iphone...
For folks who think Apple Music is the best music app for iOS, it's not difficult to convert songs, albums, or whole music libraries to ALAC.
I think they prefer it because it's in a MPEG4 container, it can be DRM encumbered with their "FairPlay" technology that they hadn't used for a while, but now use again for subscription Apple Music.
It's funny how often people still assume "on the computer" means "MP3." I don't know why you'd put up with any loss of quality anymore, even if you personally can't hear the difference.
Why would you use 3x the storage space if you can't hear the difference for a non-trivial percentage of your available storage? Literally, by definition, according to your own terms, it serves no purpose.
I'm a musician and audio developer, and it's only really in my own music, that I've listened to over and over again while creating it, that I notice the degradation in a 192 kbps MP3 – and occasionally in the high-hats of CDs that I listened to hundreds of times in high school.
FLAC's great, and definitely serves a purpose, but I use it mainly for archives, not for casual listening.
No, I did not say "it serves no purpose." Those are your words. And I didn't say I can't hear the difference, either, I said I don't care if I can't.
My purpose is "you don't throw away information."
And MP3s get stored on a lot of things that aren't SD cards, so that's a pretty weird metric.
But you're getting dangerously into gold-audio-cable-and-tinfoil-hat territory. Most people (including me, literally an audio expert) can't hear the difference in most cases so you're arguing for the increased space, and significant cost based solely on some notion of purity. That makes sense for archives, where they're being preserved for posterity and potential future processing, but not for casual listening.
Would you prefer that all websites served you only PNGs?
https://people.xiph.org/~xiphmont/demo/neil-young.html
The arguments for lossy codecs vs. dithering / bit reduction aren't identical, but it's a pretty good indictment of the SAVE ALL THE BITS argument. On the same domain as the parent article.
I hate pulling rank so fiercely, but I literally wrote the second (i.e. first non-reference) implementation of the Ogg container format (which Opus, Vorbis and sometimes FLAC use). I know these codecs.
Ogg Vorbis and AAC hit similar levels of quality as a 192 kbps MP3 around 160 kbps. (That actually depends a fair amount on the MP3 encoder. The LAME VBR is particularly good.)
But I have an 11 year old receiver and a 12 year old car that can't play them. Hell, even iTunes can't without third-party codec plugins. MP3s are about as universal as it gets. Being able to play my files everywhere is pretty high up on my list of concerns.
at current prices that's about $25 of SSD
I've got a couple of DJ friends that have taken to ripping their collections (CDs and vinyl) to WAV files as most DJ software didn't support FLAC playback at the time.
A "2 kW" sound system doesn't have any special properties by nature of its wattage, but a club does have a sound system which can reproduce frequencies that are below that what a typical home (or studio) system can. MP3s are usually encoded with a high-pass filter (usually around 20 Hz), and some club systems can get down close to that range (more often 30 Hz), but it's very questionable that they're hitting border.
It is true though that on those types of systems, you're more likely to expose the effects of doing things like double lossy encoding, use of bad encoders, etc.
My collection is lossless and nearing 2 TB in size. Too large for mobile usage on iOS, where I don't really need that kind of fidelity anyway. However I still don't want to manage a second lossy library and keep them both in sync. Luckily Apple's Music app can be configured to transcode your lossless audio to a lossy format on the fly whenever you sync your collection to your iPhone. That way I can have my whole collection in my pocket without having to manage it.
Maybe in another decade.
So are MP3s, unless you compress them to crap. FLACs are more like low 10s of MB, about 2.5× high quality MP3s in my experience.
You have to know what to listen for, and even if you do, why should you care? It's a small price to pay for being able to store several times as much music on your phone, or for saving on bandwidth while streaming.
How is this a lossless process?
I know a couple of years ago it used to be flaky. Eg:
There are other issues related to streaming the FLAC via Range requests depending if it is WebAudio, <audio> or directly in a tab, however this applies to all audio/media in general.
There is no sane approach to media. Between legacy formats, legacy tagging, and all kinds of implementation specific bugs, you are in for a ride if you want to cater to more than one decoder out there :)
Could you share more info on that?