|
09-07-2018, 04:23 AM
|
#1
|
Human being with feelings
Join Date: Sep 2018
Posts: 6
|
(SOLVED) Filter Coeffs generates noise
Hello, everyone!
I have a question about my filter's coeffs. It's working as expected but generating big noise when changing parameters.
Sometimes everything works as expected and sometimes I can hear no signal.
I initialized everything and did all works as it should be.
Thanks!
Here is my code.
Filter .h file
Code:
class PM20Hz
{
private:
double xn;
double yn;
double xnm1,xnm2,xnm3,xnm4,xnm5,ynm1,ynm2,ynm3,ynm4,ynm5;
double a0;
double a1;
double a2;
double a3;
double a4;
double b0;
double b1;
double b2;
double b3;
double b4;
public:
PM20Hz();
double fs;
double LB;
double LC;
void Calc(double fs, double LB, double LC); // Calculation
double Process(double SamplesIn);
};
Filter .cpp file
Code:
PM20Hz::PM20Hz()
{
a0 = a1 = a2 = a3 = a4 = b0 = b1 = b2 = b3 = b4 = 0.0;
xnm1 = xnm2 = xnm3 = xnm4 = xnm5 = ynm1 = ynm2 = ynm3 = ynm4 = ynm5 = 0.0;
xn = yn = 0.0;
}
void PM20Hz::Calc(double fs, double LB, double LC) // Calculation for the Process function
{
b0 = LB*(LC*(fs*(fs*(fs*(2.12420903002314e-20*fs + 1.51473474053838e-15) + 2.3753674951497e-11) + 8.17473621324202e-9) + 3.8402275729308e-6) + fs*(fs*(1.32929225908832e-18*fs + 9.47894080437029e-14) + 1.48624306962906e-9) + 4.95969476401874e-7) + LC*fs*(fs*(6.68578946878742e-19*fs + 4.74470993710557e-14) + 7.31334899956211e-10) + fs*(4.18384822827747e-17*fs + 2.96915515463426e-12) + 4.5765638295132e-8;
b1 = LB*(LC*(fs*(pow(fs,2)*(-8.49683612009257e-20*fs - 3.02946948107675e-15) + 1.6349472426484e-8) + 1.53609102917232e-5) + fs*(-2.65858451817664e-18*pow(fs,2) + 2.97248613925812e-9) + 1.98387790560749e-6) + LC*fs*(-1.33715789375748e-18*pow(fs,2) + 1.46266979991242e-9) + 5.93831030926853e-12*fs + 1.83062553180528e-7;
b2 = LB*(LC*(pow(fs,2)*(1.27452541801389e-19*pow(fs,2) - 4.75073499029941e-11) + 2.30413654375848e-5) - 1.89578816087406e-13*pow(fs,2) + 2.97581685841124e-6) - 9.48941987421113e-14*LC*pow(fs,2) - 8.36769645655494e-17*pow(fs,2) + 2.74593829770792e-7;
b3 = LB*(LC*(fs*(pow(fs,2)*(-8.49683612009257e-20*fs + 3.02946948107675e-15) - 1.6349472426484e-8) + 1.53609102917232e-5) + fs*(2.65858451817664e-18*pow(fs,2) - 2.97248613925812e-9) + 1.98387790560749e-6) + LC*fs*(1.33715789375748e-18*pow(fs,2) - 1.46266979991242e-9) - 5.93831030926853e-12*fs + 1.83062553180528e-7;
b4 = LB*(LC*(fs*(fs*(fs*(2.12420903002314e-20*fs - 1.51473474053838e-15) + 2.3753674951497e-11) - 8.17473621324202e-9) + 3.8402275729308e-6) + fs*(fs*(-1.32929225908832e-18*fs + 9.47894080437029e-14) - 1.48624306962906e-9) + 4.95969476401874e-7) + LC*fs*(fs*(-6.68578946878742e-19*fs + 4.74470993710557e-14) - 7.31334899956211e-10) + fs*(4.18384822827747e-17*fs - 2.96915515463426e-12) + 4.5765638295132e-8;
a0 = LB*(LC*(fs*(fs*(fs*(2.51450991644449e-19*fs + 1.79746853668155e-14) + 2.84278668562303e-10) + 1.42392809694474e-7) + 3.84022757379678e-6) + fs*(fs*(1.57353561729942e-17*fs + 1.11714546376725e-12) + 1.7244520548944e-8) + 4.95969476503549e-7) + LC*(fs*(fs*(7.91423239470125e-18*fs + 5.65511767200454e-13) + 8.9311647378858e-9) + 4.22441374416313e-6) + fs*(4.95258597916222e-16*fs + 3.51470493924364e-11) + 5.41745667229674e-7;
a1 = LB*(LC*(fs*(pow(fs,2)*(-1.00580396657779e-18*fs - 3.59493707336311e-14) + 2.84785619388949e-7) + 1.53609102951871e-5) + fs*(-3.14707123459885e-17*pow(fs,2) + 3.44890410978879e-8) + 1.98387790601419e-6) + LC*(fs*(-1.58284647894025e-17*pow(fs,2) + 1.78623294757716e-8) + 1.68976549766525e-5) + 7.02940987848727e-11*fs + 2.1669826689187e-6;
a2 = LB*(LC*(pow(fs,2)*(1.50870594986669e-18*pow(fs,2) - 5.68557337124606e-10) + 2.30413654427807e-5) - 2.23429092753449e-12*pow(fs,2) + 2.97581685902129e-6) + LC*(-1.13102353440091e-12*pow(fs,2) + 2.53464824649788e-5) - 9.90517195832444e-16*pow(fs,2) + 3.25047400337804e-6;
a3 = LB*(LC*(fs*(pow(fs,2)*(-1.00580396657779e-18*fs + 3.59493707336311e-14) - 2.84785619388949e-7) + 1.53609102951871e-5) + fs*(3.14707123459885e-17*pow(fs,2) - 3.44890410978879e-8) + 1.98387790601419e-6) + LC*(fs*(1.58284647894025e-17*pow(fs,2) - 1.78623294757716e-8) + 1.68976549766525e-5) - 7.02940987848727e-11*fs + 2.1669826689187e-6;
a4 = LB*(LC*(fs*(fs*(fs*(2.51450991644449e-19*fs - 1.79746853668155e-14) + 2.84278668562303e-10) - 1.42392809694474e-7) + 3.84022757379678e-6) + fs*(fs*(-1.57353561729942e-17*fs + 1.11714546376725e-12) - 1.7244520548944e-8) + 4.95969476503549e-7) + LC*(fs*(fs*(-7.91423239470125e-18*fs + 5.65511767200454e-13) - 8.9311647378858e-9) + 4.22441374416313e-6) + fs*(4.95258597916222e-16*fs - 3.51470493924364e-11) + 5.41745667229674e-7;
}
double PM20Hz::Process(double SamplesIn)
{
xn = SamplesIn;
yn = (b0*xn + b1*xnm1 + b2*xnm2 + b3*xnm3 + b4*xnm4 - a1*ynm1 - a2*ynm2 - a3*ynm3 - a4*ynm4) / a0;
xnm4 = xnm3;
xnm3 = xnm2;
xnm2 = xnm1;
xnm1 = xn;
ynm4 = ynm3;
ynm3 = ynm2;
ynm2 = ynm1;
ynm1 = yn;
return yn;
}
Plugin .h file
Code:
PM20Hz mPM20Hz;
double mProcess;
Plugin .cpp file
Code:
//Initialize//
Test::Test(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mLBoost(0.0), mLAtten(0.0)
//Processing//
*out1 = mPM20Hz.Process(*in1);
Last edited by von; 09-09-2018 at 01:31 AM.
|
|
|
09-08-2018, 06:57 AM
|
#2
|
Human being with feelings
Join Date: Sep 2018
Posts: 6
|
No help for newbie?
|
|
|
09-08-2018, 07:34 AM
|
#3
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Are you locking the IPlug mutex (or using your own mutex) when changing the filter parameters?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
09-08-2018, 07:39 AM
|
#4
|
Human being with feelings
Join Date: Sep 2018
Posts: 6
|
Quote:
Originally Posted by Xenakios
Are you locking the IPlug mutex (or using your own mutex) when changing the filter parameters?
|
Thanks for reply!
How to lock?
Like this?
Code:
void Test::Reset()
{
TRACE;
IMutexLock lock(this);
mLBoost = GetParam(kLBoost)->Value();
mLAtten = GetParam(kLAtten)->Value();
}
|
|
|
09-08-2018, 07:48 AM
|
#5
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Right, put the IMutexLock lock(this); at the top of your OnParamChange function where I am assuming you call your filter's Calc method.
That might not necessarily help, though. Many simple filter codes just do not like their parameters changed while streaming audio through them. If that is the case, you will need to use some different kind of filter code that has been designed for dynamic parameter changes.
Your code also would appear to be incompatible for stereo and higher channel counts processing. You only have one filter object instance, which allows you to only do mono processing. If pass stereo channels through that single instance, it will also cause audio glitches.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Last edited by Xenakios; 09-08-2018 at 07:56 AM.
|
|
|
09-08-2018, 08:03 AM
|
#6
|
Human being with feelings
Join Date: Sep 2018
Posts: 6
|
Quote:
Originally Posted by Xenakios
Right, put the IMutexLock lock(this); at the top of your OnParamChange function where I am assuming you call your filter's Calc method.
That might not necessarily help, though. Many simple filter codes just do not like their parameters changed while streaming audio through them. If that is the case, you will need to use some different kind of filter code that has been designed for dynamic parameter changes.
Your code also would appear to be incompatible for stereo and higher channel counts processing. You only have one filter object instance, which allows you to only do mono processing. If pass stereo channels through that single instance, it will also cause audio glitches.
|
I tried mono or stereo but no luck.
Also i followed this thread. His problem gone after buffer initialize. How about my code? Did i initialize buffers correctly?
https://forum.cockos.com/showthread....ghlight=filter
|
|
|
09-09-2018, 01:31 AM
|
#7
|
Human being with feelings
Join Date: Sep 2018
Posts: 6
|
Fixed with this smoother from MusicDSP.
Code:
class CParamSmooth
{
public:
CParamSmooth() { a = 0.99f; b = 1.f - a; z = 0; };
~CParamSmooth();
inline float Process(float in) { z = (in * b) + (z * a); return z; }
private:
float a, b, z;
};
Thanks for all helps!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:17 PM.
|