Beispiel #1
0
// set the entry and exit points
// (a) automatically
void GramSubN::SetEnds()
{
   NodeIterator entryi;

   entry = exit = NULL;
   for (NodeIterator n=nodes.begin(); n != nodes.end(); ++n){
      if ((*n)->pred.size()==0){
         if (entry != NULL){
            HRError(10751,"GramSubN:SetEnds, more than 1 start node in subnet %s",name.c_str());
            throw ATK_Error(10751);
         }
         entryi = n;
         entry = *n;
      }
      if ((*n)->succ.size()==0){
         if (exit != NULL){
            HRError(10752,"GramSubN:SetEnds, more than 1 end node in subnet %s",name.c_str());
            throw ATK_Error(10752);
         }
         exit = *n;
      }
   }
   if (entry == NULL || exit == NULL){
      HRError(10753,"GramSubN:SetEnds, cant find entry/exit nodes in subnet %s",name.c_str());
      throw ATK_Error(10753);
   }
   // make sure entry is first node in list
   if (nodes.front() != entry) {
      nodes.erase(entryi);
      nodes.push_front(entry);
   }
}
Beispiel #2
0
/* EXPORT->ReadDictWord: Read word and pron from src */
ReturnStatus ReadDictWord(Source *src,LabId *labels,float *prob, int *num)
{
   char buf[MAXSTRLEN];
   int len,nphones;
   char *ptr;
   float p=-1.0,v;

   if(!ReadString(src,buf)){
      *num=-1;
      return(SUCCESS);
   }
   if (prob!=NULL)
      *prob=1.0;
   labels[0]=GetLabId(buf,TRUE);
   labels[1]=NULL;nphones=0;
   SkipWhiteSpace(src);
   while (!src->wasNewline) {
      if (!ReadString(src,buf)){
         HRError(8050,"ReadDict: Phone or outsym expected in word %s",
                 labels[0]->name);
         return(FAIL);
      }
      len = strlen(buf);
      if (buf[0] == '[' && buf[len-1] == ']') {    /* outsym */
         if (labels[1]!=NULL || nphones!=0){ 
            HRError(8050,"ReadDict: Only single outsym allowed for word %s",
                    labels[0]->name);
            return(FAIL);
         }
         buf[len-1] = '\0';
         labels[1] = GetLabId(buf+1,TRUE);
      } 
      else {
         if (nphones==0 && p<0)
            v=strtod(buf,&ptr);
         else
            v=0.0,ptr=buf;
         if (ptr!=buf) {
            if (v<=0.0 || v>1.0 || *ptr!=0) {
               HRError(8050,"ReadDict: Probability malformed %s",buf);
               return(FAIL);
            }
            p=v;
            if (prob!=NULL) *prob=v;
         }
         else {
            if (nphones==MAXPHONES){
               HRError(8050,"ReadDict: Too many phones in word %s",
                       labels[0]->name);
               return(FAIL);
            }
            labels[2+nphones++] = GetLabId(buf,TRUE);
         }
      }
      SkipWhiteSpace(src);
   }
   labels[nphones+2] = NULL;
   *num=nphones;
   return(SUCCESS);
}
Beispiel #3
0
void gs_texture_2d::InitRenderTargets()
{
	HRESULT hr;
	if (type == GS_TEXTURE_2D) {
		hr = device->device->CreateRenderTargetView(texture, NULL,
				renderTarget[0].Assign());
		if (FAILED(hr))
			throw HRError("Failed to create render target view",
					hr);
	} else {
		D3D11_RENDER_TARGET_VIEW_DESC rtv;
		rtv.Format = dxgiFormat;
		rtv.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
		rtv.Texture2DArray.MipSlice  = 0;
		rtv.Texture2DArray.ArraySize = 1;

		for (UINT i = 0; i < 6; i++) {
			rtv.Texture2DArray.FirstArraySlice = i;
			hr = device->device->CreateRenderTargetView(texture,
					&rtv, renderTarget[i].Assign());
			if (FAILED(hr))
				throw HRError("Failed to create cube render "
				              "target view", hr);
		}
	}
}
gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t handle)
	: isShared        (true),
	  sharedHandle    (handle)
{
	HRESULT hr;
	hr = device->device->OpenSharedResource((HANDLE)(uintptr_t)handle,
			__uuidof(ID3D11Texture2D), (void**)texture.Assign());
	if (FAILED(hr))
		throw HRError("Failed to open resource", hr);

	D3D11_TEXTURE2D_DESC desc;
	texture->GetDesc(&desc);

	this->type       = GS_TEXTURE_2D;
	this->format     = ConvertDXGITextureFormat(desc.Format);
	this->levels     = 1;
	this->device     = device;

	this->width      = desc.Width;
	this->height     = desc.Height;
	this->dxgiFormat = desc.Format;

	D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc = {};
	resourceDesc.Format              = desc.Format;
	resourceDesc.ViewDimension       = D3D11_SRV_DIMENSION_TEXTURE2D;
	resourceDesc.Texture2D.MipLevels = 1;

	hr = device->device->CreateShaderResourceView(texture, &resourceDesc,
			shaderRes.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create shader resource view", hr);
}
void mssapi_captions::main_thread()
try {
	HRESULT hr;

	os_set_thread_name(__FUNCTION__);

	hr = grammar->SetDictationState(SPRS_ACTIVE);
	if (FAILED(hr))
		throw HRError("SetDictationState failed", hr);

	hr = recognizer->SetRecoState(SPRST_ACTIVE);
	if (FAILED(hr))
		throw HRError("SetRecoState(SPRST_ACTIVE) failed", hr);

	HANDLE events[] = {notify, stop};

	started = true;

	for (;;) {
		DWORD ret = WaitForMultipleObjects(2, events, false, INFINITE);
		if (ret != WAIT_OBJECT_0)
			break;

		CSpEvent event;
		bool exit = false;

		while (event.GetFrom(context) == S_OK) {
			if (event.eEventId == SPEI_RECOGNITION) {
				ISpRecoResult *result = event.RecoResult();

				CoTaskMemPtr<wchar_t> text;
				hr = result->GetText((ULONG)-1, (ULONG)-1,
						true, &text, nullptr);
				if (FAILED(hr))
					continue;

				char text_utf8[512];
				os_wcs_to_utf8(text, 0, text_utf8, 512);

				callback(text_utf8);

				blog(LOG_DEBUG, "\"%s\"", text_utf8);

			} else if (event.eEventId == SPEI_END_SR_STREAM) {
				exit = true;
				break;
			}
		}

		if (exit)
			break;
	}

	audio->Stop();

} catch (HRError err) {
	blog(LOG_WARNING, "%s failed: %s (%lX)", __FUNCTION__, err.str, err.hr);
}
void gs_device::InitFactory(uint32_t adapterIdx, IDXGIAdapter1 **padapter)
{
	HRESULT hr;
	IID factoryIID = (GetWinVer() >= 0x602) ? dxgiFactory2 :
		__uuidof(IDXGIFactory1);

	hr = CreateDXGIFactory1(factoryIID, (void**)factory.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create DXGIFactory", hr);

	hr = factory->EnumAdapters1(adapterIdx, padapter);
	if (FAILED(hr))
		throw HRError("Failed to enumerate DXGIAdapter", hr);
}
void gs_shader::UploadParams()
{
	vector<uint8_t> constData;
	bool            upload = false;

	constData.reserve(constantSize);

	for (size_t i = 0; i < params.size(); i++)
		UpdateParam(constData, params[i], upload);

	if (constData.size() != constantSize)
		throw "Invalid constant data size given to shader";

	if (upload) {
		D3D11_MAPPED_SUBRESOURCE map;
		HRESULT hr;

		hr = device->context->Map(constants, 0, D3D11_MAP_WRITE_DISCARD,
				0, &map);
		if (FAILED(hr))
			throw HRError("Could not lock constant buffer", hr);

		memcpy(map.pData, constData.data(), constData.size());
		device->context->Unmap(constants, 0);
	}
}
gs_stage_surface::gs_stage_surface(device_t device, uint32_t width,
		uint32_t height, gs_color_format colorFormat)
	: device     (device),
	  width      (width),
	  height     (height),
	  format     (colorFormat),
	  dxgiFormat (ConvertGSTextureFormat(colorFormat))
{
	D3D11_TEXTURE2D_DESC td;
	HRESULT hr;

	memset(&td, 0, sizeof(td));
	td.Width            = width;
	td.Height           = height;
	td.MipLevels        = 1;
	td.ArraySize        = 1;
	td.Format           = dxgiFormat;
	td.SampleDesc.Count = 1;
	td.CPUAccessFlags   = D3D11_CPU_ACCESS_READ;
	td.Usage            = D3D11_USAGE_STAGING;

	hr = device->device->CreateTexture2D(&td, NULL, texture.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create 2D texture", hr);
}
Beispiel #9
0
static inline void EnumD3DAdapters(
		bool (*callback)(void*, const char*, uint32_t),
		void *param)
{
	ComPtr<IDXGIFactory1> factory;
	ComPtr<IDXGIAdapter1> adapter;
	HRESULT hr;
	UINT i = 0;

	IID factoryIID = (GetWinVer() >= 0x602) ? dxgiFactory2 :
		__uuidof(IDXGIFactory1);

	hr = CreateDXGIFactory1(factoryIID, (void**)factory.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create DXGIFactory", hr);

	while (factory->EnumAdapters1(i++, adapter.Assign()) == S_OK) {
		DXGI_ADAPTER_DESC desc;
		char name[512] = "";

		hr = adapter->GetDesc(&desc);
		if (FAILED(hr))
			continue;

		/* ignore microsoft's 'basic' renderer' */
		if (desc.VendorId == 0x1414 && desc.DeviceId == 0x8c)
			continue;

		os_wcs_to_utf8(desc.Description, 0, name, sizeof(name));

		if (!callback(param, name, i - 1))
			break;
	}
}
Beispiel #10
0
void BuildRecogniser()
{
   // create some plumbing
   auChan = new ABuffer("auChan");
   feChan = new ABuffer("feChan");
   ansChan = new ABuffer("ansChan");

   bufferListener = new SSDSBufferListener();
   feChan->AddListener(bufferListener);
  
   // create a resource manager
   rman = new ARMan;
   // create active components linked by buffers
   ain = new ASource("AIn",auChan);
   acode = new ACode("ACode",auChan,feChan);
   arec = new ARec("ARec",feChan,ansChan,rman);
   // create global fixed resources
   hset = new AHmms("HmmSet"); // load info in config
   AObsData *od = acode->GetSpecimen();
   if (!hset->CheckCompatible(&(od->data))){
      HRError(9999,"SSDS: HMM set is not compatible with Coder");
      throw ATK_Error(9999);
   }
   dict = new ADict("ADict");  // load info in config
   ggrm = new AGram("GGram","global.net");
   rman->StoreHMMs(hset);
   rman->StoreDict(dict);
   rman->StoreGram(ggrm);
   // finally create Monitor
   amon = new AMonitor;
   amon->AddComponent(ain);   //register components
   amon->AddComponent(acode); //with the monitor
   amon->AddComponent(arec);
}
ID3D11DepthStencilState *gs_device::AddZStencilState()
{
	HRESULT hr;
	D3D11_DEPTH_STENCIL_DESC dsd;
	SavedZStencilState savedState(zstencilState);
	ID3D11DepthStencilState *state;

	dsd.DepthEnable      = zstencilState.depthEnabled;
	dsd.DepthFunc        = ConvertGSDepthTest(zstencilState.depthFunc);
	dsd.DepthWriteMask   = zstencilState.depthWriteEnabled ?
		D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
	dsd.StencilEnable    = zstencilState.stencilEnabled;
	dsd.StencilReadMask  = D3D11_DEFAULT_STENCIL_READ_MASK;
	dsd.StencilWriteMask = zstencilState.stencilWriteEnabled ?
		D3D11_DEFAULT_STENCIL_WRITE_MASK : 0;
	ConvertStencilSide(dsd.FrontFace, zstencilState.stencilFront);
	ConvertStencilSide(dsd.BackFace,  zstencilState.stencilBack);

	hr = device->CreateDepthStencilState(&dsd, savedState.state.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create depth stencil state", hr);

	state = savedState.state;
	zstencilStates.push_back(savedState);

	return state;
}
ID3D11BlendState *gs_device::AddBlendState()
{
	HRESULT hr;
	D3D11_BLEND_DESC bd;
	SavedBlendState savedState(blendState);
	ID3D11BlendState *state;

	memset(&bd, 0, sizeof(bd));
	for (int i = 0; i < 8; i++) {
		bd.RenderTarget[i].BlendEnable    = blendState.blendEnabled;
		bd.RenderTarget[i].BlendOp        = D3D11_BLEND_OP_ADD;
		bd.RenderTarget[i].BlendOpAlpha   = D3D11_BLEND_OP_ADD;
		bd.RenderTarget[i].SrcBlend =
			ConvertGSBlendType(blendState.srcFactor);
		bd.RenderTarget[i].DestBlend =
			ConvertGSBlendType(blendState.destFactor);
		bd.RenderTarget[i].SrcBlendAlpha =
			bd.RenderTarget[i].SrcBlend;
		bd.RenderTarget[i].DestBlendAlpha =
			bd.RenderTarget[i].DestBlend;
		bd.RenderTarget[i].RenderTargetWriteMask =
			D3D11_COLOR_WRITE_ENABLE_ALL;
	}

	hr = device->CreateBlendState(&bd, savedState.state.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create disabled blend state", hr);

	state = savedState.state;
	blendStates.push_back(savedState);

	return state;
}
void gs_swap_chain::InitTarget(uint32_t cx, uint32_t cy)
{
	HRESULT hr;

	target.width  = cx;
	target.height = cy;

	hr = swap->GetBuffer(0, __uuidof(ID3D11Texture2D),
			(void**)target.texture.Assign());
	if (FAILED(hr))
		throw HRError("Failed to get swap buffer texture", hr);

	hr = device->device->CreateRenderTargetView(target.texture, NULL,
			target.renderTarget[0].Assign());
	if (FAILED(hr))
		throw HRError("Failed to create swap render target view", hr);
}
Beispiel #14
0
// open this gram for editing
void AGram::OpenEdit()
{
   HEnterSection(lock);
   if (isOpen){
      HRError(10761,"Attempting to open an already open grammar %s",rname.c_str());
      throw ATK_Error(10761);
   }
   isOpen = TRUE;
}
void gs_duplicator::Start()
{
	ComPtr<IDXGIOutput1> output1;
	ComPtr<IDXGIOutput> output;
	HRESULT hr;

	if (!get_monitor(device, idx, output.Assign()))
		throw "Invalid monitor index";

	hr = output->QueryInterface(__uuidof(IDXGIOutput1),
			(void**)output1.Assign());
	if (FAILED(hr))
		throw HRError("Failed to query IDXGIOutput1", hr);

	hr = output1->DuplicateOutput(device->device, duplicator.Assign());
	if (FAILED(hr))
		throw HRError("Failed to duplicate output", hr);
}
Beispiel #16
0
// restore grammar from backup copy
void AGram::Restore()
{
   if (bakup == NULL){
      HRError(10796,"AGram::Restore - nothing saved!");
      throw ATK_Error(10796);
   }
   *this = *bakup;
   delete bakup; bakup = NULL;
}
Beispiel #17
0
void Initialise(int argc, char *argv[])
{
   if (InitHTK(argc,argv,ssds_version)<SUCCESS){
      HRError(9999,"SSDS: cannot initialise HTK\n");
      throw HTK_Error(9999);
   }
   printf("\nSSDS: ATK Simple Spoken Dialog System\n");
   printf("=====================================\n\n");
}
Beispiel #18
0
string AStringData::GetSource()
{
   int n = data.find("::");
   if (n==string::npos) {
      HRError(0,"AStringData:GetSource bad format %s\n",data.c_str());
      throw ATK_Error(999);
   }
   return data.substr(0,n);
}
Beispiel #19
0
// close gram to allow use by recogniser
void AGram::CloseEdit()
{
   if (!isOpen){
      HRError(10762,"Attempting to close an already closed grammar %s",rname.c_str());
      throw ATK_Error(10762);
   }
   for (SubNIterator si=subs.begin(); si!=subs.end(); ++si){
      // ensure that grammar is valid
      if (int n = (*si)->IsBroken(TRUE)){
         HRError(10731,"Attempting to close invalid grammar %s(%d)",rname.c_str(),n);
         throw ATK_Error(10731);
      }
      // ensure that entry node is the first in every nodelist
      (*si)->CheckNodeOrder();
   }
   ++version;  // ensure that ARMan rebuilds the network
   isOpen = FALSE;
   HLeaveSection(lock);
}
Beispiel #20
0
// create a new empty Subnet called name
GramSubN *AGram::NewSubN(const string& name)
{
   if (FindSubN(name) != NULL) {
      HRError(10722,"AGram::NewSubN %s already used",name.c_str());
      ATK_Error(10722);
   }
   GramSubN *s = new GramSubN(name);
   ++s->refcount;  subs.push_back(s);
   return s;
}
Beispiel #21
0
void gs_texture_2d::InitTexture(const void **data)
{
	vector<D3D11_SUBRESOURCE_DATA> srd;
	D3D11_TEXTURE2D_DESC td;
	HRESULT hr;

	memset(&td, 0, sizeof(td));
	td.Width            = width;
	td.Height           = height;
	td.MipLevels        = genMipmaps ? 0 : levels;
	td.ArraySize        = type == GS_TEXTURE_CUBE ? 6 : 1;
	td.Format           = dxgiFormat;
	td.BindFlags        = D3D11_BIND_SHADER_RESOURCE;
	td.SampleDesc.Count = 1;
	td.CPUAccessFlags   = isDynamic ? D3D11_CPU_ACCESS_WRITE : 0;
	td.Usage            = isDynamic ? D3D11_USAGE_DYNAMIC :
	                                  D3D11_USAGE_DEFAULT;

	if (type == GS_TEXTURE_CUBE)
		td.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;

	if (isRenderTarget || isGDICompatible)
		td.BindFlags |= D3D11_BIND_RENDER_TARGET;

	if (isGDICompatible)
		td.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;

	if (data)
		InitSRD(srd, data);

	hr = device->device->CreateTexture2D(&td, data ? srd.data() : NULL,
			texture.Assign());
	if (FAILED(hr))
		throw HRError("Failed to create 2D texture", hr);

	if (isGDICompatible) {
		hr = texture->QueryInterface(__uuidof(IDXGISurface1),
				(void**)gdiSurface.Assign());
		if (FAILED(hr))
			throw HRError("Failed to create GDI surface", hr);
	}
}
Beispiel #22
0
// ChkAckBuf: check acks coming from sink and update host on status
void ASyn::ChkAckBuf()
{
   if (!ackbuf->IsEmpty()){
      // first unpack the incoming packet which has the form
      //   cmd(ss,playedSamps,totalSamps)
      APacket p = ackbuf->GetPacket();
      if (p.GetKind() != CommandPacket) {
         HRError(12002,"ASyn:ChkAckBuf - non-command pkt in ackbuf\n");
         throw ATK_Error(12002);
      }
      ACommandData * cd = (ACommandData *) p.GetData();
      string ack = cd->GetCommand();
      int ss = cd->GetInt(0);
      int played = cd->GetInt(1);
      int total = cd->GetInt(2);
      // next construct reply command
      cd = new ACommandData(ack);
      // if intermediate state, then figure out what has been played
      string word;
      if (ack=="aborted" || ack=="muted" || ack=="unmuted"){
         int idx;
         float percent;
         if (ss==seqnum) {  // still current output utterance
               //printf("********* p=%d,t=%d,nw=%d,b1=%d,b2=%d\n",
               //played,total,syn->GetNumWords(),
               //syn->GetBoundary(1),syn->GetBoundary(2));
            idx = syn->GetNumWords();
            while (idx>0 && syn->GetBoundary(idx)>played) --idx;
            word = "";
            if (idx>0) word = syn->GetWord(idx);
            percent = 100.0*played/total;
         }else{
            idx=0; percent=100.0; word=".";
         }
         cd->AddArg(ss); cd->AddArg(idx);
         cd->AddArg(word); cd->AddArg(percent);
         if (ack=="aborted") syn->EndUtterance();
         if (trace&T_ABT)
            printf("ASyn: syn interrupted: ss=%d,played=%d,total=%d,idx=%d[%s]\n",
                    ss,played,total,idx,word.c_str());
      }else if (ack == "started") {
         cd->AddArg(ss); cd->AddArg(total);
      }else if (ack == "error" || ack == "finished") {
         cd->AddArg(ss); syn->EndUtterance();
      }
      APacket reppkt(cd);
      reppkt.SetStartTime(GetTimeNow());
      reppkt.SetEndTime(GetTimeNow());
      repbuf->PutPacket(reppkt);
      if (trace&T_TOP){
         printf("ASyn: reply sent - "); cd->Show(); printf("\n");
      }
   }
}
void gs_shader::BuildConstantBuffer()
{
	for (size_t i = 0; i < params.size(); i++) {
		gs_shader_param &param = params[i];
		size_t       size   = 0;

		switch (param.type) {
		case GS_SHADER_PARAM_BOOL:
		case GS_SHADER_PARAM_INT:
		case GS_SHADER_PARAM_FLOAT:     size = sizeof(float);   break;
		case GS_SHADER_PARAM_VEC2:      size = sizeof(vec2);    break;
		case GS_SHADER_PARAM_VEC3:      size = sizeof(float)*3; break;
		case GS_SHADER_PARAM_VEC4:      size = sizeof(vec4);    break;
		case GS_SHADER_PARAM_MATRIX4X4:
			size = sizeof(float)*4*4;
			break;
		case GS_SHADER_PARAM_TEXTURE:
		case GS_SHADER_PARAM_STRING:
		case GS_SHADER_PARAM_UNKNOWN:
			continue;
		}

		/* checks to see if this constant needs to start at a new
		 * register */
		if (size && (constantSize & 15) != 0) {
			size_t alignMax = (constantSize + 15) & ~15;

			if ((size + constantSize) > alignMax)
				constantSize = alignMax;
		}

		param.pos     = constantSize;
		constantSize += size;
	}

	if (constantSize) {
		D3D11_BUFFER_DESC bd;
		HRESULT hr;

		memset(&bd, 0, sizeof(bd));
		bd.ByteWidth      = (constantSize+15)&0xFFFFFFF0; /* align */
		bd.Usage          = D3D11_USAGE_DYNAMIC;
		bd.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

		hr = device->device->CreateBuffer(&bd, NULL,
				constants.Assign());
		if (FAILED(hr))
			throw HRError("Failed to create constant buffer", hr);
	}

	for (size_t i = 0; i < params.size(); i++)
		gs_shader_set_default(&params[i]);
}
Beispiel #24
0
// delete given subnet from this grammar
void AGram::DeleteSubN(GramSubN *s)
{
   for (SubNIterator si=subs.begin(); si != subs.end(); ++si){
      if (*si = s){
         if(--s->refcount == 0) delete s;
         return;
      }
   }
   HRError(10741,"AGram::DeleteSubN cannot find subnet");
   throw ATK_Error(10741);
}
Beispiel #25
0
/* EXPORT->ReadDict: read and store a dictionary definition */
ReturnStatus ReadDict(char *dictFn, Vocab *voc)
{
   LabId labels[MAXPHONES+4];
   Source src;
   Word word;
   float prob;
   int nphones;
   ReturnStatus ret;

   if(InitSource(dictFn,&src,DictFilter)<SUCCESS){
      HRError(8010,"ReadDict: Can't open file %s", dictFn);
      return(FAIL);
   }
   if (trace&T_TOP)
      printf("\nLoading Dictionary from %s\n",dictFn);
   if((ret=ReadDictWord(&src,labels,&prob, &nphones))<SUCCESS){
      CloseSource(&src);
      HRError(8013,"ReadDict: Dict format error in first entry");
      return(FAIL);
   }
   while(nphones>=0){
      word = GetWord(voc,labels[0],TRUE);
      if (labels[1]==NULL) labels[1]=labels[0];
      if (labels[1]->name[0]==0) labels[1]=NULL;
      if (voc->nullWord->wordName == word->wordName)
         HRError(-8013,"ReadDict: !NULL entry contains pronunciation");
      NewPron(voc,word,nphones,labels+2,labels[1],prob);
      if((ret=ReadDictWord(&src,labels,&prob, &nphones))<SUCCESS){
         HRError(8013,"ReadDict: Dict format error");
         return(FAIL);
      }
   }
   CloseSource(&src);

   if (trace&T_DIC)
      ShowDict(voc);
   if (trace&T_TOP)
      printf("Dictionary loaded from %s with %d words and %d prons\n\n",
             dictFn,voc->nwords,voc->nprons);
   return(SUCCESS);
}
Beispiel #26
0
// save grammar to given file
void AGram::SaveToFile(const string& fname)
{
   FILE *nf;
   char buf[100];

   strcpy(buf,fname.c_str());
   if ( (nf = fopen(buf,"w")) == NULL){
      HRError(10711,"AGram: Cannot create save file %s",buf);
      throw ATK_Error(10711);
   }
   fclose(nf);
}
Beispiel #27
0
/* EXPORT->LSave: Save transcription in fname */
ReturnStatus LSave(char *fname, Transcription *t, FileFormat fmt)
{
   FILE *f;
   char buf[MAXSTRLEN];

   if (fmt == UNDEFF){
      if (GetConfStr(cParm,numParm,"TARGETLABEL",buf))
         fmt = Str2Format(buf);
      else
         fmt = HTK;
   }
   if (outMLF != NULL) {
      if (fmt != HTK){
         HRError(6572,"LSave: cant save to MLF in %s format",Format2Str(fmt));
         return(FAIL);
      }
      f = outMLF;                      /* save to MLF file */
      fprintf(f,"\"%s\"\n",fname);
   } else                              /* else open new one */
      if ((f=fopen(fname,"wb")) == NULL){
         HRError(6511,"LSave: Unable to create label file %s",fname);
         return(FAIL);
      }
   if (trace&T_SAV)
      printf("HLabel: Saving transcription to %s in format %s\n",
             fname,Format2Str(fmt));
   switch (fmt) {
   case HTK:    SaveHTKLabels( f, t);   break;
   case ESPS:   SaveESPSLabels(f, t);   break;
   default: HRError(6572,"LSave: Illegal label file format."); 
      fclose(f);
      return(FAIL);
      break;
   }
   if (outMLF != NULL && fmt==HTK){
      fprintf(f,".\n");  fflush(f);
   }else
      fclose(f);
   return(SUCCESS);
}
Beispiel #28
0
// Initialise grammar from given file
void AGram::InitFromFile(const char * gramFN)
{
   FILE *nf;
   char gFN[512];
   Source src;
   GramSubN *sub;
   Boolean ok;

   if (trace&T_LOAD) printf("Loading HTK SLF %s\n",gramFN);
   // Open the grammar file and attach to a source
   strcpy(gFN,gramFN);
   ok = ( (nf = fopen(gFN,"r")) != NULL)?TRUE:FALSE;
   if (!ok){
      if (gFN[0]=='/') {
         gFN[0] = gFN[1]; gFN[1]=':';
         ok = ((nf = fopen(gFN,"r")) != NULL)?TRUE:FALSE;
      }
   }
   if (!ok){
      HRError(10710,"AGram: Cannot open Word Net file %s",gramFN);
      throw ATK_Error(10710);
   }
   AttachSource(nf,&src);

   // read the network defs
   sub = NewSubN(&src);
   if (sub==NULL){
      HRError(10710,"AGram: Nothing in file %s",gramFN);
      throw ATK_Error(10710);
   }
   while (sub !=NULL && sub->name != "!!MAIN!!")  {
      sub = NewSubN(&src);
   }
   main = sub;
   if (sub != NULL) main->name = rname+":main";

   // close source file
   fclose(nf);
   if (trace&T_SHOW) Show();
}
void gs_vertex_buffer::FlushBuffer(ID3D11Buffer *buffer, void *array,
		size_t elementSize)
{
	D3D11_MAPPED_SUBRESOURCE msr;
	HRESULT hr;

	if (FAILED(hr = device->context->Map(buffer, 0,
					D3D11_MAP_WRITE_DISCARD, 0, &msr)))
		throw HRError("Failed to map buffer", hr);

	memcpy(msr.pData, array, elementSize * vbd.data->num);
	device->context->Unmap(buffer, 0);
}
Beispiel #30
0
// Prime the recogniser ready to process an utterance
void ARec::PrimeRecogniser()
{
   ResourceGroup *g;

   g = (grpName=="")?rmgr->MainGroup():rmgr->FindGroup(grpName);
   if (g == NULL){
      if (grpName=="") HRError(0,"ARec: cant find main resource group\n");
      else HRError(0,"ARec: cant find resource group %s\n",grpName.c_str());
      throw ATK_Error(11001);
   }
   Network *net = g->MakeNetwork();
   LModel *lm = g->MakeNGram();
   opMap.clear();   // forget all previously output packets
   StartRecognition(pri,net,lmScale,wordPen,prScale,ngScale,lm);
   SetPruningLevels(pri,maxActive,genBeam,wordBeam,nBeam,10.0);
   frameCount = 0; tact = 0;
   if (showRD){
      string gn = (grpName=="")?"main":grpName;
      string s = "Primed with "+  gn + "\n";
      HPostMessage(HThreadSelf(),s.c_str());
   }
}