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);
			}
		}
Esempio n. 2
0
        private static void TestSoundfingerprintingAlgorithm(string filename, string name)
        {
            // work config
            WorkUnitParameterObject param = new WorkUnitParameterObject();
            param.PathToAudioFile = filename;
            param.StartAtMilliseconds = 0;
            param.MillisecondsToProcess = 0;
            param.FingerprintingConfiguration = fingerprintingConfig;

            // Soundfingerprinting Service
            FingerprintService fingerprintService = GetSoundfingerprintingService();

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

            // Configuration
            AudioServiceConfiguration audioServiceConfiguration = new AudioServiceConfiguration
            {
                LogBins = fingerprintingConfig.LogBins,
                LogBase = fingerprintingConfig.LogBase,
                MaxFrequency = fingerprintingConfig.MaxFrequency,
                MinFrequency = fingerprintingConfig.MinFrequency,
                Overlap = fingerprintingConfig.Overlap,
                SampleRate = fingerprintingConfig.SampleRate,
                WdftSize = fingerprintingConfig.WdftSize,
                NormalizeSignal = fingerprintingConfig.NormalizeSignal,
                UseDynamicLogBase = fingerprintingConfig.UseDynamicLogBase
            };

            double[][] spectrogram = fingerprintService.AudioService.CreateSpectrogram(filename, new Mirage.HannWindow(fingerprintingConfig.WdftSize), fingerprintingConfig.SampleRate, fingerprintingConfig.Overlap, fingerprintingConfig.WdftSize);
            imageService.GetSpectrogramImage(spectrogram, 600, 400).Save("imageservice_" + name + "_specgram.png");

            /*
            Comirva.Audio.Util.Maths.Matrix stftdata = new Comirva.Audio.Util.Maths.Matrix(spectrogram).Transpose();
            #if DEBUG
            if (Analyzer.DEBUG_INFO_VERBOSE) {
                if (DEBUG_OUTPUT_TEXT) {
                    stftdata.WriteAscii(name + "_stftdata2.ascii");
                    stftdata.WriteCSV(name + "_stftdata2.csv", ";");
                }

                // same as specgram(audio*32768, 2048, 44100, hanning(2048), 1024);
                stftdata.DrawMatrixImageLogValues(name + "_specgram2.png", true);

                // spec gram with log values for the y axis (frequency)
                stftdata.DrawMatrixImageLogY(name + "_specgramlog2.png", SAMPLING_RATE, 20, SAMPLING_RATE/2, 120, WINDOW_SIZE);
            }
            #endif
             */

            double[][] logSpectrogram = fingerprintService.AudioService.CreateLogSpectrogram(filename, new Mirage.HannWindow(fingerprintingConfig.WdftSize), audioServiceConfiguration);
            imageService.GetLogSpectralImages(logSpectrogram, fingerprintingConfig.Stride, fingerprintingConfig.FingerprintLength, fingerprintingConfig.Overlap, 2).Save("imageservice_" + name + "_specgram_logimages.png");

            Comirva.Audio.Util.Maths.Matrix stftdataLog = new Comirva.Audio.Util.Maths.Matrix(logSpectrogram).Transpose();
            #if DEBUG
            if (Analyzer.DEBUG_INFO_VERBOSE) {
                if (DEBUG_OUTPUT_TEXT) {
                    stftdataLog.WriteAscii(name + "_stftdataLog.ascii");
                    stftdataLog.WriteCSV(name + "_stftdataLog.csv", ";");
                }

                // same as specgram(audio*32768, 2048, 44100, hanning(2048), 1024);
                stftdataLog.DrawMatrixImageLogValues(name + "_stftdataLog.png", true);
            }
            #endif

            // Get fingerprints
            double[][] LogSpectrogram;
            List<bool[]> fingerprints = fingerprintService.CreateFingerprintsFromAudioFile(param, out LogSpectrogram);
            int width = fingerprintingConfig.FingerprintLength;
            int height = fingerprintingConfig.LogBins;
            imageService.GetImageForFingerprints(fingerprints, width, height, 2).Save("imageservice_" + name + "_fingerprints.png");

            /*
            IPermutations permutations = new LocalPermutations("Soundfingerprinting\\perms.csv", ",");
            Soundfingerprinting.DuplicatesDetector.DataAccess.Repository repository = new Soundfingerprinting.DuplicatesDetector.DataAccess.Repository(permutations);

            // Define track
            Soundfingerprinting.DuplicatesDetector.Model.Track track
                = new Soundfingerprinting.DuplicatesDetector.Model.Track {
                Title = name,
                Path = filename
            };

            // Get the HashSignatures
            List<Soundfingerprinting.DuplicatesDetector.Model.HashSignature> signatures = repository.GetSignatures(fingerprints, track, 25, 4);
            return signatures;
             */
        }
Esempio n. 3
0
		public static void SaveFingerprintingDebugImages(string fileName, double[][] logSpectrogram, List<bool[]> fingerprints, FingerprintService fingerprintService, IFingerprintingConfiguration fingerprintConfig) {
			
			ImageService imageService = new ImageService(fingerprintService.SpectrumService, fingerprintService.WaveletService);
			
			int fingerprintsPerRow = 2;
			imageService.GetSpectrogramImage(logSpectrogram, logSpectrogram.Length, logSpectrogram[0].Length).Save(fileName + "_spectrogram.png");
			imageService.GetWaveletsImages(logSpectrogram, fingerprintConfig.Stride, fingerprintConfig.FingerprintLength, fingerprintConfig.Overlap, fingerprintsPerRow).Save(fileName + "_wavelets.png");
			imageService.GetLogSpectralImages(logSpectrogram, fingerprintConfig.Stride, fingerprintConfig.FingerprintLength, fingerprintConfig.Overlap, fingerprintsPerRow).Save(fileName + "_spectrograms.png");
			imageService.GetImageForFingerprints(fingerprints, fingerprintConfig.FingerprintLength, fingerprintConfig.LogBins, fingerprintsPerRow).Save(fileName + "_fingerprints.png");
		}