AcoustID.Chromaprint.FingerprintDecompressor.Decompress C# (CSharp) Method

Decompress() public method

Decompress a fingerprint string.
public Decompress ( string data, int &algorithm ) : int[]
data string The fingerprint string.
algorithm int The algorithm used to compute the fingerprint (output).
return int[]
        public int[] Decompress(string data, out int algorithm)
        {
            algorithm = -1;

            if (data.Length < 4)
            {
                // Invalid fingerprint (shorter than 4 bytes)
                return new int[0];
            }

            algorithm = (int)data[0];

            int length = ((byte)(data[1]) << 16) | ((byte)(data[2]) << 8) | ((byte)(data[3]));

            BitStringReader reader = new BitStringReader(data);
            reader.Read(8);
            reader.Read(8);
            reader.Read(8);
            reader.Read(8);

            if (reader.AvailableBits() < length * kNormalBits)
            {
                // Invalid fingerprint (too short)
                return new int[0];
            }

            m_result = new List<int>(length);

            for (int i = 0; i < length; i++)
            {
                m_result.Add(-1);
            }

            reader.Reset();
            if (!ReadNormalBits(reader))
            {
                return new int[0];
            }

            reader.Reset();
            if (!ReadExceptionBits(reader))
            {
                return new int[0];
            }

            UnpackBits();

            // TODO: no list needed?
            return m_result.ToArray();
        }

Usage Example

        public void TestTwoItems()
        {
            int[] expected = { 1, 0 };
            byte[] data = { 0, 0, 0, 2, 65, 0 };

            FingerprintDecompressor decompressor = new FingerprintDecompressor();

            int algorithm = -1;
            int[] actual = decompressor.Decompress(Base64.ByteEncoding.GetString(data), out algorithm);
            Assert.AreEqual(0, algorithm);
            CollectionAssert.AreEqual(actual, expected);
        }
All Usage Examples Of AcoustID.Chromaprint.FingerprintDecompressor::Decompress