creating truncated rather than dithered audio

Hector MacInnes's icon

Hi everyone,

I'd like to try experimenting with using different audio sources that approximate pink noise as a dither. In order to see how these function in extreme circumstances I need a way of truncating the audio bits: i.e. reducing from MSP's internal float32 (I believe?) down to like extremes like 8 or 4 bit without any automatically applied dither, so I can then introduce other pseudo-dithers.

I would have thought this could be a pretty simple maths operation I could apply in gen~ while passing audio from one buffer to another, but I'm struggling to get my head around it.

The original crude idea was that, e.g., a four bit system would round each sample value to the nearest 1/16th, i.e. increments of 0.0625, but I'm fairly sure that's not actually how truncation actually works...

Any thoughts on this much appreciated. It used to be the case that you could export low bit depth files straight from Pro Tools and it was your own fault if they weren't dithered properly, but I don't think it allows that any more... now that it's the one thing I want to do... :/

Thanks!

Hector.

Roman Thilenius's icon

when i am not mistaken it is a bad idea to try to apply dither noise while still beeing in float, it is normally done after reducing the bitdepth.

now of course i know that you do not have 4 bit audio in max, you only have the output of degrade~ or similar. :)

i would suggest that you raise the output of degrade~ so that each "bit" is represented as an "integer" number in the signal, this makes it a bit easier to see what is going on.

alternatively you could also reproduce the classic "complement"(?) bit order of integer audio files, which should look about that for 4 bit:

0000 -> 0
0001 -> 1
0010 -> 2
0011 -> 3
0100 -> 4
0101 -> 5
0110 -> 6
0111 -> 7
1000 -> -8
1001 -> -7
1010 -> -6
1011 -> -5
1100 -> -4
1101 -> -3
1110 -> -2
1111 -> -1

if you have bad luck degrade~ already applies dithering - or has some unknown bugs. :)

but otherwise multiplication and some shifting or modulo should give you exactly those numbers, which can all be represented in float without errors... (if tey are not, trunc~ can be of help here.)

the pseudo dynamic expansion by dithering to 4 bit should be enourmous! some 10 db?

Roman Thilenius's icon

i am not sure what would be "right" here: see that the amplitude of the signal will not exceed 7/8 of 1. (i.e. normalize to that fraction below 0db), or to multiply by 7 instead of 8 after conversion... just make sure you do not cut the music signal off at +7.
but yes, it is just multiplication and rounding in real world.

Roman Thilenius's icon

okay, reverse gear.
mr. and mrs. stackexchange, which are usually more clever than me, clearly suggest that for 8 bits or lower you should add the dither noise to the float values before truncating... otherwise you can not really adjust its amount. so take the chance and play with shaping as well! :)