예제 #1
0
        public UInt64 IsFormat(StreamReader.IReader fileReader, UInt64 offset, UInt64 length)
        {
            if (fileReader.Read_16bitsBE(offset) != 0x8000)
            {
                return(0);
            }

            // Check encoding type ...
            if (fileReader.Read_8Bits(offset + 4) != 3)
            {
                return(0);
            }

            // Check Frame Size ...
            if (fileReader.Read_8Bits(offset + 5) != 18)
            {
                return(0);
            }

            // Check Bit per Samples ...
            if (fileReader.Read_8Bits(offset + 6) != 4)
            {
                return(0);
            }

            // Check for channel count & sample rate
            uint sampleRate   = fileReader.Read_32bitsBE(offset + 0x08);
            uint channelCount = fileReader.Read_8Bits(offset + 0x07);

            if (((channelCount <= 0) || (channelCount > 8)) ||
                ((sampleRate < 11025) || (sampleRate > 48000)))
            {
                return(0);
            }

            // Search for the (c)CRI signature ...
            UInt64 criOffset = fileReader.Read_16bitsBE(offset + 2);

            if ((fileReader.Read_32bitsBE(offset + criOffset - 4) != 0x00002863) &&
                (fileReader.Read_32bitsBE(offset + criOffset) != 0x29435249))
            {
                return(0);
            }

            // Find file length ...
            UInt32 totalSamples = fileReader.Read_32bitsBE(offset + 0x0C);
            UInt64 searchOffset = offset + (totalSamples * channelCount) / 32 * 18 + criOffset + 4;

            while (fileReader.Read_16bitsBE(searchOffset) != 0x8001)
            {
                searchOffset++;
                if (!fileReader.CanRead())
                {
                    break;
                }
            }

            UInt64 fileLength = (searchOffset - offset) + fileReader.Read_16bitsBE(searchOffset + 2) + 4;

            return(fileLength);
        }