A Collection of Useful C++ Classes for Signal Processing

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi, I'm just getting my feet wet with you DspFilter lib. This looks very nice, but I'm a bit confused and I can't find a simple example for what I want to do. Basically I have an input vector which I need to process in place with a butterworth filter.

The input, named segment_ is a std::vector<double> type, and it holds 1 channel of data.

I got this far:

Dsp::SimpleFilter<Dsp::Butterworth::HighPass<2>, 1> filter_;

filter_.setup(2, samplerate_, 1000);

filter_.process(segment_.size(), (double * const*)&segment_[0]);

When I run this I get an bad access exception.

I must be doing something stupid. Can you spot the problem? :help:

Also if I want to change the filter type at runtime from low to highpass, what do I store in my program? A pointer to a what generic type?

Post

0x80 wrote:filter_.process(segment_.size(), (double * const*)&segment_[0]);
Yeah you can't do that. process() wants an array of pointers. Remove the cast and fix the compile error. For example:
double* channels [1];
channels[0] = &segment_ [0];
filter_.process(segment_.size(), channels);

Post

Aha that makes sense. Thanks I got it working now:)

When dealing with multiple channels my input and output data will be interleaved. Is there a way to work (in place) with interleaved channel data or do I need to convert it to separate channels and back?

Post

0x80 wrote:Is there a way to work (in place) with interleaved channel data or do I need to convert it to separate channels and back?
You have to convert. Routines are provided in DSPFilters for doing this for you.

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Hi all, first of all I love the DSPFilter collection for it's ease of implementation and performance. I'm using it to create octave band filters. The ANSI specification defines the limits of the filters and trying to get within that specification. I'm currently using a 4th order Besselworth filter. I setup the filter as follows:

