public FindSimilarClientForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // Constructor code after the InitializeComponent() call.
            //
            this.version.Text = Mirage.Mir.VERSION;
            this.DistanceTypeCombo.DataSource = Enum.GetValues(typeof(AudioFeature.DistanceType));

            this.dataGridView1.Columns.Add("Id", "Id");
            this.dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            this.dataGridView1.Columns.Add("Path", "Path");
            this.dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            this.dataGridView1.Columns.Add("Duration_Similarity", "Duration (ms) / Similarity");
            this.dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            this.db = new Db();
            this.databaseService = DatabaseService.Instance;

            ReadAllTracks();
        }
Exemple #2
0
 public Repository(IPermutations permutations, DatabaseService dbService, FingerprintService fingerprintService)
 {
     this.permutations = permutations;
     this.minHash = new MinHash(this.permutations);
     this.dbService = dbService;
     this.fingerprintService = fingerprintService;
 }
        /// <summary>
        /// Query one specific song using MinHash algorithm.
        /// </summary>
        /// <param name="signatures">Signature signatures from a song</param>
        /// <param name="dbService">DatabaseService used to query the underlying database</param>
        /// <param name="lshHashTables">Number of hash tables from the database</param>
        /// <param name="lshGroupsPerKey">Number of groups per hash table</param>
        /// <param name="thresholdTables">Threshold percentage [0.07 for 20 LHash Tables, 0.17 for 25 LHashTables]</param>
        /// <param name="queryTime">Set buy the method, representing the query length</param>
        /// <returns>Dictionary with Tracks ID's and the Query Statistics</returns>
        public static Dictionary<Int32, QueryStats> QueryOneSongMinHash(
			IEnumerable<bool[]> signatures,
			DatabaseService dbService,
			MinHash minHash,
			int lshHashTables,
			int lshGroupsPerKey,
			int thresholdTables,
			ref long queryTime)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            Dictionary<int, QueryStats> stats = new Dictionary<int, QueryStats>();
            foreach (bool[] signature in signatures)
            {
                if (signature == null)
                {
                    continue;
                }

                // Compute Min Hash on randomly selected fingerprints
                int[] bin = minHash.ComputeMinHashSignature(signature);

                Dictionary<int, long> hashes = minHash.GroupMinHashToLSHBuckets(bin, lshHashTables, lshGroupsPerKey); /*Find all candidates by querying the database*/
                long[] hashbuckets = hashes.Values.ToArray();
                IDictionary<int, IList<HashBinMinHash>> candidates = dbService.ReadFingerprintsByHashBucketLsh(hashbuckets);
                Dictionary<int, IList<HashBinMinHash>> potentialCandidates = SelectPotentialMatchesOutOfEntireDataset(candidates, thresholdTables);
                if (potentialCandidates.Count > 0)
                {
                    IList<Fingerprint> fingerprints = dbService.ReadFingerprintById(potentialCandidates.Keys);
                    Dictionary<Fingerprint, int> finalCandidates = fingerprints.ToDictionary(finger => finger, finger => potentialCandidates[finger.Id].Count);
                    ArrangeCandidatesAccordingToFingerprints(
                        signature, finalCandidates, lshHashTables, lshGroupsPerKey, stats);
                }
            }

            stopWatch.Stop();
            queryTime = stopWatch.ElapsedMilliseconds; /*Set the query Time parameter*/
            return stats;
        }
        public FindSimilarClientForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // Constructor code after the InitializeComponent() call.
            //
            this.version.Text = Mirage.Mir.VERSION;
            this.DistanceTypeCombo.DataSource = Enum.GetValues(typeof(AudioFeature.DistanceType));

            /*
            this.dataGridView1.Columns.Add("Id", "Id");
            this.dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            this.dataGridView1.Columns.Add("Path", "Path");
            this.dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            this.dataGridView1.Columns.Add("Duration_Similarity", "Duration (ms) / Similarity");
            this.dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
             */

            this.db = new Db();

            // Instansiate soundfingerprinting Repository
            FingerprintService fingerprintService = Analyzer.GetSoundfingerprintingService();
            this.databaseService = DatabaseService.Instance;

            //IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms.csv", ",");
            IPermutations permutations = new LocalPermutations("perms-new.csv", ",");

            repository = new Repository(permutations, databaseService, fingerprintService);

            if (rbScms.Checked) {
                IgnoreFileLengthCheckBox.Visible = true;
                DistanceTypeCombo.Visible = true;
            } else {
                IgnoreFileLengthCheckBox.Visible = false;
                DistanceTypeCombo.Visible = false;
            }

            ReadAllTracks();
        }
