Convert 80 bit IEEE Std 754 floating point number to f64

⚓ Rust    📅 2026-06-11    👤 surdeus    👁️ 3      

surdeus

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

5 posts - 5 participants

Read full topic

🏷️ Rust_feed