Beispiel #1
0
void Meter::OnMeterUpdate(wxTimerEvent &evt)
{
   MeterUpdateMsg msg;
   int numChanges = 0;
  
   // There may have been several update messages since the last
   // time we got to this function.  Catch up to real-time by
   // popping them off until there are none left.  It is necessary
   // to process all of them, otherwise we won't handle peaks and
   // peak-hold bars correctly.
   while(mQueue.Get(msg)) {
      numChanges++;
      double deltaT = msg.numFrames / mRate;
      int j;
      
      if (mMeterDisabled)
         return;
      
      mT += deltaT;
      for(j=0; j<mNumBars; j++) {
         if (mDecay) {
            if (mDB) {
               float decayAmount = mDecayRate * deltaT / mDBRange;
               mBar[j].peak = floatMax(msg.peak[j],
                                       mBar[j].peak - decayAmount);
            }
            else {
               double decayAmount = mDecayRate * deltaT;
               double decayFactor = pow(10.0, -decayAmount/20);
               mBar[j].peak = floatMax(msg.peak[j],
                                       mBar[j].peak * decayFactor);
            }
         }
         else
            mBar[j].peak = msg.peak[j];

         // This smooths out the RMS signal
         mBar[j].rms = mBar[j].rms * 0.9 + msg.rms[j] * 0.1;
         
         if (mT - mBar[j].peakHoldTime > mPeakHoldDuration ||
             mBar[j].peak > mBar[j].peakHold) {
            mBar[j].peakHold = mBar[j].peak;
            mBar[j].peakHoldTime = mT;
         }
         
         if (mBar[j].peak > mBar[j].peakPeakHold )
            mBar[j].peakPeakHold = mBar[j].peak;
         
         if (msg.clipping[j] ||
             mBar[j].tailPeakCount+msg.headPeakCount[j] >=
             mNumPeakSamplesToClip)
            mBar[j].clipping = true;
         mBar[j].tailPeakCount = msg.tailPeakCount[j];
      }
   } // while
  
   if (numChanges > 0)      
      RepaintBarsNow();
}
double updateRTOTime(Timer *timer){
  double RTTValue;
  
  timer->SRTT = ((1 - alpha) * timer->SRTT) + (alpha * timer->R);
  RTTValue = (timer->SRTT - timer->R);
  if(RTTValue){
    RTTValue = RTTValue*-1;
  }  
  timer->RTTVAR = ((1 - beta) * timer->RTTVAR) + (beta * RTTValue);
  timer->RTO = timer->SRTT + floatMax(G,K*timer->RTTVAR);
}
Beispiel #3
0
int main(void) {
	//Problem 1
	printf("Problem 1\n");

	int array[20];

	fillInteger(array, 20, -20, 20);
	int n = 10;
	int i;
	for(i = 0; i < 20; i++) {
		printf("%d	", array[i]);
		if((i+1)%n==0) {
			printf("\n");
		}
	}

	findConsecutive(array, 20);

	//Problem 2
	printf("\nProblem 2\n");

	char charArr[50];

	fillCharacter(charArr, 50, 'a', 'z');
	int a;
	for(a = 0; a < 50; a++) {
		printf("%c ", charArr[a]);
	}

	findTriples(charArr, 50);

	//Problem 3
	printf("\n\nProblem 3\n");

	float floatArr[10];

	fillFloat(floatArr, 10, 1.0, 50.0);
	int b;
	for(b = 0; b < 10; b++) {
		printf("%lf  ", floatArr[b]);
	}
	
	float mean = floatMean(floatArr, 10);
	printf("\nMean of the array is %lf\n", mean);

	float min = floatMin(floatArr, 10);
	printf("Min of the array is %lf\n", min);

	float max = floatMax(floatArr, 10);
	printf("Max of the array is %lf\n", max);

}
Beispiel #4
0
void Meter::UpdateDisplay(int numChannels, int numFrames, float *sampleData)
{
   int i, j;
   float *sptr = sampleData;
   int num = intmin(numChannels, mNumBars);
   MeterUpdateMsg msg;

   msg.numFrames = numFrames;
   for(j=0; j<mNumBars; j++) {
      msg.peak[j] = 0;
      msg.rms[j] = 0;
      msg.clipping[j] = false;
      msg.headPeakCount[j] = 0;
      msg.tailPeakCount[j] = 0;
   }

   for(i=0; i<numFrames; i++) {
      for(j=0; j<num; j++) {
         msg.peak[j] = floatMax(msg.peak[j], sptr[j]);
         msg.rms[j] += sptr[j]*sptr[j];

         // In addition to looking for mNumPeakSamplesToClip peaked
         // samples in a row, also send the number of peaked samples
         // at the head and tail, in case there's a run of 
         // Send the number of peaked samples at the head and tail,
         // in case there's a run of peaked samples that crosses
         // block boundaries
         if (fabs(sptr[j])>=MAX_AUDIO) {
            if (msg.headPeakCount[j]==i)
               msg.headPeakCount[j]++;
            msg.tailPeakCount[j]++;
            if (msg.tailPeakCount[j] > mNumPeakSamplesToClip)
               msg.clipping[j] = true;
         }
         else
            msg.tailPeakCount[j] = 0;
      }
      sptr += numChannels;
   }
   for(j=0; j<mNumBars; j++)
      msg.rms[j] = sqrt(msg.rms[j]/numFrames);

   if (mDB) {
      for(j=0; j<mNumBars; j++) {
         msg.peak[j] = ToDB(msg.peak[j], mDBRange);
         msg.rms[j] = ToDB(msg.rms[j], mDBRange);
      }
   }

   mQueue.Put(msg);
}
void CFaceModel::LoadObjFilename(const std::string &filename, bool landmarks)
{
	AABBMin = float3(10000.0f, 10000.0f, 10000.0f);
	AABBMax = -AABBMin;

	mObjFilename = filename;
	{
		tObjModel objModel;
		objLoader(filename.c_str(), objModel);
		CopyOBJDataToSoftwareMesh(&objModel, &mMesh);
	}

	float boxSize = 8.0f;
	int vertCount = mMesh.GetVertCount();
	if (vertCount > 0)
	{
		float3 vmin = mMesh.Pos[0];
		float3 vmax = mMesh.Pos[0];

		for (int i = 0; i < vertCount; i++)
		{
			vmin = Min(vmin, mMesh.Pos[i]);
			vmax = Max(vmax, mMesh.Pos[i]);
		}

		float3 center = (vmax + vmin) / 2.0f;
		float3 dim = vmax - vmin;

		float maxDim = floatMax(dim.x, floatMax(dim.y, dim.z));

		mVertOffset = -center;
		mVertScale = boxSize / maxDim;

		// center to origin, scale, and rotate
		// 
		for (int i = 0; i < vertCount; i++)
		{
			float3 *pos = &mMesh.Pos[i];
			*pos -= center;
			*pos *= mVertScale;
			Swap(pos->z, pos->y);

			// save scale and rotate from RSSDK format. Z is up in rssdk
			mMesh.Tex[i].y = 1.0f - mMesh.Tex[i].y;

			AABBMin = Min(*pos, AABBMin);
			AABBMax = Max(*pos, AABBMax);
		}
	}
	LoadLandmarks();

	// load texture
	SAFE_RELEASE(mTexture);
	std::string fnString = mObjFilename;
	int lastindex = (int)fnString.find_last_of(".");
	std::string rawname = fnString.substr(0, lastindex);
	std::string textureName = rawname.append("image1.png");
	mTexture = CPUTTexture::Create(std::string("facetexture"), textureName, false);

	FlagUpdated();
}