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(); }
public static void Main(string[] args) { Analyzer.AnalysisMethod analysisMethod = Analyzer.AnalysisMethod.SCMS; //Analyzer.AnalysisMethod analysisMethod = Analyzer.AnalysisMethod.MandelEllis; string scanPath = ""; double skipDurationAboveSeconds = -1; // less than zero disables this string queryPath = ""; int queryId = -1; int numToTake = 20; double percentage = 0.4; // percentage below and above when querying bool resetdb = false; bool silent = false; AudioFeature.DistanceType distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence; // Command line parsing Arguments CommandLine = new Arguments(args); if(CommandLine["match"] != null) { queryPath = CommandLine["match"]; } if(CommandLine["matchid"] != null) { string matchId = CommandLine["matchid"]; queryId = int.Parse(matchId); } if(CommandLine["scandir"] != null) { scanPath = CommandLine["scandir"]; } if(CommandLine["skipduration"] != null) { double.TryParse(CommandLine["skipduration"], NumberStyles.Number,CultureInfo.InvariantCulture, out skipDurationAboveSeconds); } if(CommandLine["num"] != null) { string num = CommandLine["num"]; numToTake = int.Parse(num); } if(CommandLine["percentage"] != null) { double.TryParse(CommandLine["percentage"], NumberStyles.Number,CultureInfo.InvariantCulture, out percentage); } if(CommandLine["type"] != null) { string type = CommandLine["type"]; if (type.Equals("kl", StringComparison.InvariantCultureIgnoreCase)) { distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence; } else if (type.StartsWith("dtw", StringComparison.InvariantCultureIgnoreCase)) { if (type.Equals("dtwe", StringComparison.InvariantCultureIgnoreCase)) { distanceType = AudioFeature.DistanceType.Dtw_Euclidean; } else if (type.Equals("dtwe2", StringComparison.InvariantCultureIgnoreCase)) { distanceType = AudioFeature.DistanceType.Dtw_SquaredEuclidean; } else if (type.Equals("dtwman", StringComparison.InvariantCultureIgnoreCase)) { distanceType = AudioFeature.DistanceType.Dtw_Manhattan; } else if (type.Equals("dtwmax", StringComparison.InvariantCultureIgnoreCase)) { distanceType = AudioFeature.DistanceType.Dtw_Maximum; } else if (type.Equals("ucrdtw", StringComparison.InvariantCultureIgnoreCase)) { distanceType = AudioFeature.DistanceType.UCR_Dtw; } else { distanceType = AudioFeature.DistanceType.Dtw_Euclidean; } } } if(CommandLine["dtw"] != null || CommandLine["dtwe"] != null) { distanceType = AudioFeature.DistanceType.Dtw_Euclidean; } if(CommandLine["dtwe2"] != null) { distanceType = AudioFeature.DistanceType.Dtw_SquaredEuclidean; } if(CommandLine["dtwman"] != null) { distanceType = AudioFeature.DistanceType.Dtw_Manhattan; } if(CommandLine["dtwmax"] != null) { distanceType = AudioFeature.DistanceType.Dtw_Maximum; } if(CommandLine["kl"] != null) { distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence; } if(CommandLine["ucrdtw"] != null) { distanceType = AudioFeature.DistanceType.UCR_Dtw; } if(CommandLine["resetdb"] != null) { resetdb = true; } if(CommandLine["silent"] != null) { silent = true; } if(CommandLine["permutations"] != null) { Console.WriteLine("Generating hash permutations for used by the Soundfingerprinting methods."); Console.WriteLine("Saving to file: {0}", "Soundfingerprinting\\perms-new.csv"); Console.WriteLine(); PermutationGeneratorService permutationGeneratorService = new PermutationGeneratorService(); Analyzer.GenerateAndSavePermutations(permutationGeneratorService, "Soundfingerprinting\\perms-new.csv"); return; } if(CommandLine["?"] != null) { PrintUsage(); return; } if(CommandLine["help"] != null) { PrintUsage(); return; } if(CommandLine["gui"] != null) { StartGUI(); return; } if (queryPath == "" && queryId == -1 && scanPath == "") { PrintUsage(); return; } // Get database Db mandelEllisScmsDatabase = new Db(); // For MandelEllis and SCMS // Instansiate soundfingerprinting Repository FingerprintService fingerprintService = Analyzer.GetSoundfingerprintingService(); DatabaseService databaseService = DatabaseService.Instance; // For AudioFingerprinting IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms.csv", ","); //IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms-new.csv", ","); Repository repository = new Repository(permutations, databaseService, fingerprintService); if (scanPath != "") { if (IOUtils.IsDirectory(scanPath)) { if (resetdb) { // For MandelEllis and Scms mandelEllisScmsDatabase.RemoveTable(); mandelEllisScmsDatabase.AddTable(); // For AudioFingerprinting databaseService.RemoveFingerprintTable(); databaseService.AddFingerprintTable(); databaseService.RemoveHashBinTable(); databaseService.AddHashBinTable(); databaseService.RemoveTrackTable(); databaseService.AddTrackTable(); } Console.WriteLine("FindSimilar. Version {0}.", VERSION); ScanDirectory(scanPath, mandelEllisScmsDatabase, repository, skipDurationAboveSeconds, silent); } else { Console.Out.WriteLine("No directory found {0}!", scanPath); } } if (queryPath != "") { FileInfo fi = new FileInfo(queryPath); if (fi.Exists) { FindSimilar(queryPath, mandelEllisScmsDatabase, analysisMethod, numToTake, percentage, distanceType); } else { Console.Out.WriteLine("No file found {0}!", queryPath); } } if (queryId != -1) { FindSimilar(new int[] { queryId }, mandelEllisScmsDatabase, analysisMethod, numToTake, percentage, distanceType); } System.Console.ReadLine(); }
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); } }