Пример #1
0
void Butfilt::transform_enter (ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	getCoefs (stream_in.sr);

	_iir = ssi_pcast (IIR, IIR::Create (0));
	_iir->setCoefs (_coefs);
	_iir->transform_enter (stream_in, stream_out, xtra_stream_in_num, xtra_stream_in);

	_first_call = true;
}
Пример #2
0
bool Line::intersect(const Line &b, Point &point) const
{
    double a1, b1, c1, a2, b2, c2;

    getCoefs(a1, b1, c1);
    b.getCoefs(a2, b2, c2);

    // using Cramer's rule
    double den = det(a1, b1, a2, b2);  // denominator

    if (std::abs(den) < 1e-9)
        return false;

    point.setX(-det (c1, b1, c2, b2) / den);
    point.setY(-det (a1, c1, a2, c2) / den);

    return true;
}
Пример #3
0
int main(int argc, char *argv[]){
	
	/* used for functional testing */
	int lines = 7;
	while(lines--){

	ARGS *args = getArgs(argc, argv);
	COEFS *coefs = getCoefs(args);
	ROOTS *roots = solveQ(coefs);

	if(roots-> complex){
		printf("Roots are complex: ");
		printf("%.8f%+.8fi", roots->root[0], roots->root[1]);
		printf(", %.8f%+.8fi\n", roots->root[0], -roots->root[1]);
	}else if(roots-> equal){
		printf("Roots are equal: %.8f\n", roots->root[0]);
	}else if (roots-> real){
		printf("Roots are real numbers: %.8f , %.8f\n", roots->root[0], roots->root[1]);
	}

	}

	return 0;
}
Пример #4
0
double Line::C() const
{
    double a,b,c;
    getCoefs(a,b,c);
    return c;
}
Пример #5
0
double Line::B() const
{
    double a,b,c;
    getCoefs(a,b,c);
    return b;
}
Пример #6
0
double Line::A() const
{
    double a,b,c;
    getCoefs(a,b,c);
    return a;
}
Пример #7
0
void HrtfFilter::ClockProcess (float* leftData, float* rightData, int bufferLength)
{
    float ltmp, rtmp;
    float lLowerDelay, lUpperDelay, rLowerDelay, rUpperDelay;
    float lDelayDifference, rDelayDifference;
    int lrp, lwp, rrp, rwp;
    lrp = leftReadPosition;
    lwp = leftWritePosition;
    rrp = rightReadPosition;
    rwp = rightWritePosition;
    
    // delay pointers
    float* lDelayPointer = delayBuffer.getWritePointer(0);
    float* rDelayPointer = delayBuffer.getWritePointer(1);
    
    // update delays
    if (currentAngle != previousAngle)
    {
        lPreviousDelay = lCurrentDelay;
        rPreviousDelay = rCurrentDelay;
        
        lLowerDelay = hrtfDelay.get(0, (int)currentAngle/10);
        lUpperDelay = hrtfDelay.get(0, (int)(currentAngle/10)+1);
        rLowerDelay = hrtfDelay.get(1, (int)currentAngle/10);
        rUpperDelay = hrtfDelay.get(1, (int)(currentAngle/10)+1);
        
        lCurrentDelay = interpolate(lUpperDelay, lLowerDelay);
        rCurrentDelay = interpolate(rUpperDelay, rLowerDelay);
        
        lDelayDifference = lCurrentDelay - lPreviousDelay;
        rDelayDifference = rCurrentDelay - rPreviousDelay;
    
        lrp -= ((int)lDelayDifference + delayBufferLength) % delayBufferLength;
        
        rrp -= ((int)rDelayDifference + delayBufferLength) % delayBufferLength;
    }
    
    // filter vectors
    float *lLowerHrtf = hrtfBuffer.getFilter(0, (int)currentAngle/10);
    float *rLowerHrtf = hrtfBuffer.getFilter(1, (int)currentAngle/10);
    float *lUpperHrtf = hrtfBuffer.getFilter(0, (int)(currentAngle/10)+1);
    float *rUpperHrtf = hrtfBuffer.getFilter(1, (int)(currentAngle/10)+1);
    int filterLength = hrtfBuffer.getLength();
    
    float *lFilterBuffer = getCoefs(0);
    float *rFilterBuffer = getCoefs(1);
    
    for (int n = 0; n < bufferLength; n++)
    {
        // write input to delay buffers
        lDelayPointer[lwp] = leftData[n];
        rDelayPointer[rwp] = leftData[n];
        
        // filter interpolation
        if (currentAngle != previousAngle)
        {
            if (n < filterLength)
            {
                lFilterBuffer[n] = interpolate(lUpperHrtf[n], lLowerHrtf[n]);
                rFilterBuffer[n] = interpolate(rUpperHrtf[n], rLowerHrtf[n]);
            }
        }
        
        // filtering
        ltmp = 0.0f;
        rtmp = 0.0f;
        for (int i = 0; i < filterLength; i++)
        {
            // left channel
            if (lrp - i < 0)
                ltmp += lDelayPointer[lrp - i + delayBufferLength] * lFilterBuffer[i];
            else
                ltmp += lDelayPointer[lrp - i] * lFilterBuffer[i];
            
            // right channel
            if (rrp - i < 0)
                rtmp += rDelayPointer[rrp - i + delayBufferLength] * rFilterBuffer[i];
            else
                rtmp += rDelayPointer[rrp - i] * rFilterBuffer[i];
        }
        // limiter
        if (ltmp > 1.0f)
            ltmp = 1.0f;
        if (ltmp < -1.0f)
            ltmp = -1.0f;
        if (rtmp > 1.0f)
            rtmp = 1.0f;
        if (rtmp < -1.0f)
            rtmp = -1.0f;
        
        // write output
        leftData[n] = ltmp;
        rightData[n] = rtmp;
        
        // advance pointers
        if (lrp == delayBufferLength)
            lrp = 0;
        else
            ++lrp;
        if (lwp == delayBufferLength)
            lwp = 0;
        else
            ++lwp;
        if (rrp == delayBufferLength)
            rrp = 0;
        else
            ++rrp;
        if (rwp == delayBufferLength)
            rwp = 0;
        else
            ++rwp;
    }
    
    // update delay buffer pointers
    leftReadPosition = lrp;
    leftWritePosition = lwp;
    rightReadPosition = rrp;
    rightWritePosition = rwp;
}