D:/work/code_by/CbmrEngine/example/cbmrmain.cpp

查看本檔案說明文件.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include "InputStream.h"
00004 #include "WaveFile.h"
00005 #include "pitchlib.h"
00006 #include "SongDb.h"
00007 
00008 int main(int argc, char *argv[])
00009 {
00010   TFileInputStream *IndexStream, *DbStream;
00011   TCipherInputStream *CDbStream;
00012   TSongDb SongDb;
00013   TWaveFile Wave;
00014   float *fpitch;
00015   int *pitch, pitchSize;
00016   int i, from, to;
00017 
00018   if (argc < 2)
00019   {
00020     printf("Usage: cbmr <wav file> [head|any]\n");
00021     return 1;
00022   }
00023 
00024   printf("> Loading wav file...\n");
00025   if (!Wave.Load(argv[1]))
00026   {
00027     printf("Load wav file %s failed.\n", argv[1]);
00028     return 3;
00029   }
00030 
00031   printf("> Loading database...\n");
00032   IndexStream = new TFileInputStream();
00033   IndexStream->Open("demo.txt");
00034 //  IndexStream->Open("20020618.txt");
00035 
00036   DbStream = new TFileInputStream();
00037   DbStream->Open("demo.db");
00038 //  DbStream->Open("20020618.db");
00039   if (!SongDb.Read(IndexStream, DbStream, false))
00040   {
00041     printf("Load database failed.\n");
00042     return 2;
00043   }
00044   delete DbStream;
00045   delete IndexStream;
00046 
00047   SongDb.SetOption(COMPARE_FROM_HEAD);
00048   if (argc > 2)
00049     if (strcmp(argv[2], "any") == 0)
00050       SongDb.SetOption(COMPARE_FROM_ANYWHERE);
00051 
00052   Wave.SetFormat(11025, 8);
00053 
00054   printf("> Feature extracting...\n");
00055   fpitch = NULL;
00056   pitchSize = waveToPitch(Wave.wave, Wave.waveSize, 11025, 16, fpitch, NULL);
00057   limitPitch(fpitch, pitchSize, 34.0f, 80.0f);
00058   smoothPitch(fpitch, pitchSize, 7);
00059   trimPitch(fpitch, pitchSize, from, to);
00060   pitchSize = to - from + 1;
00061 
00062   pitch = new int[pitchSize];
00063   for (i = 0; i < pitchSize; i++)
00064     pitch[i] = fpitch[from + i] * 10;
00065   delete[] fpitch;
00066 
00067   printf("> Searching...\n");
00068   SongDb.Compare(pitch, pitchSize);
00069   delete[] pitch;
00070 
00071   for (i = 0; i < 10; i++)
00072     printf("%s %.2f\n", SongDb.GetTopSong(i)->Fields->Values("songName"), SongDb.GetTopSong(i)->score);
00073 
00074   return 0;
00075 }
00076 

產生日期:Tue Jul 11 11:52:19 2006, 專案:cbmr, 產生器:  doxygen 1.4.7