mqa-identify 0.1.1

A minimal library, to check if a flac file has been encoded by/with MQA
Documentation
pub fn identify_mqa(path: impl AsRef<std::path::Path>) -> Result<bool, claxon::Error> {
    let mut decoder = claxon::FlacReader::open(path)?;
    let position = decoder.streaminfo().bits_per_sample - 16;

    let mut frame_reader = decoder.blocks();
    let block = vec![];
    let mut current_block = frame_reader.read_next_or_eof(block);

    let mut buffer0 = 0u64;
    let mut buffer1 = 0u64;
    let mut buffer2 = 0u64;

    while let Ok(Some(samples)) = current_block {
        for (x, y) in samples.stereo_samples() {
            buffer0 |= ((x as u64 ^ y as u64) >> position) & 1;
            buffer1 |= ((x as u64 ^ y as u64) >> (position + 1)) & 1;
            buffer2 |= ((x as u64 ^ y as u64) >> (position + 2)) & 1;

            if buffer0 == 0xbe0498c88 || buffer1 == 0xbe0498c88 || buffer2 == 0xbe0498c88 {
                return Ok(true);
            }

            buffer0 = (buffer0 << 1) & 0xFFFFFFFFF;
            buffer1 = (buffer1 << 1) & 0xFFFFFFFFF;
            buffer2 = (buffer2 << 1) & 0xFFFFFFFFF;
        }

        current_block = frame_reader.read_next_or_eof(samples.into_buffer());
    }

    Ok(false)
}