public FingerprintService(
     IAudioService audioService,
     FingerprintDescriptor fingerprintDescriptor,
     SpectrumService spectrumService,
     IWaveletService waveletService)
 {
     this.SpectrumService       = spectrumService;
     this.WaveletService        = waveletService;
     this.FingerprintDescriptor = fingerprintDescriptor;
     this.AudioService          = audioService;
 }
Exemplo n.º 2
0
        public FingerprintService(
			IAudioService audioService,
			FingerprintDescriptor fingerprintDescriptor,
			SpectrumService spectrumService,
			IWaveletService waveletService)
        {
            this.SpectrumService = spectrumService;
            this.WaveletService = waveletService;
            this.FingerprintDescriptor = fingerprintDescriptor;
            this.AudioService = audioService;
        }
Exemplo n.º 3
0
        public static FingerprintService GetSoundfingerprintingService()
        {
            // Audio service
            IAudioService audioService = new AudioService();

            // Fingerprint Descriptor
            FingerprintDescriptor fingerprintDescriptor = new FingerprintDescriptor();

            // SpectrumService
            SpectrumService spectrumService = new SpectrumService();

            // Wavelet Service
            IWaveletDecomposition waveletDecomposition = new Soundfingerprinting.Fingerprinting.Wavelets.StandardHaarWaveletDecomposition();
            IWaveletService waveletService = new WaveletService(waveletDecomposition);

            // Fingerprint Service
            FingerprintService fingerprintService = new FingerprintService(audioService,
                                                                           fingerprintDescriptor,
                                                                           spectrumService,
                                                                           waveletService);

            return fingerprintService;
        }
 /// <summary>
 ///   Hash Fingerprints using Neural hasher component for solving k-nearest neighbor problem
 /// </summary>
 /// <param name = "listOfFingerprintsToHash">List of fingerprints already inserted in the database</param>
 /// <param name = "track">Track of the corresponding fingerprints</param>
 private void HashFingerprintsUsingNeuralHasher(IEnumerable<Fingerprint> listOfFingerprintsToHash, Track track)
 {
     FingerprintDescriptor descriptor = new FingerprintDescriptor();
     List<HashBinNeuralHasher> listToInsert = new List<HashBinNeuralHasher>();
     foreach (Fingerprint fingerprint in listOfFingerprintsToHash)
     {
         ensemble.ComputeHash(descriptor.DecodeFingerprint(fingerprint.Signature));
         long[] hashbins = ensemble.ExtractHashBins();
         for (int i = 0; i < hashbins.Length; i++)
         {
             HashBinNeuralHasher hash = new HashBinNeuralHasher(i, hashbins[i], i, track.Id);
             listToInsert.Add(hash);
         }
     }
     dalManager.InsertHashBin(listToInsert);
 }
        /// <summary>
        ///   Compute hashes using neural network ensemble
        /// </summary>
        private void ComputeHashesUsingNeuralHasher()
        {
            string connectionString = null;
            _cmbValidationConnectionStringNeuralHasher.Invoke(new Action(() => { connectionString = _cmbValidationConnectionStringNeuralHasher.SelectedItem.ToString(); }));

            FingerprintDescriptor descriptor = new FingerprintDescriptor();

            if (String.IsNullOrEmpty(connectionString))
            {
                MessageBox.Show(Resources.SelectValidationDB);
                return;
            }

            dalManager.SetConnectionString(connectionString);
            string path = _tbStoredEnsembleFilename.Text;
            if (String.IsNullOrEmpty(path))
            {
                MessageBox.Show(Resources.SelectPathToSerializedEnsemble, Resources.SelectFile, MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            NNEnsemble ensemble = NNEnsemble.Load(path); /*Load the serialized ensemble used to create hashes*/
            List<Track> tracks = dalManager.ReadTracks(); /*Read all tracks from the database for which the ensemble will create hashes*/
            _pbProgress.Invoke(new Action(() =>
                                          {
                                              _pbProgress.Minimum = 1;
                                              _pbProgress.Maximum = tracks.Count;
                                              _pbProgress.Value = 1;
                                              _pbProgress.Step = 1;
                                          }));

            /*Create hashes for each fingerprint in the database*/
            for (int index = 0; index < tracks.Count; index++)
            {
                Track track = tracks[index];
                List<Fingerprint> fingerprints;
                try
                {
                    fingerprints = dalManager.ReadFingerprintsByTrackId(track.Id, 0);
                    if (fingerprints == null)
                        continue;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                List<HashBinNeuralHasher> listToInsert = new List<HashBinNeuralHasher>();
                foreach (Fingerprint fingerprint in fingerprints) /*For each track's fingerprint create hash*/
                {
                    ensemble.ComputeHash(descriptor.DecodeFingerprint(fingerprint.Signature));
                    long[] hashbins = ensemble.ExtractHashBins(); /*Extract hash bin / hash table*/
                    for (int i = 0; i < hashbins.Length; i++)
                    {
                        HashBinNeuralHasher hash = new HashBinNeuralHasher(i, hashbins[i], i, track.Id);
                        listToInsert.Add(hash);
                    }
                }
                dalManager.InsertHashBin(listToInsert);
                _pbProgress.Invoke(new Action(() => _pbProgress.PerformStep()));
            }
        }
Exemplo n.º 6
0
        ///<summary>
        ///  Gets tracks/fingerprints from the database
        ///</summary>
        ///<param name = "function">Activation function</param>
        ///<param name = "fingerprintsPerTrack">Fingerprints per track</param>
        ///<param name = "outputs">Number of outputs from the neural network</param>
        ///<returns>Dictionary (Int32 - track id, List - list of corresponding fingerprints</returns>
        public Dictionary<Int32, List<BasicMLData>> GetNormalizedTrackFingerprints(IActivationFunction function, int fingerprintsPerTrack, int outputs)
        {
            List<Track> tracks = _dalManager.ReadTracks();
            Dictionary<Int32, List<Fingerprint>> unnormalized = _dalManager.ReadFingerprintsByMultipleTrackId(tracks, fingerprintsPerTrack);
            Dictionary<Int32, List<BasicMLData>> retVal = new Dictionary<Int32, List<BasicMLData>>();
            int neededTracks = (int) Math.Pow(2, outputs);
            int count = 0;

            FingerprintDescriptor descriptor = new FingerprintDescriptor();
            foreach (KeyValuePair<Int32, List<Fingerprint>> pair in unnormalized)
            {
                retVal.Add(pair.Key, new List<BasicMLData>());
                foreach (Fingerprint fingerprint in pair.Value)
                    retVal[pair.Key].Add(new BasicMLData(NormalizeUtils.NormalizeDesiredInputInPlace(function, descriptor.DecodeFingerprint(fingerprint.Signature))));
                count++;
                if (count > neededTracks - 1)
                    break;
            }
            return retVal;
        }