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

 Cockos Confederated Forums Bessel filter implementation
 Register Projects Search Today's Posts Mark Forums Read

 03-21-2011, 02:51 AM #1 Tale Mortal     Join Date: Jul 2008 Location: Holland Posts: 1,609 Bessel filter implementation Hi, I have added a low-pass Bessel filter (besselfilter.h) implementation using matched Z-transform to my WDL repository. I have extracted this implementation from from the source code of mkfilter. I have divided the implementation into three classes: one for calculating coefficients (WDL_BesselFilterCoeffs), one for the actual filter (WDL_BesselFilterStage), and a third class combining both (WDL_BesselFilter). Here are a couple of (pseudo) code examples of its use: Example #1: Code: ```// 8th order anti-alias filter #define WDL_BESSEL_FILTER_ORDER 8 #include "besselfilter.h" int oversampling = 8; WDL_BesselFilterCoeffs bessel; WDL_BesselFilterStage filter; bessel.Calc(0.5 / (double)oversampling); filter.Reset(); for (int i = 0; i < nFrames; ++i) { filter.Process(inputs[0][i], bessel.Coeffs()); outputs[0][i] = filter.Output(); }``` Example #2: Code: ```#include "besselfilter.h" int order = 4; int oversampling = 8; // 2 cascaded filters WDL_BesselFilterStage filter[2]; filter[0].Reset(); filter[1].Reset(); WDL_BesselFilterCoeffs coeffs; coeffs.Calc(0.5 / (double)oversampling, order); for (int i = 0; i < nFrames; ++i) { filter[0].Process(inputs[0][i], &coeffs); filter[1].Process(filter[0].Output(), &coeffs); outputs[0][i] = filter[1].Output(); }``` Example #3: Code: ```#include "besselfilter.h" int order = 8; int oversampling = 8; WDL_BesselFilter bessel; bessel.Calc(0.5 / (double)oversampling, order); bessel.Reset(); for (int i = 0; i < nFrames; ++i) { bessel.Process(inputs[0][i]); outputs[0][i] = bessel.Output(); }``` __________________ Combo Model F - JS mono_synth & libs - WDL.git (?) - "Oh, Rats!"
 03-21-2011, 03:01 AM #2 junioreq Mortal     Join Date: Aug 2008 Location: Buffalo NY Posts: 1,083 Tale this is Great! But the first thing that popped out was the oversampling.. Could this be "modded" to work on its own oversampling without the filter? Seems oversampling for distortions etc is just way over my head at the moment. Thanks for the class though, its so nice to have these things built in and ready for use. ~Rob.
 03-21-2011, 04:55 AM #3 olilarkin Mortal     Join Date: Apr 2009 Location: York, UK Posts: 683 wow, thanks for this tale! rob - the filter is part of the oversampling - you need to filter out frequencies above the nyquist when up or down sampling __________________ pMix | Endless Series V3 Shepard Tone Plugin | WDL-OL Plugin dev framework Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)
 03-26-2011, 03:22 PM #4 Tale Mortal     Join Date: Jul 2008 Location: Holland Posts: 1,609 I tried to include besselfilter.h in an Xcode project today, but my MacBook wouldn't build it because _hypot is supposed to be called hypot (although Microsoft seems to disagree). Anyway, this has now been fixed (see my Git repository). __________________ Combo Model F - JS mono_synth & libs - WDL.git (?) - "Oh, Rats!"
 09-18-2011, 06:38 AM #5 Tale Mortal     Join Date: Jul 2008 Location: Holland Posts: 1,609 Added denormal fix I have added the option to zero denormals in the output of the Bessel filter. I have also added an example using this filter for oversampling: Code: ```mAntiAlias.Calc(0.5 / (double)mOversampling); ... double sample = ; double output; for (int j = 0; j < mOversampling; ++j) { // Upsample if (j > 0) sample = 0.; mUpsample.Process(sample, mAntiAlias.Coeffs()); sample = (double)mOversampling * mUpsample.Output(); ... // Downsample mDownsample.Process(sample, mAntiAlias.Coeffs()); if (j == 0) output = mDownsample.Output(); } = output;``` The complete (working) example can be found in WDL/IPlug/Example/Distortion in my WDL Git repository. __________________ Combo Model F - JS mono_synth & libs - WDL.git (?) - "Oh, Rats!"
 10-20-2011, 01:42 AM #6 olilarkin Mortal     Join Date: Apr 2009 Location: York, UK Posts: 683 Do you get a dc offset/clicks when you change the drive amount in your example? __________________ pMix | Endless Series V3 Shepard Tone Plugin | WDL-OL Plugin dev framework Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)
10-20-2011, 04:55 AM   #7
Tale
Mortal

Join Date: Jul 2008
Location: Holland
Posts: 1,609

Quote:
 Originally Posted by olilarkin Do you get a dc offset/clicks when you change the drive amount in your example?
Yes. Adding a small DC offset and then removing it again is part of the distortion algorithm. I remove the DC offset again by sending the downsampled signal through a high-pass filter, which causes the clicks. I guess it would be better to simply substract the distorted DC offset:

