// https://github.com/horsicq/Detect-It-Easy signature file
// Author: Kaens TG@kaens

init("audio", "Interplay ACM waveform audio (.ACM)");
includeScript("read");

function detect(bShowType, bShowVersion, bShowOptions) {
    //from https://github.com/dtiefling/snd2acm-portable/blob/master/src/general.h
    if (!File.compare("97280301") || File.getSize() < 0x10) return false;
    var smp = File.read_uint32(4),
        ch = File.read_uint16(8),
        r = File.read_uint16(0xA);

    if (!smp || !isWithin(ch, 1, 2) || !isWithin(r, 6000, 49716)) return false;
    bDetected = true;
    if (Binary.isVerbose()) {
        var sr = (r / 1000).toFixed(1);
        sOption('ch: ' + ch + ' s/r: ' + sr + 'kHz len: ' + secondsToTimeStr(Util.divu64(smp + (r >> 1), r * ch)));
    }

    return result(bShowType, bShowVersion, bShowOptions);
}