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: Low peak 24-bit audio to 16-bit (Read 3389 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Low peak 24-bit audio to 16-bit

I have a few 24-bit audio files and i'm wondering if there's a way to convert them to 16-bit losslessly (sort of but not technically lossless i guess?).
They have very low peaks, so i figured it might be as simple as amplifying them a specific amount and then lowering the bit depth to 16 without dither.

Any tips?

Re: Low peak 24-bit audio to 16-bit

Reply #1
Lossless volume change is only possible in 6dB steps so 24bit to 16bit could be done lossless if the source has a peak below -48dB.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Re: Low peak 24-bit audio to 16-bit

Reply #2
Lossless volume change is only possible in 6dB steps so 24bit to 16bit could be done lossless if the source has a peak below -48dB.
In other words, if all of the information is contained in the low 16 bits then just throw away the top 8 bits.

If all you are after is sort of lossless then just apply enough gain so that when you throw away the low 8 bits, or reduce the bit depth with dither, the difference will be down 96 dB, i.e. inaudible.

Re: Low peak 24-bit audio to 16-bit

Reply #3
Let's say that your bits are numbered 0 to 23, with 0 the most-significant, then
Code: [Select]
sox -D in.wav -b16 out.wav vol 8
extracts bits 3 to 18 from the input and stores them unmodified in the output.

Doubling the volume shifts another bit, so vol 16 gets you bits 4 to 19, etc.

However, it may still make sense to dither (remove the -D).


Re: Low peak 24-bit audio to 16-bit

Reply #4
Thanks for the responses everyone, you're a big help :)

bandpass: If what Wombat said is true, then shouldn't the code be something like this?
Code: [Select]
sox -D in.wav -b16 out.wav vol 6dB
You had it set to an amplitude of 8 or ~18dB.
Or maybe i misunderstood...

Re: Low peak 24-bit audio to 16-bit

Reply #5
Decibels are usually used for volume (gain) change, but for a lossless bit shift the number needed would be 6.02059.... I.e. an irrational number, so in this case it is easier to use a simple linear multiplier.

Re: Low peak 24-bit audio to 16-bit

Reply #6
I guess a simple volume change does not create much of an error. One should come away without dither even.
Btw. here i describe the uncomfortable way to shift bit by bit lossless with sox. https://hydrogenaud.io/index.php/topic,102681.msg845676.html#msg845676
pdq says to simply throw away the top bits. This i don't know how to do.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Re: Low peak 24-bit audio to 16-bit

Reply #7
Well, you don't (need to). Each 2x multiplication is equal to one left bit shift, vol 8 = 2^3. Take the remaining bits and you've effectively thrown away the (hopfully zeroed)  3 most significant bits.

And yup, 2x is not +6 dB, it's 20*log10(2) = 6.02... what bandpass wrote.
"I hear it when I see it."

Re: Low peak 24-bit audio to 16-bit

Reply #8
Oh, okay! I get it now.
So to convert 24-bit to 16-bit "losslessly", i would use an amplitude of 256, correct?

Re: Low peak 24-bit audio to 16-bit

Reply #9
Only if the audio is contained ENTIRELY in the low 16 bits (which is unlikely).

Re: Low peak 24-bit audio to 16-bit

Reply #10
Only if the 8 most significant bits are zeroed, yes, otherwise there's definitely loss and probably severe digital clipping.

This is quite untypical however. While a 16-bit full-scale value (2^15 = 0 dBFS) could be carried over one-to-one to 24 bits (2^15/2^23 = 1/256 = -48.17 dBFS ... you see the problem?) the 16-bit value is typically left shifted by 8 bits, so that the lossless operation would be right shifting again by 8 bits (division by 2^8).

What's the peak sample value of your files? Is it higher than -48.17 dBFS?

edit: pdq beat me to it
"I hear it when I see it."

Re: Low peak 24-bit audio to 16-bit

Reply #11
Bit-shift vol (linear) gain (dB)
8 256 48.1647993062
7 128 42.144199393
6 64 36.1235994797
5 32 30.1029995664
4 16 24.0823996531
3 8 18.0617997398
2 4 12.0411998266
1 2 6.0205999133
0 1 0
–1 0.5 –6.0205999133
–2 0.25 –12.0411998266
–3 0.125 –18.0617997398
–4 0.0625 –24.0823996531
–5 0.03125 –30.1029995664
–6 0.015625 –36.1235994797
–7 0.0078125 –42.144199393
–8 0.00390625 –48.1647993062
In fact, if you use all the digits shown you'll probably get lossless even with dB (since the error in the irrationals is less than 1/2 lsb @ 16-bit).

Re: Low peak 24-bit audio to 16-bit

Reply #12
Yeah, my files have peaks much higher than -48dBFS, so it doesn't work here.
That answers all my questions. You're all great. Rather than just giving a straight solution you've helped me understand bit depth a lot better. Now i know why the amplification works in some cases and why it won't in mine. Thanks so much all of you!

Re: Low peak 24-bit audio to 16-bit

Reply #13
Quote
They have very low peaks
How low?

Quote
Now i know why the amplification works in some cases and why it won't in mine.
It should work fine!!!!   If the recording is too quiet, you're probably cranking-up the playback volume, and analog amplification isn't perfect either.

Volume adjustments and downsampling to 16-bits is done every day.      Most commercial recordings have gone through many volume adjustments during mixing/processing* and although it's not mathematically lossless or perfectly-mathematically reversible, it's not considered a lossy process and nobody worries about it.   

So, I'd just go-ahead an normalize the 24-file (assuming you want it louder, and assuming normalizing for 0dB peaks doesn't make it too loud), then downsample.   

