AIFF's 80-bit sample rate value
Using the readfloat16() and readfloat64() functions I can get the two values. But how do I combine them into one float? And, staying in the JS environment, is there a simpler method?
Just an update…
I found a slightly better source regarding these 80-bit monsters, here it is for posterity: http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
It has been over a month and I finally figured out how to do this (let it be noted that I haven’t spent the whole month working on this problem!). I am posting my solution for anyone mad enough to want to do the same.
Using info from here (http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/) I figured out that the first 16-bit block of the 80 represents the bit depth of the second 16-bit block… a little bit of explanation required:
For 44100Hz and 48000Hz files the first 16-bits is always 16398. When 16382 is subtracted from this the result is the bit length of the value that holds the sample rate – in this case 16. For 96000Hz this value is 16399 and for 192000Hz it is 16400.
This is the interesting part… you use the first value retrieved to create a lowest-significant-bit pad for the second value, thus allowing it scale up into the higher sample rates: subtracting 16398 from the first value creates the number of bits of the pad, the bit shift (to the left) the second value by the first and you have the correct file sample rate!
A quick example: for a 96000Hz file the first 16-bit value is 16399. Subtract 16398 from this to get your LSB pad, in this case 1.
Read the second 16-bit as 2 bytes (readbytes(2)), in this case the values 187 and 128. Bit shift 187 left by 8 bits (187 < < 8 = 47872) and add the 128 (48000).
Then bit shift that value using the LSB pad, so 48000 < < 1 = 96000.
The code for this is attached.
wow this is convoluted… I think there is an interesting historical coding study to do here, to find the motivation of such a convoluted way of doing things…
in all case, bravo!
Hi there, you said in your case above that the "code is attached", but I don’t see it here. Is there any way you could share it ?
Either way, extremely helpful work, thank you so much.