Exemple #5
0
        //private static Mfcc mfccOptimized = new Mfcc(WINDOW_SIZE, SAMPLING_RATE, MEL_COEFFICIENTS, MFCC_COEFFICIENTS);
        //private static MFCC mfccComirva = new MFCC(SAMPLING_RATE, WINDOW_SIZE, MFCC_COEFFICIENTS, true, 20.0, SAMPLING_RATE/2, MEL_COEFFICIENTS);

        #endif

        #region Methods

        public static bool AnalyzeAndAdd(FileInfo filePath, Db db, DatabaseService databaseService, bool doOutputDebugInfo=DEFAULT_DEBUG_INFO, bool useHaarWavelet = true)
        {
            DbgTimer t = new DbgTimer();
            t.Start ();

            float[] audiodata = AudioFileReader.Decode(filePath.FullName, SAMPLING_RATE, SECONDS_TO_ANALYZE);
            if (audiodata == null || audiodata.Length == 0)  {
                Dbg.WriteLine("Error! - No Audio Found");
                return false;
            }

            // Read TAGs using BASS
            FindSimilar.AudioProxies.BassProxy bass = FindSimilar.AudioProxies.BassProxy.Instance;
            Un4seen.Bass.AddOn.Tags.TAG_INFO tag_info = bass.GetTagInfoFromFile(filePath.FullName);

            // Name of file being processed
            string name = StringUtils.RemoveNonAsciiCharacters(Path.GetFileNameWithoutExtension(filePath.Name));

            #if DEBUG
            if (Analyzer.DEBUG_INFO_VERBOSE) {
                if (DEBUG_OUTPUT_TEXT) WriteAscii(audiodata, name + "_audiodata.ascii");
                if (DEBUG_OUTPUT_TEXT) WriteF3Formatted(audiodata, name + "_audiodata.txt");
            }
            #endif

            if (doOutputDebugInfo) {
                DrawGraph(MathUtils.FloatToDouble(audiodata), name + "_audiodata.png");
            }

            // Calculate duration in ms
            double duration = (double) audiodata.Length / SAMPLING_RATE * 1000;

            // Explode samples to the range of 16 bit shorts (–32,768 to 32,767)
            // Matlab multiplies with 2^15 (32768)
            // e.g. if( max(abs(speech))<=1 ), speech = speech * 2^15; end;
            MathUtils.Multiply(ref audiodata, AUDIO_MULTIPLIER); // 65536

            // zero pad if the audio file is too short to perform a mfcc
            if (audiodata.Length < (fingerprintingConfig.WdftSize + fingerprintingConfig.Overlap))
            {
                int lenNew = fingerprintingConfig.WdftSize + fingerprintingConfig.Overlap;
                Array.Resize<float>(ref audiodata, lenNew);
            }

            // Get fingerprint signatures using the Soundfingerprinting methods
            IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms.csv", ",");
            Repository repository = new Repository(permutations, databaseService, fingerprintService);

            // Image Service
            ImageService imageService = new ImageService(
                fingerprintService.SpectrumService,
                fingerprintService.WaveletService);

            // work config
            WorkUnitParameterObject param = new WorkUnitParameterObject();
            param.FingerprintingConfiguration = fingerprintingConfig;
            param.AudioSamples = audiodata;
            param.PathToAudioFile = filePath.FullName;
            param.MillisecondsToProcess = SECONDS_TO_ANALYZE * 1000;
            param.StartAtMilliseconds = 0;

            // build track
            Track track = new Track();
            track.Title = name;
            track.TrackLengthMs = (int) duration;
            track.FilePath = filePath.FullName;
            track.Id = -1; // this will be set by the insert method

            #region parse tag_info
            if (tag_info != null) {
                Dictionary<string, string> tags = new Dictionary<string, string>();

                //if (tag_info.title != string.Empty) tags.Add("title", tag_info.title);
                if (tag_info.artist != string.Empty) tags.Add("artist", tag_info.artist);
                if (tag_info.album != string.Empty) tags.Add("album", tag_info.album);
                if (tag_info.albumartist != string.Empty) tags.Add("albumartist", tag_info.albumartist);
                if (tag_info.year != string.Empty) tags.Add("year", tag_info.year);
                if (tag_info.comment != string.Empty) tags.Add("comment", tag_info.comment);
                if (tag_info.genre != string.Empty) tags.Add("genre", tag_info.genre);
                if (tag_info.track != string.Empty) tags.Add("track", tag_info.track);
                if (tag_info.disc != string.Empty) tags.Add("disc", tag_info.disc);
                if (tag_info.copyright != string.Empty) tags.Add("copyright", tag_info.copyright);
                if (tag_info.encodedby != string.Empty) tags.Add("encodedby", tag_info.encodedby);
                if (tag_info.composer != string.Empty) tags.Add("composer", tag_info.composer);
                if (tag_info.publisher != string.Empty) tags.Add("publisher", tag_info.publisher);
                if (tag_info.lyricist != string.Empty) tags.Add("lyricist", tag_info.lyricist);
                if (tag_info.remixer != string.Empty) tags.Add("remixer", tag_info.remixer);
                if (tag_info.producer != string.Empty) tags.Add("producer", tag_info.producer);
                if (tag_info.bpm != string.Empty) tags.Add("bpm", tag_info.bpm);
                //if (tag_info.filename != string.Empty) tags.Add("filename", tag_info.filename);
                tags.Add("channelinfo", tag_info.channelinfo.ToString());
                //if (tag_info.duration > 0) tags.Add("duration", tag_info.duration.ToString());
                if (tag_info.bitrate > 0) tags.Add("bitrate", tag_info.bitrate.ToString());
                if (tag_info.replaygain_track_gain != -100f) tags.Add("replaygain_track_gain", tag_info.replaygain_track_gain.ToString());
                if (tag_info.replaygain_track_peak != -1f) tags.Add("replaygain_track_peak", tag_info.replaygain_track_peak.ToString());
                if (tag_info.conductor != string.Empty) tags.Add("conductor", tag_info.conductor);
                if (tag_info.grouping != string.Empty) tags.Add("grouping", tag_info.grouping);
                if (tag_info.mood != string.Empty) tags.Add("mood", tag_info.mood);
                if (tag_info.rating != string.Empty) tags.Add("rating", tag_info.rating);
                if (tag_info.isrc != string.Empty) tags.Add("isrc", tag_info.isrc);

                foreach(var nativeTag in tag_info.NativeTags) {
                    string[] keyvalue = nativeTag.Split('=');
                    tags.Add(keyvalue[0], keyvalue[1]);
                }
                track.Tags = tags;
            }
            #endregion

            double[][] logSpectrogram;
            if (repository.InsertTrackInDatabaseUsingSamples(track, 25, 4, param, out logSpectrogram)) {

                // store logSpectrogram as Matrix
                Comirva.Audio.Util.Maths.Matrix logSpectrogramMatrix = new Comirva.Audio.Util.Maths.Matrix(logSpectrogram);
                logSpectrogramMatrix = logSpectrogramMatrix.Transpose();

                #region Debug for Soundfingerprinting Method
                if (doOutputDebugInfo) {
                    imageService.GetLogSpectralImages(logSpectrogram, fingerprintingConfig.Stride, fingerprintingConfig.FingerprintLength, fingerprintingConfig.Overlap, 2).Save(name + "_specgram_logimages.png");

                    logSpectrogramMatrix.DrawMatrixImageLogValues(name + "_specgram_logimage.png", true);

                    if (DEBUG_OUTPUT_TEXT) {
                        logSpectrogramMatrix.WriteCSV(name + "_specgram_log.csv", ";");
                    }
                }
                #endregion

                #region Insert Statistical Cluster Model Similarity Audio Feature as well
                Comirva.Audio.Util.Maths.Matrix scmsMatrix = null;
                if (useHaarWavelet) {
                    #region Wavelet Transform
                    int lastHeight = 0;
                    int lastWidth = 0;
                    scmsMatrix = mfccMirage.ApplyWaveletCompression(ref logSpectrogramMatrix, out lastHeight, out lastWidth);

                    #if DEBUG
                    if (Analyzer.DEBUG_INFO_VERBOSE) {
                        if (DEBUG_OUTPUT_TEXT) scmsMatrix.WriteAscii(name + "_waveletdata.ascii");
                    }
                    #endif

                    if (doOutputDebugInfo) {
                        scmsMatrix.DrawMatrixImageLogValues(name + "_waveletdata.png", true);
                    }

                    #if DEBUG
                    if (Analyzer.DEBUG_INFO_VERBOSE) {
                        #region Inverse Wavelet
                        // try to do an inverse wavelet transform
                        Comirva.Audio.Util.Maths.Matrix stftdata_inverse_wavelet = mfccMirage.InverseWaveletCompression(ref scmsMatrix, lastHeight, lastWidth, logSpectrogramMatrix.Rows, logSpectrogramMatrix.Columns);

                        if (DEBUG_OUTPUT_TEXT) stftdata_inverse_wavelet.WriteCSV(name + "_specgramlog_inverse_wavelet.csv", ";");
                        stftdata_inverse_wavelet.DrawMatrixImageLogValues(name + "_specgramlog_inverse_wavelet.png", true);
                        #endregion
                    }
                    #endif
                    #endregion
                } else {
                    #region DCT Transform
                    // It seems the Mirage way of applying the DCT is slightly faster than the
                    // Comirva way due to less loops
                    scmsMatrix = mfccMirage.ApplyDCT(ref logSpectrogramMatrix);

                    #if DEBUG
                    if (Analyzer.DEBUG_INFO_VERBOSE) {
                        if (DEBUG_OUTPUT_TEXT) scmsMatrix.WriteAscii(name + "_mfccdata.ascii");
                    }
                    #endif

                    if (doOutputDebugInfo) {
                        scmsMatrix.DrawMatrixImageLogValues(name + "_mfccdata.png", true);
                    }

                    #if DEBUG
                    if (Analyzer.DEBUG_INFO_VERBOSE) {
                        #region Inverse MFCC
                        // try to do an inverse mfcc
                        Comirva.Audio.Util.Maths.Matrix stftdata_inverse_mfcc = mfccMirage.InverseDCT(ref scmsMatrix);

                        if (DEBUG_OUTPUT_TEXT) stftdata_inverse_mfcc.WriteCSV(name + "_stftdata_inverse_mfcc.csv", ";");
                        stftdata_inverse_mfcc.DrawMatrixImageLogValues(name + "_specgramlog_inverse_mfcc.png", true);
                        #endregion
                    }
                    #endif
                    #endregion
                }

                // Store in a Statistical Cluster Model Similarity class.
                // A Gaussian representation of a song
                Scms audioFeature = Scms.GetScms(scmsMatrix, name);

                if (audioFeature != null) {

                    // Store image if debugging
                    if (doOutputDebugInfo) {
                        audioFeature.Image = scmsMatrix.DrawMatrixImageLogValues(name + "_featuredata.png", true, false, 0, 0, true);
                    }

                    // Store bitstring hash as well
                    string hashString = GetBitString(scmsMatrix);
                    audioFeature.BitString = hashString;

                    // Store duration
                    audioFeature.Duration = (long) duration;

                    // Store file name
                    audioFeature.Name = filePath.FullName;

                    int id = track.Id;
                    if (db.AddTrack(ref id, audioFeature) == -1) {
                        Console.Out.WriteLine("Failed! Could not add audioFeature to database {0}!", name);
                    }
                }
                #endregion

            } else {
                // failed
                return false;
            }

            Dbg.WriteLine ("AnalyzeAndAdd - Total Execution Time: {0} ms", t.Stop().TotalMilliseconds);
            return true;
        }
		public CompareAudioForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			
			// Instansiate Soundfingerprinting Repository
			FingerprintService fingerprintService = Analyzer.GetSoundfingerprintingService();
			this.databaseService = DatabaseService.Instance;

			IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms.csv", ",");
			//IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms-new.csv", ",");
			
			IFingerprintingConfiguration fingerprintingConfigCreation = new FullFrequencyFingerprintingConfiguration();
			repository = new Repository(permutations, databaseService, fingerprintService);
			ImageService imageService = new ImageService(fingerprintService.SpectrumService, fingerprintService.WaveletService);
			
			FileInfo filePathAudio1 = new FileInfo(@"C:\Users\perivar.nerseth\Music\Test Samples Database\VDUB1 Snare 004.wav");
			FileInfo filePathAudio2 = new FileInfo(@"C:\Users\perivar.nerseth\Music\Test Samples Search\VDUB1 Snare 004 - Start.wav");
			
			int fingerprintsPerRow = 2;

			double[][] logSpectrogram1 = null;
			double[][] logSpectrogram2 = null;
			List<bool[]> fingerprints1 = null;
			List<bool[]> fingerprints2 = null;
			
			WorkUnitParameterObject file1Param = Analyzer.GetWorkUnitParameterObjectFromAudioFile(filePathAudio1);
			if (file1Param != null) {
				file1Param.FingerprintingConfiguration = fingerprintingConfigCreation;
				
				// Get fingerprints
				fingerprints1 = fingerprintService.CreateFingerprintsFromAudioSamples(file1Param.AudioSamples, file1Param, out logSpectrogram1);
				
				pictureBox1.Image = imageService.GetSpectrogramImage(logSpectrogram1, logSpectrogram1.Length, logSpectrogram1[0].Length);
				pictureBoxWithInterpolationMode1.Image = imageService.GetImageForFingerprints(fingerprints1, file1Param.FingerprintingConfiguration.FingerprintLength, file1Param.FingerprintingConfiguration.LogBins, fingerprintsPerRow);
			}

			WorkUnitParameterObject file2Param = Analyzer.GetWorkUnitParameterObjectFromAudioFile(filePathAudio2);
			if (file2Param != null) {
				file2Param.FingerprintingConfiguration = fingerprintingConfigCreation;
				
				// Get fingerprints
				fingerprints2 = fingerprintService.CreateFingerprintsFromAudioSamples(file2Param.AudioSamples, file2Param, out logSpectrogram2);
				
				pictureBox2.Image = imageService.GetSpectrogramImage(logSpectrogram2, logSpectrogram2.Length, logSpectrogram2[0].Length);
				pictureBoxWithInterpolationMode2.Image = imageService.GetImageForFingerprints(fingerprints2, file2Param.FingerprintingConfiguration.FingerprintLength, file2Param.FingerprintingConfiguration.LogBins, fingerprintsPerRow);
			}
			

			MinHash minHash = repository.MinHash;
			
			// only use the first signatures
			bool[] signature1 = fingerprints1[0];
			bool[] signature2 = fingerprints2[0];

			if (signature1 != null && signature2 != null) {
				int hammingDistance = MinHash.CalculateHammingDistance(signature1, signature2);
				double jaqSimilarity = MinHash.CalculateJaqSimilarity(signature1, signature2);
				
				lblSimilarity.Text = String.Format("Hamming: {0} JAQ: {1}", hammingDistance, jaqSimilarity);
			}
		}