It's "standard practice" to dither when you downsample, but that's up to you since you usually can't hear dither (or the effects of dither) at 16-bits or better.






* Plus all kinds of processing that's not intended to be lossless.

Re: Low peak 24-bit audio to 16-bit

Reply #14
How low?
-16dBFS. Quiet, but nowhere near low enough. I feel silly for thinking it might have worked now :P

Quote
If the recording is too quiet, you're probably cranking-up the playback volume, and analog amplification isn't perfect either.
I'm using replaygain, so no worries there.

Quote
Volume adjustments and downsampling to 16-bits is done every day.      Most commercial recordings have gone through many volume adjustments during mixing/processing* and although it's not mathematically lossless or perfectly-mathematically reversible, it's not considered a lossy process and nobody worries about it.   
So, I'd just go-ahead an normalize the 24-file (assuming you want it louder, and assuming normalizing for 0dB peaks doesn't make it too loud), then downsample.  
It's "standard practice" to dither when you downsample, but that's up to you since you usually can't hear dither (or the effects of dither) at 16-bits or better.
Don't worry, i know this.
I have a kind of obsession with keeping data, even if it's technically useless (e.g. I have a HDD full of 1:1 Blu-Rays).
I will be downsampling and dithering my files. I was just hoping for a way to keep the data and downsample.

Re: Low peak 24-bit audio to 16-bit

Reply #15
Thanks bandpass at this point! No idea how often i stared at the SoX manual and didn't grasp how -vol easily can shift bits.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!


Re: Low peak 24-bit audio to 16-bit

Reply #17
Lossless volume change is only possible in 6dB steps so 24bit to 16bit could be done lossless if the source has a peak below -48dB.

How can a volume change not be lossless when you are going to follow it by truncating (+dither) 8 bits?

Re: Low peak 24-bit audio to 16-bit

Reply #18
Lossless volume change is only possible in 6dB steps so 24bit to 16bit could be done lossless if the source has a peak below -48dB.

How can a volume change not be lossless when you are going to follow it by truncating (+dither) 8 bits?
As soon you dither it is lossy. Shifting 8 bits when the upper 8 bits are silent can be undone and the original data restored. This i call lossless.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Re: Low peak 24-bit audio to 16-bit

Reply #19
Lossless volume change is only possible in 6dB steps so 24bit to 16bit could be done lossless if the source has a peak below -48dB.

How can a volume change not be lossless when you are going to follow it by truncating (+dither) 8 bits?
As soon you dither it is lossy. Shifting 8 bits when the upper 8 bits are silent can be undone and the original data restored. This i call lossless.

But if you truncate anything (or clip), then it's still lossy. 

The point being in this scenario is that we can just multiply and still get the 16 bits ultimately being kept correct. Any error will be due to quantization/dither/clipping and not the multiplication, no?

Re: Low peak 24-bit audio to 16-bit

Reply #20
No. The idea is to shift out bits that are zero.  Restoring means shifting the bits the other way, restoring the zeros that were shifted out.

If this is about audio content, the more ideal solution is to loudness normalize and/or peak normalize with dither and not be preoccupied about whether the process is lossless (as was already stated).

EDIT: The answer to your question is probably yes since you likely agree with the second paragraph above. I read your response too quickly.

Re: Low peak 24-bit audio to 16-bit

Reply #21
I just don't want to make people fear a simple multiplication. :)

Re: Low peak 24-bit audio to 16-bit

Reply #22
P.S. I just lately used a 6 bit louder shift to make different noise of shaped 16bit dither easy audible. Using dither on these may have been a bit counter productive :)
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Re: Low peak 24-bit audio to 16-bit

Reply #23
@drewfx:
Right and I agree 100%. I realized that was your point after posting.

If there is a reason to maintain precision (e.g.: in scientific study of specialized data) then I can respect the desire to use a lossless process. For content consumption, using a process that is bonafide lossless is just placebo-based OCD wanking.  If audibly different (and that's a huge if), maintaining a lossless conversion could end up being the inferior choice, no?

What should always be kept in mind is whether the LSBs of the 24-bit file actually contain worthwhile content and isn't just noise.