www.pudn.com > VRecognize.rar > Test.cpp
// Test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "dllSudx.h" typedef vectorTStringArray; struct ASampleSet { char name[256]; TSoundTag tags[301]; }; typedef vector TSampleSetList; int ListWavFiles(char* dir, TStringArray& fileList) { struct _finddata_t c_file; long hFile; char tmp[1024]; int retVal = 0; sprintf(tmp, "%s\\%s", dir, "*.wav"); /* Find first .c file in current directory */ if( (hFile = _findfirst( tmp, &c_file )) == -1L ) return retVal; else { sprintf(tmp, "%s\\%s", dir, c_file.name); fileList.push_back(tmp); retVal++; while( _findnext( hFile, &c_file ) == 0 ) { sprintf(tmp, "%s\\%s", dir, c_file.name); fileList.push_back(tmp); retVal++; } _findclose( hFile ); } return retVal; } int ListVecFiles(char* dir, TStringArray& fileList) { struct _finddata_t c_file; long hFile; char tmp[1024]; int retVal = 0; sprintf(tmp, "%s\\%s", dir, "*.vec"); /* Find first .c file in current directory */ if( (hFile = _findfirst( tmp, &c_file )) == -1L ) return retVal; else { sprintf(tmp, "%s\\%s", dir, c_file.name); fileList.push_back(tmp); retVal++; while( _findnext( hFile, &c_file ) == 0 ) { sprintf(tmp, "%s\\%s", dir, c_file.name); fileList.push_back(tmp); retVal++; } _findclose( hFile ); } return retVal; } int LoadVecFiles(TStringArray& fileList, TSampleSetList& sampleSetList) { int retVal = 0; for(int i=0; i <样本目录> <音量标志>\n"); printf("\t声音文件名是要被识别的声音文件,样本目录中包含已经预先处理好的样本\n" "\t 音量标志: 表示识别时是否采用音量相关的方式,为0表示识别时不管音量大小,为1表示识别时需要考虑音量大小\n" "Press any key continue..."); getch(); return -1; }*/ int volFlag = atol(argv[3]); if(volFlag) { sudxSetCompVolumeFlag(TRUE); printf("采用与音量相关的方式比较\n"); } else { sudxSetCompVolumeFlag(FALSE); printf("采用与音量无关的方式比较\n"); } TStringArray sampleList; int i = ListVecFiles(argv[2], sampleList); if(i<=0) { printf("No sample files in dir [%s]\n", argv[2]); return -2; } TSampleSetList sampleSetList; int vector_count = LoadVecFiles(sampleList, sampleSetList); if(vector_count<=0) { printf("没有找到样本集合文件\n"); return -3; } if(!sudxInit()) { printf("初始化识别引擎错误!\n"); return -4; } int old_clock = clock(); printf("开始计算\n"); i = sudxCalcFile(argv[1], (char*)g_TestVectorFileName.c_str()); printf("计算结束, 耗时%d ms\nPress any key continue...\n", clock()-old_clock); getch(); if(i==0) { FILE* fp = fopen(g_TestVectorFileName.c_str(), "rb"); if(fp) { fseek(fp, 0L, SEEK_END); int fSize = ftell(fp); int compare_turn = fSize/sizeof(TSoundTag)-1-64; if(compare_turn<=0) { printf("输入的声音过短,不能比较\n"); fclose(fp); } else { TSoundTag* pInput = new TSoundTag[compare_turn+1+64]; fseek(fp, 0L, SEEK_SET); fread(pInput, sizeof(TSoundTag), compare_turn+1+64, fp); fclose(fp); old_clock = clock(); for(i=0; i 300) { if(sudxCompare(pInput+1+i, sampleSetList[j].tags+1, TRUE)) printf("Slow Match at sample pos %d, file[%s]\n", (i+1)*128, sampleSetList[j].name); else printf("!!Slow Not Match at sample pos %d, file[%s]\n", (i+1)*128, sampleSetList[j].name); } } } } int time_passed = clock()-old_clock; printf("计算结束, 耗时%d ms\n", time_passed); printf("比较速度为每秒钟可查找%f秒音乐\n", double(compare_turn)*128.0/8000.0/(double(time_passed)/1000.0)); } } } else printf("计算声音向量错误[%d]\n", i); sudxExit(); printf("==========all finished============\nPress any key continue...\n"); getch(); return 0; }