Just four letters: FLAC.
Some explanation / thoughts on the subject
Warning: this includes personal opinions that aren't necessarily mainstream-accepted. See AJ Henderson's answer for a somewhat more moderate view.
I'd first like to say: being pedantic, there is no such thing as a lossless audio file. Audio is an analogue phenomenon, anything digital can only ever be an approximation. So there is no quite as fundamental difference between "lossless" and lossy codecs as it is always said. If you compare a 11.025 kHz / 8 bit mono .wav
file to a 110 kbit/s 48 kHz .mp3
or .ogg
by ear, the "lossy" format will clearly win quality-wise, while having almost the same size. That's because these lossy codecs omit information "cleverly", i.e. in such a way as to minimize the impact on how the audio sounds, whereas .wav
just quantises time and amplitude everywhere uniformly1.
The human ear has some rather simply specifiable, and some more complicated limits.
Any Fourier components above ca. 20 kHz in a signal are virtually inaudible. So (by the Shannon-Nyqvist theorem), technically perfect PAM sampling with rates above 40 kHz yields a representation of the signal that our ears cannot distinguish from the original.
Since our body has a finite temperature, there is necessarily some noise floor in our ears. If any noise introduced by digital quantisation stays below this threshold, it won't be audible. Effectively, the dynamic range of the human ear is no more than 140 dB (oftentimes the useful range is much lower); 24-bit integers cover a range of 144 dB. So a properly dithered 24-bit PCM version of a 48 kHz PAM signal will still be indistinguishable (by bare ear) from the analogue original signal.
This is why we call such .wav
files (or even CD-quality ones) lossless: the losses are inaudible, so for all relevant purposes they don't exist.
Wait a moment. Is listening really the only thing you do with an audio file? Why, no, you might first pull the signal through all kinds of audio effects. Many of those (e.g. reverb or basic EQing) won't really change anything about the sampling limit and dynamic range. But of others, this can't be said. Most obviously, a compressor takes in a signal with some dynamic range and outputs a signal with lower one. If you still want the final result to have "lossless" quality, you need to make sure the intermediate file has a higher dynamic range than what you want on your ears. This is why professional recordings are nowadays never done on less-than-24-bit files, even if you ultimately need only 16 bit CD-quality. High bit depths pretty much solve the problem for everything ever used in 99% of all audio productions, but it's quite obvious that there are effects where it's not enough: consider simply a strong pitch-down effect. You'd expect this to make ultrasonic sounds audible, but this can't possibly work if the recorded file has only 44.1 kHz sampling rate. Fortunately, such stuff is seldom needed.
Back to out ears' limits – I said there are more complicated ones. Which is why I'm not going to discuss them in detail here, but they're mostly about masking effects: during silence, even very quiet noise is audible, but while there is loud music much higher levels of noise would go unnoticed. So at these parts, you can quantise much rougher – that's easiest done with floating-point samples. This is especially efficient when not working purely in time space but confining the artifacts to frequency ranges where there is also high amounts of signal. To this extend, most lossy algorithms (apart from mp3 I'd like to mention Ogg Vorbis, which BTW doesn't have those patent issues) use a type of Fourier transform, usually DCT, before their main quantisation step. This can work very effectively, as demonstrated by small yet well-sounding .ogg
files. In fact, continuing the logic used above: if we manage to produce such a file that humans can in a double-blind test not distinguish from the original, why should we not call this file lossless? It has "errors" (artifacts), but again a .wav
file isn't exact either.
However, artifacts in .mp3
are much more complicated than simple quantisation noise or high-frequency band cutoffs. Even when they're still inaudible to the ear, they may have a much more significant effect when fed into further processing, like recompression to another format or audio effects. They're just not designed for that. OTOH, bandlimiting and quantisation noise are very well understood and modelled mathematically exact; you can transform between different sample rates without generation loss, you can re-dither to other bit depths etc.. This makes it acceptable to call lossless formats thus, even though really they aren't lossless. And it's why they are the right choice during audio processing2.
⟨/rant⟩
So how do formats like .flac
fit into all this? Lossless means again to keep the benefits of plain PCM like .wav
, i.e. not allowing bad-to-handle artifacts. In fact it means you are able to convert a .flac
file back to a .wav
that will be identical to the original source .wav
.
Question is, do we have to live with he large size of PCM files?
If you think about it, there must be physical reasons why our ears are so insensitive to e.g. DCT-quantisation artifacts. From one point, it appears that they mechanically aren't able to properly follow those. From another point, you might also say that real-world sound happens to be of a kind that de-emphasises such artifacts. These arguments are in fact interchangable, as any sound transmitter is also a receiver and an instrument's body is in a way analogue to the eardrum (more literally, a microphone is equivalent to a small loudspeaker). So it should be possible to make up a compression scheme the other way around: instead of thinking "how do we leave out information so the difference won't be notable?" we go "where do we expect to find no information in the first place?" Because then we can use entropy coding, which basically just shuffles data around in a clever way, such that information that was already expected takes up little space while only (seldom-occurring) unexpected information is fully expanded. When we then feed such an algorithm with an audio file that conforms with our expectations (and thus with our ears', which has pretty good experience in those matters), the compressed version will be significantly smaller yet digitally equivalent to the .wav
version. And this does in fact work quite well.
1 Actually, there are several rather crude "better-quality" compression schemes that .wav
can use. Much more primitive than the DCT-based algorithms that mpeg or Vorbis employ.
2 (this isn't so much a footnote as a conclusion) I should still add that there's another consideration for audio processing: unlike in a simple music player, a DAW needs to access many audio files simultaneously, very quickly, and possibly non-sequentially. This is very easy with a format like .wav
, which is encoded completely in the time domain: want to enter at 2:35? Why, just add the offset 155*samplerate*bytespersample to the file position and start playing from there. By contrast, both lossy and lossless compressed file formats have the data somewhat disordered by the various transformations. You usually still have some kind of time-chunks that you can each access directly, but you can't quite as easily just start playing at some arbitrary point – there's always some pre-load, latency, memory&processing overhead and whatnot. So even though .flac
may seen the perfect alternative, I actually don't use it that much: disk space is cheap nowadays, so .wav
is rather fine. If I need 20GB for a song I'm working on for 20 hours, the storage cost is pretty much neglectable: I can just get a new external HDD when I need it. So there's not much reason to switch to .flac
and if it might cause latency issues during an important recording session, I'd have quite a problem. So that's not going to happen.
With finished mastered song files it's rather different: those are just going to be fed into your ears, nothing else. So here the crucial thing is subjectively lossless again: lossless to the ear. Now, I positively dislike the sound of so-called "CD-quality" 128 kBit/s .mp3
files, but for >200 kBit/s, done with a good encoder like lame (with the more maturely designed Vorbis or e.g. .aac
you can go even lower) you won't be able to tell the difference. You just won't. So it ******* is lossless, and these files will be quite a lot smaller than the tightest that "lossless codecs" can do.