nsPicoService::~nsPicoService() { // We don't worry about removing the voices because this gets // destructed at shutdown along with the voice registry. MonitorAutoLock autoLock(mVoicesMonitor); mVoices.Clear(); if (mThread) { mThread->Shutdown(); } UnloadEngine(); }
void nsPicoService::LoadEngine(PicoVoice* aVoice) { PicoApi::pico_Status status = 0; if (mPicoSystem) { UnloadEngine(); } if (!mPicoMemArea) { mPicoMemArea = MakeUnique<uint8_t[]>(PICO_MEM_SIZE); } status = sPicoApi.pico_initialize(mPicoMemArea.get(), PICO_MEM_SIZE, &mPicoSystem); PICO_ENSURE_SUCCESS_VOID("pico_initialize", status); status = sPicoApi.pico_loadResource(mPicoSystem, aVoice->mTaFile.get(), &mTaResource); PICO_ENSURE_SUCCESS_VOID("pico_loadResource", status); status = sPicoApi.pico_loadResource(mPicoSystem, aVoice->mSgFile.get(), &mSgResource); PICO_ENSURE_SUCCESS_VOID("pico_loadResource", status); status = sPicoApi.pico_createVoiceDefinition(mPicoSystem, PICO_VOICE_NAME); PICO_ENSURE_SUCCESS_VOID("pico_createVoiceDefinition", status); char taName[PICO_RETSTRINGSIZE]; status = sPicoApi.pico_getResourceName(mPicoSystem, mTaResource, taName); PICO_ENSURE_SUCCESS_VOID("pico_getResourceName", status); status = sPicoApi.pico_addResourceToVoiceDefinition( mPicoSystem, PICO_VOICE_NAME, taName); PICO_ENSURE_SUCCESS_VOID("pico_addResourceToVoiceDefinition", status); char sgName[PICO_RETSTRINGSIZE]; status = sPicoApi.pico_getResourceName(mPicoSystem, mSgResource, sgName); PICO_ENSURE_SUCCESS_VOID("pico_getResourceName", status); status = sPicoApi.pico_addResourceToVoiceDefinition( mPicoSystem, PICO_VOICE_NAME, sgName); PICO_ENSURE_SUCCESS_VOID("pico_addResourceToVoiceDefinition", status); status = sPicoApi.pico_newEngine(mPicoSystem, PICO_VOICE_NAME, &mPicoEngine); PICO_ENSURE_SUCCESS_VOID("pico_newEngine", status); if (sSingleton) { sSingleton->mCurrentVoice = aVoice; } }
//读取引擎消息 DWORD CEngine::ReadMsg(char *msg,int size) { DWORD dwRead; HANDLE hFile=NULL; if(linkType==UNNAMEDPIPE) hFile=pde.platform_read; else if(linkType==NAMEDPIPE) hFile=pde.hPipe; else { MsgBox("连接程序类型出错!","Error",0); return 0; } if(hFile==NULL) { MsgBox("与连接程序之间的通信管道出错!","Error",0); return 0; } if(!ReadFile(hFile,msg,size,&dwRead,NULL))//读取管道消息 { int t = GetLastError(); if (t == 109)//管道已结束,引擎异常退出 { if (UnloadEngine())//卸载引擎 { MsgBox("引擎已退出,请结束对弈!", "Msg", 0); } else { MsgBox("pipe have closed!", "error", 0); } } else { CHAR error1[50]; sprintf(error1, "ReadMsg failed!\n\nerror: %d", GetLastError()); MessageBox(NULL, error1, "error", MB_OK); } return 0; } if(linkType==UNNAMEDPIPE) WriteFile(pde.console_write,msg,dwRead,&dwRead,NULL); return dwRead; }