Code: Select all (#)

Dsp::Filter* f = new Dsp::SmoothedFilterDesign
        <Dsp::Butterworth::Design::BandPass <4>, 1, Dsp::DirectFormII> (numberOfSamples);
        
Dsp::Params params;
params[0] = samplingRate; // sample rate
params[1] = 4; // order
params[2] = centerFrequency; // center frequency
params[3] = bandWidth; // band width
f->setParams (params);
Now when I test this filter with a frequency sweep I get the following result:

http://db.tt/jxsuaM7C (http://db.tt/jxsuaM7C)

1. First of all the center frequency seems to be off. In this example I set it to 1000 Hz with a bandwidth of 707.106812 Hz.

2. The dropoff is not what I would expect from a Butterworth filter (maybe caused by cascading 2nd order filters?)

3. How could I improve this?

Post

I just wanted to drop a quick note here as I saw previous posters struggle with getting this to build with linker errors.

The "Download Now" button on the site is an old build (which is the one your most likely trying to build and then include the libs.)

If you download the updated version via the "ZIP" button via GitHub, it will allow you to include 2 files without any libs and build just fine.

Just thought I'd post this as I struggled at first to figure out where these files were that were being referred to in this thread, and then realized that the "Download Now" zip file is out of date.

Enjoy!

Brett

Post

Yep, and to make things worse Github has removed the "download" feature so I can't update those files. They will disappear soon (because of Github).

Post

Hello. First of all, thanks for supplying such a wide variety of filters and source ready to drop in. I had been searching for an LPF to handle noise from upsampling and was very happy to find your code project.

I was not able to use the examples from documentation.cpp as they produced compile errors and was wondering if they were out of date? For example, these 2 lines from the sample do not compile for me under VS 2008:

Dsp::SmoothedFilterDesign <Dsp::RBJ::Design::LowPass, 2> f (1024);
Dsp::Filter* f = new Dsp::SmoothedFilterDesign <Dsp::Butterworth::Design::BandPass <4>, 2, Dsp::DirectFormII> (1024);

These 2 do:

Dsp::Filter* f = new Dsp::FilterDesign <Dsp::Butterworth::Design::LowPass <LPF_ORDER>, 1>;
Dsp::Filter* f = new Dsp::FilterDesign <Dsp::Butterworth::Design::LowPass <LPF_ORDER>, 1, Dsp::DirectFormII>;

Perhaps an issue with SmoothedFilterDesign or my setup? I'm thinking something may have changed since the time documentation.cpp was written.

From some of the posts I've read, it seems I am not alone in being naive in the understanding of filters. I would greatly appreciate setup sample code for all the filters as it does not seem straightforward or rather not straightforward to someone that isn't fluent in filter design. For example, since the params are generic, the "order" param can be in any position. I wanted to try different LPF filters to see which I might prefer for general use but it seems necessary to dive into the code to suss it out. Filter::getParamInfo() sounded useful but I couldn't get the syntax to use it it. Also, I don't know what Direct Form II realization is but I liked the result better on my test case.

If I missed any of this in the documentation, I apologize. Perhaps I should have made the subject should be clues for the clueless. There are several more filters I'd like to use. Filtering is a necessity for the project I'm working on. I'm hoping I can just drop in the ones that work best for my needs (being lazy by nature). I'm willing to learn more but it's clear that I am not likely to ever have a full understanding of the subject and I greatly appreciate the work done to make these filters available to everyone.

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Hi! Can you help me? i have got a problem with including dspfilters files to my project in vs2012.
The following method

Code: Select all (#)

I suppose I should make things more clear. 

 There are no libraries...you just add the one source file dsp_filters.cpp to your project, and that's it!
is causing the link error 2005:

Code: Select all (#)

Spectrum.obj : error LNK2005: "public: class std::vector<struct Dsp::PoleZeroPair,class std::allocator<struct Dsp::PoleZeroPair> > __thiscall Dsp::Cascade::getPoleZeros(void)const " (?getPoleZeros@Cascade@Dsp@@$$FQBE?AV?$vector@UPoleZeroPair@Dsp@@V?$allocator@UPoleZeroPair@Dsp@@@std@@@std@@XZ) already defined in dsp_filters.obj
i have tried to disaple precompiled headers but it does not produce any effect.
what i should to do to avoid this error?

Post

Eric56 wrote:Hi! Can you help me? i have got a problem with including dspfilters files to my project in vs2012.
The following method

Code: Select all

I suppose I should make things more clear. 

 There are no libraries...you just add the one source file dsp_filters.cpp to your project, and that's it!
is causing the link error 2005:

Code: Select all

Spectrum.obj : error LNK2005: "public: class std::vector<struct Dsp::PoleZeroPair,class std::allocator<struct Dsp::PoleZeroPair> > __thiscall Dsp::Cascade::getPoleZeros(void)const " (?getPoleZeros@Cascade@Dsp@@$$FQBE?AV?$vector@UPoleZeroPair@Dsp@@V?$allocator@UPoleZeroPair@Dsp@@@std@@@std@@XZ) already defined in dsp_filters.obj
i have tried to disaple precompiled headers but it does not produce any effect.
what i should to do to avoid this error?
this error is typical when you include some .cpp into another .cpp file and compile and link both. i suppose "Spectrum.cpp" somehow includes "dsp_filters.cpp" (maybe indirectly via "Spectrum.h") and both files get compiled. the remedy is to either get rid of of the inclusion of the dsp_filters.cpp file (and include a corresponding .h file instead) or the exclude dsp_filters.cpp from the build (right-click on the file, open the "Properties" and set "Excluded From Build" to "Yes" - a red sign appears on top of the icon of the file)
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Just found out about this, and I wanted to say thanks. I'll be checking it out in the next days, but as a software engineer, I can say I really like some of the design decisions from the README.md.

Post

Not sure if its bad form to ask such a basic question.

I am interested in using your wonderful filter library.
However I have so far only ever included single .cpp/.h files when I have wanted to use a library that someone else has created.

Building the DSPFilters.xcodeproj works fine for me with no errors.

I am working in Xcode and would like to include your filter library in my future work as it looks so thorough.

However I am not sure how to add all the files to... for example my vst iplug project or an openframeworks iphone template project etc.

There is a source folder and a include folder with the DspFilter folder.
I can see that the source folder contains all the .cpp files and the DspFilter folder includes all the .h files

I understand that to include all of your dsp library in my Application.h file I should write #include Dsp.h
or for example in my VST I should write #include Dsp.h in my MyPlugin.h

However I don't know how to correctly add the DSPFilter folder and Source folder to my Xcode project.

Apologies for asking such a basic question but the libraries that I have used so far have just been in a .cpp/.h format and I have just had to drag them (add them) into the top part of the navigator area and make such they are added and them included in my App/vst.

Any guidance appreciated
thanks
GEoff

Post

Hi Guys, hi Vinn

First of all: Really GREEEAAAAAT WORK! Thank you for this awesome collection!

i have a question about implementation in VST framework(s).

Is my method the right method? Or are there other methods?

Code: Select all



Dsp::Filter* f = new Dsp::SmoothedFilterDesign <Dsp::RBJ::Design::LowPass, 2> (1024);


void DSPFILTERTEST::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  
  double fs = (double) GetSampleRate();

  double *filteredInput[2];
  
  filteredInput[0] = new double[nFrames];
  filteredInput[1] = new double[nFrames];
  
  filteredInput[0] = *inputs;
  filteredInput[1] = *inputs;
 

    Dsp::Params params;
    params[0] = fs; // sample rate
    params[1] = mFreq; // cutoff frequency
    params[2] = 1.25; // Q
    f->setParams (params);
    f->process (nFrames, filteredInput);

    // Normally here is a while or for statement. Is it necessary in your code?

    outputs[0] = filteredInput[0];
    outputs[1] = filteredInput[1];


}
Seems it works all.
Some people can feel the rain,while others are just wet.

Post

cisdsp wrote:Hi Guys, hi Vinn

First of all: Really GREEEAAAAAT WORK! Thank you for this awesome collection!

i have a question about implementation in VST framework(s).

Is my method the right method? Or are there other methods?

Code: Select all



Dsp::Filter* f = new Dsp::SmoothedFilterDesign <Dsp::RBJ::Design::LowPass, 2> (1024);


void DSPFILTERTEST::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  
  double fs = (double) GetSampleRate();

  double *filteredInput[2];
  
  filteredInput[0] = new double[nFrames];
  filteredInput[1] = new double[nFrames];
  
  filteredInput[0] = *inputs;
  filteredInput[1] = *inputs;
 

    Dsp::Params params;
    params[0] = fs; // sample rate
    params[1] = mFreq; // cutoff frequency
    params[2] = 1.25; // Q
    f->setParams (params);
    f->process (nFrames, filteredInput);

    // Normally here is a while or for statement. Is it necessary in your code?

    outputs[0] = filteredInput[0];
    outputs[1] = filteredInput[1];


}
Seems it works all.
The processing part looks fine, but..

You've got quite the memory leak there. Regardless, you don't want to allocate memory inside the processing block. Dynamic memory allocation is relatively slow, so putting it inside a block that gets called repeatedly many many times is a waste.

Most allocation, declaration and initializing of objects should go in resume() (e.g. updating the sample rate) unless it needs to go in the process block (updating frequency and Q). The processing block should be as lean as possible for performance reasons.

And remember to delete objects created with new. :)

