-
Notifications
You must be signed in to change notification settings - Fork 384
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
Container of filters. How ? #21
Comments
Probably no longer relevant, but you cannot create a container containing child classes of polymorphic classes, you have to use pointers, e.g. |
I found another solution for this problem -don't remember which one though- but thanks for the hint ! :) |
So is there some elegant way to create a universal container for all the filter types so that data locality is preserved? One of the main problems in realtime systems is data access speed so one has to avoid creating objects on the heap. |
@1eqinfinity I would use a tagged union with needed template instances. Not very elegant but very local and thus fast, also no virtual functions would be used. Another hack is to make an oversized fake child class. But you'll have to control that you don't put large objects to your vector. If you really need polymorphism and don't like hacks, you could use bumping pointer allocator to allocate objects in stack-like pool instead of heap. This pool could be allocated on stack itself. So you'll have to use pointers and virtual functions but the data are stored locally. |
Does it really matter if the object is on the stack or heap once it is created? I mean, you do not create those filter objects in your inner loops, you create them once at startup. If you create them all at the same time, chances are also high that they are all placed next to each other in memory. |
@galchinsky @sagamusix Thank you! @sagamusix I must not place filters into array, but right now I'm trying to place them as members of objects that are arranged in an array. I sure don't create filters in tight loops but want to use them in realtime audio. I know that they will anyway be cached, but even rarely fetching them from the heap doesn't look good to me. |
Sooo... I had some hard time setting up correct building and linking properties in my VS15 solution, but it compiles now. Thanks to @vinniefalco for leaving a note about VS linking bug, it was a nice starting point.
So my guess is that if one wants to use, say, Right now I'm trying to figure out the biggest filter type during compilation to avoid templatization of the aggregating class, but I'm not sure that my beard is long enough. |
Before you go through all the hassle of this - did you verify that just allocating each filter separately and putting pointers into a vector is indeed too slow for your scenario? You know, don't optimize where there is nothing to optimize... ;) |
I totally get what you mean and agree with you that I should measure first. It is easy to run basic things and get real performance numbers right away with just one selected filter type. I'll do it even out of sheer interest. |
Fair enough, doing things for exercise and out of interest is of course nice. |
DSPFilters is not intended as the end-all of IIR filtering, it offers reasonable performance and a launch pad for people who want to get into filtering. As @sagamusix said, you will always get better results hand-rolling code. |
Yep, writing my filters... after some self-educating in this area I'm past the time when this idea scared me, but still there's a lot of work, and Vinnie already did most of what I need. Perhaps writing my own stuff based on Vinnie's is what I should do. |
There's no need for a synth to type-erase the filter, or to support changing the order at run-time. |
So I ran the performance tests o_O Btw, my naive assumption that using polymorphic classes with the biggest flt as a container would work appeared to be wrong for release builds: got memory errors on most of the methods calls after the compiler's optimizations. I used 32 fixed type (Chebyshev II 4-th order LPF) filters, ran the test for 1 minute with continuous per-sample cut-off frequency modulation, on 48KHz sr.
The difference is insignificant. Because the optimizations were so good and/or because the rest of my code is so amazingly good/bad. So if there's only one parameter that needs to be modulated, Dsp::Filter could be extended with methods such as |
Hi,
Nice project but I'm stumbling on a problem. The class SimpleFilter is template and has no non-template base which makes impossible to put it in a container.
I tried to make a container of Filter and use "new Dsp::SmoothedFilterDesign Dsp::RBJ::Design::LowPass,2,Dsp::DirectFormI(1024);" to populate it but my sound is completely garbled ! Does anyone knows how can I do ?
The text was updated successfully, but these errors were encountered: