void cTumkwsaSink::ATKresultThread() { Boolean term; smileMutexLock(terminatedMtx); term = terminated; smileMutexUnlock(terminatedMtx); while (term==FALSE) { APacket p = ansChan->GetPacket(); if (p.GetKind() == StringPacket){ AStringData * sd = (AStringData *)p.GetData(); if (sd->data.find("TERMINATED") != string::npos) { smileMutexLock(terminatedMtx); terminated = TRUE; smileMutexUnlock(terminatedMtx); } } // TODO: string output: (call printResult function...) processResult(0, 0, 0.0, &p); smileMutexLock(terminatedMtx); term = terminated; smileMutexUnlock(terminatedMtx); } }
cTumkwsaSink::~cTumkwsaSink() { //TODO: properly terminate ATK threads... if (arec != NULL) { arec->SendMessage("terminate()"); arec->Join(); } smileMutexLock(terminatedMtx); terminated = TRUE; smileMutexUnlock(terminatedMtx); smileThreadJoin(ATKresThread); if(arec!=NULL) delete arec; if(rman!=NULL) delete rman; if(hset!=NULL) delete hset; if(dict!=NULL) delete dict; if(gram!=NULL) delete gram; if(feChan!=NULL) delete feChan; if(ansChan!=NULL) delete ansChan; if (queue != NULL) delete queue; smileMutexDestroy(terminatedMtx); }
int cTumkwsaSink::myTick(long long t) { if (!atkIsSetup) { if (!setupATK()) return 0; } SMILE_DBG(4,"tick # %i, passing frame to ASR engine",t); cVector *vec= reader->getNextFrame(); //new cVector(nValues+1); if (vec == NULL) return 0; //else reader->nextFrame(); long vi = vec->tmeta->vIdx; double tm = vec->tmeta->time; APacket * p; if (makeFeaturePacket(vec->dataF,vec->N-1, (int)(vec->dataF[vec->N-1]), &p)) { feChan->PutPacket(*p); delete p; } // tick success? int res = 0; smileMutexLock(terminatedMtx); if (terminated == FALSE) res = 1; smileMutexUnlock(terminatedMtx); return res; }
cSmileLogger::~cSmileLogger() { smileMutexLock(logmsgMtx); if (msg != NULL) free(msg); closeLogfile(); if (logfile != NULL) free(logfile); smileMutexUnlock(logmsgMtx); smileMutexDestroy(logmsgMtx); }
// main log message dispatcher void cSmileLogger::logMsg(int itype, char *s, int level, const char *m) { if (!silence) { // check loglevel and type const char *type=NULL; switch (itype) { case LOG_PRINT : if (level > ll_msg) { free(s); return; } type=NULL; break; case LOG_MESSAGE : if (level > ll_msg) { free(s); return; } type=NULL; break; case LOG_ERROR : if (level > ll_err) { free(s); return; } type="ERROR"; break; case LOG_WARNING : if (level > ll_wrn) { free(s); return; } type="WARN"; break; case LOG_DEBUG : if (level > ll_dbg) { free(s); return; } type="DBG"; break; default: return; } smileMutexLock(logmsgMtx); // format log message if (itype == LOG_PRINT) { if (msg != NULL) { free(msg); msg = NULL; } msg = myvprint("%s",s); if (_enableLogPrint) { // write to file writeMsgToFile(1); } } else { fmtLogMsg(type,s,level,m); // write to file writeMsgToFile(); } free(s); // print to console if ((stde)||(logf == NULL)||(itype==LOG_PRINT)) printMsgToConsole(); smileMutexUnlock(logmsgMtx); } }
cTumkwsjSink::~cTumkwsjSink() { smileMutexLock(dataFlgMtx); terminated = TRUE; smileCondSignal( tickCond ); smileMutexUnlock(dataFlgMtx); if (decoderThread != NULL) smileThreadJoin(decoderThread); /* release all */ j_recog_free(recog); //if (logfile) fclose(fp); smileMutexDestroy(terminatedMtx); smileMutexDestroy(dataFlgMtx); smileCondDestroy(tickCond); }
void cTumkwsjSink::juliusDecoderThread() { bool term; smileMutexLock(terminatedMtx); term = terminated; smileMutexUnlock(terminatedMtx); /* enter recongnition loop */ int ret = j_open_stream(recog, NULL); switch(ret) { case 0: /* succeeded */ break; case -1: /* error */ /* go on to next input */ //continue; case -2: /* end of recognition process */ if (jconf->input.speech_input == SP_RAWFILE) { // fprintf(stderr, "%d files processed\n", file_counter); } else if (jconf->input.speech_input == SP_STDIN) { fprintf(stderr, "reached end of input on stdin\n"); } else { fprintf(stderr, "failed to begin input stream\n"); } return; } /* if (outfile_enabled) { outfile_set_fname(j_get_current_filename()); } */ // TODO: terminate mechanism!! /* start recognizing the stream */ ret = j_recognize_stream(recog); }
// this is called from julius decoder thread... int cTumkwsjSink::getFv(float *vec, int n) { int ret=0; smileMutexLock(dataFlgMtx); if (terminated) { smileMutexUnlock(dataFlgMtx); recog->process_want_terminate = TRUE; return -1; } // we should wait for main thread to provide data, then set a flag that data was read.. SMILE_IDBG(4,"yes... julius requests features from us (n=%i)!",n); int end=0; do { lockMessageMemory(); turnStartSmileTimeCur = turnStartSmileTime; // handle pre/post silence and turn detector interface if (turnStart) { // process old turnEnd message first... if ((turnEnd)&&(vIdxEnd < vIdxStart)) { turnEnd = 0; isTurn = 0; ret=-3; end=1; turnStartSmileTimeCur = turnStartSmileTimeLast; SMILE_IDBG(2,"processed turn end message!"); } turnStart = 0; curVidx = vIdxStart-preSil; isTurn = 1; SMILE_IDBG(2,"received turn start message!"); } if (turnEnd) { SMILE_IDBG(4,"received turn end message!"); if (curVidx >= vIdxEnd+postSil) { turnEnd = 0; isTurn = 0; ret=-3; end=1; SMILE_IDBG(2,"processed turn end message!"); turnStartSmileTimeCur = turnStartSmileTimeLast; } // if no frames have been written... if (curVidx == vIdxStart) { SMILE_IWRN(2,"turn (vIdx %i - vIdx %i) has 0 frames (curVidx = %i)!",vIdxStart,vIdxEnd,curVidx); turnEnd=0; isTurn=0; } } unlockMessageMemory(); if (!isTurn) { smileCondWaitWMtx( tickCond, dataFlgMtx ); // wait one smile tick for things to change } if (terminated) { smileMutexUnlock(dataFlgMtx); recog->process_want_terminate = TRUE; return -1; } } while ((!isTurn)&&(!end)); //printf("turn getFv\n"); if (isTurn) { int result=0; curVec = NULL; while (curVec == NULL) { curVec = reader->getFrame(curVidx, -1, 0, &result); // TODO: check if curVidx is behind ringbuffer storage space!! if (result & DMRES_OORleft) { long tmp = reader->getMinR()+10; if (tmp > curVidx) { SMILE_IWRN(2,"ASR processing tried to get feature data behind beginning of ringbuffer, which is no more available! Skipping a few frames to catch up... (%i) : %i -> %i",tmp-curVidx, curVidx, tmp); curVidx = tmp; } } if (curVec == NULL) { smileCondWaitWMtx( tickCond, dataFlgMtx ); if (terminated) { smileMutexUnlock(dataFlgMtx); recog->process_want_terminate = TRUE; return -1; } } } curVidx++; } //printf("turn: %f n=%i\n",curVec->dataF[curVec->N-1],curVec->N); smileMutexUnlock(dataFlgMtx); int i; if (curVec != NULL) { for (i=0; i<MIN( curVec->N, n ); i++) { vec[i] = (float)(curVec->dataF[i]); } } else { for (i=0; i<n; i++) { vec[i] = 0.0; } } // TODO: input segmentation (via smile ComponentMessages...??) return ret; }