Code:
```// Distortion
if (WDL_DENORMAL_OR_ZERO_DOUBLE_AGGRESSIVE(&sample))
sample = mSilence;
else
sample = mGain * fast_tanh(mDC + mDrive * sample);

sample -= mSilence;```
Of course this can be further optimized, and the high-pass filter can then be removed altogether. It will still use a tiny bit more CPU than the original version, but there will be no more clicks.

EDIT: I have updated the distortion example in my Git repository (currently on the "next" branch).

Last edited by Tale; 10-20-2011 at 05:28 AM. Reason: Updated Git repository

11-06-2011, 04:30 AM   #8
Mich
Mortal

Join Date: May 2009
Posts: 1,265

Quote:
 Originally Posted by Tale I tried to include besselfilter.h in an Xcode project today, but my MacBook wouldn't build it because _hypot is supposed to be called hypot (although Microsoft seems to disagree).
It is supposed to be called hypot() according to the ANSI C99 standard.
But Microsoft is somewhat confused about it.
__________________
Quote:
 Originally Posted by vBulletin Message Sorry pipelineaudio is a moderator/admin and you are not allowed to ignore him or her.

 07-24-2012, 02:55 AM #9 onqel Mortal     Join Date: Jun 2007 Location: Tromsø, Norway Posts: 215 I tried this on one of my high gain ampsims, it can't compete with my original polyphase approach unfortunately (for 2X/4X oversampling), aliasing all over the place.. I tried order up to 10 Last edited by onqel; 07-24-2012 at 03:06 AM.
 07-24-2012, 06:48 AM #10 Tale Mortal     Join Date: Jul 2008 Location: Holland Posts: 1,609 Yeah, polyphase should surely give you better quality, but the Bessel filter is probably less CPU costly (I hope so anyway). I use 6 consecutive 4th order Bessel filters with 64x oversampling to suppress aliases on naive waveforms, with virtually no audible aliasing. Then again, polyphase might also work just as well in my specific case, but I haven't been able to really wrap my head around it yet. __________________ Combo Model F - JS mono_synth & libs - WDL.git (?) - "Oh, Rats!"
 11-30-2012, 07:44 AM #11 random_id Mortal     Join Date: May 2012 Location: PA, USA Posts: 98 Thank you for your oversampling Distortion sample. I am trying to implement oversampling in my own plugin and I have two questions (due to my extremely small math/dsp brain). 1. When changing oversampling from 4X, 8X, 16X, etc., should you also change the WDL_BESSEL_FILTER_ORDER? In your example, you have this set to 8, and oversampling set to 8X. I think this determines the filter order and would not be related to the oversampling. 2. You mention DC offset. Is this inherent to the oversampling process? I know that you solved it in your example by subtracting out a similar value. Thanks __________________ Website: LVC-Audio
11-30-2012, 08:18 AM   #12
Tale
Mortal

Join Date: Jul 2008
Location: Holland
Posts: 1,609

Quote:
 Originally Posted by random_id 1. When changing oversampling from 4X, 8X, 16X, etc., should you also change the WDL_BESSEL_FILTER_ORDER? In your example, you have this set to 8, and oversampling set to 8X. I think this determines the filter order and would not be related to the oversampling.
The filter order and oversampling are not related. In my example both the oversampling and the filter order happen to be 8, but you could just as well use a filter order of 8 with 16x oversampling (or whatever other combination suits your purpose).

Quote:
 Originally Posted by random_id 2. You mention DC offset. Is this inherent to the oversampling process? I know that you solved it in your example by subtracting out a similar value.
The DC offset is part of the distortion algorithm, not the oversampling process.

 11-30-2012, 08:40 AM #13 random_id Mortal     Join Date: May 2012 Location: PA, USA Posts: 98 Thanks for responding to my ignorance. __________________ Website: LVC-Audio

 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 BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home General Discussion     General Discussion (aka spam trap) REAPER Forums     REAPER General Discussion Forum     REAPER OS X Forum     REAPER Color Themes and Icon Sets     REAPER Q&A, Tips, Tricks and Howto     REAPER Compatibility     REAPER Bug Reports     REAPER Feature Requests     REAPER Non-English Speaking User Forums         Forum de REAPER en français         Foro de REAPER en Español         Fórum do REAPER em português         Forum di REAPER in italiano         Deutschsprachiges REAPER Userforum     Dstruct's Casa De Nitpicks     Recording Technologies and Techniques     MIDI and other music/audio protocols     JS and ReaScript Discussion     REAPER Music/Collaboration Discussion     newbieland     REAPER Developer Forum     REAPER Pre-Release Discussion     REAPER lounge NINJAM Discussion     User Discussion     NINJAM Developer Discussion Cockos and Friends Software Discussion     WDL users forum     LICEcap Discussion     SnapEase Discussion     PathSync Discussion     Assniffer Discussion     TunnelVision Discussion     LanMon Discussion     Debris Discussion     Wifight Discussion     The Camel Farm     Stashbox & Shup

All times are GMT -7. The time now is 05:47 PM.

 -- Cockos ---- Reaper 3 ---- Reaper 2 ---- Reaper 1 Contact Us - Cockos Incorporated - Archive - Top