Jump to content

  • Log In with Google      Sign In   
  • Create Account


polpoint

Member Since 13 Jul 2006
Offline Last Active Mar 08 2012 09:19 AM

Topics I've Started

Problem with SAPI Dynamic Grammars in C++

02 March 2012 - 11:20 AM

Good morning. I have been making a Speech to Text program using SAPI and am having some problems with loading, activating and deactivating dynamic grammars. Basically I am displaying a picture on the screen. If the user states the correct response, as defined by the dynamic grammar rule, then that rule is deactivated, and another picture is displayed and its corresponding grammar rule is activated.

I want the dynamic rules to be topLevel, so they just have to state the object without any prefix etc.

My problem is the rules activating/ deactivating do not seem to be consistent. Sometimes the grammar will accept any of the rules, sometimes it will accept only the correct rule.

Any help would be appreciated. If you need more info/ code please let me know. Thanks!

I am pretty sure it is something I am missing when it comes to the grammar rules/ word transition. The other thing I thought might be possible was that I am somehow creating a rule with the memory address of LPCWSTR pikk as opposed to the actual data - but that doesn't seem like it is the problem since the first parameter of GetRule is a LPCWSTR - unless I am converting incorrectly?


Loading dynamic grammar rules:

//curNumb = current number of exercise
//curNumbID = curNumb + numOffest (500) so I reserve #1-500 for whatever other hard-coded grammar rules I add
std::wstring stemp;
LPCWSTR pikk;
//add in the grammar:
//reserve curNumb
int reserveNum = curNumb;
//loop through all object_data and load dynamic rules into grammar:
for(int pip = 0; pip < data.numObjects.size(); pip++)
{
stemp = s2ws(data.object_data[curNumb].title);
pikk = stemp.c_str();
hr = g_cpCmdGrammar->GetRule(pikk, data.object_data[curNumb].programID, SPRAF_TopLevel, TRUE, &hStateTravel);
if(FAILED(hr))
{
  ErrorDescription(hr);
}
		 //loop through all words in object_data
std::list<std::string>::iterator st_it = data.object_data[curNumb].words.begin();
for(; st_it != data.object_data[curNumb].words.end(); st_it++)
{
  std::cout<<"adding word: "<<(*st_it)<<"\n";
  stemp = s2ws((*st_it));
  pikk = stemp.c_str();
  hr = g_cpCmdGrammar->AddWordTransition(hStateTravel, NULL, pikk, L"", SPWT_LEXICAL, 1, NULL);
  if(FAILED(hr))
  {
   ErrorDescription(hr);
  }	
}
curNumb++;
}
//reset curNumb back to reserveNum
curNumb = reserveNum;
//activate curNumb grammar rule
stemp = s2ws(data.object_data[curNumb].title);
pikk = stemp.c_str();
std::cout<<"activate new rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n";
hr = g_cpCmdGrammar->SetRuleIdState(curNumbID, SPRS_ACTIVE);
if(FAILED(hr))
{
ErrorDescription(hr);
std::cout<<"FAILURE at activate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n";
}
else
{
std::cout<<"ruleActivated...\n";
}

hr = g_cpCmdGrammar->Commit(0);

//deactivate old rule/ activate new rule code:
std::cout<<"curScore++ ("<<curScore<<"->";
curScore++;  
std::cout<<curScore<<")\n";
//clear old exercise:	
  
std::wstring stemp = s2ws(data.object_data[curNumb].title);
LPCWSTR pikk = stemp.c_str();
std::cout<<"deactivate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n";
hr = g_cpCmdGrammar->SetRuleIdState(curNumbID, SPRS_INACTIVE);
if(FAILED(hr))
{
ErrorDescription(hr);
std::cout<<"FAILURE at deactivate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n";
}
else
{
std::cout<<"ruleDeactivated...\n";
}
curNumb++;
if(curNumb > data.numObjects.size())
{
curNumb = 1;
}
curNumbID = curNumb + exerciseOffset;
//activate next rule:
stemp = s2ws(data.object_data[curNumb].title);
pikk = stemp.c_str();
std::cout<<"activate new rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n";
hr = g_cpCmdGrammar->SetRuleIdState(curNumbID, SPRS_ACTIVE);
if(FAILED(hr))
{
ErrorDescription(hr);
std::cout<<"FAILURE at activate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n";
}
else
{
std::cout<<"ruleActivated...\n";
}