Post

The processing part looks fine, but..

You've got quite the memory leak there. Regardless, you don't want to allocate memory inside the processing block. Dynamic memory allocation is relatively slow, so putting it inside a block that gets called repeatedly many many times is a waste.

Most allocation, declaration and initializing of objects should go in resume() (e.g. updating the sample rate) unless it needs to go in the process block (updating frequency and Q). The processing block should be as lean as possible for performance reasons.

And remember to delete objects created with new.
Thanks for this.


resume() is the word of the day :)
I started using IPlug because it's very easy and has very very easy GUI handling. I haven't found out 'til now if there's a resume() in there :roll:

Can you give me maybe a hint how to delete the "new" stuff? I thought must not delete the object " filteredInput[0] = new double[nFrames];" - for example...

I asked about implementations because of following situation:

I did a four Band Filter with HP and LP with the RBJ Filterclass. This was very easy and fast done. In the Process Block for example

Code: Select all

for(i = 0; ......) {
outLeft = HiPass->process(LowShelf->process(Peak1->process(Peak2->process(HiShelf->process(LowPass->process(inLeft))))));
}
Really easy to implement.

With Vinn's Classes it's a little different :shock:

I have to figure out how this works.


PS: I hope I'm not confusing you [/code][/quote]
Some people can feel the rain,while others are just wet.

Post Reply

Return to “DSP and Plugin Development”