public void StaticStrideClassTest() { const int Value = 5115; StaticStride stride = new StaticStride(Value); Assert.AreEqual(Value, stride.NextStride); }
public void CutLogarithmizedSpectrumWithSpectrumWhichIsLessThanMinimalLengthOfOneFingerprintTest() { var stride = new StaticStride(0, 0); var config = new DefaultSpectrogramConfig { Stride = stride }; int logSpectrumLength = config.ImageLength - 1; var logSpectrum = GetLogSpectrum(logSpectrumLength); var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, config); Assert.AreEqual(0, cutLogarithmizedSpectrum.Count); }
public void CutLogarithmizedSpectrumOfJustOneFingerprintTest() { var stride = new StaticStride(0, 0); var configuration = new DefaultSpectrogramConfig { Stride = stride }; int logSpectrumLength = configuration.ImageLength; // 128 var logSpectrum = GetLogSpectrum(logSpectrumLength); var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, configuration); Assert.AreEqual(1, cutLogarithmizedSpectrum.Count); }
public void CutLogarithmizedSpectrumWithSpectrumWhichIsLessThanMinimalLengthOfOneFingerprintTest() { DefaultFingerprintConfiguration config = new DefaultFingerprintConfiguration(); int logSpectrumLength = config.FingerprintLength - 1; var stride = new StaticStride(0, 0); var logSpectrum = new float[logSpectrumLength][]; for (int i = 0; i < logSpectrumLength; i++) { logSpectrum[i] = new float[32]; } var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, stride, config.FingerprintLength, config.Overlap); Assert.AreEqual(0, cutLogarithmizedSpectrum.Count); }
public void CutLogarithmizedSpectrumTest() { DefaultFingerprintConfiguration config = new DefaultFingerprintConfiguration(); const int LogSpectrumLength = 1024; var stride = new StaticStride(0, 0); var logSpectrum = new float[LogSpectrumLength][]; for (int i = 0; i < LogSpectrumLength; i++) { logSpectrum[i] = new float[32]; } var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, stride, config.FingerprintLength, config.Overlap); Assert.AreEqual(8, cutLogarithmizedSpectrum.Count); }
public ShortSamplesSpectrogramConfig() { // 11,6 ms is 64/5512 or 512/44100 or 372/32000 // The closest power of 2 in 2's complement format: // 1024 / 32000 = 32 ms // 512 / 32000 = 16 ms // 256 / 32000 = 8 ms Overlap = 1024; // Original 64 // 371 ms is 2048/5512 or 16384/44100 or 11889/32000 // The closest power of 2 in 2's complement format: // 8192 / 32000 = 256 ms // 4096 / 32000 = 128 ms // 2048 / 32000 = 64 ms // Due to using this on many small samples, we need to reduce the window and overlap sizes // A transient is around 50 ms WdftSize = 2048; // 4096; // Original 2048 FrequencyRange = new FrequencyRange(40, 16000); // Original FrequencyRange(318, 2000); LogBase = System.Math.E; // Original 2 LogBins = 32; ImageLength = 128; // Original 128 // calculate samples per fingerprint //int samplesPerFingerprint = ImageLength * Overlap; UseDynamicLogBase = false; // Original true // 0,928 sec is 5115 / 5512 or 40924 / 44100 or 29695/32000 //Stride = new IncrementalStaticStride(29695, 0, samplesPerFingerprint); // Original IncrementalStaticStride(512); // a static stride of 0 means no gaps between consecutive images (fingerprints) Stride = new StaticStride(0); // Original IncrementalStaticStride(512); Window = new HanningWindow(); ScalingFunction = (value, max) => { float scaled = System.Math.Min(value / max, 1); int domain = 255; float c = (float)(1 / System.Math.Log(1 + domain)); return((float)(c * System.Math.Log(1 + scaled * domain))); }; }
public void CutLogarithmizedSpectrumTest() { var stride = new StaticStride(0, 0); var configuration = new CustomSpectrogramConfig { Stride = stride }; const int LogSpectrumLength = 1024; var logSpectrum = GetLogSpectrum(LogSpectrumLength); var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, configuration); Assert.AreEqual(8, cutLogarithmizedSpectrum.Count); double lengthOfOneFingerprint = (double)configuration.ImageLength * configuration.Overlap / SampleRate; for (int i = 0; i < cutLogarithmizedSpectrum.Count; i++) { Assert.IsTrue( System.Math.Abs(cutLogarithmizedSpectrum[i].Timestamp - (i * lengthOfOneFingerprint)) < Epsilon); } }
public void CustomValuesAreSetOnFingerprintConfiguration() { var staticStride = new StaticStride(2048); var customConfiguration = new CustomFingerprintConfiguration { FingerprintLength = 256, LogBase = 4, LogBins = 46, MaxFrequency = 22050, MinFrequency = 5512, NormalizeSignal = true, NumberOfLSHTables = 30, NumberOfMinHashesPerTable = 4, Overlap = 32, SampleRate = 10024, Stride = staticStride, TopWavelets = 250, UseDynamicLogBase = true, WdftSize = 4048 }; Assert.AreEqual(256, customConfiguration.FingerprintLength); Assert.AreEqual(4, customConfiguration.LogBase); Assert.AreEqual(46, customConfiguration.LogBins); Assert.AreEqual(22050, customConfiguration.MaxFrequency); Assert.AreEqual(5512, customConfiguration.MinFrequency); Assert.IsTrue(customConfiguration.NormalizeSignal); Assert.AreEqual(30, customConfiguration.NumberOfLSHTables); Assert.AreEqual(4, customConfiguration.NumberOfMinHashesPerTable); Assert.AreEqual(32, customConfiguration.Overlap); Assert.AreEqual(10024, customConfiguration.SampleRate); Assert.AreEqual(staticStride, customConfiguration.Stride); Assert.AreEqual(250, customConfiguration.TopWavelets); Assert.IsTrue(customConfiguration.UseDynamicLogBase); Assert.AreEqual(4048, customConfiguration.WdftSize); }
/// <summary> /// Draw the fingerprints of an audio file /// </summary> private void BtnDrawFingerprintsClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(_tbPathToFile.Text)) { MessageBox.Show(Resources.SelectAPathToBeDrawn, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text))) { MessageBox.Show(Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (_lbImageTypes.SelectedIndex == 0) { string fileName = Path.GetFileNameWithoutExtension(_tbPathToFile.Text); SaveFileDialog sfd = new SaveFileDialog { FileName = fileName + "_fingerprints_" + ".jpg", Filter = Resources.FileFilterJPeg }; if (sfd.ShowDialog() == DialogResult.OK) { string path = Path.GetFullPath(sfd.FileName); FadeControls(false); Action action = () => { using (IAudio proxy = new BassProxy()) { FingerprintManager manager = new FingerprintManager(); StaticStride stride = new StaticStride((int) _nudStride.Value); int totalFingerprints = 0; List<bool[]> fingerprints = manager.CreateFingerprints(proxy, Path.GetFullPath(_tbPathToFile.Text), stride); int width = manager.FingerprintLength; int height = manager.LogBins; Bitmap image = Imaging.GetFingerprintsImage(fingerprints, width, height); image.Save(path); image.Dispose(); } }; action.BeginInvoke((result) => { FadeControls(true); MessageBox.Show(Resources.ImageIsDrawn, Resources.Finished, MessageBoxButtons.OK, MessageBoxIcon.Information); action.EndInvoke(result); }, action); } } else if (_lbImageTypes.SelectedIndex == 1) { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { string path = fbd.SelectedPath; string fileName = Path.GetFileName(_tbPathToFile.Text); FadeControls(false); Action action = () => { using (IAudio proxy = new BassProxy()) { FingerprintManager manager = new FingerprintManager(); StaticStride stride = new StaticStride((int) _nudStride.Value); List<bool[]> result = manager.CreateFingerprints(proxy, Path.GetFullPath(_tbPathToFile.Text), stride); int i = -1; int width = manager.FingerprintLength; int height = manager.LogBins; foreach (bool[] item in result) { Image image = Imaging.GetFingerprintImage(item, width, height); image.Save(path + "\\" + fileName + i++ + ".jpg", ImageFormat.Jpeg); } } }; action.BeginInvoke((result) => { FadeControls(true); MessageBox.Show(Resources.ImageIsDrawn, Resources.Finished, MessageBoxButtons.OK, MessageBoxIcon.Information); action.EndInvoke(result); } , action); } } }
/// <summary> /// Draw wavelets /// </summary> private void BtnDrawWaveletsClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(_tbPathToFile.Text)) { MessageBox.Show(Resources.SelectAPathToBeDrawn, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text))) { MessageBox.Show(Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string fileName = Path.GetFileNameWithoutExtension(_tbPathToFile.Text); SaveFileDialog sfd = new SaveFileDialog { FileName = fileName + ".jpg", Filter = Resources.FileFilterJPeg }; if (sfd.ShowDialog() == DialogResult.OK) { string path = Path.GetFullPath(sfd.FileName); FadeControls(false); Action action = () => { using (IAudio proxy = new BassProxy()) { FingerprintManager manager = new FingerprintManager(); StaticStride stride = new StaticStride((int) _nudStride.Value); Image image = Imaging.GetWaveletSpectralImage(Path.GetFullPath(_tbPathToFile.Text), stride, proxy, manager); image.Save(path); image.Dispose(); } }; action.BeginInvoke((result) => { FadeControls(true); MessageBox.Show(Resources.ImageIsDrawn, Resources.Finished, MessageBoxButtons.OK, MessageBoxIcon.Information); action.EndInvoke(result); }, action); } }
/// <summary> /// Dump information into file /// </summary> private void BtnDumpInfoClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(_tbPathToFile.Text)) { MessageBox.Show(Resources.ErrorNoFileToAnalyze, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (String.IsNullOrEmpty(_tbOutputPath.Text)) { MessageBox.Show(Resources.SelectPathToDump, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text))) { MessageBox.Show(Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (_chbCompare.Checked) { if (String.IsNullOrEmpty(_tbSongToCompare.Text)) { MessageBox.Show(Resources.ErrorNoFileToAnalyze, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } Action action = () => { using (BassProxy proxy = new BassProxy()) { FadeControls(false); int minFreq = (int) _nudFreq.Value; int topWavelets = (int) _nudTopWavelets.Value; int stride = (int) _nudStride.Value; IStride objStride = (_chbStride.Checked) ? (IStride) new RandomStride(0, stride) : new StaticStride(stride); FingerprintManager manager = new FingerprintManager {MinFrequency = minFreq, TopWavelets = topWavelets}; DumpResults resultObj = new DumpResults(); string pathToInput = _tbPathToFile.Text; string pathToOutput = _tbOutputPath.Text; int hashTables = (int) _nudTables.Value; int hashKeys = (int) _nudKeys.Value; stride = (int) _nudQueryStride.Value; int numFingerprints = (int) _nudNumberOfSubsequent.Value; IStride queryStride = (_chbQueryStride.Checked) ? (IStride) new RandomStride(0, stride) : new StaticStride(stride); queryStride = new StaticStride(5115, 5115/2); GetFingerprintSimilarity(manager, objStride, queryStride, numFingerprints, proxy, pathToInput, resultObj); GetHashSimilarity(manager, objStride, queryStride, numFingerprints, hashTables, hashKeys, proxy, pathToInput, resultObj); if (_chbCompare.Checked) { string pathToDifferent = _tbSongToCompare.Text; GetFingerprintSimilarity(manager, objStride, proxy, pathToInput, pathToDifferent, resultObj); } resultObj.Info.MinFrequency = minFreq; resultObj.Info.TopWavelets = topWavelets; resultObj.Info.StrideSize = stride; resultObj.Info.RandomStride = _chbStride.Checked; resultObj.Info.Filename = pathToInput; resultObj.ComparisonDone = _chbCompare.Checked; XmlSerializer serializer = new XmlSerializer(typeof (DumpResults)); TextWriter writer = new StreamWriter(pathToOutput); serializer.Serialize(writer, resultObj); writer.Close(); } }; action.BeginInvoke( (result) => { action.EndInvoke(result); FadeControls(true); }, null); }
static void Process(Files.File file) { var audio = new Files.AudioFile { ID = file.ID, ContentType = file.ContentType, Name = file.Name, Size = file.Size, Url = file.Url, FullPath = file.FullPath }; audio.AlterPath = file.FullPath.ToLower().Replace("mp3", "wav"); var proxy = new BassProxy(); if (!File.Exists(audio.AlterPath)) proxy.RecodeTheFile(file.FullPath, audio.AlterPath, 5512); FingerprintManager manager = new FingerprintManager(); manager.FingerprintLength = Length; manager.TopWavelets = 150; manager.MaxFrequency = 2048; manager.MinFrequency = 512; //float[][] spec = manager.CreateSpectrogram(proxy, audio.AlterPath, 0, 0); var StaticStride = new StaticStride(0); audio.Finger = manager.CreateFingerprints(proxy, audio.AlterPath, StaticStride).ToArray(); FileProvider.Save(audio); }