public DefaultQueryConfiguration() { ThresholdVotes = 5; MaxTracksToReturn = 25; Clusters = Enumerable.Empty<string>(); FingerprintConfiguration = new DefaultFingerprintConfiguration(); }
public void CreateFingerprintsTest() { float[] samples = TestUtilities.GenerateRandomFloatArray(5512 * 10); var configuration = new DefaultFingerprintConfiguration(); float[][] logarithmizedSpectrum = new[] { TestUtilities.GenerateRandomFloatArray(2048), TestUtilities.GenerateRandomFloatArray(2048), TestUtilities.GenerateRandomFloatArray(2048) }; List<float[][]> dividedLogSpectrum = new List<float[][]> { new[] { TestUtilities.GenerateRandomFloatArray(2048) }, new[] { TestUtilities.GenerateRandomFloatArray(2048) }, new[] { TestUtilities.GenerateRandomFloatArray(2048) } }; spectrumService.Setup(service => service.CreateLogSpectrogram(samples, configuration)).Returns(logarithmizedSpectrum); spectrumService.Setup(service => service.CutLogarithmizedSpectrum(logarithmizedSpectrum, configuration.Stride, configuration.FingerprintLength, configuration.Overlap)) .Returns(dividedLogSpectrum); waveletDecomposition.Setup(service => service.DecomposeImagesInPlace(dividedLogSpectrum)); fingerprintDescriptor.Setup(descriptor => descriptor.ExtractTopWavelets(It.IsAny<float[][]>(), configuration.TopWavelets)).Returns(GenericFingerprint); List<bool[]> rawFingerprints = fingerprintService.CreateFingerprints(samples, configuration); Assert.AreEqual(3, rawFingerprints.Count); foreach (bool[] fingerprint in rawFingerprints) { Assert.AreEqual(GenericFingerprint, fingerprint); } }
public DefaultQueryConfiguration() { ThresholdVotes = 5; MaxTracksToReturn = 25; Clusters = Enumerable.Empty <string>(); FingerprintConfiguration = new DefaultFingerprintConfiguration(); }
public void QueryCommandIsBuiltWithCustomFingerprintConfigCorrectly() { var customConfig = new DefaultFingerprintConfiguration(); var command = queryCommandBuilder.BuildQueryCommand() .From("path-to-file", 10, 0) .WithFingerprintConfig(customConfig) .UsingServices(modelService.Object, audioService.Object); Assert.AreSame(command.FingerprintConfiguration, customConfig); }
public DefaultQueryConfiguration() { ThresholdVotes = Configs.Threshold.Default; MaxTracksToReturn = 25; Clusters = Enumerable.Empty <string>(); AllowMultipleMatchesOfTheSameTrackInQuery = false; FingerprintConfiguration = new DefaultFingerprintConfiguration { Stride = Configs.QueryStrides.DefaultStride, FrequencyRange = Configs.FrequencyRanges.Default }; }
public void CreateLogSpectrogramFromSamplesLessThanFourierTransformWindowLength() { var configuration = new DefaultFingerprintConfiguration(); float[] samples = TestUtilities.GenerateRandomFloatArray(configuration.WdftSize - 1); logUtility.Setup(utility => utility.GenerateLogFrequenciesRanges(configuration)).Returns(new int[33]); float[][] result = spectrumService.CreateLogSpectrogram(samples, configuration); logUtility.Verify(utility => utility.GenerateLogFrequenciesRanges(configuration), Times.Once()); Assert.AreEqual(0, result.Length); // 128 }
public DefaultQueryConfiguration() { ThresholdVotes = Configs.Threshold.Default; MaxTracksToReturn = 25; PermittedGap = 2d; AllowMultipleMatchesOfTheSameTrackInQuery = false; FingerprintConfiguration = new DefaultFingerprintConfiguration { Stride = Configs.QueryStrides.DefaultStride, FrequencyRange = Configs.FrequencyRanges.Default }; MetaFieldsFilter = new Dictionary <string, string>(); QueryMediaType = MediaType.Audio; }
public void CorrectFingerprintConfigurationIsUsedWithInstanceConfigTest() { 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 AudioSamplesAreNormalized() { const int TenSeconds = 5512 * 10; var samples = TestUtilities.GenerateRandomAudioSamples(TenSeconds); var fingerprintConfig = new DefaultFingerprintConfiguration { NormalizeSignal = true }; var dividedLogSpectrum = GetDividedLogSpectrum(); spectrumService.Setup(service => service.CreateLogSpectrogram(samples, It.IsAny<DefaultSpectrogramConfig>())).Returns(dividedLogSpectrum); waveletDecomposition.Setup(service => service.DecomposeImageInPlace(It.IsAny<float[][]>())); fingerprintDescriptor.Setup(descriptor => descriptor.ExtractTopWavelets(It.IsAny<float[][]>(), fingerprintConfig.TopWavelets)) .Returns(GenericFingerprint); audioSamplesNormalizer.Setup(normalizer => normalizer.NormalizeInPlace(samples.Samples)); fingerprintService.CreateFingerprints(samples, fingerprintConfig); }
public void CutLogarithmizedSpectrumOfJustOneFingerprintTest() { DefaultFingerprintConfiguration config = new DefaultFingerprintConfiguration(); int logSpectrumLength = config.FingerprintLength; // 128 var stride = new StaticStride(0, 0); var logSpectrum = new float[logSpectrumLength][]; for (int i = 0; i < logSpectrumLength; i++) { logSpectrum[i] = new float[32]; } var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, stride, config.FingerprintLength, config.Overlap); Assert.AreEqual(1, cutLogarithmizedSpectrum.Count); }
public void FingerprintConfigurationInheritsDefaultValues() { var customConfiguration = new CustomFingerprintConfiguration(); var defaultConfiguration = new DefaultFingerprintConfiguration(); Assert.AreEqual(defaultConfiguration.FingerprintLength, customConfiguration.FingerprintLength); Assert.AreEqual(defaultConfiguration.LogBase, customConfiguration.LogBase); Assert.AreEqual(defaultConfiguration.LogBins, customConfiguration.LogBins); Assert.AreEqual(defaultConfiguration.MaxFrequency, customConfiguration.MaxFrequency); Assert.AreEqual(defaultConfiguration.MinFrequency, customConfiguration.MinFrequency); Assert.AreEqual(defaultConfiguration.NormalizeSignal, customConfiguration.NormalizeSignal); Assert.AreEqual(defaultConfiguration.NumberOfLSHTables, customConfiguration.NumberOfLSHTables); Assert.AreEqual(defaultConfiguration.NumberOfMinHashesPerTable, customConfiguration.NumberOfMinHashesPerTable); Assert.AreEqual(defaultConfiguration.Overlap, customConfiguration.Overlap); Assert.AreEqual(defaultConfiguration.SampleRate, customConfiguration.SampleRate); Assert.AreEqual(defaultConfiguration.SamplesPerFingerprint, customConfiguration.SamplesPerFingerprint); Assert.IsTrue(defaultConfiguration.Stride.GetType() == customConfiguration.Stride.GetType()); Assert.AreEqual(defaultConfiguration.TopWavelets, customConfiguration.TopWavelets); Assert.AreEqual(defaultConfiguration.UseDynamicLogBase, customConfiguration.UseDynamicLogBase); Assert.AreEqual(defaultConfiguration.WdftSize, customConfiguration.WdftSize); }
public void CreateFingerprints() { const int TenSeconds = 5512 * 10; var samples = TestUtilities.GenerateRandomAudioSamples(TenSeconds); var configuration = SpectrogramConfig.Default; var fingerprintConfig = new DefaultFingerprintConfiguration(); var dividedLogSpectrum = GetDividedLogSpectrum(); spectrumService.Setup(service => service.CreateLogSpectrogram(samples, configuration)).Returns(dividedLogSpectrum); waveletDecomposition.Setup(service => service.DecomposeImageInPlace(It.IsAny<float[][]>())); fingerprintDescriptor.Setup(descriptor => descriptor.ExtractTopWavelets(It.IsAny<float[][]>(), fingerprintConfig.TopWavelets)) .Returns(GenericFingerprint); var fingerprints = fingerprintService.CreateFingerprints(samples, fingerprintConfig); Assert.AreEqual(dividedLogSpectrum.Count, fingerprints.Count); for (int index = 0; index < fingerprints.Count; index++) { Assert.AreEqual(GenericFingerprint, fingerprints[index].Signature); Assert.AreEqual(dividedLogSpectrum[index].Timestamp, fingerprints[index].Timestamp, Epsilon); } }
private void BtnStartClick(object sender, EventArgs e) { DefaultFingerprintConfiguration configuration = new DefaultFingerprintConfiguration(); switch (hashAlgorithm) { case HashAlgorithm.LSH: if (!fileList.Any()) { MessageBox.Show(Resources.SelectFolderWithSongs, Resources.Songs, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } WinQueryResults winQueryResults = new WinQueryResults( _numSecondsToAnalyze.Enabled ? (int)_numSecondsToAnalyze.Value : 0, _numStartAtSecond.Enabled ? (int)_numStartAtSecond.Value : 0, (int)_nudHashtables.Value, (int)_nudKeys.Value, Convert.ToInt32(_nudThreshold.Value), WinUtils.GetStride((StrideType)_cmbStrideType.SelectedIndex, (int)_nudQueryStrideMax.Value, (int)_nudQueryStrideMin.Value, configuration.SamplesPerFingerprint), tagService, modelService, audioService, queryCommandBuilder); winQueryResults.Show(); winQueryResults.Refresh(); winQueryResults.ExtractCandidatesWithMinHashAlgorithm(fileList); break; case HashAlgorithm.NeuralHasher: throw new NotImplementedException(); case HashAlgorithm.None: throw new NotImplementedException(); } }
private void BtnQueryFromMicrophoneClick(object sender, EventArgs e) { DefaultFingerprintConfiguration configuration = new DefaultFingerprintConfiguration(); int secondsToRecord = (int)_nudSecondsToRecord.Value; int sampleRate = (int)_nudSampleRate.Value; string pathToFile = "mic_" + DateTime.Now.Ticks + ".wav"; _gbQueryMicrophoneBox.Enabled = false; Task<float[]>.Factory.StartNew(() => audioService.ReadMonoSamplesFromMicrophone(sampleRate, secondsToRecord)).ContinueWith( task => { var samples = task.Result; audioService.WriteSamplesToWaveFile(pathToFile, samples, sampleRate); _gbQueryMicrophoneBox.Enabled = true; WinQueryResults winQueryResults = new WinQueryResults( secondsToRecord, 0, (int)_nudHashtables.Value, (int)_nudKeys.Value, (int)_nudThreshold.Value, WinUtils.GetStride((StrideType)_cmbStrideType.SelectedIndex, (int)_nudQueryStrideMax.Value, (int)_nudQueryStrideMin.Value, configuration.SamplesPerFingerprint), tagService, modelService, audioService, queryCommandBuilder); winQueryResults.Show(); winQueryResults.Refresh(); winQueryResults.ExtractCandidatesUsingSamples(task.Result); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public void CreateFingerprintFromSamplesWhichAreExactlyEqualToMinimumLength() { DefaultFingerprintConfiguration config = new DefaultFingerprintConfiguration(); AudioSamples samples = GenerateRandomAudioSamples(config.SamplesPerFingerprint + config.SpectrogramConfig.WdftSize); var hash = fingerprintCommandBuilder.BuildFingerprintCommand() .From(samples) .UsingServices(bassAudioService) .Hash() .Result; Assert.AreEqual(1, hash.Count); }
public void CreateFingerprintFromSamplesWhichAreExactlyEqualToMinimumLength() { DefaultFingerprintConfiguration config = new DefaultFingerprintConfiguration(); float[] samples = TestUtilities.GenerateRandomFloatArray(config.SamplesPerFingerprint + config.WdftSize); var hash = fingerprintCommandBuilder.BuildFingerprintCommand() .From(samples) .WithDefaultFingerprintConfig() .UsingServices(bassAudioService) .Hash() .Result; Assert.AreEqual(1, hash.Count); }
public void CutLogarithmizedSpectrumWithAnIncrementalStaticStride() { DefaultFingerprintConfiguration config = new DefaultFingerprintConfiguration(); int logSpectrumLength = (config.FingerprintLength * 24) + config.Overlap; var stride = new IncrementalStaticStride(config.SamplesPerFingerprint / 2, config.SamplesPerFingerprint, 0); var logSpectrum = new float[logSpectrumLength][]; for (int i = 0; i < logSpectrumLength; i++) { logSpectrum[i] = new float[32]; } var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, stride, config.FingerprintLength, config.Overlap); Assert.AreEqual(48, cutLogarithmizedSpectrum.Count); }
internal FingerprintCommand(IFingerprintService fingerprintService, ILocalitySensitiveHashingAlgorithm lshAlgorithm) { this.fingerprintService = fingerprintService; this.lshAlgorithm = lshAlgorithm; FingerprintConfiguration = new DefaultFingerprintConfiguration(); }
public void SilenceIsNotFingerprinted() { var samples = TestUtilities.GenerateRandomAudioSamples(5512 * 10); var configuration = new DefaultFingerprintConfiguration(); var dividedLogSpectrum = GetDividedLogSpectrum(); spectrumService.Setup(service => service.CreateLogSpectrogram(samples, It.IsAny<DefaultSpectrogramConfig>())).Returns(dividedLogSpectrum); waveletDecomposition.Setup(decomposition => decomposition.DecomposeImageInPlace(It.IsAny<float[][]>())); fingerprintDescriptor.Setup(descriptor => descriptor.ExtractTopWavelets(It.IsAny<float[][]>(), configuration.TopWavelets)).Returns( new[] { false, false, false, false, false, false, false, false }); var rawFingerprints = fingerprintService.CreateFingerprints(samples, configuration); Assert.IsTrue(rawFingerprints.Count == 0); }
private void BtnStartClick(object sender, EventArgs e) { DefaultFingerprintConfiguration configuration = new DefaultFingerprintConfiguration(); switch (hashAlgorithm) { case HashAlgorithm.LSH: if (!fileList.Any()) { MessageBox.Show(Resources.SelectFolderWithSongs, Resources.Songs, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } WinQueryResults winQueryResults = new WinQueryResults(10, 20, 25, 4, 5, WinUtils.GetStride(StrideType.IncrementalRandom, 512, 256, configuration.SamplesPerFingerprint), tagService, modelService, audioService, queryCommandBuilder); winQueryResults.Show(); winQueryResults.Refresh(); winQueryResults.ExtractCandidatesWithMinHashAlgorithm(fileList); break; case HashAlgorithm.NeuralHasher: throw new NotImplementedException(); case HashAlgorithm.None: throw new NotImplementedException(); } }