public void TestSpectralImagesAreInsertedInDataSource()
        {
            TrackData track = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var trackReference = this.TrackDao.InsertTrack(track);
            var audioSamples = this.audioService.ReadMonoSamplesFromFile(
                PathToMp3, FingerprintConfiguration.Default.SampleRate);
            var spectralImages = this.spectrumService.CreateLogSpectrogram(audioSamples, SpectrogramConfig.Default);
            var concatenatedSpectralImages = new List<float[]>();
            foreach (var spectralImage in spectralImages)
            {
                var concatenatedSpectralImage = ArrayUtils.ConcatenateDoubleDimensionalArray(spectralImage.Image);
                concatenatedSpectralImages.Add(concatenatedSpectralImage);
            }
            
            this.SpectralImageDao.InsertSpectralImages(concatenatedSpectralImages, trackReference);

            var readSpectralImages = this.SpectralImageDao.GetSpectralImagesByTrackId(trackReference);
            Assert.AreEqual(concatenatedSpectralImages.Count, readSpectralImages.Count);
            foreach (var readSpectralImage in readSpectralImages)
            {
                var expectedSpectralImage = concatenatedSpectralImages[readSpectralImage.OrderNumber];
                for (int i = 0; i < expectedSpectralImage.Length; i++)
                {
                    Assert.AreEqual(
                        concatenatedSpectralImages[readSpectralImage.OrderNumber][i], expectedSpectralImage[i]);
                }
            }
        }
        public void ShouldInsertTrack()
        {
            var track = new TrackData("isrc", "artist", "title", "album", 1986, 3.6);
            var reference = trackDao.InsertTrack(track);

            Assert.IsNotNull(reference);
        }
        public void DeleteHashBinsAndSubfingerprintsOnTrackDelete()
        {
            TagInfo tagInfo = GetTagInfo();
            int releaseYear = tagInfo.Year;
            var track = new TrackData(tagInfo.ISRC, tagInfo.Artist, tagInfo.Title, tagInfo.Album, releaseYear, (int)tagInfo.Duration);
            var trackReference = trackDao.InsertTrack(track);
            var hashData = fingerprintCommandBuilder
                .BuildFingerprintCommand()
                .From(GetAudioSamples())
                .WithFingerprintConfig(config =>
                    {
                        config.Stride = new StaticStride(0);
                    })
                .UsingServices(audioService)
                .Hash()
                .Result;

            subFingerprintDao.InsertHashDataForTrack(hashData, trackReference);
            var actualTrack = trackDao.ReadTrackByISRC(tagInfo.ISRC);
            Assert.IsNotNull(actualTrack);
            AssertTracksAreEqual(track, actualTrack);

            // Act
            int modifiedRows = trackDao.DeleteTrack(trackReference);

            Assert.IsNull(trackDao.ReadTrackByISRC(tagInfo.ISRC));
            Assert.AreEqual(0, subFingerprintDao.ReadHashedFingerprintsByTrackReference(actualTrack.TrackReference).Count);
            Assert.AreEqual(1 + hashData.Count + (25 * hashData.Count), modifiedRows);
        }
        public void ShouldIdentifyAsEqual()
        {
            var dto0 = new TrackData(string.Empty, string.Empty, string.Empty, string.Empty, 1990, 0d, new ModelReference<int>(0));
            var dto1 = new TrackData(string.Empty, string.Empty, string.Empty, string.Empty, 1990, 0d, new ModelReference<int>(0));

            Assert.AreEqual(dto0, dto1);
        }
 public IModelReference InsertTrack(TrackData track)
 {
     int id = PrepareStoredProcedure(SpInsertTrack)
                     .WithParametersFromModel(track)
                     .Execute()
                     .AsScalar<int>();
     return track.TrackReference = new ModelReference<int>(id);
 }
 protected void AssertTracksAreEqual(TrackData expectedTrack, TrackData actualTrack)
 {
     Assert.AreEqual(expectedTrack.TrackReference, actualTrack.TrackReference);
     Assert.AreEqual(expectedTrack.Album, actualTrack.Album);
     Assert.AreEqual(expectedTrack.Artist, actualTrack.Artist);
     Assert.AreEqual(expectedTrack.Title, actualTrack.Title);
     Assert.AreEqual(expectedTrack.Length, actualTrack.Length);
     Assert.AreEqual(expectedTrack.ISRC, actualTrack.ISRC);
 }
 public TrackDataExternal(TrackData t)
 {
     Album = t.Album;
     Artist = t.Artist;
     GroupId = t.GroupId;
     ReleaseYear = t.ReleaseYear;
     Title = t.Title;
     TrackLengthSec = t.TrackLengthSec;
 }
        public void InsertSubFingerprintTest()
        {
            TrackData track = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var trackReference = trackDao.InsertTrack(track);

            var subFingerprintReference = subFingerprintDao.InsertSubFingerprint(GenericSignature, 123, 0.928, trackReference);

            AssertModelReferenceIsInitialized(subFingerprintReference);
        }
        public void InsertTest()
        {
            TrackData track = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var trackReference = TrackDao.InsertTrack(track);

            var fingerprintReference = FingerprintDao.InsertFingerprint(new FingerprintData(GenericFingerprint, trackReference));

            AssertModelReferenceIsInitialized(fingerprintReference);
        }
        public void ShouldInsertFingerprintInStorage()
        {
            var track = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var trackReference = trackDao.InsertTrack(track);

            var fingerprintReference = fingerprintDao.InsertFingerprint(new FingerprintData(GenericFingerprint(), trackReference));

            AssertModelReferenceIsInitialized(fingerprintReference);
        }
        public void ShouldReadTrack()
        {
            var expected = new TrackData("isrc", "artist", "title", "album", 1994, 4.0);
            var reference = trackDao.InsertTrack(expected);

            var actual = trackDao.ReadTrack(reference);

            AssertTracksAreEqual(expected, actual);
        }
        public void ReadSubfingerprintTest()
        {
            TrackData track = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var trackReference = trackDao.InsertTrack(track);
            var subFingerprintReference = subFingerprintDao.InsertSubFingerprint(GenericSignature, 123, 0.928, trackReference);

            var actual = subFingerprintDao.ReadSubFingerprint(subFingerprintReference);

            AsserSubFingerprintsAreEqual(new SubFingerprintData(GenericSignature, 123, 0.928, subFingerprintReference, trackReference), actual);
        }
        public void ReadByIdTest()
        {
            var track = new TrackData("isrc", "artist", "title", "album", 2012, 200)
                {
                    GroupId = "group-id"
                };

            var trackReference = this.TrackDao.InsertTrack(track);

            this.AssertTracksAreEqual(track, this.TrackDao.ReadTrack(trackReference));
        }
 internal ResultEntry(TrackData track, double queryMatchStartsAt, double queryMatchLength, double originStartsAt, double trackStartsAt, double confidence, int hammingSimilaritySum, double queryLength, MatchedPair bestMatch)
 {
     Track = track;
     QueryMatchStartsAt = queryMatchStartsAt;
     QueryMatchLength = queryMatchLength;
     TrackMatchStartsAt = originStartsAt;
     Confidence = confidence;
     HammingSimilaritySum = hammingSimilaritySum;
     TrackStartsAt = trackStartsAt;
     QueryLength = queryLength;
     BestMatch = bestMatch;
 }
        public void ShouldDeleteTrack()
        {
            var expected = new TrackData("isrc", "artist", "title", "album", 1994, 4.0);
            var reference = trackDao.InsertTrack(expected);
            var actual = trackDao.ReadTrack(reference);
            AssertTracksAreEqual(expected, actual);

            trackDao.DeleteTrack(reference);

            var tracks = trackDao.ReadAll();
            Assert.AreEqual(0, tracks.Count);
        }
        public void MultipleFingerprintsInsertTest()
        {
            const int NumberOfFingerprints = 100;
            for (int i = 0; i < NumberOfFingerprints; i++)
            {
                var trackData = new TrackData("isrc" + i, "artist", "title", "album", 2012, 200);
                var trackReference = TrackDao.InsertTrack(trackData);
                var fingerprintReference = FingerprintDao.InsertFingerprint(new FingerprintData(GenericFingerprint, trackReference));

                AssertModelReferenceIsInitialized(fingerprintReference);
            }
        }
        public IModelReference InsertTrack(TrackData track)
        {
            Guid id = Guid.NewGuid();
            var dto = new TrackDTO
                {
                    Id = id.ToString(),
                    Album = track.Album,
                    Artist = track.Artist,
                    GroupId = track.GroupId,
                    ISRC = track.ISRC,
                    ReleaseYear = track.ReleaseYear,
                    Title = track.Title,
                    TrackLengthSec = track.TrackLengthSec
                };

            this.solrForTracksCore.Add(dto);
            this.solrForTracksCore.Commit();
            return new SolrModelReference(id.ToString());
        }
        public void ShouldCreateFingerprintsInsertThenQueryAndGetTheRightResult()
        {
            const int SecondsToProcess = 10;
            const int StartAtSecond = 30;
            var track = new TrackData("isrc-solr", "artist", "title", "album", 1986, 4);
            var trackReference = modelService.InsertTrack(track);

            var hashDatas = fingerprintCommandBuilder
                                            .BuildFingerprintCommand()
                                            .From(PathToMp3, SecondsToProcess, StartAtSecond)
                                            .UsingServices(this.audioService)
                                            .Hash()
                                            .Result;

            modelService.InsertHashDataForTrack(hashDatas, trackReference);

            var queryResult = queryFingerprintService.QueryWithTimeSequenceInformation(modelService, hashDatas, new DefaultQueryConfiguration());

            Assert.IsTrue(queryResult.IsSuccessful);
            Assert.AreEqual(1, queryResult.ResultEntries.Count);
            Assert.AreEqual(trackReference, queryResult.ResultEntries[0].Track.TrackReference);
        }
        public void ReadTest()
        {
            const int NumberOfFingerprints = 100;
            TrackData track = new TrackData("isrc", "artist", "title", "album", 1986, 200);
            var trackReference = TrackDao.InsertTrack(track);

            for (int i = 0; i < NumberOfFingerprints; i++)
            {
                FingerprintDao.InsertFingerprint(new FingerprintData(GenericFingerprint, trackReference));
            }

            var fingerprints = FingerprintDao.ReadFingerprintsByTrackReference(trackReference);

            Assert.IsTrue(fingerprints.Count == NumberOfFingerprints);

            foreach (var fingerprint in fingerprints)
            {
                Assert.IsTrue(GenericFingerprint.Length == fingerprint.Signature.Length);
                for (var i = 0; i < GenericFingerprint.Length; i++)
                {
                    Assert.AreEqual(GenericFingerprint[i], fingerprint.Signature[i]);
                }
            }
        }
 private string ToTrackString(TrackData actualTrack)
 {
     return string.Format("{0}-{1}", actualTrack.Artist, actualTrack.Title);
 }
        public void DeleteHashBinsAndSubfingerprintsOnTrackDelete()
        {
            const int StaticStride = 5115;
            const int SecondsToProcess = 20;
            const int StartAtSecond = 30;

            var tagInfo = GetTagInfo();
            int releaseYear = tagInfo.Year;
            TrackData track = new TrackData(tagInfo.ISRC, tagInfo.Artist, tagInfo.Title, tagInfo.Album, releaseYear, (int)tagInfo.Duration);
            var trackReference = trackDao.InsertTrack(track);
            var hashData = fingerprintCommandBuilder
                .BuildFingerprintCommand()
                .From(PathToMp3, SecondsToProcess, StartAtSecond)
                .WithFingerprintConfig(config =>
                {
                    config.SpectrogramConfig.Stride = new IncrementalStaticStride(StaticStride, config.SamplesPerFingerprint);
                })
                .UsingServices(audioService)
                .Hash()
                .Result;

            var subFingerprintReferences = new List<IModelReference>();
            foreach (var hash in hashData)
            {
                var subFingerprintReference = subFingerprintDao.InsertSubFingerprint(hash.SubFingerprint, hash.SequenceNumber, hash.Timestamp, trackReference);
                hashBinDao.InsertHashBins(hash.HashBins, subFingerprintReference, trackReference);
                subFingerprintReferences.Add(subFingerprintReference);
            }

            var actualTrack = trackDao.ReadTrackByISRC(tagInfo.ISRC);
            Assert.IsNotNull(actualTrack);
            AssertTracksAreEqual(track, actualTrack);

            // Act
            int modifiedRows = trackDao.DeleteTrack(trackReference);

            Assert.IsNull(trackDao.ReadTrackByISRC(tagInfo.ISRC));
            foreach (var id in subFingerprintReferences)
            {
                Assert.IsTrue(id.GetHashCode() != 0);
                Assert.IsNull(subFingerprintDao.ReadSubFingerprint(id));
            }

            Assert.IsTrue(hashBinDao.ReadHashedFingerprintsByTrackReference(actualTrack.TrackReference).Count == 0);
            Assert.AreEqual(1 + hashData.Count + (FingerprintConfiguration.Default.HashingConfig.NumberOfLSHTables * hashData.Count), modifiedRows);
        }
 private object[] GetFoundLine(string actualTrack, TrackData recognizedTrack, bool isSuccessful, QueryResult queryResult)
 {
     var bestMatch = queryResult.BestMatch;
     return new object[]
         {
             actualTrack, ToTrackString(recognizedTrack), isSuccessful,
             bestMatch.HammingSimilaritySum, bestMatch.Confidence,
             bestMatch.Coverage,
             bestMatch.QueryMatchLength, bestMatch.TrackStartsAt
         };
 }
 private IModelReference InsertTrack(string file)
 {
     var tags = GetTagsFromFile(file);
     var trackData = new TrackData(tags);
     return modelService.InsertTrack(trackData);
 }
        public TrackData InsertToDatabase(string filePath)
        {
            TrackData trackData = null;

            IStride stride = WinUtils.GetStride(StrideType.IncrementalRandom, 5115, 0, configuration.SamplesPerFingerprint);

            TagInfo tags = tagService.GetTagInfo(filePath); // Get Tags from file
            if (tags == null || tags.IsEmpty)
            {
                // tags null
            }

            string artist = tags.Artist; // Artist
            string title = tags.Title; // Title
            int releaseYear = tags.Year;
            string album = tags.Album;
            double duration = tags.Duration; // Duration

            // Check whether the duration is OK
            if (duration < MinTrackLength || duration > MaxTrackLength)
            {
                // Duration too small
            }

            IModelReference trackReference;
            try
            {
                lock (this)
                {
                    trackData = new TrackData(artist, title, album, releaseYear, (int)duration);
                    trackReference = modelService.InsertTrack(trackData); // Insert new Track in the database
                }
            }
            catch (Exception e)
            {
                // catch any exception and abort the insertion
                return trackData;
            }

            int count;
            try
            {
                var hashDatas = fingerprintCommandBuilder
                                    .BuildFingerprintCommand()
                                    .From(filePath)
                                    .WithFingerprintConfig(
                                        config =>
                                        {
                                            config.TopWavelets = 200;
                                            config.SpectrogramConfig.Stride = stride;
                                        })
                                    .UsingServices(audioService)
                                    .Hash()
                                    .Result; // Create SubFingerprints

                modelService.InsertHashDataForTrack(hashDatas, trackReference);
                count = hashDatas.Count;
                return trackData;
            }
            catch (Exception e)
            {
                // catch any exception and abort the insertion
                return null;
            }
        }
 private IModelReference InsertTrack()
 {
     var trackData = new TrackData("isrc", "artist", "title", "album", 2012, 200);
     return trackDao.InsertTrack(trackData);
 }
        public void InserTrackShouldAcceptEmptyEntriesCodes()
        {
            TrackData track = new TrackData(string.Empty, string.Empty, string.Empty, string.Empty, 1986, 200);
            var trackReference = trackDao.InsertTrack(track);

            var actualTrack = trackDao.ReadTrack(trackReference);

            AssertModelReferenceIsInitialized(trackReference);
            AssertTracksAreEqual(track, actualTrack);
        }
 private TrackData Convert(TrackDTO dto)
 {
     var track = new TrackData(
         dto.ISRC,
         dto.Artist,
         dto.Title,
         dto.Album,
         dto.ReleaseYear,
         dto.TrackLengthSec,
         new SolrModelReference(dto.Id)) { GroupId = dto.GroupId };
     return track;
 }
        public void ReadByIdTest()
        {
            var track = new TrackData("isrc", "artist", "title", "album", 2012, 200);

            var trackReference = trackDao.InsertTrack(track);

            AssertTracksAreEqual(track, trackDao.ReadTrack(trackReference));
        }
 public IModelReference InsertTrack(TrackData track)
 {
     var trackReference = new ModelReference<int>(Interlocked.Increment(ref counter));
     storage.Tracks[trackReference] = track;
     return track.TrackReference = trackReference;
 }
 private void AssertTracksAreEqual(TrackData expectedTrack, TrackData actualTrack)
 {
     Assert.AreEqual(expectedTrack.Album, actualTrack.Album);
     Assert.AreEqual(expectedTrack.Artist, actualTrack.Artist);
     Assert.AreEqual(expectedTrack.Title, actualTrack.Title);
     Assert.AreEqual(expectedTrack.TrackLengthSec, actualTrack.TrackLengthSec);
     Assert.AreEqual(expectedTrack.ISRC, actualTrack.ISRC);
     Assert.AreEqual(expectedTrack.GroupId, actualTrack.GroupId);
 }