DSPDemo: register new demos


#1

Hello,

The DSPDemo project can be found in JUCE’s examples folder. I have created an all-pass filter demo that I would like to add to add to DSPDemo. How do I do I add my new demo to the demos list?

I hope that my all-pass filter demo helps everybody once I am able to make it show up on the demos list!

Regards,

HubriSonics


#2

To make your demo appear in the list of demos in the DSPDemo application, the most straightforward approach would be to copy an existing demo into a new .cpp file, add this file to the DSPDemo project in the Projucer, then rename the top-level classes in that file.

If you want to make a contribution to JUCE then you’re welcome to submit a pull request on GitHub. However, there’s no guarantee that the JUCE team will incorporate your ideas (particularly at the moment - the new few months are extremely busy). Posting the code for your new demo on the forum is a much easier way to share knowledge and get feedback.


#3

I would like to upload a version of IIRFilterDemo.cpp that includes an option for an all-pass filter. However, since I am a new member, I cannot upload files.


#4

If you indent all lines by four spaces you can paste it directly into a forum message and it will be automatically formatted and highlighted.


#5

Here is an altered version of IIRFilter.cpp that includes an all-pass filter option. All-pass filters can be used to mitigate (or increase) group delay in recorded music.

/*
  ==============================================================================

   This file is part of the JUCE library.
   Copyright (c) 2017 - ROLI Ltd.

   JUCE is an open source library subject to commercial or open-source
   licensing.

   By using JUCE, you agree to the terms of both the JUCE 5 End-User License
   Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
   27th April 2017).

   End User License Agreement: www.juce.com/juce-5-licence
   Privacy Policy: www.juce.com/juce-5-privacy-policy

   Or: You may also use this code under the terms of the GPL v3 (see
   www.gnu.org/licenses).

   JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
   EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
   DISCLAIMED.

  ==============================================================================

  This file was modified by HubriSonics on September 29, 2017.

  1) The option for an all-pass filter was added. 
  2) The low end of the Q range was changed from 0.3 to 0.02.
  3) The skew of both sliders was changed from 0.5 to 0.25.  
  ==============================================================================
*/

#include "../DSPDemo.h"

//==============================================================================
// @@ START_DEMO
struct IIRFilterDemo
{
    void prepare (const ProcessSpec& spec)
    {
        sampleRate = spec.sampleRate;

        iir.state = IIR::Coefficients<float>::makeLowPass (sampleRate, 440.0);
        iir.prepare (spec);
    }

    void process (const ProcessContextReplacing<float>& context)
    {
        iir.process (context);
    }

    void reset()
    {
        iir.reset();
    }

    void updateParameters()
    {
        if (sampleRate != 0)
        {
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
            auto qVal   = static_cast<float> (qParam.getCurrentValue());

            switch (typeParam.getCurrentSelectedID())
            {
                case 1:     *iir.state = *IIR::Coefficients<float>::makeLowPass  (sampleRate, cutoff, qVal); break;
                case 2:     *iir.state = *IIR::Coefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
                case 3:     *iir.state = *IIR::Coefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
                case 4:     *iir.state = *IIR::Coefficients<float>::makeAllPass  (sampleRate, cutoff, qVal); break;
                default:    break;
            }
        }
    }

    //==============================================================================
    ProcessorDuplicator<IIR::Filter<float>, IIR::Coefficients<float>> iir;

    ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass", "All-pass"}, 1, "Type" };
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.25, 440.0f, "Cutoff", "Hz" };
    SliderParameter qParam { { 0.02, 20.0 }, 0.25, 1.0 / std::sqrt(2.0), "Q" };

    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
    double sampleRate = 0;
};
// @@ END_DEMO

RegisterDSPDemo<IIRFilterDemo> iirDemo ("IIR Filter", BinaryData::IIRFilterDemo_cpp);