HISE Logo Forum
    • Categories
    • Register
    • Login

    [Free Dsp] Analog Filter (24dB/oct)

    Scheduled Pinned Locked Moved ScriptNode
    19 Posts 10 Posters 1.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey @griffinboy
      last edited by

      @griffinboy said in Free Effect: Analog Filter for scriptnode (24dB/oct):

      Now restart hise, and you will be able to use the Node:

      I think the process has changed with the latest version of HISE?

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      griffinboyG 1 Reply Last reply Reply Quote 0
      • griffinboyG
        griffinboy @d.healey
        last edited by

        @d-healey

        Did it! I'm not on the latest version of hise, what is different? I should update

        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @griffinboy
          last edited by

          @griffinboy I'm basing my assumption on this thread - https://forum.hise.audio/topic/11731/scriptnode-compilation-workflow-and-what-to-do-about-it

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          Christoph HartC 1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart @d.healey
            last edited by

            Now restart hise, and you will be able to use the Node:

            Yes. it should read now:

            Now press OK and you will be able to use the node

            It's the small details :)

            griffinboyG 1 Reply Last reply Reply Quote 4
            • griffinboyG
              griffinboy @Christoph Hart
              last edited by

              @Christoph-Hart

              Nice update!

              ustkU 1 Reply Last reply Reply Quote 0
              • DabDabD
                DabDab @griffinboy
                last edited by

                @griffinboy Waiting for your Youtube Tutorials.

                Bollywood Music Producer and Trance Producer.

                1 Reply Last reply Reply Quote 1
                • ustkU
                  ustk @griffinboy
                  last edited by

                  @griffinboy Nice one! 👍 👍

                  Can't help pressing F5 in the forum...

                  1 Reply Last reply Reply Quote 0
                  • DabDabD
                    DabDab
                    last edited by

                    I have tried to make it a High Pass Filter from the Griffin_LadderFilter.h provided by @griffinboy
                    I am not a good C++ DSP programmer. Test it whether it is working or not.

                    /*
                    Copyright (c) 2024 griffinboy
                    
                    Permission is hereby granted, free of charge, to any person obtaining a copy
                    of this software and associated documentation files (the "Software"), to deal
                    in the Software without restriction, including without limitation the rights
                    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                    copies of the Software, and to permit persons to whom the Software is
                    furnished to do so, subject to the following conditions:
                    
                    The above copyright notice and this permission notice shall be included in all
                    copies or substantial portions of the Software.
                    
                    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
                    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
                    SOFTWARE.
                    */
                    
                    #pragma once
                    #include <JuceHeader.h>
                    
                    namespace project
                    {
                        using namespace juce;
                        using namespace hise;
                        using namespace scriptnode;
                    
                        template <typename T>
                        class ScopedValue
                        {
                        public:
                            explicit ScopedValue(T& val) : value(val), ref(val) {}
                            ~ScopedValue() { ref = value; }
                            T& get() { return value; }
                    
                        private:
                            T value;
                            T& ref;
                            ScopedValue(const ScopedValue&) = delete;
                            ScopedValue& operator=(const ScopedValue&) = delete;
                        };
                    
                        template <int NV>
                        struct Griffin_HighPassFilter : public data::base
                        {
                            SNEX_NODE(Griffin_HighPassFilter);
                    
                            struct MetadataClass
                            {
                                SN_NODE_ID("Griffin_HighPassFilter");
                            };
                    
                            static constexpr bool isModNode() { return false; }
                            static constexpr bool isPolyphonic() { return NV > 1; }
                            static constexpr bool hasTail() { return true; }
                            static constexpr bool isSuspendedOnSilence() { return false; }
                            static constexpr int getFixChannelAmount() { return 2; }
                    
                            static constexpr int NumTables = 0;
                            static constexpr int NumSliderPacks = 0;
                            static constexpr int NumAudioFiles = 0;
                            static constexpr int NumFilters = 0;
                            static constexpr int NumDisplayBuffers = 0;
                    
                            void prepare(PrepareSpecs specs)
                            {
                                filtersLeft.prepare(specs);
                                filtersRight.prepare(specs);
                    
                                for (auto& filter : filtersLeft)
                                    filter.prepare(specs.sampleRate);
                    
                                for (auto& filter : filtersRight)
                                    filter.prepare(specs.sampleRate);
                            }
                    
                            void reset()
                            {
                                for (auto& filter : filtersLeft)
                                    filter.reset();
                    
                                for (auto& filter : filtersRight)
                                    filter.reset();
                            }
                    
                            template <typename ProcessDataType>
                            void process(ProcessDataType& data)
                            {
                                auto& fixData = data.template as<ProcessData<getFixChannelAmount()>>();
                                auto audioBlock = fixData.toAudioBlock();
                    
                                auto* leftChannelData = audioBlock.getChannelPointer(0);
                                auto* rightChannelData = audioBlock.getChannelPointer(1);
                                int numSamples = (int)data.getNumSamples();
                    
                                for (auto& leftFilter : filtersLeft)
                                {
                                    leftFilter.process(leftChannelData, numSamples);
                                }
                    
                                for (auto& rightFilter : filtersRight)
                                {
                                    rightFilter.process(rightChannelData, numSamples);
                                }
                            }
                    
                            class AudioEffect
                            {
                            public:
                                AudioEffect() = default;
                    
                                void prepare(float sampleRate)
                                {
                                    fs = sampleRate;
                                    reset();
                                }
                    
                                void reset()
                                {
                                    x1 = x2 = y1 = y2 = 0.0f;
                                }
                    
                                void updateCoefficients(float fc, float q)
                                {
                                    float omega = 2.0f * MathConstants<float>::pi * fc / fs;
                                    float alpha = std::sin(omega) / (2.0f * q);
                                    float cosOmega = std::cos(omega);
                    
                                    float a0 = 1.0f + alpha;
                                    b0 = (1.0f + cosOmega) / (2.0f * a0);
                                    b1 = -(1.0f + cosOmega) / a0;
                                    b2 = (1.0f + cosOmega) / (2.0f * a0);
                                    a1 = (-2.0f * cosOmega) / a0;
                                    a2 = (1.0f - alpha) / a0;
                                }
                    
                                void process(float* samples, int numSamples)
                                {
                                    for (int i = 0; i < numSamples; ++i)
                                    {
                                        samples[i] = processSample(samples[i]);
                                    }
                                }
                    
                            private:
                                float fs = 44100.0f;
                                float b0 = 0.0f, b1 = 0.0f, b2 = 0.0f;
                                float a1 = 0.0f, a2 = 0.0f;
                                float x1 = 0.0f, x2 = 0.0f;
                                float y1 = 0.0f, y2 = 0.0f;
                    
                                inline float processSample(float input)
                                {
                                    float output = b0 * input + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
                                    
                                    x2 = x1;
                                    x1 = input;
                                    y2 = y1;
                                    y1 = output;
                                    
                                    return output;
                                }
                            };
                    
                            template <int P>
                            void setParameter(double value)
                            {
                                if (P == 0) // Cutoff Frequency
                                {
                                    cutoffFrequency = static_cast<float>(value);
                                    for (auto& filter : filtersLeft)
                                        filter.updateCoefficients(cutoffFrequency, q);
                    
                                    for (auto& filter : filtersRight)
                                        filter.updateCoefficients(cutoffFrequency, q);
                                }
                                else if (P == 1) // Q Factor
                                {
                                    q = static_cast<float>(value);
                                    for (auto& filter : filtersLeft)
                                        filter.updateCoefficients(cutoffFrequency, q);
                    
                                    for (auto& filter : filtersRight)
                                        filter.updateCoefficients(cutoffFrequency, q);
                                }
                            }
                    
                            void createParameters(ParameterDataList& data)
                            {
                                {
                                    parameter::data p("Cutoff Frequency", { 20.0, 20000.0, 1.0 });
                                    registerCallback<0>(p);
                                    p.setDefaultValue(1000.0);
                                    data.add(std::move(p));
                                }
                                {
                                    parameter::data p("Q Factor", { 0.1, 10.0, 0.01 });
                                    registerCallback<1>(p);
                                    p.setDefaultValue(0.707);
                                    data.add(std::move(p));
                                }
                            }
                    
                            void setExternalData(const ExternalData& data, int index) {}
                            void handleHiseEvent(HiseEvent& e) {}
                    
                            template <typename FrameDataType>
                            void processFrame(FrameDataType& data) {}
                    
                        private:
                            PolyData<AudioEffect, NV> filtersLeft;
                            PolyData<AudioEffect, NV> filtersRight;
                            float cutoffFrequency = 1000.0f;
                            float q = 0.707f;
                        };
                    }
                    
                    

                    Bollywood Music Producer and Trance Producer.

                    1 Reply Last reply Reply Quote 1
                    • HISEnbergH
                      HISEnberg @griffinboy
                      last edited by

                      @griffinboy Just curious, have you figured out how to incorporate the filter display in external C++ nodes?

                      griffinboyG 1 Reply Last reply Reply Quote 0
                      • griffinboyG
                        griffinboy @HISEnberg
                        last edited by

                        @HISEnberg

                        You know what, I've never tried it but it should be possible.

                        HISEnbergH 1 Reply Last reply Reply Quote 0
                        • HISEnbergH
                          HISEnberg @griffinboy
                          last edited by

                          @griffinboy Ya I haven't tried either, I was just be lazy and reaching out for a solution first before trying it myself. I'll look through some of the stock HISE filters and post here once I find the solution.

                          griffinboyG 1 Reply Last reply Reply Quote 2
                          • griffinboyG
                            griffinboy @HISEnberg
                            last edited by

                            @HISEnberg

                            Make a new post if you find anything

                            OrvillainO 1 Reply Last reply Reply Quote 2
                            • OrvillainO
                              Orvillain @griffinboy
                              last edited by

                              @griffinboy @HISEnberg I'd love to know this too. I would imagine it is similar to the thing I wanted to do where I wanted to send out modified audio buffers to a display. I gave up in the end coz I couldn't figure it out.

                              HISEnbergH 1 Reply Last reply Reply Quote 0
                              • HISEnbergH
                                HISEnberg @Orvillain
                                last edited by

                                @Orvillain Ah yes I meant to revisit that. I did figure it out but the solution was admittedly more AI-influenced than I care to admit, so I was waiting until I have a more proper understanding of it to share.

                                1 Reply Last reply Reply Quote 1
                                • HISEnbergH HISEnberg referenced this topic
                                • First post
                                  Last post

                                22

                                Online

                                1.8k

                                Users

                                12.1k

                                Topics

                                105.0k

                                Posts