コード例 #1
0
        private void addSongsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter      = "all files (*.*)|*.*|mp3 files (*.mp3)|*.mp3|wav files (*.wav)|*.wav";
            openFile.Multiselect = true;
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                fingerPrinter = new AudioFingerPrinter();
                wavConverter  = new WavConverter();

                foreach (var file in openFile.FileNames)
                {
                    if (wavConverter.isWav(file))
                    {
                        songs.Add(new Song(Path.GetFileNameWithoutExtension(file), fingerPrinter.determineKeyPoints(wavConverter.convertWavFile(file))));
                    }
                    else
                    {
                        wavConverter.mp3ToWav(file);
                        songs.Add(new Song(Path.GetFileNameWithoutExtension(file), fingerPrinter.determineKeyPoints(wavConverter.convertWavFile(wavConverter.mp3Path))));
                    }
                }
                MessageBox.Show("Songs successfully added!");
            }
        }
コード例 #2
0
        private void recognizeBtn_Click(object sender, EventArgs e)
        {
            if (songs.Count == 0)
            {
                MessageBox.Show("List of songs is empty!");
                return;
            }
            if (microphone == null && songPath == null)
            {
                MessageBox.Show("Please, record song or open it on your disk driver!");
                return;
            }
            matchesGridView.Rows.Clear();
            matchesGridView.Refresh();
            fingerPrinter = new AudioFingerPrinter();

            List <DataPoint> dataCheck;
            WavConverter     converter = new WavConverter();

            if (microphone != null)
            {
                dataCheck = fingerPrinter.determineKeyPoints(converter.convertWavFile(songRecorder.path));
            }
            else
            {
                if (converter.isWav(songPath))
                {
                    var song1 = converter.convertWavFile(songPath);
                    dataCheck = fingerPrinter.determineKeyPoints(converter.convertWavFile(songPath));
                }
                else
                {
                    converter.mp3ToWav(songPath);
                    dataCheck = fingerPrinter.determineKeyPoints(converter.convertWavFile(converter.mp3Path));
                }
            }

            List <Match> matches = findMatches(dataCheck, songs);

            writeMatches(matches);
            microphone         = null;
            songPath           = null;
            songPathField.Text = "";
        }
コード例 #3
0
        public void TestDetermineKeyPoints()
        {
            AudioFingerPrinter audioFingerPrinter = new AudioFingerPrinter();
            WavConverter       converter          = new WavConverter();

            byte[] array = new byte[1024];
            for (int i = 0; i < 1024; i++)
            {
                array[i] = 100;
            }
            List <DataPoint> points = audioFingerPrinter.determineKeyPoints(array);
            long             expect = 800402610;
            long             result = points[0].hash;

            Assert.AreEqual(expect, result);
        }