// Detect It Easy: detection rule file
// Author: Kae <TG@kaens>

// https://github.com/vgmstream/vgmstream/blob/master/src/meta/riff_ima.c
meta("audio", "Nintendo DS RIFF IMA-ADPCM stream (.STRM,.BIN,.LBIN)");

function detect() {
    if (X.c("'RIFF'") && X.c("'IMA '", 8) && X.U32(0xC) && X.U32(4) >= 0x2D) {
        bDetected = true;

        if (X.isVerbose()) {
            var ch = X.U32(0x24), len = Util.divu64((X.U32(4) - 0x2C) << 8, X.U16(0xC)) >> 8;

            sOption(
                'ch:' + ch + ' len ' + secondsToTimeStr(len) + ' s/r:' + X.U32(0xC) + 'Hz ' +
                ['not looped', 'looped'][+(X.U32(0x20) != 0)] + ' sz:' + outSz(X.U32(4))
            );
        }
    }

    return result();
}