Пример #1
0
        /// <summary>
        ///   Get track samples
        /// </summary>
        /// <param name = "track">Track from which to gather samples</param>
        /// <param name = "proxy">Proxy used in gathering samples</param>
        /// <param name = "sampleRate">Sample rate used in gathering samples</param>
        /// <param name = "secondsToRead">Milliseconds to gather</param>
        /// <param name = "startAtSecond">Starting millisecond</param>
        /// <returns>Music samples</returns>
        public static float[] GetTrackSamples(Track track, IAudioService proxy, int sampleRate, int secondsToRead, int startAtSecond)
        {
            if (track == null || track.Path == null)
            {
                return null;
            }

            return proxy.ReadMonoFromFile(track.Path, sampleRate, secondsToRead, startAtSecond);
        }
Пример #2
0
        public static Track GetTrack(int mintracklen, int maxtracklen, string filename, ITagService tagService)
        {
            TagInfo tags = tagService.GetTagInfo(filename); // get file tags
            string artist, title;
            double duration;
            if (tags == null)
            {
                /*The song does not contain any tags*/
                artist = "Unknown Artist";
                title = "Unknown Title";
                duration = new FileInfo(filename).Length;
            }
            else
            {
                /*The song contains related tags*/
                artist = tags.Artist;
                title = tags.Title;
                duration = tags.Duration;
            }

            /*assign a name to music files that don't have tags*/
            if (string.IsNullOrEmpty(artist))
            {
                artist = "Unknown Artist";
            }

            /*assign a title to music files that don't have tags*/
            if (string.IsNullOrEmpty(title))
            {
                title = "Unknown Title";
            }

            /*check the duration of a music file*/
            if (duration < mintracklen || duration > maxtracklen)
            {
                return null;
            }

            Track track = new Track(artist, title, Path.GetFullPath(filename), duration);
            return track;
        }
Пример #3
0
        /// <summary>
        ///   Create fingerprints out of down sampled samples
        /// </summary>
        /// <param name = "samples">Down sampled to 5512 samples</param>
        /// <param name = "track">Track</param>
        /// <param name = "stride">Stride</param>
        /// <param name = "hashTables">Number of hash tables</param>
        /// <param name = "hashKeys">Number of hash keys</param>
        public void CreateInsertFingerprints(float[] samples, Track track, IStride stride, int hashTables, int hashKeys)
        {
            if (track == null)
            {
                return; /*track is not eligible*/
            }

            /*Create fingerprints that will be used as initial fingerprints to be queried*/
            List<bool[]> fingerprints = fingerprintUnitBuilder.BuildFingerprints()
                                                       .On(samples)
                                                       .WithCustomConfiguration(config => config.Stride = stride)
                                                       .RunAlgorithm()
                                                       .Result;

            storage.InsertTrack(track); /*Insert track into the storage*/
            /*Get signature's hash signature, and associate it to a specific track*/
            IEnumerable<HashSignature> creationalsignatures = GetSignatures(fingerprints, track, hashTables, hashKeys);
            foreach (HashSignature hash in creationalsignatures)
            {
                storage.InsertHash(hash);
            }
        }
Пример #4
0
        private IEnumerable<HashSignature> GetSignatures(IEnumerable<bool[]> fingerprints, Track track, int hashTables, int hashKeys)
        {
            List<HashSignature> signatures = new List<HashSignature>();
            foreach (bool[] fingerprint in fingerprints)
            {
                long[] buckets = combinedHashingAlgorithm.Hash(fingerprint, hashTables, hashKeys).Item2;
                long[] hashSignature = new long[buckets.Length];
                int tableCount = 0;
                foreach (long bucket in buckets)
                {
                    hashSignature[tableCount++] = bucket;
                }

                HashSignature hash = new HashSignature(track, hashSignature); /*associate track to hash-signature*/
                signatures.Add(hash);
            }

            return signatures; /*Return the signatures*/
        }
Пример #5
0
        /// <summary>
        ///   Gets the list of hash signatures that are available in the storage for a specific track
        /// </summary>
        /// <param name = "track">Requested track</param>
        /// <returns>A set of fingerprints (hash signatures) that correspond to a specific track id</returns>
        public HashSet<HashSignature> GetHashSignatures(Track track)
        {
            if (fingerprints.ContainsKey(track))
            {
                return fingerprints[track];
            }

            return null;
        }
Пример #6
0
 /// <summary>
 ///   Remove track from the RAM storage
 /// </summary>
 /// <param name = "track">Track to be removed</param>
 public void RemoveTrack(Track track)
 {
     if (fingerprints.ContainsKey(track))
     {
         fingerprints.Remove(track);
     }
 }
Пример #7
0
 /// <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 HashSet<HashSignature>();
         }
     }
 }
Пример #8
0
 public HashSignature(Track track, long[] signature)
 {
     Track = track;
     Signature = signature;
     id = Interlocked.Increment(ref increment);
 }