COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 01-05-2017, 07:11 AM   #1
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default This Biquad Filter into IPlugEffect(Denormals - Samplerate - Buffer)

I want to implement Biquad Filter into IPlugEffect.(IPlugEffect is my starting point everytime.)

Downloaded from http://www.earlevel.com/main/2012/11...c-source-code/

Everything is ok but gain is really strange.

And i saw this in comments.Can you explain me how can i implement this Biquad Filter (or any filter) to IPlugEffect.

Hallo, Nigel.
An impressive code and i managed to implement it in my first vst plugin. Thank you for sharing! I don’t have much of programming experience, except for some small stuff in c++ and also ActionScript way back, so i am still quite the newbie.

The only problem is that, i can hear a lot of artifacts being added to the signal, already at +1db. I read some of the other comments, where the same problem is mentioned. Obviously nothing is clipping and i have the Filter creation seperated from the processing part. I am modulating the variables there also, which, as i read in your comment, is not really suggested.

Filter_5->setPeakGain(mFilter_5 * 100);
*output = Filter_5->process(*output);

and i defined the Variable like this:
GetParam(mFilter_5)->InitDouble(“Hi Mids”, 0, -12, 12, 0.1);

I had to multiply it with 100, for it to work at all, which is what i also don’t really understand, because the value should be given in in dB, not in dB * 100, right?

Or should i try getting my feet wet with oversampling?

Reply
Nigel Redmon says:
April 18, 2016 at 1:38 pm
Your message (and the follow-up attempt) were kicked to the spam folder—I’m not sure why offhand.

OK, it’s clear you’re using wdl with IPlug (wdl-ol or other). First, I assure you that the filter code works fine, and does not glitch or distort, so this is really an issue of debugging your first plugin. Your best bet is to get in an interactive discussion on a board like kvraudio, or the wdl discussion in the cockos forums. You’ll need to show a lot more of your code.

In a nutshell, be sure that you understand that the filter is instantiated in your initialization, that control changes (the setPeakGain call, for instance) are handled via your OnParamChange handler, and the process call is in your ProcessDoubleReplacing handler.

Last edited by Tunca; 01-05-2017 at 03:14 PM.
Tunca is offline   Reply With Quote
Old 01-05-2017, 01:50 PM   #2
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

Well...

I solved it! Now i can use my calculations!

But i need advice about sample rate and buffer size.How to set them?They are changing freqs and gain.How to set them to DAW and get always same freq and gain?

I'm using buffer size 128 and sample rate 44100.I'm hearing artifacts.When i change DAW's sample rate,freqs changing.

And if i change buffer size to bigger,artifacts gone but DAW can't handle and crashing.

Last edited by Tunca; 01-05-2017 at 02:21 PM.
Tunca is offline   Reply With Quote
Old 01-06-2017, 12:26 AM   #3
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Your plug-in's Reset() is called when the sample rate changes, so you will probably want to update the coefficients in Reset() as well as in OnParamChange().

Alternatively you could just set a flag in Reset() and OnParamChange(), and update the coefficients in ProcessDoubleReplacing() when this flag is set.
Tale is offline   Reply With Quote
Old 01-06-2017, 02:11 AM   #4
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

Quote:
Originally Posted by Tale View Post
Your plug-in's Reset() is called when the sample rate changes, so you will probably want to update the coefficients in Reset() as well as in OnParamChange().

Alternatively you could just set a flag in Reset() and OnParamChange(), and update the coefficients in ProcessDoubleReplacing() when this flag is set.
Thanks for reply.

But i can't understand...Tried with resample.h and resample.cpp but luck.

Can you explain me how to do this,please?
Tunca is offline   Reply With Quote
Old 01-06-2017, 12:23 PM   #5
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

I found how to resample it.

Used "void setSampleRate(float sampleRate);".Then wrote mSampleRate to where sample rate should be.

But now i guess i have problem about buffer size.Cause i'm hearing artifacts.

Last edited by Tunca; 01-06-2017 at 12:33 PM.
Tunca is offline   Reply With Quote
Old 01-06-2017, 02:55 PM   #6
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Are you running your plug-in in debug mode? Because that could cause artifacts. Biquad filters generally shouldn't use too much CPU (almost none, really)...
Tale is offline   Reply With Quote
Old 01-06-2017, 03:35 PM   #7
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