Need help with some errors in my bilinear interpolation function

28 September 2009 - 10:49 AM

Quote:
+---0,0---+---1,0---+ |? ? ? ? ?|? ? ? ? ?|... |? ? ? ? ?|? ? ? ? ?|... |? ? A ? ?|? ? B ? ?|... |? ? ? ? ?|? ? ? ? ?|... |? ? ? ? ?|? ? ? ? ?|... +---0,1---+---1,1---+ |? ? ? ? ?|? ? ? ? ?|... |? ? ? ? ?|? ? ? ? ?|... |? ? C ? ?|? ? D ? ?|... |? ? ? ? ?|? ? ? ? ?|... |? ? ? ? ?|? ? ? ? ?|... +---------+---------+ | ... | ... |...
I know the values of A, B, C & D and I want to interpolate between those values to fill in the rest of the ?'s Below is the source code as I currently have it, but I am doing something wrong somewhere and I can't figure it out. In the code below the NW quadrant == 0 NE quadrant == 1 SW quadrant == 2 SE quadrant == 3
	for(int pix = 0; pix < RMAP_X; pix++)
	{
		for(int piy = 0; piy < RMAP_Y; piy++)
		{
			quadrant = -1;
			if(pix < (halfRMAP_X) && piy <(halfRMAP_Y))
			{
				quadrant = 0;
			}
			else if(pix >= (halfRMAP_X) && piy < (halfRMAP_Y))
			{
				quadrant = 1;
			}
			else if(pix < (halfRMAP_X) && piy >= (halfRMAP_Y))
			{
				quadrant = 2;
			}
			else if(pix >= (halfRMAP_X) && piy >= (halfRMAP_Y))
			{
				quadrant = 3;
			}


			if(quadrant == 0)
			{
				//nw quadrant - 
				//pix < halfRMAP_X
				//piy < halfRMAP_Y

				float nwDist = 0;
				float nDist = 0;
				float wDist = 0;
				float centDist = 0;
				nDist = 1 / linearDist(pix,piy,pix + (halfRMAP_X - pix),piy - (halfRMAP_Y + piy));
				wDist = 1 / linearDist(pix,piy,pix - (halfRMAP_X + pix),piy + (halfRMAP_Y - piy));
				nwDist = 1 / linearDist(pix,piy, pix - (halfRMAP_X + pix), piy - (halfRMAP_Y - piy));
				centDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X - pix), piy + (halfRMAP_Y - piy));
				
				float sum = nDist + wDist + nwDist + centDist;

				nDist = nDist / sum;
				wDist = wDist / sum;
				nwDist = nwDist / sum;
				centDist = centDist / sum;
				
				world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = nw*nwDist + n*nDist + w*wDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist;

			}
			else if(quadrant == 1)
			{
				//ne quadrant
				//pix >= halfRMAP_X
				//piy < halfRMAP_Y

				float neDist = 0;
				float nDist = 0;
				float eDist = 0;
				float centDist = 0;
				nDist = 1 / linearDist(pix,piy, pix - (pix - halfRMAP_X), piy - (halfRMAP_Y + piy));
				eDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X - pix)), piy + (halfRMAP_Y - piy));
				neDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X - pix)), piy - (halfRMAP_Y + piy));
				centDist = 1 / linearDist(pix,piy, pix - (pix - halfRMAP_X), piy + (halfRMAP_Y - piy));

				float sum = nDist + eDist + neDist + centDist;

				nDist = nDist / sum;
				eDist = eDist / sum;
				neDist = neDist / sum;
				centDist = centDist / sum;

				world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = ne*neDist + n*nDist + e*eDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist;

			}
			else if(quadrant == 2)
			{
				//sw quadrant
				//pix < halfRMAP_X
				//piy >= halfRMAP_Y

				float swDist = 0;
				float sDist = 0;
				float wDist = 0;
				float centDist = 0;

				wDist = 1 / linearDist(pix,piy,pix - (halfRMAP_X + pix), piy - (piy - halfRMAP_Y));
				sDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X - pix), piy + (halfRMAP_Y + (RMAP_Y - piy)));
				swDist = 1 / linearDist(pix,piy, pix - (halfRMAP_X + pix), piy + (halfRMAP_Y + (RMAP_Y - piy)));
				centDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X - pix), piy - (piy - halfRMAP_Y));

				float sum = sDist + wDist + swDist + centDist;

				sDist = sDist / sum;
				wDist = wDist / sum;
				swDist = swDist / sum;
				centDist = centDist / sum;


				world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = sw*swDist + s*sDist + w*wDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist;

			}
			else if(quadrant == 3)
			{
				//se quadrant
				//pix >= halfRMAP_X
				//piy >= halfRMAP_Y

				float seDist = 0;
				float sDist = 0;
				float eDist = 0;
				float centDist = 0;

				eDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X - pix)), piy - (piy - halfRMAP_Y));
				sDist = 1 / linearDist(pix,piy, pix - (pix - halfRMAP_X), piy + (halfRMAP_Y + (RMAP_Y - piy)));
				seDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X - pix)), piy + (halfRMAP_Y + (RMAP_Y - piy)));
				centDist = 1 / linearDist(pix,piy, pix - (pix - halfRMAP_X), piy - (piy - halfRMAP_Y));

				float sum = sDist + eDist + seDist + centDist;

				sDist = sDist / sum;
				eDist = eDist / sum;
				seDist = seDist / sum;
				centDist = centDist / sum;



				world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = se*seDist + s*sDist + e*eDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist;

			}
		}
	}



