Пример #1
0
float
Math::Log(
    float arg,
    float base
    )
{
    return (base==10.0f) ? Log10(arg) : (Log10(arg) / Log10(base));

} // Math::Log
Пример #2
0
void CChannelEstimation::GetTransferFunction(CVector<_REAL>& vecrData,
											 CVector<_REAL>& vecrGrpDly)
{
	/* Init output vectors */
	vecrData.Init(iNumCarrier, (_REAL) 0.0);
	vecrGrpDly.Init(iNumCarrier, (_REAL) 0.0);

	/* Do copying of data only if vector is of non-zero length which means that
	   the module was already initialized */
	if (iNumCarrier != 0)
	{
		_REAL rDiffPhase, rOldPhase;

		/* Lock resources */
		Lock();

		/* Init constant for normalization */
		const _REAL rTu = (CReal) iFFTSizeN / SOUNDCRD_SAMPLE_RATE;

		/* Copy data in output vector and set scale 
		   (carrier index as x-scale) */
		for (int i = 0; i < iNumCarrier; i++)
		{
			/* Transfer function */
			CReal rNormChanEst = Abs(veccChanEst[i]) / (CReal) iNumCarrier;
				
			if (rNormChanEst > 0)
				vecrData[i] = (CReal) 20.0 * Log10(rNormChanEst);
			else
				vecrData[i] = RET_VAL_LOG_0;

			/* Group delay */
			if (i == 0)
			{
				/* At position 0 we cannot calculate a derivation -> use
				   the same value as position 0 */
				rDiffPhase = Angle(veccChanEst[1]) - Angle(veccChanEst[0]);
			}
			else
				rDiffPhase = Angle(veccChanEst[i]) - rOldPhase;

			/* Take care of wrap around of angle() function */
			if (rDiffPhase > WRAP_AROUND_BOUND_GRP_DLY)
				rDiffPhase -= 2.0 * crPi;
			if (rDiffPhase < -WRAP_AROUND_BOUND_GRP_DLY)
				rDiffPhase += 2.0 * crPi;

			/* Apply normalization */
			vecrGrpDly[i] = rDiffPhase * rTu * 1000.0 /* ms */;

			/* Store old phase */
			rOldPhase = Angle(veccChanEst[i]);

		}

		/* Release resources */
		Unlock();
	}
}
Пример #3
0
/* Bogus random spiky-looking function to simulate a QA value,
  which hovers within +/- 10% of perfect (100%), but
  with relatively infrequent spiky errors */
int TfrmMain::_QAProblemScatter()
{
  double n,m;

  randomize();
  n = Log10(random(10000)+1);  // Random is my favourite function. How about you? -WP
  n = n * Log10(random(10000)+1);
  m = Log10(random(10000)+1);
  m = m * Log10(random(10000)+1);
  n = abs(100 + n - m);
  if (n<0)
    n = 0;
  if (n>150)
    n = 150;

  return floor(n+0.5);
}
Пример #4
0
char*
UnsignedIntToCharPointer(unsigned int x) {
	unsigned int n = Log10(x) + 1;
	char* nArray = (char*)calloc(n + 1, sizeof(char));

	for(unsigned int i = 0; i < n; ++i, n /= 10) {
		nArray[i] = (x % 10) + '0';
	}

	return(nArray);
}
Пример #5
0
void main()
{
    vec3 EyePosition = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
    vec3 VertexPosition = vec3(gl_ModelViewProjectionMatrix * gl_Vertex);

    // z = log(z / zn) / log(zf / zn)
    vec3 Extents = vec3(gl_ModelViewMatrix * vec4(BoxSize, BoxSize, BoxSize, 1.0));

    float maxd = length(Extents);
    float dist = length(EyePosition); // / maxd;
    float pscale = PointScale;

    vDistance = (pscale / dist / maxd);
    vPointSize = ParticleRadius * (pscale / dist);
    vIncident = normalize(-VertexPosition);
    vDensity = LinearRemap(Log10(ParticleDensity), Log10(DensityRange.x), Log10(DensityRange.y), 0.0, 1.0);
    vColor = ParticleColor;
    vEye = EyePosition;

    gl_PointSize = vPointSize;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
    gl_FrontColor = gl_Color;
}
Пример #6
0
      static base_t my_log10p1(const base_t &i) 
	{
	  return Log10(i+1.0);
	}
Пример #7
0
      static base_t my_log10(const base_t &i) 
	{
	  return Log10(i);
	}
