Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Use of non 8/16/24-bit audio, like 12-bit audio (Read 16555 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

Use of non 8/16/24-bit audio, like 12-bit audio

Hi all,

Currently I'm trying to build a nice set of test files for FLAC decoders. In a recent post on this board, I mentioned that there might be quite a few hardware decoders out there that do not support a FLAC file with a variable blocksize. Instead of just distributing a single file so people can check their devices, I thought making a comprehensive set of files with all kinds of FLAC features that are not often used would be even nicer.

Anyway, FLAC's format supports 8, 12, 16, 20 and 24 bit audio within it's subset. I have been looking around to find some tool to create 12 and 20 bit audio to feed to a FLAC encoder, but I can't really find anything.

Does anyone know of 12-bit and 20-bit audio being used anywhere? Or should I just ignore this part of the specification?
Music: sounds arranged such that they construct feelings.


Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #2
20 bit can be found on some DVD-Audio discs.

Thanks! That's a very good reason to include a 20-bit test file.

I just hacked the FLAC encoder to accept 12-bit raw, so I'm no longer looking for tools to do this. The question remains, where else these bitdepths might be used.
Music: sounds arranged such that they construct feelings.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #3
For example, Sonar claims to be able to export to some "12 bit DWVW AIFF (Apple/SGI) " - https://www.cakewalk.com/Documentation?product=SONAR&language=3&help=Dialogs2.146.html
sndfile-convert also has such option - https://helpmanual.io/help/sndfile-convert/
Audacity has such option too (amongst "Other uncompressed formats"), but it doesn't works for me for reasons unknown.

After looking at Wikiipedia i realized that DWVW is "Delta with variable word width", so don't know if it can be PCM at all - https://en.wikipedia.org/wiki/Audio_Interchange_File_Format#Common_compression_types



 

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #6
ffmpeg reports wood12.aiff as bitrate 705 pcm_16be (fb2k: 706, due to different round-off conventions).
Indicating 16 bits (mono)?
Whatever flac.exe's error message means ...

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #7
More 20 bits in CoolEdit: https://hydrogenaud.io/index.php&topic=3404.msg33299#msg33299

As for 12 bit, it was part of the DAT specification. Also, apparently, Sony used it in video cameras. But (cf. that link), that does not mean anyone got 12-bit files.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #8
The only program I know of that can write 20-bit flac is Awave Audio by FMJ-Software. But since only new players are compatible with it, saving as 24-bit with a tiny overhead is preferable.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #9
You can create such files easily with qaac/refalac. Use -b option.
qaac/refalac actually allows arbitrary bits per sample in 2-31.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #10
ffmpeg reports wood12.aiff as bitrate 705 pcm_16be (fb2k: 706, due to different round-off conventions).
Indicating 16 bits (mono)?
From the format spec:
Quote
Sample points are stored in an integral number of contiguous bytes.  One to 8 bit wide sample
points are stored in one byte, 9 to 16 bit wide sample points are stored in two bytes, ...
So effectively it is 12 bits in 16 bits container.
Whatever flac.exe's error message means ...
Mine says:
Quote
ERROR during read, sample data (channel#0 sample#0 = 2) has non-zero least-significant bits
  WAVE/AIFF header said the last 4 bits are not significant and should be zero.
My guess, again, from the format spec:
Quote
When the width of a sample point is less than a multiple of 8 bits, the sample point data is left
justified, with the remaining bits zeroed.
and that is not what happens in that file:
Code: [Select]
53 53  4e 44   00 00 0c b4   00 00 00 00   00 00 00 00   00 02 ...
"SSND"         chunk size    offset        block size    data

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #11
In the attachment there is a fixed wood12 sample and a flac created from it:
Code: [Select]
]$ metaflac --list --block-type=STREAMINFO wood12fix.flac
METADATA block #0
  type: 0 (STREAMINFO)
  is last: false
  length: 34
  minimum blocksize: 4096 samples
  maximum blocksize: 4096 samples
  minimum framesize: 1394 bytes
  maximum framesize: 1394 bytes
  sample_rate: 44100 Hz
  channels: 1
  bits-per-sample: 12
  total samples: 1622
  MD5 signature: fa5ac05726a6fb8d5f4e31613e6710ac

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #12
So, it seems after whole-byte bitdepths (8/16/24) there are few cases of using the whole-nibble bitdepths that are in-between (12/20). Wikipedia seems to mention 10 and 11 bit for the NICAM compression format. µ-law can be losslessly converted to 14 bit LPCM and A-law to 13-bit LPCM if I understand correctly. Any others?
Music: sounds arranged such that they construct feelings.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #13
You can create such files easily with qaac/refalac. Use -b option.
qaac/refalac actually allows arbitrary bits per sample in 2-31.
This was a life saver when dealing with some HDCD files and being far too anal about how to "best" store them as efficiently as possible. wavpack's "pre-quantize" option was out of the question because it still reported the "original" bit-depth.
I let foobar decode an album with Peak Extend, told foo_hdcd not to halve volume, and then used the album ReplayGain value under "Processing" while outputting to float32 PCM to prevent clipping according to peaks. The ReplayGain values did take the HDCD decoding into account, peaks of ~1.23 on the unconverted CD rip, since it was scanned with foo_hdcd active.
refalac will happily accept float input and truncate as many bits as you ask it to, with or without dither. I was going to convert to wavpack or FLAC since they're always at least slightly more efficient than ALAC and I haven't had an iPod in a decade, then I looked at the actual float32 WAVs. There isn't a single point in the entire album that goes below -96 dB, even "silence" - back through refalac again with -b 16 --no-dither. Would've been storing an extra ~100-150 MB of useless quantization noise at 24 or even 20 bits.
Speaking of wavpack, it's got an interesting peculiarity, at least if you use foobar to encode. Try encoding a 20-bit FLAC to wavpack and note the MD5: it changes. Encode it to FLAC again, get your original MD5 back...
Now re-encode that wavpack file to 24-bit by manually selecting that bit-depth, your MD5 will not change, neither will the filesize. The wavpack encoder is smart enough to not only realize it's padding 4 bits of zeros, but actually throw them away entirely. It will still ID itself as a 24-bit file. Now decode either of them to 24-bit FLAC, or manually pad that first 20-bit FLAC to 24-bits, and note that all of those files have the same MD5 as the 20-bit wavpack file...
Not sure if the bug lies with foobar or with how wavpack calculates MD5s, but it sounds like it pads any bit-depth between 17 and 23 to 24 before calculating it.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #14
If you halve the amplitude by a factor of exactly 2, then you can store the data more efficiently, by only using additional bits during moments when peak extend or gain are active. But if you normalize to peak, or enter any number in decibels (you can't input exactly 0.5), the word length expands and dither must be used. Files processed wtih a declipper can be treated similarly. You could choose to quantize to 18 bits, effectively giving no more than an extra bit for peaks and fades.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #15
You can create such files easily with qaac/refalac. Use -b option.
qaac/refalac actually allows arbitrary bits per sample in 2-31.

Hm?
ERROR: Not supported bit depth for ALAC


(Oh, and: if ALAC can produce e.g. 13-bit files, could it then be used with LossyWav?)

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #16
You can create such files easily with qaac/refalac. Use -b option.
qaac/refalac actually allows arbitrary bits per sample in 2-31.
Hm?
ERROR: Not supported bit depth for ALAC
Since "arbitrary bits per sample" is only allowed in PCM (not ALAC), you need -D option.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #17
Technically, it should be possible to have fractional bit depths as well: For instance have every even sample be 10bit and ever odd sample be 11bit.
The practicality of it is probably not great, but from a pure technical perspective there's no reason something like that shouldn't be possible. Depending on how samples are labeled, you can do something like UTF-8 but for audio samples: each sample can be between 8 and 64 bit in depth.
I could see it'd be interesting to tinker with something like that.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #18
I just hacked the FLAC encoder to accept 12-bit raw, so I'm no longer looking for tools to do this.
Did you manage to test these 12-bit by ear?

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #19
Did you manage to test these 12-bit by ear?
I do not understand that question? What is there to test?
Music: sounds arranged such that they construct feelings.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #20
Is the difference between 12bit and 16bit perceptible by ear? Anyone will hear the difference between 8bit and 16bit.

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #21
Is the difference between 12bit and 16bit perceptible by ear? Anyone will hear the difference between 8bit and 16bit.
That wasn't really the purpose of this thread. Or rather: if your player refuses a 20-bit file, then the difference between 20-bit files and 24-bit files is absolutely "perceptible".
So the underlying question was whether 12-bit files and 20-bit files should be included in a test bench, to check whether players can actually handle them. On one hand, the FLAC format does include 12-bit or 20-bit files, which points at "yes, test it!"; on the other hand, it would not be of much value had no application been writing to 12-bit file or a 20-bit files. But yes there are some.


Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #22
That wasn't really the purpose of this thread. Or rather: if your player refuses a 20-bit file, then the difference between 20-bit files and 24-bit files is absolutely "perceptible".
Were those 20-bit honest or with a boost/restore to 24-bit?

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #23
20-bit files - FLAC, WAVE, AIFF ... - are less widespread, so the question for a FLAC testbench would be how many players can handle 20-bit FLAC files.

24-bit FLAC files can of course carry 20-bit PCM signals by zeroing out the least four bits, and without any size penalty (FLAC just flags "four wasted bits!"). Indeed, some applications do that for compatibility reasons (not only for FLAC compatibility, but also for other formats), and thus making 20-bit FLAC even scarcer.
24-bit FLAC files carrying 20-bit PCM will be decoded to 24-bit WAV. (Well at least I know no decoder that will scan the FLAC file, note that the number of wasted bits is always at least four but sometimes less than eight, and therefore output a 20-bit file.)

(Several lossless formats support only multiples of 8. At the other end, WavPack provides for any (integer) number of bits from 1 to 32.)

Re: Use of non 8/16/24-bit audio, like 12-bit audio

Reply #24
FLAC files with arbitrary bits per sample must be handled specifically by the player that uses libFLAC. All bit depths are decoded to the least significant N bits of the 32 bit integer format buffers by libFLAC, it's up to the app to promote these to a usable bit depth on its own.

For instance, foobar could be interleaving the buffers on its own, then using the audio_math function to convert 32 bit integer to 32 bit float, with a gain value relative to the bit depth used by the file.

My player, Cog, upshifts the bits to the most significant bits of a field at least as many bytes as it takes to represent the file bit depth. Then my int to float converter promotes these to float32.