What do you mean by "running debug mode"?(sorry i'm newbie)

I guess i need to toggle Xcode to release mode,right?

I just compile IPlugEffect and running with Reaper.

When i use "mBlockSize" as buffer size,cpu going crazy.But if i set buffer size to small values in plugin,i'm getting artifacts.

Last edited by Tunca; 01-06-2017 at 03:46 PM.
Tunca is offline   Reply With Quote
Old 01-06-2017, 03:46 PM   #8
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

i guess,i just tried Release mode but still same...

I changed edited scheme and changed build congif. under "Run" to release but no luck.

Last edited by Tunca; 01-06-2017 at 03:55 PM.
Tunca is offline   Reply With Quote
Old 01-07-2017, 02:31 AM   #9
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Right, so you are running a release build now, good!

What exactly do you mean with setting a buffer size? To be clear: The host determines the buffer size (and sample rate), you just receive its value in Reset(). But I don't understand why would buffer size would be important for a biquad filter plug-in...

Maybe you can post some code? Or maybe, later on, I can post an simple example filter plug-in.
Tale is offline   Reply With Quote
Old 01-07-2017, 02:44 AM   #10
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

// filter a buffer of input samples, in-place
for (int idx = 0; idx < mBlockSize; idx++)
*out1 = filter2->process(filter1->process(in1[idx])),
*out2 = filter22->process(filter11->process(in2[idx]));

Here is processing section."mBlockSize" getting buffer size from host(i guess).But it causes artifacts.When i use bigger buffer size(1024 or more),DAW going crazy and chopping sound.If i use smaller buffer size,plugin working good but hearing artifcts.
Tunca is offline   Reply With Quote
Old 01-07-2017, 03:37 AM   #11
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Ah I see... You run that loop in ProcessDoubleReplacing(), right? Try this then (i.e. nFrames instead of mBlockSize):

Code:
for (int idx = 0; idx < nFrames; idx++)
Note that nFrames is not the same as mBlockSize. In fact, nFrames can be anything from 0 up to (and including) mBlockSize, and it can vary from call to call.
Tale is offline   Reply With Quote
Old 01-07-2017, 03:51 AM   #12
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

Yes,running in ProcessDoubleReplacing().

I already tried nFrames but still same.


IPlugEffect::~IPlugEffect() {}

void IPlugEffect::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
// Mutex is already locked for us.

double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];



void setSampleRate(float sampleRate);

for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2)
{
Biquad *filter1 = new Biquad(bq_type_peak, 200.0 / mSampleRate, 1.0, mGain1);
Biquad *filter2 = new Biquad(bq_type_highshelf, 6000.0 / mSampleRate, 5.0, mGain);
Biquad *filter11 = new Biquad(bq_type_peak, 200.0 / mSampleRate, 1.0, mGain1);
Biquad *filter22 = new Biquad(bq_type_highshelf, 6000.0 / mSampleRate, 5.0, mGain);

// filter a buffer of input samples, in-place
for (int idx = 0; idx < nFrames; idx++)
*out1 = filter2->process(filter1->process(in1[idx])),
*out2 = filter22->process(filter11->process(in2[idx]));
}
}
Tunca is offline   Reply With Quote
Old 01-07-2017, 04:06 AM   #13
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

By the way is this buffer size problem or denormals?
Tunca is offline   Reply With Quote
Old 01-07-2017, 05:26 AM   #14
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

No, I think the problem is that you are creating new filter objects inside your sample loop, while you should create your filters in your plug-in's constructor.
Tale is offline   Reply With Quote
Old 01-07-2017, 06:15 AM   #15
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

https://dl.dropboxusercontent.com/u/...PlugEffect.zip

I added my project.Can you check and show where should i add filters,please?
Tunca is offline   Reply With Quote
Old 01-07-2017, 08:23 AM   #16
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by Tunca View Post
https://dl.dropboxusercontent.com/u/...PlugEffect.zip

I added my project.Can you check and show where should i add filters,please?
Yeah sure! Not tested, but I think this should work:

http://www.taletn.com/temp/20170107_...PlugEffect.zip
Tale is offline   Reply With Quote
Old 01-07-2017, 11:34 AM   #17
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

*out1 = filter2->process(filter1->process(*in1));
*out2 = filter22->process(filter11->process(*in2));

Says "use of undeclared indentifier "filter**"" for filters.Can't figure it out...

We initalized filters but which parameter will process audio?
Tunca is offline   Reply With Quote
Old 01-07-2017, 12:40 PM   #18
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Oops, my bad! That should have been:

Code:
      *out1 = mFilter2->process(mFilter1->process(*in1));
      *out2 = mFilter22->process(mFilter11->process(*in2));
Tale is offline   Reply With Quote
Old 01-07-2017, 12:49 PM   #19
Tunca
Human being with feelings
 
Join Date: Apr 2016
Posts: 264
Default

Man! Thank you so much!

But i used this

*out1 = mFilter2.process(mFilter1.process(*in1));
*out2 = mFilter22.process(mFilter11.process(*in2));

instead of this.

*out1 = mFilter2->process(mFilter1->process(*in1));
*out2 = mFilter22->process(mFilter11->process(*in2));

Used dot.

I understood how can i implement my filter calculations into C++.That's great!

Now i can start to build my first plugin.

Last edited by Tunca; 01-07-2017 at 12:54 PM.
Tunca is offline   Reply With Quote
Old 01-08-2017, 03:55 AM   #20
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by Tunca View Post
Man! Thank you so much!
You're welcome.

Quote:
Originally Posted by Tunca View Post
But i used this

*out1 = mFilter2.process(mFilter1.process(*in1));
*out2 = mFilter22.process(mFilter11.process(*in2));

instead of this.

*out1 = mFilter2->process(mFilter1->process(*in1));
*out2 = mFilter22->process(mFilter11->process(*in2));

Used dot.
Yes of course, the filters are now objects, not pointers, doh!

Quote:
Originally Posted by Tunca View Post
I understood how can i implement my filter calculations into C++.That's great!

Now i can start to build my first plugin.
Cool!
Tale is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.