Skip to content

Commit

Permalink
Finish Transfer Source codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhyume committed Jul 21, 2014
1 parent eb90d97 commit 39d552c
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/build.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "iFlyBuild.h"
#include "hash.h"
#include "fingerprint.h"

using namespace std;

THash myhash;
TExtractFeature fingerprint;

int Initialize(){
myhash.BuildInit();
return 0;
}

int ProcessBuildRes(const char *szResDir, const char *szResPath){
myhash.AddSongList(T2A(FileName));
fingerprint.ExtractPair(T2A(finder.GetFilePath()), myhash, 0, (float)0.98, index, 0);
fingerprint.UnInit();
myhash.Hash2File(szResPath);
printf("%d.\n", index);
system("pause");
return 0;
}

int unInitialize(){
myhash.BuildUnInit();
return 0;
}
41 changes: 41 additions & 0 deletions src/build.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _IFLY_RES_BUILD_H_
#define _IFLY_RES_BUILD_H_

#include <string>

#ifdef WIN32
#define __EXPORT __declspec(dllexport)
#else
#define __EXPORT
#endif /* WIN32 */

//+---------------------------------------------------------------------------+
//+ 初始化
//+ 对需要的数据结构进行初始化操作
//+---------------------------------------------------------------------------+
//+ return - 返回码
//+---------------------------------------------------------------------------+
extern "C" __EXPORT int Initialize();
typedef int(*Proc_Initialize)();

//+---------------------------------------------------------------------------+
//+ 数据打包
//+ 对给出的歌单进行打包,输出资源文件
//+---------------------------------------------------------------------------+
//+ szResDir - 歌曲文件夹输入路径
//+ szResPath - 资源输出路径
//+ return - 返回码
//+---------------------------------------------------------------------------+
extern "C" __EXPORT int ProcessBuildRes(const char *szResDir, const char *szResPath);
typedef int(*Proc_ProcessBuildRes)(const char *szResDir, const char *szResPath);

//+---------------------------------------------------------------------------+
//+ 逆初始化
//+ 对需要的数据结构进行析构
//+---------------------------------------------------------------------------+
//+ return - 返回码
//+---------------------------------------------------------------------------+
extern "C" __EXPORT int unInitialize();
typedef int(*Proc_unInitialize)();

#endif//_IFLY_RES_BUILD_H_
49 changes: 49 additions & 0 deletions src/recog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// iFlySelect.cpp : 定义 DLL 应用程序的导出函数。
//

#include "stdafx.h"
#include "iFlySelect.h"
#include "Hash.h"
#include "fingerprint.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 唯一的应用程序对象
THash myhash;
TExtractFeature fingerprint;

CWinApp theApp;

using namespace std;

int Initialize(const char *szResPath){
myhash.File2Hash(szResPath);

myhash.ReBuildInit();
return 0;
}

int ProcessSelelct(const char *szAudioPath, std::string &szResultString){
myhash.VoteInit();
fingerprint.ExtractPair(szAudioPath, myhash, 0, (float)0.98, 0, 1);
fingerprint.UnInit();
fingerprint.ExtractPair(szAudioPath, myhash, 64, (float)0.98, 0, 1);
fingerprint.UnInit();
fingerprint.ExtractPair(szAudioPath, myhash, 128, (float)0.98, 0, 1);
fingerprint.UnInit();
fingerprint.ExtractPair(szAudioPath, myhash, 192, (float)0.98, 0, 1);
fingerprint.UnInit();
size_t offset;
size_t result = myhash.VoteResult(offset);
printf("The song is %s, the offset is %f s.\n", myhash.song_list[result], (float)(offset*(float)FRAME_HOP / 8000.0));
szResultString = myhash.song_list[result];

return 0;
}

int unInitialize(){
return 0;
}
42 changes: 42 additions & 0 deletions src/recog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef _IFLY_RES_SELECT_H_
#define _IFLY_RES_SELECT_H_

#include <string>

#ifdef WIN32
#define __EXPORT __declspec(dllexport)
#else
#define __EXPORT
#endif /* WIN32 */

//+---------------------------------------------------------------------------+
//+ 初始化
//+ 对需要的数据结构进行初始化操作
//+---------------------------------------------------------------------------+
//+ szResPath - 资源输入路径
//+ return - 返回码
//+---------------------------------------------------------------------------+
extern "C" __EXPORT int Initialize(const char *szResPath);
typedef int(*Proc_Initialize)(const char *szResPath);

//+---------------------------------------------------------------------------+
//+ 资源检索
//+ 加载编译好的资源包,对输入的音频进行检索,并输出对应的歌曲名
//+---------------------------------------------------------------------------+
//+ szAudioPath - 待检索音频路径
//+ szResultString - 输出结果,格式:{[忘情水]}
//+ return - 返回码
//+---------------------------------------------------------------------------+
extern "C" __EXPORT int ProcessSelelct(const char *szAudioPath, std::string &szResultString);
typedef int(*Proc_ProcessSelelct)(const char *szAudioPath, std::string &szResultString);

//+---------------------------------------------------------------------------+
//+ 逆初始化
//+ 对需要的数据结构进行析构
//+---------------------------------------------------------------------------+
//+ return - 返回码
//+---------------------------------------------------------------------------+
extern "C" __EXPORT int unInitialize();
typedef int(*Proc_unInitialize)();

#endif//_IFLY_RES_SELECT_H_

0 comments on commit 39d552c

Please sign in to comment.