// Detect It Easy: detection rule file
// Author: LinXP
// Status: WIP

meta("audio", "FMOD Sample Bank (.FSB)");

function detect() {
    if (Binary.getSize() >= 0x24) {
        if (Binary.compare("'FSB'..")) {
            var nSamples, nExtVer, nMode;
            var sID = Binary.getString(0, 4);
            sVersion = sID;
            bDetected = true;
            switch (sID) {
                case "FSB1":
                    nSamples = Binary.read_int32(0x04);
                    break;

                case "FSB2":
                    nSamples = Binary.read_int32(0x04);
                    break;

                case "FSB3":
                    nSamples = Binary.read_int32(0x04);
                    nExtVer = Binary.read_int32(0x10);
                    nMode = Binary.read_int32(0x14);
                    break;

                case "FSB4":
                    nSamples = Binary.read_int32(0x04);
                    nExtVer = Binary.read_int32(0x10);
                    nMode = Binary.read_int32(0x14);
                    break;

                case "FSB5":
                    nSamples = Binary.read_int32(0x08);
                    nExtVer = Binary.read_int32(0x10);
                    nMode = Binary.read_int32(0x18);
                    switch (nMode) {
                        case 0x01:
                            sOption("PCM8");
                            break; // 8bit integer PCM data.
                        case 0x02:
                            sOption("PCM16");
                            break; // 16bit integer PCM data.
                        case 0x03:
                            sOption("PCM24");
                            break; // 24bit integer PCM data.
                        case 0x04:
                            sOption("PCM32");
                            break; // 32bit integer PCM data.
                        case 0x05:
                            sOption("PCMFLOAT");
                            break; // 32bit floating point PCM data.
                        case 0x06:
                            sOption("GCADPCM");
                            break; // Compressed Nintendo 3DS/Wii DSP data.
                        case 0x07:
                            sOption("IMA ADPCM");
                            break; // Compressed IMA ADPCM data.
                        case 0x08:
                            sOption("VAG");
                            break; // Compressed PlayStation Portable ADPCM data.
                        case 0x09:
                            sOption("HEVAG");
                            break; // Compressed PSVita ADPCM data.
                        case 0x0A:
                            sOption("XMA");
                            break; // Compressed Xbox360 XMA data.
                        case 0x0B:
                            sOption("MP3");
                            break; // Compressed MPEG layer 2 or 3 data.
                        case 0x0C:
                            sOption("CELT");
                            break; // Compressed CELT data.
                        case 0x0D:
                            sOption("AT9");
                            break; // Compressed PSVita ATRAC9 data.
                        case 0x0E:
                            sOption("XWMA");
                            break; // Compressed Xbox360 xWMA data.
                        case 0x0F:
                            sOption("VORBIS");
                            break; // Compressed Vorbis data.
                        case 0x10:
                            sOption("FADPCM");
                            break;
                        case 0x11:
                            sOption("OPUS");
                            break;
                        default:
                            bDetected = false;
                    }
                    break;

                default:
                    bDetected = false;
            }
            sOption("Samples:" + nSamples);
        }

    }

    return result();
}