/// <summary> /// Insert a track into the RAM Storage /// </summary> /// <param name = "track">Track to be inserted</param> public void InsertTrack(Track track) { lock (LockObject) { if (!_fingerprints.ContainsKey(track)) _fingerprints[track] = new Hashes(); } }
/// <summary> /// Constructor /// </summary> /// <param name="track">Hashed track</param> /// <param name="signature">Signature of the track</param> public HashSignature(Track track, int[] signature) { Track = track; Signature = signature; lock (LockObject) { _id = _increment++; } }
/// <summary> /// Remove track from the RAM storage /// </summary> /// <param name = "track"></param> public void RemoveTrack(Track track) { if (_fingerprints.ContainsKey(track)) _fingerprints.Remove(track); }
/// <summary> /// Gets the list of hash signatures that are available in the storage for a specific track /// </summary> /// <param name = "track">Requested track</param> /// <param name = "type">Type of the hashes toe gathered</param> /// <returns>A set of fingerprints (hash signatures) that correspond to a specific track id</returns> public HashSet<HashSignature> GetHashSignatures(Track track, HashType type) { if (_fingerprints.ContainsKey(track)) { switch (type) { case HashType.Creational: return _fingerprints[track].Creational; case HashType.Query: return _fingerprints[track].Query; } } return null; }
// ReSharper restore ReturnTypeCanBeEnumerable.Local // ReSharper disable ReturnTypeCanBeEnumerable.Local private List<HashSignature> GetSignatures(IEnumerable<bool[]> fingerprints, Track track, int hashTables, int hashKeys) { List<HashSignature> signatures = new List<HashSignature>(); foreach (bool[] fingerprint in fingerprints) { int[] signature = _hasher.ComputeMinHashSignature(fingerprint); /*Compute min-hash signature out of fingerprint*/ Dictionary<int, long> buckets = _hasher.GroupMinHashToLSHBuckets(signature, hashTables, hashKeys); /*Group Min-Hash signature into LSH buckets*/ int[] hashSignature = new int[buckets.Count]; foreach (KeyValuePair<int, long> bucket in buckets) hashSignature[bucket.Key] = (int) bucket.Value; HashSignature hash = new HashSignature(track, hashSignature); /*associate track to hash-signature*/ signatures.Add(hash); } return signatures; /*Return the signatures*/ }
/// <summary> /// Get track from the filename /// </summary> /// <param name="mintracklen">Min track length</param> /// <param name="maxtracklen">Max track length</param> /// <param name="filename">Filename from which to extract the requested info</param> /// <param name="proxy">Audio proxy to read tags</param> /// <returns>Track to be analyzed further / null if the track is not eligible</returns> private static Track GetTrack(int mintracklen, int maxtracklen, string filename, BassProxy proxy) { TAG_INFO tags = proxy.GetTagInfoFromFile(filename); //get file tags string artist, title; double duration; if (tags == null) { /*The song does not contain any tags*/ artist = "Unknown"; title = "Unknown"; duration = 60; } else { /*The song contains related tags*/ artist = tags.artist; title = tags.title; duration = tags.duration; } if (String.IsNullOrEmpty(artist)) /*assign a name to music files that don't have tags*/ artist = "Unknown"; if (String.IsNullOrEmpty(title)) /*assign a title to music files that don't have tags*/ title = "Unknown"; if (duration < mintracklen || duration > maxtracklen) /*check the duration of a music file*/ { System.Diagnostics.Debug.WriteLine(String.Format("File {0} failed the duration validation. Duration: {1} [Min: {2}, Max: {3}]", filename, duration, mintracklen, maxtracklen) ); return null; } Track track = new Track {Artist = artist, Title = title, TrackLength = duration, Path = Path.GetFullPath(filename)}; return track; }