Exemple #7
0
			/// <summary>
			/// Scan a directory recursively and add all the audio files found to the database
			/// </summary>
			/// <param name="path">path to directory</param>
			/// <param name="db">database</param>
			/// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param>
			/// <param name="skipDurationAboveSeconds">skip files with duration longer than this number of seconds (0 or less disables this)</param>
			public static void ScanDirectoryOLD(string path, Db db, DatabaseService databaseService, Analyzer.AnalysisMethod analysisMethod, double skipDurationAboveSeconds) {
				
				Stopwatch stopWatch = Stopwatch.StartNew();
				
				FAILED_FILES_LOG.Delete();
				WARNING_FILES_LOG.Delete();
				
				// scan directory for audio files
				try
				{
					// By some reason the IOUtils.GetFiles returns a higher count than what seams correct?!
					IEnumerable<string> filesAll =
						Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
						.Where(f => extensions.Contains(Path.GetExtension(f).ToLower()));
					
					//IEnumerable<string> filesAll = IOUtils.GetFiles(path, extensionsWithStar, SearchOption.AllDirectories);
					Console.Out.WriteLine("Found {0} files in scan directory.", filesAll.Count());
					
					// get all already processed files stored in the database
					// store in memory
					// It seems to work well with huge volumes of file (200k)
					IList<string> filesAlreadyProcessed = null;
					if (analysisMethod != Analyzer.AnalysisMethod.AudioFingerprinting) {
						// if we are not using the audio fingerprinting database
						filesAlreadyProcessed = db.ReadTrackFilenames();
					} else {
						// Get database
						filesAlreadyProcessed = databaseService.ReadTrackFilenames();
					}
					
					Console.Out.WriteLine("Database contains {0} already processed files.", filesAlreadyProcessed.Count);

					// find the files that has not already been added to the database
					List<string> filesRemaining = filesAll.Except(filesAlreadyProcessed).ToList();
					Console.Out.WriteLine("Found {0} files remaining in scan directory to be processed.", filesRemaining.Count);

					int filesCounter = 1;
					int filesAllCounter = filesAlreadyProcessed.Count + 1;
					
					#if !DEBUG
					Console.Out.WriteLine("Running in multi-threaded mode!");
					Parallel.ForEach(filesRemaining, file =>
					                 {
					                 	#else
					                 	Console.Out.WriteLine("Running in single-threaded mode!");
					                 	foreach (string file in filesRemaining)
					                 	{
					                 		#endif

					                 		FileInfo fileInfo = new FileInfo(file);

					                 		// Try to use Un4Seen Bass to check duration
					                 		BassProxy bass = BassProxy.Instance;
					                 		double duration = bass.GetDurationInSeconds(fileInfo.FullName);

					                 		// check if we should skip files longer than x seconds
					                 		if ( (skipDurationAboveSeconds > 0 && duration > 0 && duration < skipDurationAboveSeconds)
					                 		    || skipDurationAboveSeconds <= 0
					                 		    || duration < 0) {

					                 			AudioFeature feature = null;
					                 			switch (analysisMethod) {
					                 				case Analyzer.AnalysisMethod.MandelEllis:
					                 					feature = Analyzer.AnalyzeMandelEllis(fileInfo);
					                 					break;
					                 				case Analyzer.AnalysisMethod.SCMS:
					                 					feature = Analyzer.AnalyzeScms(fileInfo);
					                 					break;
					                 				case Analyzer.AnalysisMethod.AudioFingerprinting:
					                 					feature = Analyzer.AnalyzeSoundfingerprinting(fileInfo);
					                 					break;
					                 			}
					                 			if (feature != null) {
					                 				if (analysisMethod != Analyzer.AnalysisMethod.AudioFingerprinting) {
					                 					// if we are not using the audio fingerprinting database
					                 					db.AddTrack(ref filesAllCounter, feature);
					                 				} else {
					                 					// if we are using the audio fingerprinting database, we have already added the track
					                 				}
					                 				
					                 				Console.Out.WriteLine("[{1}/{2} - {3}/{4}] Succesfully added {0} to database ({5} ms) (Thread: {6})", fileInfo.Name, filesCounter, filesRemaining.Count, filesAllCounter, filesAll.Count(), feature.Duration, Thread.CurrentThread.ManagedThreadId);
					                 				filesCounter++;
					                 				filesAllCounter++;
					                 				feature = null;
					                 			} else {
					                 				Console.Out.WriteLine("Failed! Could not generate audio fingerprint for {0}!", fileInfo.Name);
					                 				IOUtils.LogMessageToFile(FAILED_FILES_LOG, fileInfo.FullName);
					                 			}
					                 		} else {
					                 			Console.Out.WriteLine("Skipping {0} since duration exceeds limit ({1:0.00} > {2:0.00} sec.)", fileInfo.Name, duration, skipDurationAboveSeconds);
					                 		}
					                 		
					                 		fileInfo = null;
					                 	}
					                 	
					                 	#if !DEBUG
					                 	);
					                 	#endif
					                 	int filesActuallyProcessed = filesCounter -1;
					                 	Console.WriteLine("Added {0} out of a total remaining set of {1} files. (Of {2} files found).", filesActuallyProcessed, filesRemaining.Count(), filesAll.Count());
					                 }
					                 catch (UnauthorizedAccessException UAEx)
					                 {
					                 	Console.WriteLine(UAEx.Message);
					                 }
					                 catch (PathTooLongException PathEx)
					                 {
					                 	Console.WriteLine(PathEx.Message);
					                 }

					                 Console.WriteLine("Time used: {0}", stopWatch.Elapsed);
					}
		/// <summary>
		/// Query one specific song using MinHash algorithm.
		/// </summary>
		/// <param name="signatures">Signature signatures from a song</param>
		/// <param name="dbService">DatabaseService used to query the underlying database</param>
		/// <param name="lshHashTables">Number of hash tables from the database</param>
		/// <param name="lshGroupsPerKey">Number of groups per hash table</param>
		/// <param name="thresholdTables">Minimum number of hash tables that must be found for one signature to be considered a candidate (0 = return all candidates, 2+ = return only exact matches)</param>
		/// <param name="queryTime">Set by the method, representing the query length</param>
		/// <param name="doSearchEverything">disregard the local sensitivity hashes and search the whole database</param>
		/// <param name="splashScreen">The "please wait" splash screen (or null)</param>
		/// <returns>Dictionary with Tracks ID's and the Query Statistics</returns>
		public static Dictionary<Int32, QueryStats> QueryOneSongMinHash(
			IEnumerable<bool[]> signatures,
			DatabaseService dbService,
			MinHash minHash,
			int lshHashTables,
			int lshGroupsPerKey,
			int thresholdTables,
			ref long queryTime,
			bool doSearchEverything = false,
			SplashSceenWaitingForm splashScreen = null)
		{
			Stopwatch stopWatch = new Stopwatch();
			stopWatch.Start();
			
			int signatureCounter = 0;
			int signatureTotalCount = signatures.Count();
			Dictionary<int, QueryStats> stats = new Dictionary<int, QueryStats>();
			foreach (bool[] signature in signatures) {
				
				#region Please Wait Splash Screen Cancel Event
				// check if the user clicked cancel
				if (splashScreen.CancellationPending) {
					break;
				}
				#endregion

				if (signature == null) {
					continue;
				}

				IDictionary<int, IList<HashBinMinHash>> candidates = null;
				if (doSearchEverything) {
					candidates = dbService.ReadAllFingerprints();
				} else {
					// Compute Min Hash on randomly selected fingerprint
					int[] bin = minHash.ComputeMinHashSignature(signature);
					
					// Find all hashbuckets to care about
					Dictionary<int, long> hashes = minHash.GroupMinHashToLSHBuckets(bin, lshHashTables, lshGroupsPerKey);
					long[] hashbuckets = hashes.Values.ToArray();
					
					// Find all candidates by querying the database for those hashbuckets
					candidates = dbService.ReadFingerprintsByHashBucketLsh(hashbuckets);
				}
				
				// Reduce the potential candidates list if the number of hash tables found for each signature are less than the threshold
				Dictionary<int, IList<HashBinMinHash>> potentialCandidates = SelectPotentialMatchesOutOfEntireDataset(candidates, thresholdTables);
				
				// get the final candidate list by only using the potential candidate list
				if (potentialCandidates.Count > 0) {
					IList<Fingerprint> fingerprints = dbService.ReadFingerprintById(potentialCandidates.Keys);
					Dictionary<Fingerprint, int> finalCandidates = fingerprints.ToDictionary(finger => finger, finger => potentialCandidates[finger.Id].Count);
					ArrangeCandidatesAccordingToFingerprints(signature,
					                                         finalCandidates,
					                                         lshHashTables,
					                                         lshGroupsPerKey,
					                                         stats);
				}
				
				#region Please Wait Splash Screen Update
				// calculate a percentage between 5 and 90
				int percentage = (int) ((float) (signatureCounter) / (float) signatureTotalCount * 85) + 5;
				if (splashScreen != null) splashScreen.SetProgress(percentage, String.Format("Searching for similar fingerprints.\n(Signature {0} of {1})", signatureCounter+1, signatureTotalCount));
				signatureCounter++;
				#endregion Updat
			}

			stopWatch.Stop();
			queryTime = stopWatch.ElapsedMilliseconds; /*Set the query Time parameter*/
			return stats;
		}
		public FindSimilarClientForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// Constructor code after the InitializeComponent() call.
			//
			this.version.Text = Mirage.Mir.VERSION;
			this.DistanceTypeCombo.DataSource = Enum.GetValues(typeof(AudioFeature.DistanceType));
			this.ThresholdTablesCombo.DataSource = Enum.GetValues(typeof(ThresholdTables));
			
			// Instansiate SCMS or Mandel Ellis Repository
			this.db = new Db();
			
			// Instansiate Soundfingerprinting Repository
			FingerprintService fingerprintService = Analyzer.GetSoundfingerprintingService();
			this.databaseService = DatabaseService.Instance;

			IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms.csv", ",");
			//IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms-new.csv", ",");
			
			repository = new Repository(permutations, databaseService, fingerprintService);
			
			if (rbScms.Checked) {
				IgnoreFileLengthCheckBox.Visible = true;
				DistanceTypeCombo.Visible = true;
				LessAccurateCheckBox.Visible = false;
				ThresholdTablesCombo.Visible = false;
				SearchAllFilesCheckbox.Visible = false;
			} else {
				IgnoreFileLengthCheckBox.Visible = false;
				DistanceTypeCombo.Visible = false;
				LessAccurateCheckBox.Visible = true;
				ThresholdTablesCombo.Visible = true;
				SearchAllFilesCheckbox.Visible = true;
			}
			
			ReadAllTracks();
		}