Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fb combfilters: generalize/optimize feed-back comb filters #218

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oleg-nesterov
Copy link
Contributor

If this PR is accepted, I'll try to do more similar changes (fbcombfilter, allpass_comb, and ff_comb).

The next patch will add the users of the new funtion.
To ensure this patch is correct I used the following test-case

	maxdel = 10;
	N = 7.5; b0 = 1/2; aN = 1/3;

	maxerr = abs : max~_;

	// Old implementations before this patch
	o_fb_comb(maxdel,N,b0,aN) = (+ <: de.delay(maxdel,N-1),_) ~ *(-aN) : !,*(b0) : mem;
	o_fb_fcomb(maxdel,N,b0,aN) = (+ <: de.fdelay(maxdel,float(N)-1.0),_) ~ *(-aN) : !,*(b0) : mem;

	process = no.noise <:
		fi.fb_comb(maxdel,N,b0,aN)
		-o_fb_comb(maxdel,N,b0,aN),

		fi.fb_fcomb(maxdel,N,b0,aN)
		-o_fb_fcomb(maxdel,N,b0,aN)

		: par(i,2,maxerr);

compiled with "-a plot.cpp". Result:

	$ ./test-plot -n 1000000 | tail -n 1
	0		0

This patch makes the source code more understandable and the generated code
more efficient.

For example, the generated code for

	process = fi.fb_comb(15,10,1/3,1/4);

before this patch:

	// class variables
	float fVec0[10];
	float fRec0[2];
	float fRec1[2];
	int fSampleRate;

	void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs)
	{
		FAUSTFLOAT* input0 = inputs[0];
		FAUSTFLOAT* output0 = outputs[0];
		for (int i0 = 0; i0 < count; i0 = i0 + 1) {
			float fTemp0 = float(input0[i0]) - 0.25f * fRec0[1];
			fVec0[0] = fTemp0;
			fRec0[0] = fVec0[9];
			fRec1[0] = fTemp0;
			output0[i0] = FAUSTFLOAT(0.33333334f * fRec1[1]);
			for (int j0 = 9; j0 > 0; j0 = j0 - 1) {
				fVec0[j0] = fVec0[j0 - 1];
			}
			fRec0[1] = fRec0[0];
			fRec1[1] = fRec1[0];
		}
	}

after this patch:

	// class variables
	float fRec0[11];
	int fSampleRate;

	void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs)
	{
		FAUSTFLOAT* input0 = inputs[0];
		FAUSTFLOAT* output0 = outputs[0];
		for (int i0 = 0; i0 < count; i0 = i0 + 1) {
			fRec0[0] = 0.33333334f * float(input0[i0]) - 0.25f * fRec0[10];
			output0[i0] = FAUSTFLOAT(fRec0[1]);
			for (int j0 = 10; j0 > 0; j0 = j0 - 1) {
				fRec0[j0] = fRec0[j0 - 1];
			}
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant