Convert 80 bit IEEE Std 754 floating point number to f64

I am writing a program that reads the contents of an .aiff audio file. I have gotten as far as reading all of the meta data up to the left and right audio channels with one exception. The sample rate, which for a CD is 44,100, is represented as an 80 bit IEEE Standard 754 floating point number. I can read the 10 bytes into a variable but cannot figure out how to decode/convert it to a rust type such as f64. It is my understanding, and I could be wrong, there is a sign (1 bit) a fractional part (63 bits) and an exponent (15 bits) but totals 1 bit shy of 80. There is also a bias of 16383 which is subtracted from the exponent. I just do not know how to even start. Any assistance will be appreciated. Below is a part of my function and the println! output for the entire function.

fn read_aiff(file_path: &str) -> io::Result<()> {

    let mut file = File::open(file_path)?;
    let mut buffer2 = [0; 2];
    let mut buffer4 = [0; 4];
    let mut buffer10 = [0; 10];
    .....
    let _ = file.read_exact(&mut buffer10);
    println!("sample rate = {:?}", buffer10);   

text FORM = "FORM"
form size = 9389783
text AIFF = "AIFF"
text COMM = "COMM"
chunk size = 18
num channels = 2
number of sample frames = 2319872
sample size = 16
sample rate = [64, 14, 172, 68, 0, 0, 0, 0, 0, 0]
text SSND = "SSND"
chunk size = 9279496
offset = 0
block size = 0

Note that it's not in the https://en.wikipedia.org/wiki/IEEE_754#Basic_and_interchange_formats list, so personally I probably wouldn't call it "an 80 bit IEEE Standard 754 floating point number."

I guess it's probably the x87 extension? https://en.wikipedia.org/wiki/Extended_precision#x86_extended-precision_format suggests that's 64 bits of mantissa.

But you should probably find some data where you know the expected decodings and test against them. Who knows what it's doing.

FWIW, that's how the AIFF spec here defines its extended data type, "80 bit IEEE Standard 754 floating point number (Standard Apple Numeric Environment [SANE] data type Extended)."

It also says, "All data is stored in Motorola 68000 format," so it might be the one where Wikipedia says:

(similar to the Intel format, although padded to a 96-bit format with 16 unused bits inserted between the exponent and significand fields, and values with exponent zero and bit 63 one are normalized values)

It might be easier to find another AIFF library and see how they deal with this.

I don't know in what format .aiff files stores the date. there's an extended crate on crates.io, it's very small, give it a try:

play with the endianness and see if the value looks correct.

There's a SANE manual here that indicates the 80-bit format has an explicit 1 bit preceding the fractional part (semantic page 18, PDF page 42; key is two pages prior). No guarantees from me that's actually what you need :slight_smile:.