void *listenThread(void *arg) { printf("Listen Thread: init sphinx...\n"); if(!sphinxInit()) exit(-1); if(!recordInit()) exit(-1); while(!getExitApp()) { if(getRun()) { printf("Listen Thread: starting to decode...\n"); pthread_barrier_wait(&startBarrier); if(!decode()) exit(-1); printf("Listen Thread: decoding finished...\n"); if (!printResult()) exit(-1); pthread_barrier_wait(&endBarrier); } else { usleep(1000); } } recordClose(); sphinxClose(); printf("Listen thread terminated.\n"); return NULL; }
int decode() { int ret; int16 buf[BUFFER_SIZE]; printf("Listening for input...\n"); if (ad_start_rec(ad) < 0) { printf("Error starting recording.\n"); return 0; } //check if not silent while ((ret = cont_ad_read(c_ad, buf, BUFFER_SIZE)) == 0) usleep(1000); if (ps_start_utt(ps, NULL) < 0) { printf("Failed to start utterance.\n"); return 0; } ret = ps_process_raw(ps, buf, BUFFER_SIZE, 0, 0); if (ret < 0) { printf("Error decoding.\n"); return 0; } do { ret = cont_ad_read(c_ad, buf, BUFFER_SIZE); if (ret < 0) { printf("Failed to record audio.\n"); return 0; } else if(ret > 0) { // Valid speech data read. ret = ps_process_raw(ps, buf, 4096, 0, 0); if (ret < 0) { printf("Error decoding.\n"); return 0; } } else { //no data usleep(1000); } } while(getRun()); ad_stop_rec(ad); while (ad_read(ad, buf, BUFFER_SIZE) >= 0); cont_ad_reset(c_ad); ps_end_utt(ps); return 1; }
void * MeshUpdateThread::Thread() { ThreadStarted(); log_register_thread("MeshUpdateThread"); DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER while(getRun()) { /*// Wait for output queue to flush. // Allow 2 in queue, this makes less frametime jitter. // Umm actually, there is no much difference if(m_queue_out.size() >= 2) { sleep_ms(3); continue; }*/ QueuedMeshUpdate *q = m_queue_in.pop(); if(q == NULL) { sleep_ms(3); continue; } ScopeProfiler sp(g_profiler, "Client: Mesh making"); scene::SMesh *mesh_new = NULL; mesh_new = makeMapBlockMesh(q->data); MeshUpdateResult r; r.p = q->p; r.mesh = mesh_new; r.ack_block_to_server = q->ack_block_to_server; /*infostream<<"MeshUpdateThread: Processed " <<"("<<q->p.X<<","<<q->p.Y<<","<<q->p.Z<<")" <<std::endl;*/ m_queue_out.push_back(r); delete q; } END_DEBUG_EXCEPTION_HANDLER(errorstream) return NULL; }
const std::string& getOutputRoot() { return get( brion::CONFIGSECTION_RUN, getRun(), BLUECONFIG_OUTPUT_PATH_KEY ); }
const std::string& getCircuitTarget() { return get( brion::CONFIGSECTION_RUN, getRun(), BLUECONFIG_CIRCUIT_TARGET_KEY ); }
void *EmergeThread::Thread() { ThreadStarted(); log_register_thread("EmergeThread" + itos(id)); DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER v3s16 last_tried_pos(-32768,-32768,-32768); // For error output v3s16 p; u8 flags; map = (ServerMap *)&(m_server->m_env->getMap()); emerge = m_server->m_emerge; mapgen = emerge->mapgen[id]; enable_mapgen_debug_info = emerge->mapgen_debug_info; while (getRun()) try { if (!popBlockEmerge(&p, &flags)) { qevent.wait(); continue; } last_tried_pos = p; if (blockpos_over_limit(p)) continue; bool allow_generate = flags & BLOCK_EMERGE_ALLOWGEN; EMERGE_DBG_OUT("p=" PP(p) " allow_generate=" << allow_generate); /* Try to fetch block from memory or disk. If not found and asked to generate, initialize generator. */ BlockMakeData data; MapBlock *block = NULL; std::map<v3s16, MapBlock *> modified_blocks; if (getBlockOrStartGen(p, &block, &data, allow_generate)) { { ScopeProfiler sp(g_profiler, "EmergeThread: Mapgen::makeChunk", SPT_AVG); TimeTaker t("mapgen::make_block()"); mapgen->makeChunk(&data); if (enable_mapgen_debug_info == false) t.stop(true); // Hide output } { //envlock: usually 0ms, but can take either 30 or 400ms to acquire JMutexAutoLock envlock(m_server->m_env_mutex); ScopeProfiler sp(g_profiler, "EmergeThread: after " "Mapgen::makeChunk (envlock)", SPT_AVG); map->finishBlockMake(&data, modified_blocks); block = map->getBlockNoCreateNoEx(p); if (block) { /* Do some post-generate stuff */ v3s16 minp = data.blockpos_min * MAP_BLOCKSIZE; v3s16 maxp = data.blockpos_max * MAP_BLOCKSIZE + v3s16(1,1,1) * (MAP_BLOCKSIZE - 1); // Ignore map edit events, they will not need to be sent // to anybody because the block hasn't been sent to anybody MapEditEventAreaIgnorer ign(&m_server->m_ignore_map_edit_events_area, VoxelArea(minp, maxp)); { // takes about 90ms with -O1 on an e3-1230v2 SERVER_TO_SA(m_server)->environment_OnGenerated( minp, maxp, emerge->getBlockSeed(minp)); } EMERGE_DBG_OUT("ended up with: " << analyze_block(block)); m_server->m_env->activateBlock(block, 0); } } } /* Set sent status of modified blocks on clients */ // NOTE: Server's clients are also behind the connection mutex //conlock: consistently takes 30-40ms to acquire JMutexAutoLock lock(m_server->m_con_mutex); // Add the originally fetched block to the modified list if (block) modified_blocks[p] = block; // Update weather data in mapblock for(std::map<v3s16, MapBlock *>::iterator i = modified_blocks.begin(); i != modified_blocks.end(); ++i) { map->getHeat(m_server->m_env, MAP_BLOCKSIZE*i->first ,i->second); map->getHumidity(m_server->m_env, MAP_BLOCKSIZE*i->first, i->second); } // Set the modified blocks unsent for all the clients for (std::map<u16, RemoteClient*>::iterator i = m_server->m_clients.begin(); i != m_server->m_clients.end(); ++i) { RemoteClient *client = i->second; if (modified_blocks.size() > 0) { // Remove block from sent history client->SetBlocksNotSent(modified_blocks); } } } catch (VersionMismatchException &e) { std::ostringstream err; err << "World data version mismatch in MapBlock "<<PP(last_tried_pos)<<std::endl; err << "----"<<std::endl; err << "\""<<e.what()<<"\""<<std::endl; err << "See debug.txt."<<std::endl; err << "World probably saved by a newer version of Minetest."<<std::endl; m_server->setAsyncFatalError(err.str()); } catch (SerializationError &e) { std::ostringstream err; err << "Invalid data in MapBlock "<<PP(last_tried_pos)<<std::endl; err << "----"<<std::endl; err << "\""<<e.what()<<"\""<<std::endl; err << "See debug.txt."<<std::endl; err << "You can ignore this using [ignore_world_load_errors = true]."<<std::endl; m_server->setAsyncFatalError(err.str()); } END_DEBUG_EXCEPTION_HANDLER(errorstream) log_deregister_thread(); return NULL; }