Ejemplo n.º 1
0
        public void Add(SubFingerprintsGeneratedEventArgs e)
        {
            if (e.SubFingerprints.Count == 0)
            {
                return;
            }

            lock (this) {
                if (!store.ContainsKey(e.AudioTrack))
                {
                    store.Add(e.AudioTrack, new List <SubFingerprintHash>());
                }

                foreach (var sfp in e.SubFingerprints)
                {
                    if (!sfp.IsVariation)
                    {
                        // store the sub-fingerprint in the sequential list of the audio track
                        store[e.AudioTrack].Add(sfp.Hash);
                    }

                    // insert a track/index lookup entry for the sub-fingerprint
                    collisionMap.Add(sfp.Hash, new SubFingerprintLookupEntry(e.AudioTrack, sfp.Index));
                }
            }
        }
Ejemplo n.º 2
0
        public void Add(SubFingerprintsGeneratedEventArgs e, bool suppressSilentCollisions = false)
        {
            if (e.SubFingerprints.Count == 0)
            {
                return;
            }

            lock (this) {
                if (!store.ContainsKey(e.AudioTrack))
                {
                    store.Add(e.AudioTrack, new List <SubFingerprintHash>());
                }

                foreach (var sfp in e.SubFingerprints)
                {
                    if (!sfp.IsVariation)
                    {
                        // store the sub-fingerprint in the sequential list of the audio track
                        store[e.AudioTrack].Add(sfp.Hash);
                    }

                    if (suppressSilentCollisions && sfp.Hash.Value == 0)
                    {
                        // Skip a silent hash, i.e. a hash without any changes, as it happens with silent signals as input
                        continue;
                    }

                    // insert a track/index lookup entry for the sub-fingerprint
                    collisionMap.Add(sfp.Hash, new SubFingerprintLookupEntry(e.AudioTrack, sfp.Index));
                }
            }
        }
Ejemplo n.º 3
0
        public void Add(SubFingerprintsGeneratedEventArgs e)
        {
            if (e.SubFingerprints.Count == 0)
            {
                return;
            }

            lock (this) {
                // Make sure there's a store for the track and get it
                if (!store.ContainsKey(e.AudioTrack))
                {
                    store.Add(e.AudioTrack, new TrackStore());
                }
                var trackStore = store[e.AudioTrack];

                int            hashListIndex = 0;
                SubFingerprint hash;

                // Iterate through the sequence of input hashes and add them to the store (in batches of the same frame index)
                while (e.SubFingerprints.Count > hashListIndex)
                {
                    int storeHashIndex = trackStore.hashes.Count;
                    int storeIndex     = e.SubFingerprints[hashListIndex].Index;
                    int hashCount      = 0;

                    // Count all sequential input hashes with the same frame index (i.e. batch) and add them to the store
                    while (e.SubFingerprints.Count > hashListIndex + hashCount &&
                           (hash = e.SubFingerprints[hashListIndex + hashCount]).Index == storeIndex)
                    {
                        // Insert hash into the sequential store
                        trackStore.hashes.Add(hash.Hash);

                        // Insert a track/index lookup entry for the fingerprint hash
                        collisionMap.Add(hash.Hash, new SubFingerprintLookupEntry(e.AudioTrack, hash.Index));

                        hashCount++;
                    }

                    // Add an index entry which tells where a hash with a specific frame index can be found in the store
                    if (hashCount > 0)
                    {
                        TrackStore.IndexEntry ie;
                        // If there is already an entry for the frame index, take it and update its length, ...
                        if (trackStore.index.ContainsKey(storeIndex))
                        {
                            ie         = trackStore.index[storeIndex];
                            ie.length += hashCount;
                            trackStore.index.Remove(storeIndex);
                        }
                        else   // ... else create a new entry
                        {
                            ie = new TrackStore.IndexEntry(storeHashIndex, hashCount);
                        }
                        // Add the current length of the hash list as start pointer for all hashes belonging to the current index
                        trackStore.index.Add(storeIndex, ie);
                    }

                    hashListIndex += hashCount;
                }
            }
        }