My results are below: as you can see, things don't line up correctly and some other stuff isn't working out correctly. It looks like it is something with the se quadrant, because it seems from the shore in the 2nd picture that the sw & ne quadrants will line up, but I'm not sure. [Edited by - polpoint on September 28, 2009 7:08:48 PM]

averaging elevation

27 September 2009 - 02:00 PM

Hey! I have a 2d-grid of squares. Each square contains it's own grid of lets say 11x11 squares. Every square also has an elevation value. I want to average out the elevation of the little squares within one of the larger squares with the surrounding larger squares elevations. Basically I want the middle small square to equal it's large square's elevation and the little squares surrounding that to gradually equal 1/2 the dif between the original big square's elevation and the neighbor big square's elevation while taking into account at least 2 of the other 7 neighboring large square's elevation. What sorts of solutions are available to solve my problem? [Edited by - polpoint on September 28, 2009 6:41:54 PM]

[RESOLVED] functions w/ pointers as variables

03 March 2009 - 06:35 AM

I don't like pointers and mostly try to avoid them, but there are some places where they would be very useful. I have an object, regionMap, that contain vectors of vectors of another object, regionTile. Can I create a function that takes a pointer as a variable that points to one of a couple of values (all the same type, lets say ints) in regionTile, and manipulates them? Basically what I want to do is create a function that takes a pointer as a variable. The pointer can point to either var1, var2 or var3, which are ints in regionTile. The function will then loop through the vectors of regionTile and replace/ manipulate var1, var2 or var3, depending on which pointer I sent to the function. It sounds possible to me, but I can't seem to find what I am looking for or figure out what it would be called. [Edited by - polpoint on March 3, 2009 3:28:03 PM]

glListBase & differently sized structures created with call lists

16 November 2008 - 05:32 PM

Ok - I have a 2d tile-based game that I display with quads that are looked at head-on. I have each of the 16 x 16 tiles associated with a call list that I create. I read the bmp into memeory then create the call lists at a certain size then if I want to zoom in I have a very inefficient way of doing it - I build the call list over again in the new dimensions - I have two types of display functions with the one I call glListBase(gl_base) and it prints to whatever size I currently have built with the other one I call glListBase(1) and it prints to the original size that I built at the beginning of the progaam running and does not change based upon my rebuilding the call list with new dimensions - my question is why does this happen?

PARTNERS