Exemplo n.º 1
0
        public static void TestRandom(string dataBaseFile, string file, string correctName)
        {
            DataBase dataBase = new DataBase(new LongHash());
            dataBase.Load(dataBaseFile);

            dataBase.RandomQuerySigleFile(file, 40, correctName);
        }
Exemplo n.º 2
0
        public static void Test(string dataBaseFile, string file, string correctName)
        {
            DataBase dataBase = new DataBase(new LongHash());
            dataBase.Load(dataBaseFile);

            //dataBase.QuestSigleFile(file, 500, 10, 0, correctName);
            dataBase.QuestRandomSigleFile(file, 500, 10, 4, correctName);
        }
Exemplo n.º 3
0
        static void AppendData(string indexFile, IHashMaker hashMaker, string dataFolder)
        {
            if (!Directory.Exists(dataFolder))
            {
                WriteLog(string.Format("'{0}' doesn't exist! ", dataFolder));
                return;
            }

            if (!File.Exists(indexFile))
            {
                WriteLog(string.Format("'{0}' file doesn't exist! ", indexFile));
                return;
            }

            DataBase dataBase = new DataBase(hashMaker);
            dataBase.CheckDuplicate = true;
            dataBase.Load(indexFile);
            dataBase.BuildDataBase(dataFolder);
            dataBase.Save(indexFile);
        }
Exemplo n.º 4
0
 public static void ConvertIndexFileFromTextToBinary(string textFile, string binaryFile, IHashMaker hashMaker)
 {
     DataBase dataBase = new DataBase(hashMaker);
     dataBase.Load(textFile);
     dataBase.SaveInBinary(binaryFile);
 }
Exemplo n.º 5
0
        public static void SimpleTest(string indexFile, IHashMaker hashMaker, bool bQuiet)
        {
            bool bTextFile = IsTextFile(indexFile);
            DataBase dataBase = new DataBase(hashMaker);
            if (bTextFile)
                dataBase.Load(indexFile);
            else
                dataBase.LoadFromBinary(indexFile);
            dataBase.Quiet = bQuiet;
            int seconds = 10;

            while (true)
            {
                Console.WriteLine("Press any key to identify a new song, press ESC to exit.\n");
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Escape)
                    break;

                byte[] audio = null;
                Console.WriteLine("Start recording audio from mic ...", seconds);
                MicRecorder recorder = new MicRecorder();
                recorder.Seconds = seconds;
                recorder.RequestStop = false;
                recorder.RecStart();

                audio = recorder.GetAudioData();
                dataBase.UseFFTW = false;
                Indexing(dataBase, audio);
                dataBase.UseFFTW = true;
                Indexing(dataBase, audio);
                dataBase.UseSort = true;
                Indexing(dataBase, audio);

                //dataBase.UseFilter = true;
                //timeInterval.Reset();
                //id = dataBase.GetBestHit(audio, 16);
                //intervalInSecond = timeInterval.GetDurationInSecond();

                //Console.WriteLine("--------------------");
                //Console.Write("Final Match ({0}s):\t", intervalInSecond);
                //if (id < 0)
                //    Console.WriteLine("No match!");
                //else
                //    Console.WriteLine(dataBase.GetNameByID(id));
                //Console.WriteLine("--------------------");
            }
        }
Exemplo n.º 6
0
        public static void Test(string dataFolder, string dataBaseFile)
        {
            DataBase dataBase = new DataBase(new LongHash());
            dataBase.Load(dataBaseFile);

            FileInfo[] fileInfoArray = Utility.GetFiles(dataFolder, "*.wav");
            if(fileInfoArray.Length <= 0)
            {
                Console.WriteLine("No wav file found.");
                return;
            }

            int[] startIndices = new int[TEST_COUNT];
            int length = Mp3ToWavConverter.ReadBytesFromWav(fileInfoArray[0].FullName).Length;
            //Console.Write("\t");
            for(int i = 0; i < TEST_COUNT; i++)
            {
                startIndices[i] = GetRandomStartIndex(length);
                Console.Write("\t{0}", startIndices[i]);
            }
            Console.WriteLine();

            foreach (FileInfo fileInfo in fileInfoArray)
            {
                Console.Write(fileInfo.Name);
                TestSingleFile(fileInfo.FullName, startIndices, dataBase);
                Console.WriteLine();
            }
        }
