void TimeFreqPeakConnectivity::InitMatrix (mrs_realvec &Matrix, unsigned char **traceback, mrs_natural rowIdx, mrs_natural colIdx)
{
	mrs_natural i,j,				
				numRows = Matrix.getRows (),
				numCols = Matrix.getCols ();
	mrs_natural iCol;

	Matrix.setval(0);
	
	traceback[rowIdx][colIdx]	= kFromLeft;

	// left of point of interest
	for (i = 0; i < numRows; i++)
	{
		for (j = 0; j < colIdx; j++)
		{
			Matrix(i,j)		= costInit;
			traceback[i][j]	= kFromLeft;
		}
	}
	//cout << Matrix << endl;
	//upper left corner
	for (i = 0; i < rowIdx; i++)
	{
		iCol	= MyMin (rowIdx - i + colIdx, numCols);
		for (j = colIdx; j < iCol; j++)
		{
			Matrix(i,j)		= costInit;
			traceback[i][j]	= kFromLeft;
		}
	}
	//cout << Matrix << endl;
	// lower left corner
	for (i = rowIdx + 1; i < numRows; i++)
	{
		iCol	= MyMin (i - rowIdx + colIdx, numCols);
		for (j = colIdx; j < iCol; j++)
		{
			Matrix(i,j)		= costInit;
			traceback[i][j]	= kFromLeft;
		}
	}
	//cout << Matrix << endl;
}
Beispiel #2
0
void
SimulMaskingFft::CalcSpreading (mrs_realvec &bandLevels, mrs_realvec &result)
{
  // this is level dependent adapted from ITU-R BS.1387

  mrs_natural    iBarkj,                 // Masker
                 iBarkk;                 // Maskee

  mrs_real  fTmp1,
            fTmp2,
            fSlope,
            fScale      = sqrt(8./3.),
            fBRes       = barkRes_,//hertz2bark (.5*audiosrate_, h2bIdx)/numBands_,
            *pfEnPowTmp = processBuff_.getData (),
             *pfSlopeUp  = helpBuff_.getData ();
  mrs_real  *pfSlope    = slopeSpread_.getData (),
             *pfNorm     = normSpread_.getData ();

  // initialize pfResult
  result.setval(0);

  fSlope                      = exp ( -fBRes * 2.7 * 2.302585092994045684017991454684364207601101488628772976033);
  fTmp2						= 1.0 / (1.0 - fSlope);
  for (iBarkj = 0; iBarkj < numBands_; iBarkj++)
  {
    pfSlopeUp[iBarkj]       = pfSlope[iBarkj] * pow (bandLevels(iBarkj)*fScale,  .2 * fBRes);
    fTmp1    				= (1.0 - IntPow (fSlope, iBarkj+1)) * fTmp2;
    fTmp2    			    = (1.0 - IntPow(pfSlopeUp[iBarkj], numBands_ - iBarkj)) / (1.0 - pfSlopeUp[iBarkj]);
    if (bandLevels(iBarkj) < 1e-20)
    {
      pfSlopeUp[iBarkj]   = 0;
      pfEnPowTmp[iBarkj]  = 0;
      continue;
    }
    pfSlopeUp[iBarkj]       = exp (0.4 * log (pfSlopeUp[iBarkj]));
    pfEnPowTmp[iBarkj]      = exp (0.4 * log (bandLevels(iBarkj)/(fTmp1 + fTmp2 -1)));
  }
  fSlope                      = exp ( 0.4 * log (fSlope));

  // lower slope
  result(numBands_-1)     = pfEnPowTmp[numBands_-1];
  for (iBarkk = numBands_-2; iBarkk >= 0; iBarkk--)
    result(iBarkk)        = pfEnPowTmp[iBarkk] + result(iBarkk + 1) * fSlope;

  // upper slope
  for (iBarkj = 0; iBarkj < numBands_-1; iBarkj++)
  {
    fSlope                  = pfSlopeUp[iBarkj];
    fTmp1                   = pfEnPowTmp[iBarkj];
    for (iBarkk = iBarkj+1; iBarkk < numBands_; iBarkk++)
    {
      mrs_real  dTmp1       = fTmp1 * fSlope;
      fTmp1               = (dTmp1 < 1e-30)? 0 : (mrs_real)dTmp1;
      result(iBarkk)   += fTmp1;
    }
  }

  // normalization
  for (iBarkk = 0; iBarkk < numBands_; iBarkk++)
  {
    mrs_real  dTmp      = result(iBarkk);
    result(iBarkk)		= sqrt(dTmp) * dTmp * dTmp *pfNorm[iBarkk];
    //result(iBarkk)        = sqrt (result(iBarkk));
    //result(iBarkk)       *= result(iBarkk)*result(iBarkk)*result(iBarkk)*result(iBarkk);
    //result(iBarkk)       *= pfNorm[iBarkk];
  }
  return;
}