/// <summary>
        ///   Draw the spectrogram of the audio file
        /// </summary>
        private void BtnDrawSpectrumClick(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;
            }

            SaveFileDialog sfd = new SaveFileDialog
                                 {
                                     Filter = Resources.FileFilterJPeg,
                                     FileName = Path.GetFileNameWithoutExtension(_tbPathToFile.Text) + "_spectrum_" + ".jpg"
                                 };
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                FadeControls(false);
                Action action = () =>
                                {
                                    using (BassProxy proxy = new BassProxy())
                                    {
                                        FingerprintManager manager = new FingerprintManager();
                                        float[][] data = manager.CreateSpectrogram(proxy, Path.GetFullPath(_tbPathToFile.Text), 0, 0);
                                        double duration = proxy.GetTagInfoFromFile(Path.GetFullPath(_tbPathToFile.Text)).duration;
                                        Bitmap image = Imaging.GetSpectrogramImage(data, (int) _nudWidth.Value, (int) _nudHeight.Value);
                                        image.Save(sfd.FileName, ImageFormat.Jpeg);
                                        image.Dispose();
                                    }
                                };

                action.BeginInvoke(((result) =>
                                    {
                                        FadeControls(true);
                                        action.EndInvoke(result);
                                        MessageBox.Show(Resources.ImageIsDrawn, Resources.Finished, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }), null);
            }
        }
Exemple #2
0
        static void Process(string path)
        {
            Console.WriteLine(path);
            var proxy = new BassProxy();
            proxy.RecodeTheFile(path + ".mp3",  path + ".wav", 5512);
            var data = File.CreateText(path + ".txt");

            FingerprintManager manager = new FingerprintManager();
            manager.FingerprintLength = Length;
            manager.TopWavelets = 150;
            manager.MaxFrequency = 2048;
            manager.MinFrequency = 512;
            float[][] spec = manager.CreateSpectrogram(proxy, path + ".wav", 0, 0);

            var StaticStride = ( path == "7" ) ?  new StaticStride(Milliseconds) : new StaticStride(0);

            var fingerprint = manager.CreateFingerprints(proxy, path + ".wav", StaticStride);
            if (path == "4") { sfinger = fingerprint; }

            foreach (var finger in fingerprint)
            {
                int[] bits = finger.Select(f => f ? 1 : 0).ToArray();
                data.WriteLine(string.Join(";", bits));
            }
            data.Close();

            if(File.Exists( path + ".jpg") )
                File.Delete(path + ".jpg");
            if (spec.Length > 0)
            {
                Bitmap image = Imaging.GetSpectrogramImage(spec, 800, 600);
                image.Save(path + ".jpg", ImageFormat.Jpeg);
            }
            

            if (path == "7")
            {
                var hasMin = new MinHash(new LocalPermutations("2.txt", ";"));
                var result = File.CreateText("r.txt");
                
                Dictionary<int, int> count = new Dictionary<int, int>();

                foreach (var finger in sfinger)
                {
                    //var t = fingerprint.Select(p => MinHash.CalculateSimilarity(finger, p)).OrderByDescending(p => p).ToArray();
                    //var t = fingerprint.Select(p => MinHash.CalculateHammingDistance (finger, p)).OrderByDescending(p => p).ToArray();
                    //var t = sfinger.Select(p => MinHash.CalculateSimilarity(finger, p)).OrderByDescending(p => p).ToArray();

                    for (int i = 0; i < fingerprint.Count; i++)
                    {
                        var similarity = MinHash.CalculateSimilarity(finger, fingerprint[i]);
                        if (similarity > 0.5f)
                        {
                            if (!count.ContainsKey(i))
                                count.Add(i, 0);
                            count[i]++;
                            result.Write("{1}:{0};", similarity.ToString("#.000"), i, i * 11.6f * Block, (i + 1) * 11.6f * Block);
                        }
                    }
                    result.WriteLine();
                }
                foreach (var c in count.OrderByDescending(p => p.Value))
                    result.Write("{0}:{1};", c.Key, c.Value);

                result.WriteLine("-------------------");
                foreach (var c in count.OrderBy(p => p.Key))
                    result.WriteLine("{0}:{1} Time: {2} ms;", c.Key, c.Value, c.Key * 11.6f * Block);

                result.Close();
            }
        }