Different filters to the positive and negative portions of the wave in SNEX
-
The below is a basic waveshaper in SNEX.
How can we add a high shelf filter to the positive part of the sound wave and a low shelf filter to the negative part?
template <int NV> struct Wshpr { SNEX_NODE(Wshpr); float getSamples(float input) { input = Math.tanh(input * 10.0f); return input; } // Initialise the processing specs here void prepare(PrepareSpecs ps) { } // Reset the processing pipeline here void reset() { } // Process the signal here template <typename ProcessDataType> void process(ProcessDataType& data) { for(auto ch: data) { for(auto& s: data.toChannelData(ch)) { s = getSamples(s); } } } // Process the signal as frame here template <int C> void processFrame(span<float, C>& data) { for(auto& s: data) { s = getSamples(s); } } // Process the MIDI events here void handleHiseEvent(HiseEvent& e) { } // Use this function to setup the external data void setExternalData(const ExternalData& d, int index) { } template <int P> void setParameter(double v) { } };
-
Something like this:
if(input >= 0){ //apply positive processing } else{ //apply negative processing }
-
Yes of course.
There is a filter example in snippet browser, but I couldn't figure out how to add filter to sequence the processing like;
waveshaper >>>> filter
-
@orange ahh... lemme take a look at the snip
-
@orange Assuming you'll end up with two processing functions, probably something like
for (auto& s: data[ch]) { s = processWaveshaper(s); s = processFilter(s); }
-
process both filters for each sample input (so that the internal filter state is updated) and then return only one of the processed values based on the input's value sign. But how are you avoiding signal inconsistencies when jumping from one to the other?
-
@Christoph-Hart said in Different filters to the positive and negative portions of the wave in SNEX:
But how are you avoiding signal inconsistencies when jumping from one to the other?
I don't know if it's excessive not, but this inconsistency is what I was looking for :)
But somehow a basic snippet could be so helpful.
-
@orange Here's an example:
HiseSnippet 1549.3ocuV02SaaDF2FvsKYcSsR6emz8WUtqHZRgBkQaWgPxZzJgHLEUooIzg8Y7Ibtyx2Yfro9+6i09.rOL6av1yycNINjzWVzVopfumW+cOudrq0LQDK5TkfmkwzNNtK2OWFxTJYtia8iGlwbbuiWvPgNoUBkKb5tui6W6c.UoY4DKo8FlQUJVjiq6x+HRvs1JNle9qeXOZJUDxlPxw4DIOj8Z9.tdB09u7m3oocnQri4CpH8FuranTzRlJK.7rrWCmLZ3Ez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EUwMVTEexhp3lKphasnJ9zOth3KL2sPKGXmgAE48aaJBccaKvdGSerCCF4GAuq0t0AqUGSAZsKajbci43.9kv+XQx2No0+Q2nUcsjQObxYo+bEOMC5agMGjmwEZRuSdAQoyKB0janFtuInW62dZuC2us+MX9fcfkQ0dziH3yu3zTthQzIrQ63.IHvX1PEIgkypW6RIOZzRS+91+FX3mAa.qAdBr16JM4QLESeSqkwyXovn3pFLGEzeF8et8GRmtu931GEL5b8ZwoRpdjQeE+7jfDVZrukrZUBFOBSJsWNSWjKHpcHfIK0gj.JQTnVjXSnnDNFWOk4es7p+0VGVo8oY7pIC06wC7Xhuh7BBrAMFHM1kyb8AEAk1od8aJx3qvHILHwDhKeEgIIo3mKnokXcRwkFFehklijEq0wQpufTVLXn5eCt2mDAeUdEfpVk1bqfWB0Jg7bCy0fEB8vy1gt9Hvf.TsXYNwGEl+7F6P3OynC7wCeHd8Q6YEgBMg2mn9diw9Y9uXBNF10TfKlaHFCtF+fg.7+ip0lSffpHw3ppYhHH1ZM80uCJnuJiJdlIKtJHP0Pv7byAc2uKgcIzNOU2EDNhRYuBZDai77G+08IrYZQdiockql7pSsj.MSEYFWvtFt03cAQRo8AtsKIiIKeaxoJI.31ZPtHhc8L9LXTS83E4yMB0uLBA9a7Je+HYALgjbYEi9tcp637Oh1I.+.
You "just" have to implement your filter algorithms and manage per channel integrators (
ch
arg)