private bool ConsecutiveMatchesAreLongerThanTheQuery(double queryLength, List<MatchedPair> sortedMatches, int index, FingerprintConfiguration config)
 {
     return SubFingerprintsToSeconds.AdjustLengthToSeconds(
         sortedMatches[index].SubFingerprint.SequenceAt,
         sortedMatches[index - 1].SubFingerprint.SequenceAt,
         config) > queryLength;
 }
 private void NormalizeAudioIfNecessary(AudioSamples samples, FingerprintConfiguration configuration)
 {
     if (configuration.NormalizeSignal)
     {
         audioSamplesNormalizer.NormalizeInPlace(samples.Samples);
     }
 }
        private List<Fingerprint> CreateFingerprintsFromLogSpectrum(IEnumerable<SpectralImage> spectralImages, FingerprintConfiguration configuration)
        {
            var fingerprints = new ConcurrentBag<Fingerprint>();
            Parallel.ForEach(spectralImages, spectralImage =>
            {
                waveletDecomposition.DecomposeImageInPlace(spectralImage.Image);
                bool[] image = fingerprintDescriptor.ExtractTopWavelets(spectralImage.Image, configuration.TopWavelets);
                if (!IsSilence(image))
                {
                    fingerprints.Add(new Fingerprint(image, spectralImage.StartsAt, spectralImage.SequenceNumber));
                }
            });

            return fingerprints.ToList();
        }
        private List<Fingerprint> CreateFingerprintsFromLogSpectrum(IEnumerable<SpectralImage> spectralImages, FingerprintConfiguration configuration)
        {
            var fingerprints = new List<Fingerprint>();
            foreach (var spectralImage in spectralImages)
            {
                waveletDecomposition.DecomposeImageInPlace(spectralImage.Image); 
                bool[] image = fingerprintDescriptor.ExtractTopWavelets(spectralImage.Image, configuration.TopWavelets);
                if (!IsSilence(image))
                {
                    fingerprints.Add(new Fingerprint { Signature = image, Timestamp = spectralImage.Timestamp, SequenceNumber = spectralImage.SequenceNumber });
                }
            }

            return fingerprints;
        }
        public Coverage GetCoverage(SortedSet<MatchedPair> matches, double queryLength, FingerprintConfiguration configuration)
        {
            int minI = 0, maxI = 0, curMinI = 0, maxLength = 0;
            var sortedMatches = matches.ToList();
            for (int i = 1; i < sortedMatches.Count; ++i)
            {
                if (ConsecutiveMatchesAreLongerThanTheQuery(queryLength, sortedMatches, i, configuration))
                {
                    // potentialy a new start of best matched sequence
                    curMinI = i;
                }

                if (i - curMinI > maxLength)
                {
                    maxLength = i - curMinI;
                    maxI = i;
                    minI = curMinI;
                }
            }

            double notCovered = 0d;
            for (int i = minI + 1; i <= maxI; ++i)
            {
                if (sortedMatches[i].SubFingerprint.SequenceAt - sortedMatches[i - 1].SubFingerprint.SequenceAt > configuration.FingerprintLengthInSeconds)
                {
                    notCovered += sortedMatches[i].SubFingerprint.SequenceAt - (sortedMatches[i - 1].SubFingerprint.SequenceAt + configuration.FingerprintLengthInSeconds);
                }
            }

            double sourceMatchLength = SubFingerprintsToSeconds.AdjustLengthToSeconds(
                    sortedMatches[maxI].SubFingerprint.SequenceAt,
                    sortedMatches[minI].SubFingerprint.SequenceAt,
                    configuration) - notCovered;

            double sourceMatchStartsAt = sortedMatches[minI].HashedFingerprint.StartsAt;
            double originMatchStartsAt = sortedMatches[minI].SubFingerprint.SequenceAt;
            return new Coverage(sourceMatchStartsAt, sourceMatchLength, originMatchStartsAt);
        }
 public static double AdjustLengthToSeconds(double endsAt, double startsAt, FingerprintConfiguration configuration)
 {
     return endsAt - startsAt + configuration.FingerprintLengthInSeconds;
 }
 public List<Fingerprint> CreateFingerprints(AudioSamples samples, FingerprintConfiguration configuration)
 {
     NormalizeAudioIfNecessary(samples, configuration);
     var spectrum = spectrumService.CreateLogSpectrogram(samples, configuration.SpectrogramConfig);
     return CreateFingerprintsFromLogSpectrum(spectrum, configuration);
 }
 public IUsingFingerprintServices WithFingerprintConfig(FingerprintConfiguration configuration)
 {
     FingerprintConfiguration = configuration;
     return this;
 }
Ejemplo n.º 9
0
 public IUsingQueryServices WithConfigs(FingerprintConfiguration fingerprintConfiguration, QueryConfiguration configuration)
 {
     QueryConfiguration = configuration;
     FingerprintConfiguration = fingerprintConfiguration;
     return this;
 }
Ejemplo n.º 10
0
 public IUsingQueryServices WithFingerprintConfig(FingerprintConfiguration fingerprintConfiguration)
 {
     FingerprintConfiguration = fingerprintConfiguration;
     return this;
 }