public void ShouldInsertAllSubfingerprintsForTrack() { var hashedFingerprints = fcb.BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(audioService) .Hash() .Result; var track = new TrackData("isrc", "artist", "title", "album", 1986, 4d); var trackReference = modelService.InsertTrack(track); modelService.InsertHashDataForTrack(hashedFingerprints, trackReference); }
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 SameNumberOfHashBinsIsInsertedInAllTablesWhenFingerprintingEntireSongTest() { var track = new TrackData(GetTagInfo()); var trackReference = trackDao.InsertTrack(track); var hashedFingerprints = fingerprintCommandBuilder .BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(audioService) .Hash() .Result; InsertHashedFingerprintsForTrack(hashedFingerprints, trackReference); var hashes = subFingerprintDao.ReadHashedFingerprintsByTrackReference(track.TrackReference); Assert.AreEqual(hashedFingerprints.Count, hashes.Count); foreach (var data in hashes) { Assert.AreEqual(25, data.HashBins.Length); } }
public void SameNumberOfHashBinsIsInsertedInAllTablesWhenFingerprintingEntireSongTest() { var track = new TrackInfo("isrc", "title", "artist"); var trackData = trackDao.InsertTrack(track, 120d); var hashedFingerprints = fingerprintCommandBuilder .BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(audioService) .Hash() .Result; InsertHashedFingerprintsForTrack(hashedFingerprints.Audio, trackData.TrackReference); var hashes = subFingerprintDao.ReadHashedFingerprintsByTrackReference(trackData.TrackReference) .Select(ToHashedFingerprint()).ToList(); hashedFingerprints.Count.Should().Be(hashes.Count); foreach (var data in hashes) { data.HashBins.Length.Should().Be(25); } }
private List <HashedFingerprint> HashFingerprintsForTrack(IModelReference firstTrackReference, params string[] clusters) { var hashedFingerprintsForFirstTrack = fingerprintCommandBuilder.BuildFingerprintCommand() .From(GetAudioSamples()) .WithFingerprintConfig(config => { config.Clusters = clusters; }) .UsingServices(audioService) .Hash() .Result; InsertHashedFingerprintsForTrack(hashedFingerprintsForFirstTrack, firstTrackReference); return(hashedFingerprintsForFirstTrack); }
public void FingerprintsAreBuiltCorrectlyFromFile() { const string PathToAudioFile = "path-to-audio-file"; const int TenSeconds = 10; var samples = new AudioSamples { Samples = TestUtilities.GenerateRandomFloatArray(SampleRate * TenSeconds) }; const int ThreeFingerprints = 3; var rawFingerprints = GetGenericFingerprints(ThreeFingerprints); audioService.Setup(service => service.ReadMonoSamplesFromFile(PathToAudioFile, SampleRate)).Returns(samples); fingerprintService.Setup(service => service.CreateFingerprints(samples, It.IsAny <DefaultFingerprintConfiguration>())).Returns(rawFingerprints); var fingerprints = ((FingerprintCommand)fingerprintCommandBuilder.BuildFingerprintCommand() .From(PathToAudioFile) .UsingServices(audioService.Object)) .Fingerprint() .Result; Assert.AreEqual(ThreeFingerprints, fingerprints.Count); Assert.AreSame(rawFingerprints, fingerprints); }
public void ShouldCreateExactlyTheSameFingerprints() { var fcb0 = new FingerprintCommandBuilder( new FingerprintService( new SpectrumService(new LomontFFT()), new StandardHaarWaveletDecomposition(), new FingerprintDescriptor(), new AudioSamplesNormalizer()), new LocalitySensitiveHashingAlgorithm( new MinHashService(new DefaultPermutations()), new HashConverter())); var fcb1 = new FingerprintCommandBuilder( new FingerprintService( new SpectrumService(new LomontFFT()), new StandardHaarWaveletDecomposition(), new FastFingerprintDescriptor(), new AudioSamplesNormalizer()), new LocalitySensitiveHashingAlgorithm( new MinHashService(new DefaultPermutations()), new HashConverter())); var fingerprints0 = fcb0.BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(new NAudioService()) .Hash() .Result; fingerprints0.Sort( (fingerprint, hashedFingerprint) => fingerprint.SequenceNumber.CompareTo(hashedFingerprint.SequenceNumber)); var fingerprints1 = fcb1.BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(new NAudioService()) .Hash() .Result; fingerprints1.Sort( (fingerprint, hashedFingerprint) => fingerprint.SequenceNumber.CompareTo(hashedFingerprint.SequenceNumber)); for (int i = 0; i < fingerprints0.Count; ++i) { CollectionAssert.AreEqual(fingerprints0[i].SubFingerprint, fingerprints1[i].SubFingerprint); } }
public void ShoudUseCorrectFingerprintConfigurationIsUsedWithInstanceConfig() { const string PathToAudioFile = "path-to-audio-file"; var configuration = new DefaultFingerprintConfiguration { SpectrogramConfig = new DefaultSpectrogramConfig { ImageLength = 1234 } }; var fingerprintCommand = fingerprintCommandBuilder.BuildFingerprintCommand() .From(PathToAudioFile) .WithFingerprintConfig(configuration) .UsingServices(audioService.Object); Assert.AreSame(configuration, fingerprintCommand.FingerprintConfiguration); Assert.AreEqual(configuration.SpectrogramConfig.ImageLength, fingerprintCommand.FingerprintConfiguration.SpectrogramConfig.ImageLength); }
public void ShouldCreateExactlyTheSameFingerprints() { var fcb0 = new FingerprintCommandBuilder( new FingerprintService( new SpectrumService(new LomontFFT(), new LogUtility()), new LocalitySensitiveHashingAlgorithm( new MinHashService(new DefaultPermutations()), new HashConverter()), new StandardHaarWaveletDecomposition(), new FingerprintDescriptor())); var fcb1 = new FingerprintCommandBuilder( new FingerprintService( new SpectrumService(new LomontFFT(), new LogUtility()), new LocalitySensitiveHashingAlgorithm( new MinHashService(new DefaultPermutations()), new HashConverter()), new StandardHaarWaveletDecomposition(), new FastFingerprintDescriptor())); var audioService = new SoundFingerprintingAudioService(); var audioSamples = GetAudioSamples(); int testRuns = 5; for (int i = 0; i < testRuns; ++i) { var hashDatas0 = fcb0.BuildFingerprintCommand() .From(audioSamples) .UsingServices(audioService) .Hash() .Result; var hashDatas1 = fcb1.BuildFingerprintCommand() .From(audioSamples) .UsingServices(audioService) .Hash() .Result; AssertHashDatasAreTheSame(hashDatas0, hashDatas1); } }
public void FingerprintsAreBuiltCorrectlyFromFile() { const string PathToAudioFile = "path-to-audio-file"; float[] samples = TestUtilities.GenerateRandomFloatArray(SampleRate * 10); List <bool[]> rawFingerprints = new List <bool[]>(new[] { GenericFingerprint, GenericFingerprint, GenericFingerprint }); audioService.Setup(service => service.ReadMonoFromFile(PathToAudioFile, SampleRate, 0, 0)).Returns(samples); fingerprintService.Setup(service => service.CreateFingerprints(samples, It.IsAny <DefaultFingerprintConfiguration>())).Returns(rawFingerprints); List <bool[]> fingerprints = fingerprintCommandBuilder.BuildFingerprintCommand() .From(PathToAudioFile) .WithDefaultFingerprintConfig() .Fingerprint() .Result; Assert.AreEqual(3, fingerprints.Count); Assert.AreEqual(rawFingerprints, fingerprints); }
public void ShouldFingerprintAndQuerySuccessfully() { var modelService = new InMemoryModelService(); for (int i = 0; i < 30; ++i) { var samples = new AudioSamples(GetRandomSamples(120), "${i}", 5512); var hashes = fcb.BuildFingerprintCommand() .From(samples) .UsingServices(audioService) .Hash() .Result; var track = new TrackData("${i}", "", "", "", 2017, 120); var trackReference = modelService.InsertTrack(track); modelService.InsertHashDataForTrack(hashes, trackReference); } Console.WriteLine("Fingerprinting Time, Query Time, Candidates Found"); double avgFingerprinting = 0, avgQuery = 0; int totalRuns = 10; for (int i = 0; i < totalRuns; ++i) { var samples = new AudioSamples(GetRandomSamples(120), "${i}", 5512); var queryResult = qcb.BuildQueryCommand() .From(samples) .UsingServices(modelService, this.audioService) .Query() .Result; Console.WriteLine("{0,10}ms{1,15}ms{2,15}", queryResult.Stats.FingerprintingDuration, queryResult.Stats.QueryDuration, queryResult.Stats.TotalFingerprintsAnalyzed); avgFingerprinting += queryResult.Stats.FingerprintingDuration; avgQuery += queryResult.Stats.QueryDuration; } Console.WriteLine("Avg. Fingerprinting: {0,0:000}ms, Avg. Query: {1, 0:000}ms", avgFingerprinting / totalRuns, avgQuery / totalRuns); }
public async Task ShouldCreateExactlyTheSameFingerprints() { var fcbWithOldFingerprintDescriptor = new FingerprintCommandBuilder( new FingerprintService( new SpectrumService(new LomontFFT(), new LogUtility()), LocalitySensitiveHashingAlgorithm.Instance, new StandardHaarWaveletDecomposition(), new FingerprintDescriptor())); var fcbWithFastFingerprintDescriptor = new FingerprintCommandBuilder( new FingerprintService( new SpectrumService(new LomontFFT(), new LogUtility()), LocalitySensitiveHashingAlgorithm.Instance, new StandardHaarWaveletDecomposition(), new FastFingerprintDescriptor())); var audioService = new SoundFingerprintingAudioService(); var audioSamples = GetAudioSamples(); int runs = 5; for (int i = 0; i < runs; ++i) { var hashDatas0 = await fcbWithOldFingerprintDescriptor.BuildFingerprintCommand() .From(audioSamples) .UsingServices(audioService) .Hash(); var hashDatas1 = await fcbWithFastFingerprintDescriptor.BuildFingerprintCommand() .From(audioSamples) .UsingServices(audioService) .Hash(); AssertHashDatasAreTheSame(hashDatas0, hashDatas1); } }