Exemplo n.º 7
0
        public static void SimpleTest(string dataBaseFile)
        {
            DataBase dataBase = new DataBase(new LongHash());
            dataBase.Load(dataBaseFile);

            int seconds = 10;
            while (true)
            {
                Console.WriteLine("Press any key to identify a new song, press ESC to exit.\n");
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Escape)
                    break;

                byte[] audio = null;

                Console.WriteLine("Start recording audio from mic ...", seconds);
                MicRecorder recorder = new MicRecorder();
                recorder.Seconds = seconds;
                recorder.RequestStop = false;
                recorder.RecStart();

                audio = recorder.GetAudioData();
                Console.WriteLine("Length of audio data is {0}.", audio.Length);

                int id = GetBestHit(audio, dataBase, 16);
                Console.WriteLine("[Normal] The name of this song is : {0}", dataBase.GetNameByID(id));

                int peakPercent = 95;
                double normPercent = 1.0;
                sbyte minPeak;
                sbyte maxPeak;
                sbyte peak;
                double ratio = 1.0;

                Normalize.getPeaks8(audio, out minPeak, out maxPeak);
                Console.WriteLine("Normal Peak : {0} {1}", minPeak, maxPeak);

                minPeak *= -1;
                peak = (minPeak > maxPeak) ? minPeak : maxPeak;

                ratio = 127.0 / peak * normPercent;
                Console.WriteLine("Ratio : {0}", ratio);
                byte[] newData = Normalize.Amplify(audio, ratio);

                id = GetBestHit(newData, dataBase, 16);
                Console.WriteLine("[Normal Peak] The name of this song is : {0}", dataBase.GetNameByID(id));

                if (!Normalize.getSmartPeaks8(audio, peakPercent, out minPeak, out maxPeak))
                    Console.WriteLine("Error in Normalize.getSmartPeaks8");
                else
                {
                    Console.WriteLine("Smart Peak : {0} {1}", minPeak, maxPeak);
                    minPeak *= -1;
                    peak = (minPeak > maxPeak) ? minPeak : maxPeak;

                    ratio = 127.0 / peak * normPercent;
                    Console.WriteLine("Ratio : {0}", ratio);
                    newData = Normalize.Amplify(audio, ratio);

                    Normalize.getPeaks8(newData, out minPeak, out maxPeak);
                    Console.WriteLine("Normal Peak After Amplify : {0} {1}", minPeak, maxPeak);

                    id = GetBestHit(newData, dataBase, 16);
                    Console.WriteLine("[Smart Peak] The name of this song is : {0}", dataBase.GetNameByID(id));
                }

            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                PrintUsage();
                return;
            }
            else
            {
                string firstArg = args[0].ToLower();
                string secondArg = args[1];
                if (firstArg.CompareTo("build") == 0)
                {
                    if (args.Length < 3)
                    {
                        WriteLog("Not enough parameters!");
                        PrintUsage();
                        return;
                    }
                    string thirdArg = args[2];
                    bool shutDown = false;
                    if (args.Length > 3)
                        shutDown = bool.Parse(args[3]);
                    BuildDataBase(secondArg, new KeyPointHash(), thirdArg, shutDown);
                }
                else if (firstArg.CompareTo("test") == 0)
                {
                    string dataBaseFile = secondArg;
                    DataBase.SimpleTest(dataBaseFile, new KeyPointHash(), true);
                }
                else if (firstArg.CompareTo("convert") == 0)
                {
                    string inputFile = args[1];
                    string outputFile = args[2];
                    DataBase.ConvertIndexFileFromTextToBinary(inputFile, outputFile, new KeyPointHash());
                }
                else if (firstArg.CompareTo("append") == 0)
                {
                    string indexFile = secondArg;
                    string dataFolder = args[2];

                    AppendData(indexFile, new KeyPointHash(), dataFolder);
                }
                else if (firstArg.CompareTo("combine") == 0)
                {
                    if (args.Length < 3)
                    {
                        PrintUsage();
                    }
                    else
                    {
                        string listFile = args[1];
                        string outputFile = args[2];
                        using (StreamReader sr = new StreamReader(listFile, Encoding.GetEncoding("GB2312")))
                        {
                            DataBase finalDataBase = null;

                            while (!sr.EndOfStream)
                            {
                                string indexFile = sr.ReadLine();
                                if (!File.Exists(indexFile))
                                {
                                    Console.WriteLine("File doesn't exist: {0}", indexFile);
                                    continue;
                                }

                                DataBase tmpDataBase = new DataBase(new KeyPointHash());
                                tmpDataBase.Load(indexFile);
                                if (finalDataBase == null)
                                    finalDataBase = tmpDataBase;
                                else
                                {
                                    Console.WriteLine("Combining...");
                                    finalDataBase.Combine(tmpDataBase);
                                }
                            }

                            finalDataBase.Save(outputFile);
                        }
                    }
                }
                else
                {
                    PrintUsage();
                }
            }
        }
Exemplo n.º 9
0
        static void RunRecordAutoTest(bool shutDown)
        {
            //DataBase dataBase = new DataBase(new LongHash());
            //dataBase.Load(@"D:\Music\Avatar\DataBase.txt");
            DataBase dataBase = new DataBase(new KeyPointHash());
            dataBase.Load(@"D:\Music\DataBase.txt");
            dataBase.Quiet = true;

            AutoTest.TEST_COUNT = 10;
            AutoTest.SHIFT_COUNT = 64;
            //AutoTest.Test(@"D:\Music\李建.-.[音乐傲骨].专辑.(MP3)\", "*.wav", @"D:\Music\李建.-.[音乐傲骨].专辑.(MP3)\FileIndex_4_8_keyPoint.txt", dataBase);
            AutoTest.AnalyseFailure(@"D:\Music\李建.-.[音乐傲骨].专辑.(MP3)\", "*.wav", @"D:\Music\李建.-.[音乐傲骨].专辑.(MP3)\FileIndex_4_8_keyPoint.txt", dataBase);
            if (shutDown)
                Utility.ShutDown();
        }
Exemplo n.º 10
0
        static void RunAutoTest(bool shutDown)
        {
            //DataBase dataBase = new DataBase(new LongHash());
            DataBase dataBase = new DataBase(new KeyPointHash());
            dataBase.Load(@"d:\Music\DataBase.txt");
            dataBase.Quiet = true;

            AutoTest.Test(@"D:\Music\", ".mp3", @"D:\Music\Avatar\FileIndex_3_26_keyPoint.txt", dataBase);
            if (shutDown)
                Utility.ShutDown();
        }