[flac-dev] FLAC compression experiment
brianw at audiobanshee.com
Sun Aug 20 07:49:50 UTC 2017
There are several errors and misinterpretations in your example.
Your first error is that at 5% volume, starting with a 16-bit file results in less than 12 bits of resolution. There is no way to get back the original 16-bit quality unless you promote the 16-bit file to a 24-bit file at the same time as you reduce the volume to 5%. While that might work at the expense of using 24-bit FLAC for a 16-bit WAV, it would fail to be lossless if you start with a true 24-bit WAV. In the latter case, your FLAC would only preserve less than 20 bits of audio, and that is not lossless.
Your second error is that WAV file sizes are always identical for all WAV files with the same bit depth and time duration (and channel count - in this case, stereo). That is the definition of uncompressed audio file sizes. However, even with identical source WAV file sizes, the corresponding FLAC file sizes are expected to vary a great deal because FLAC is required to be lossless. An MP3 can have a fixed compression ratio because it is lossy - sound quality is lost. FLAC cannot have a fixed compression ratio because is must be lossless, and thus differences in the input audio will change the size. That is expected.
The misinterpretation I refer to is that the relationship between the volume level (amplitude) of the original audio and the size of the compressed FLAC file is expected to be exactly like you have discovered. FLAC uses many mathematical algorithms to reduce the size of audio without losing any information. One of these processes is to use differential values rather than absolute values. The second is to use Rice coding so that small values take less space than large values. There's a lot more going on than just those two algorithms, but the point is that sounds with a lower amplitude will always compress smaller than sounds with a higher amplitude.
I can guarantee, mathematically, that there is no way to reduce the volume of a 16-bit audio recording to 5% and then restore is to it's original value (at least not without cheating and using 24-bit storage in between) without losing something. Your 5% volume is a reduction in signal-to-noise ratio of 26 dB, and there's no way to get that back losslessly.
In other words, your suggestion to add a volume header for normalization defeats the purpose of FLAC, because your technique will not be lossless. There are plenty of compression algorithms that can lose 26 dB of S/N and create smaller files.
Thanks for writing, though. It's always fun to discover how FLAC works. In my personal usage, I make live recordings and then use FLAC to archive the originals. Since live recording should never allow the volume to reach the Full Scale limits, my live recordings always compress smaller than the equivalent 24-bit audio for distribution. I discovered the same things you discovered when I went through the mastering process - which increases the volume - and noticed that the final FLAC files were much larger than the original FLAC files. This was really only because I increased the volume. In this case, I might be able to release unmastered audio recordings with a "normalization" value and keep the FLAC files smaller. But that only works because the original audio is already quieter. It doesn't work losslessly if you artificially reduce the volume - because then you're losing information.
On Aug 19, 2017, at 2:37 PM, z1x2c3v4z1x2c3v4 <z1x2c3v4z1x2c3v4 at hotmail.com> wrote:
> I feel I have found a super high compression way of FLAC. I have tested a 1 hour WAV file of 440HTZ with a 5,25,50,75,100 normalize volume preset. This dramatically changes the compression size of the end FLAC file even though the WAV file size is identical for all 5 WAV files. Only the volume is different. When you renormalize the WAV to its original volume the file is still 100% original.
> My tests are the following.
> source file WAV. 1 hour 440HTZ tone. 600MB.
> volume at 100. FLAC file size is 184MB.
> volume at 75. FLAC file size is 166MB.
> volume at 50. FLAC file size is 143MB.
> volume at 25. FLAC file size is 109MB.
> volume at 5. FLAC file size is 96MB.
> From184MB to 96MB.
> As you can see from the full 100 normalize volume to the 5 normalize volume it is half the file size.
> So to put it. I think that you should have your compression of FLAC to also include a normalize volume shift to further compress the end product. Either have a default setting or allow a user to input an option in the command line arguments to add a normalize volume value. Then to uncompress it back to a WAV file FLAC would read the volume header in the FLAC file to apply the WAV original normalize volume and expand it back to its original state.
> Then have the FLAC decoder for all the players out there to read the volume header so to play the FLAC at the WAV original normalize volume.
> I hope I have helped to develop FLAC further.
More information about the flac-dev