Пример #8
0
void CookbookEq::computeFilterCoefs()
{
    float tmp = 0.0f;
    float omega, sn, cs, alpha, beta;
    bool zeroCoefs = false; // this is used if the freq is too high

    // do not allow frequencies bigger than samplerate/2
    float freq = _freq;
    if (freq > (static_cast<float>(_sampleRate) / 2.0f - 500.0f))
    {
        freq = static_cast<float>(_sampleRate) / 2.0f - 500.0f;
        zeroCoefs = true;
    }
    freq = std::max(freq, 0.1f);

    const float gain = static_cast<float>(::exp(_gainDb * Log10() / 20.0));

    // do not allow bogus Q
    float q = std::max(_q, 0.0f);

    // most of theese are implementations of
    // the "Cookbook formulae for audio EQ" by Robert Bristow-Johnson
    switch (_type)
    {
    case LoPass1:
        if (!zeroCoefs)
        {
            tmp = static_cast<float>(::exp(-2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate)));
        }
        _c[0] = 1.0f - tmp;
        _c[1] = 0.0f;
        _c[2] = 0.0f;
        _d[1] = tmp;
        _d[2] = 0.0f;
        _order = 1;
        break;
    case HiPass1:
        if (!zeroCoefs)
        {
            tmp = static_cast<float>(::exp(-2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate)));
        }
        _c[0] = (1.0f + tmp) / 2.0f;
        _c[1] = -(1.0f + tmp) / 2.0f;
        _c[2] = 0.0f;
        _d[1] = tmp;
        _d[2] = 0.0f;
        _order = 1;
        break;
    case LoPass2:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin (omega);
            cs = cos (omega);
            alpha = sn / (2.0f * q);
            tmp = 1.0f + alpha;
            _c[0] = (1.0f - cs) / 2.0f / tmp;
            _c[1] = (1.0f - cs) / tmp;
            _c[2] = (1.0f - cs) / 2.0f / tmp;
            _d[1] = -2.0f * cs / tmp * (-1.0f);
            _d[2] = (1.0f - alpha) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = 1.0f;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    case HiPass2:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin (omega);
            cs = cos (omega);
            alpha = sn / (2.0f * q);
            tmp = 1.0f + alpha;
            _c[0] = (1.0f + cs) / 2.0f / tmp;
            _c[1] = -(1.0f + cs) / tmp;
            _c[2] = (1.0f + cs) / 2.0f / tmp;
            _d[1] = -2.0f * cs / tmp * (-1.0f);
            _d[2] = (1.0f - alpha) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = 0.0f;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    case BandPass:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin(omega);
            cs = cos(omega);
            alpha = sn / (2.0f * q);
            tmp = 1.0f + alpha;
            _c[0] = alpha / tmp * sqrt (q + 1.0f);
            _c[1] = 0.0f;
            _c[2] = -alpha / tmp * sqrt (q + 1.0f);
            _d[1] = -2.0f * cs / tmp * (-1.0f);
            _d[2] = (1.0f - alpha) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = 0.0f;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    case Notch:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin(omega);
            cs = cos(omega);
            alpha = sn / (2 * sqrt (q));
            tmp = 1.0f + alpha;
            _c[0] = 1.0f / tmp;
            _c[1] = -2.0f * cs / tmp;
            _c[2] = 1.0f / tmp;
            _d[1] = -2.0f * cs / tmp * (-1.0f);
            _d[2] = (1.0f - alpha) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = 1.0f;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    case Peak:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin(omega);
            cs = cos(omega);
            q *= 3.0;
            alpha = sn / (2 * q);
            tmp = 1 + alpha / gain;
            _c[0] = (1.0f + alpha * gain) / tmp;
            _c[1] = (-2.0f * cs) / tmp;
            _c[2] = (1.0f - alpha * gain) / tmp;
            _d[1] = -2.0f * cs / tmp * (-1.0f);
            _d[2] = (1.0f - alpha / gain) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = 1.0f;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    case LoShelf:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin (omega);
            cs = cos (omega);
            q = sqrt (q);
            alpha = sn / (2 * q);
            beta = sqrt (gain) / q;
            tmp = (gain + 1.0f) + (gain - 1.0f) * cs + beta * sn;
            _c[0] = gain * ((gain + 1.0f) - (gain - 1.0f) * cs + beta * sn) / tmp;
            _c[1] = 2.0f * gain * ((gain - 1.0f) - (gain + 1.0f) * cs) / tmp;
            _c[2] = gain * ((gain + 1.0f) - (gain - 1.0f) * cs - beta * sn) / tmp;
            _d[1] = -2.0f * ((gain - 1.0f) + (gain + 1.0f) * cs) / tmp * (-1.0f);
            _d[2] = ((gain + 1.0f) + (gain - 1.0f) * cs - beta * sn) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = gain;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    case HiShelf:
        if (!zeroCoefs)
        {
            omega = static_cast<float>(2.0 * Pi() * static_cast<double>(freq) / static_cast<double>(_sampleRate));
            sn = sin(omega);
            cs = cos(omega);
            q = sqrt(q);
            alpha = sn / (2.0f * q);
            beta = sqrt (gain) / q;
            tmp = (gain + 1.0f) - (gain - 1.0f) * cs + beta * sn;
            _c[0] = gain * ((gain + 1.0f) + (gain - 1.0f) * cs + beta * sn) / tmp;
            _c[1] = -2.0f * gain * ((gain - 1.0f) + (gain + 1.0f) * cs) / tmp;
            _c[2] = gain * ((gain + 1.0f) + (gain - 1.0f) * cs - beta * sn) / tmp;
            _d[1] = 2.0f * ((gain - 1.0f) - (gain + 1.0f) * cs) / tmp * (-1.0f);
            _d[2] = ((gain + 1.0f) - (gain - 1.0f) * cs - beta * sn) / tmp * (-1.0f);
        }
        else
        {
            _c[0] = 1.0f;
            _c[1] = 0.0f;
            _c[2] = 0.0f;
            _d[1] = 0.0f;
            _d[2] = 0.0f;
        }
        _order = 2;
        break;
    default: // wrong type
        assert(false);
        break;
    }
}