Because I might encode my music in lossy format for other devices or edit them, I prefer to keep a high-res copy of my music. However, I know that it is possible to upsample a file using ffmpeg and it would appear the same as an authentic high-res file with ffprobe. Is there anyway I can tell apart a "fake" high-res file (converted from CD-quality or mp3/aac) apart from a "real" high-res file (exported high-res by the producer)?
Let's get some basics out of the way first.
An audio format is basically defined by three different things: sample rate, bit depth and compression type. The compression type can be either lossless (WAV, PCM, FLAC, ALAC) or "lossy" (AAC, MP3, OGG, MQA, etc). Lossy compression works by shaping the quantization noise so it's masked by the remaining content and inaudible. Lossy formats are characterized by their bit-rate: the higher the bit-rate, the less quantization is done.
The typical life cycle is the following: recording, mixing and happens at 96kHz floating point. When that's done, there are typically two masters made: a studio master at 96kHz/24-bit and a CD master at 44.1kHz/16-bit.
The label will send one of these two to the distribution channel, e.g. Spotify. Which one depends on the contract. Spotify will then create the formats that they need for their streaming platform, which almost always includes lossy compression. For example Spotify uses OGG at 320 kb/s. Apple Music uses AAC at 256 kb/s. Which format gets to the customer depends on the contract between the customer and the distribution.
Is there anyway I can tell apart a "fake" high-res file (converted from CD-quality or mp3/aac) apart from a "real" high-res file
Here are a few things to look for in a spectral analysis
- Each format has it's own rolloff: CD drops like a rock at 20 kHz and MP3 drops steeply at 16 kHz. If you have a 96 kHz file with these sharp drop offs, it's likely been up-sampled.
- Inspect the content above 20 kHz. If there is random "noise like" features in there, it's probably genuine. If it has very little content and/or the content looks like a low-pass filtered mirror image of the content below 20 kHz, it's been up-sampled.
- You can look at correlation at high frequencies. For a genuine recording this will mostly be uncorrelated. If there is significant correlation, it's a potential sign of "joint stereo coding" which could hint at lossy compression.
- Look at the recording date: If it's been made before 1990 it's almost guaranteed to be up-sampled. There never was a digital studio master and the best they can do is to sample a tape master.
Some formats like MQA, include authentication, i.e. they put a "seal" on the content and can detect whether the "seal" has been tampered with. It's also possible to put a watermark on the content.
You may be able to detect bit padding as well: Any "decent" CD quality file have been properly noise shaped and dithered. It's possible that signs of this will survive the up sampling process can be detected. I've neve tried that, so I don't know how feasible it is, but it sure would be interesting to try.
@Hilmar's answer has this pretty much sewn up. The only addition I will make is a visualisation of what an up-sampled spectrum would look like.
Here is a bassoon that was recorded at 96kHz. The recording was reasonably dirty so you can see a fair amount of frequency content above 22kHz (~44.1kHz Nyquist).
Bassoon at 96kHz
The 96 kHz file was then downsampled to a 44.1kHz wav file. Downsampling will involve low pass filtering the original audio data. When the 44.1 kHz version is upsampled back to 96kHz, we can see that frequency content has been thrown away.
Bassoon exported to 44.1 kHz then upsampled back to 96kHz
A file that where the signal path has been kept 96kHz from microphone to loudspeaker has the potential for signal components up to 48kHz. Most physical sound sources, rooms and microphones will roll off towards those frequencies, but slowly and gently.
If the spectrum of a 96kHz file has signs of brick-wall filtering at 22 or 24kHz, this could be a sign that somewhere in the signal chain, 44.1 or 48kHz sampling was used. It could mean that the synth used by the musician had 48kHz D/A converters.
In the end, if you cannot hear the difference, does it matter? Afaik, no-one has reliably been able to hear the degradation of a 44.1/16-bit system in fair conditions (in a way that would let you publish results in a scientific journal. Anecdotal claims about all kinds of stuff flourish among hifi people).
You could try using spectrograms to do some forensics. I don’t think there’s a generalized solution, or any way to say for certain which formats can be detected as having been up sampled. Refer to the following for nifty photos: https://sound.stackexchange.com/questions/37730/which-spectrogram-shows-higher-quality-of-the-song
MP3 works using a lossless compression scheme known as Huffman coding, which can achieve very high compression ratios when redundant data is present. An encoder might do a time-frequency analysis of the input using the MDCT-IV (I think), compare the result to psychoacoustic models, and zero out content in a way that the audible distortion is minimized. This zeroing is what makes the compression lossy. The more zeros, the more redundant data, the better the compression. Note that this is very broad, and the MP3 spec/implementations are more involved. If you look at the MP3 spectrograms in the linked answer, especially the 128kbps example, you can use visual inspection to see all the black, boxy stuff around the orangish/reddish signal. This would suggest a lossy codec was used. It can be a little tricky to tell, because they typically/always have a boxy quality to them, but we’re looking for black/zero data where it doesn’t look natural.
Upsampling the sample rate from a CD might have a similar effect. Let’s say we start with 44.1kHz and go to 192kHz. Our input has a bandwidth 22.1kHz, and the output a bandwidth of 96kHz. The upsampler needs to figure out what to do with all that content. A sensible approach would be to ‘set’ all that content to zero, so a spectrogram would show all black in that upper range. So if we see the upper bandwidth isn’t being used, that might suggest it’s been upsampled from a lower rate. It might also be that the recording just had a lower bandwidth, which basically means that it could have been recorded at a lower sample rate without loss of information. This is just a hypothetical upsampler though, there isn’t international law pertaining to how it’s done, and there are practical limitations to how effective the ‘zeroing’ is, including the cleverness of whomever designed it.
Checking for a change in bit depth is something I’ve not ever tried to do, but I’ll hazard a guess anyway. Audible distortion from bit depth is most apparent at low signal levels, and will either manifest as harmonic distortion or noise. I’d look for a segment where the signal fades to silence and see what’s going on there. Maybe we’d see some harmonics pop up, or some noise that doesn’t seem like it should be there, and perhaps the magnitudes would give us an estimate of the bit depth.