migrating to the latest JUCE version
This commit is contained in:
		
							
								
								
									
										8
									
								
								deps/juce/examples/DSP/CMakeLists.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								deps/juce/examples/DSP/CMakeLists.txt
									
									
									
									
										vendored
									
									
								
							@@ -1,15 +1,15 @@
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
#
 | 
			
		||||
#  This file is part of the JUCE library.
 | 
			
		||||
#  Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
#  Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
#
 | 
			
		||||
#  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 6 End-User License
 | 
			
		||||
#  Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
 | 
			
		||||
#  By using JUCE, you agree to the terms of both the JUCE 7 End-User License
 | 
			
		||||
#  Agreement and JUCE Privacy Policy.
 | 
			
		||||
#
 | 
			
		||||
#  End User License Agreement: www.juce.com/juce-6-licence
 | 
			
		||||
#  End User License Agreement: www.juce.com/juce-7-licence
 | 
			
		||||
#  Privacy Policy: www.juce.com/juce-privacy-policy
 | 
			
		||||
#
 | 
			
		||||
#  Or: You may also use this code under the terms of the GPL v3 (see
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										406
									
								
								deps/juce/examples/DSP/ConvolutionDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										406
									
								
								deps/juce/examples/DSP/ConvolutionDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,203 +1,203 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             ConvolutionDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Convolution demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        ConvolutionDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct ConvolutionDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
        convolution.prepare (spec);
 | 
			
		||||
        updateParameters();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (ProcessContextReplacing<float> context)
 | 
			
		||||
    {
 | 
			
		||||
        context.isBypassed = bypass;
 | 
			
		||||
 | 
			
		||||
        // Load a new IR if there's one available. Note that this doesn't lock or allocate!
 | 
			
		||||
        bufferTransfer.get ([this] (BufferWithSampleRate& buf)
 | 
			
		||||
        {
 | 
			
		||||
            convolution.loadImpulseResponse (std::move (buf.buffer),
 | 
			
		||||
                                             buf.sampleRate,
 | 
			
		||||
                                             Convolution::Stereo::yes,
 | 
			
		||||
                                             Convolution::Trim::yes,
 | 
			
		||||
                                             Convolution::Normalise::yes);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        convolution.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        convolution.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        auto* cabinetTypeParameter = dynamic_cast<ChoiceParameter*> (parameters[0]);
 | 
			
		||||
 | 
			
		||||
        if (cabinetTypeParameter == nullptr)
 | 
			
		||||
        {
 | 
			
		||||
            jassertfalse;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (cabinetTypeParameter->getCurrentSelectedID() == 1)
 | 
			
		||||
        {
 | 
			
		||||
            bypass = true;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            bypass = false;
 | 
			
		||||
 | 
			
		||||
            auto selectedType = cabinetTypeParameter->getCurrentSelectedID();
 | 
			
		||||
            auto assetName = (selectedType == 2 ? "guitar_amp.wav" : "cassette_recorder.wav");
 | 
			
		||||
 | 
			
		||||
            auto assetInputStream = createAssetInputStream (assetName);
 | 
			
		||||
 | 
			
		||||
            if (assetInputStream == nullptr)
 | 
			
		||||
            {
 | 
			
		||||
                jassertfalse;
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            AudioFormatManager manager;
 | 
			
		||||
            manager.registerBasicFormats();
 | 
			
		||||
            std::unique_ptr<AudioFormatReader> reader { manager.createReaderFor (std::move (assetInputStream)) };
 | 
			
		||||
 | 
			
		||||
            if (reader == nullptr)
 | 
			
		||||
            {
 | 
			
		||||
                jassertfalse;
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            AudioBuffer<float> buffer (static_cast<int> (reader->numChannels),
 | 
			
		||||
                                       static_cast<int> (reader->lengthInSamples));
 | 
			
		||||
            reader->read (buffer.getArrayOfWritePointers(), buffer.getNumChannels(), 0, buffer.getNumSamples());
 | 
			
		||||
 | 
			
		||||
            bufferTransfer.set (BufferWithSampleRate { std::move (buffer), reader->sampleRate });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    struct BufferWithSampleRate
 | 
			
		||||
    {
 | 
			
		||||
        BufferWithSampleRate() = default;
 | 
			
		||||
 | 
			
		||||
        BufferWithSampleRate (AudioBuffer<float>&& bufferIn, double sampleRateIn)
 | 
			
		||||
            : buffer (std::move (bufferIn)), sampleRate (sampleRateIn) {}
 | 
			
		||||
 | 
			
		||||
        AudioBuffer<float> buffer;
 | 
			
		||||
        double sampleRate = 0.0;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    class BufferTransfer
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        void set (BufferWithSampleRate&& p)
 | 
			
		||||
        {
 | 
			
		||||
            const SpinLock::ScopedLockType lock (mutex);
 | 
			
		||||
            buffer = std::move (p);
 | 
			
		||||
            newBuffer = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Call `fn` passing the new buffer, if there's one available
 | 
			
		||||
        template <typename Fn>
 | 
			
		||||
        void get (Fn&& fn)
 | 
			
		||||
        {
 | 
			
		||||
            const SpinLock::ScopedTryLockType lock (mutex);
 | 
			
		||||
 | 
			
		||||
            if (lock.isLocked() && newBuffer)
 | 
			
		||||
            {
 | 
			
		||||
                fn (buffer);
 | 
			
		||||
                newBuffer = false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        BufferWithSampleRate buffer;
 | 
			
		||||
        bool newBuffer = false;
 | 
			
		||||
        SpinLock mutex;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
    bool bypass = false;
 | 
			
		||||
 | 
			
		||||
    MemoryBlock currentCabinetData;
 | 
			
		||||
    Convolution convolution;
 | 
			
		||||
 | 
			
		||||
    BufferTransfer bufferTransfer;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter cabinetParam { { "Bypass", "Guitar amplifier 8''", "Cassette recorder" }, 1, "Cabinet Type" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &cabinetParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct ConvolutionDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    ConvolutionDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<ConvolutionDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             ConvolutionDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Convolution demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        ConvolutionDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct ConvolutionDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
        convolution.prepare (spec);
 | 
			
		||||
        updateParameters();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (ProcessContextReplacing<float> context)
 | 
			
		||||
    {
 | 
			
		||||
        context.isBypassed = bypass;
 | 
			
		||||
 | 
			
		||||
        // Load a new IR if there's one available. Note that this doesn't lock or allocate!
 | 
			
		||||
        bufferTransfer.get ([this] (BufferWithSampleRate& buf)
 | 
			
		||||
        {
 | 
			
		||||
            convolution.loadImpulseResponse (std::move (buf.buffer),
 | 
			
		||||
                                             buf.sampleRate,
 | 
			
		||||
                                             Convolution::Stereo::yes,
 | 
			
		||||
                                             Convolution::Trim::yes,
 | 
			
		||||
                                             Convolution::Normalise::yes);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        convolution.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        convolution.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        auto* cabinetTypeParameter = dynamic_cast<ChoiceParameter*> (parameters[0]);
 | 
			
		||||
 | 
			
		||||
        if (cabinetTypeParameter == nullptr)
 | 
			
		||||
        {
 | 
			
		||||
            jassertfalse;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (cabinetTypeParameter->getCurrentSelectedID() == 1)
 | 
			
		||||
        {
 | 
			
		||||
            bypass = true;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            bypass = false;
 | 
			
		||||
 | 
			
		||||
            auto selectedType = cabinetTypeParameter->getCurrentSelectedID();
 | 
			
		||||
            auto assetName = (selectedType == 2 ? "guitar_amp.wav" : "cassette_recorder.wav");
 | 
			
		||||
 | 
			
		||||
            auto assetInputStream = createAssetInputStream (assetName);
 | 
			
		||||
 | 
			
		||||
            if (assetInputStream == nullptr)
 | 
			
		||||
            {
 | 
			
		||||
                jassertfalse;
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            AudioFormatManager manager;
 | 
			
		||||
            manager.registerBasicFormats();
 | 
			
		||||
            std::unique_ptr<AudioFormatReader> reader { manager.createReaderFor (std::move (assetInputStream)) };
 | 
			
		||||
 | 
			
		||||
            if (reader == nullptr)
 | 
			
		||||
            {
 | 
			
		||||
                jassertfalse;
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            AudioBuffer<float> buffer (static_cast<int> (reader->numChannels),
 | 
			
		||||
                                       static_cast<int> (reader->lengthInSamples));
 | 
			
		||||
            reader->read (buffer.getArrayOfWritePointers(), buffer.getNumChannels(), 0, buffer.getNumSamples());
 | 
			
		||||
 | 
			
		||||
            bufferTransfer.set (BufferWithSampleRate { std::move (buffer), reader->sampleRate });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    struct BufferWithSampleRate
 | 
			
		||||
    {
 | 
			
		||||
        BufferWithSampleRate() = default;
 | 
			
		||||
 | 
			
		||||
        BufferWithSampleRate (AudioBuffer<float>&& bufferIn, double sampleRateIn)
 | 
			
		||||
            : buffer (std::move (bufferIn)), sampleRate (sampleRateIn) {}
 | 
			
		||||
 | 
			
		||||
        AudioBuffer<float> buffer;
 | 
			
		||||
        double sampleRate = 0.0;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    class BufferTransfer
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        void set (BufferWithSampleRate&& p)
 | 
			
		||||
        {
 | 
			
		||||
            const SpinLock::ScopedLockType lock (mutex);
 | 
			
		||||
            buffer = std::move (p);
 | 
			
		||||
            newBuffer = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Call `fn` passing the new buffer, if there's one available
 | 
			
		||||
        template <typename Fn>
 | 
			
		||||
        void get (Fn&& fn)
 | 
			
		||||
        {
 | 
			
		||||
            const SpinLock::ScopedTryLockType lock (mutex);
 | 
			
		||||
 | 
			
		||||
            if (lock.isLocked() && newBuffer)
 | 
			
		||||
            {
 | 
			
		||||
                fn (buffer);
 | 
			
		||||
                newBuffer = false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        BufferWithSampleRate buffer;
 | 
			
		||||
        bool newBuffer = false;
 | 
			
		||||
        SpinLock mutex;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
    bool bypass = false;
 | 
			
		||||
 | 
			
		||||
    MemoryBlock currentCabinetData;
 | 
			
		||||
    Convolution convolution;
 | 
			
		||||
 | 
			
		||||
    BufferTransfer bufferTransfer;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter cabinetParam { { "Bypass", "Guitar amplifier 8''", "Cassette recorder" }, 1, "Cabinet Type" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &cabinetParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct ConvolutionDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    ConvolutionDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<ConvolutionDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										230
									
								
								deps/juce/examples/DSP/FIRFilterDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										230
									
								
								deps/juce/examples/DSP/FIRFilterDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,115 +1,115 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             FIRFilterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      FIR filter demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        FIRFilterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct FIRFilterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
 | 
			
		||||
        fir.state = FilterDesign<float>::designFIRLowpassWindowMethod (440.0f, sampleRate, 21,
 | 
			
		||||
                                                                       WindowingFunction<float>::blackman);
 | 
			
		||||
        fir.prepare (spec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        fir.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        fir.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
 | 
			
		||||
            auto windowingMethod = static_cast<WindowingFunction<float>::WindowingMethod> (typeParam.getCurrentSelectedID() - 1);
 | 
			
		||||
 | 
			
		||||
            *fir.state = *FilterDesign<float>::designFIRLowpassWindowMethod (cutoff, sampleRate, 21, windowingMethod);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    ProcessorDuplicator<FIR::Filter<float>, FIR::Coefficients<float>> fir;
 | 
			
		||||
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
 | 
			
		||||
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.4, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    ChoiceParameter typeParam { { "Rectangular", "Triangular", "Hann", "Hamming", "Blackman", "Blackman-Harris", "Flat Top", "Kaiser" },
 | 
			
		||||
                                5, "Windowing Function" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &cutoffParam, &typeParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct FIRFilterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    FIRFilterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<FIRFilterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             FIRFilterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      FIR filter demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        FIRFilterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct FIRFilterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
 | 
			
		||||
        fir.state = FilterDesign<float>::designFIRLowpassWindowMethod (440.0f, sampleRate, 21,
 | 
			
		||||
                                                                       WindowingFunction<float>::blackman);
 | 
			
		||||
        fir.prepare (spec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        fir.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        fir.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
 | 
			
		||||
            auto windowingMethod = static_cast<WindowingFunction<float>::WindowingMethod> (typeParam.getCurrentSelectedID() - 1);
 | 
			
		||||
 | 
			
		||||
            *fir.state = *FilterDesign<float>::designFIRLowpassWindowMethod (cutoff, sampleRate, 21, windowingMethod);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    ProcessorDuplicator<FIR::Filter<float>, FIR::Coefficients<float>> fir;
 | 
			
		||||
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
 | 
			
		||||
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.4, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    ChoiceParameter typeParam { { "Rectangular", "Triangular", "Hann", "Hamming", "Blackman", "Blackman-Harris", "Flat Top", "Kaiser" },
 | 
			
		||||
                                5, "Windowing Function" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &cutoffParam, &typeParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct FIRFilterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    FIRFilterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<FIRFilterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										200
									
								
								deps/juce/examples/DSP/GainDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										200
									
								
								deps/juce/examples/DSP/GainDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,100 +1,100 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             GainDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Gain demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        GainDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct GainDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec&)
 | 
			
		||||
    {
 | 
			
		||||
        gain.setGainDecibels (-6.0f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        gain.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        gain.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        gain.setGainDecibels (static_cast<float> (gainParam.getCurrentValue()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    Gain<float> gain;
 | 
			
		||||
    SliderParameter gainParam { { -100.0, 20.0 }, 3.0, -6.0, "Gain", "dB" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &gainParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct GainDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    GainDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<GainDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             GainDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Gain demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        GainDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct GainDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec&)
 | 
			
		||||
    {
 | 
			
		||||
        gain.setGainDecibels (-6.0f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        gain.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        gain.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        gain.setGainDecibels (static_cast<float> (gainParam.getCurrentValue()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    Gain<float> gain;
 | 
			
		||||
    SliderParameter gainParam { { -100.0, 20.0 }, 3.0, -6.0, "Gain", "dB" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &gainParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct GainDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    GainDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<GainDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										238
									
								
								deps/juce/examples/DSP/IIRFilterDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										238
									
								
								deps/juce/examples/DSP/IIRFilterDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,119 +1,119 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             IIRFilterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      IIR filter demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        IIRFilterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct IIRFilterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    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.0)
 | 
			
		||||
        {
 | 
			
		||||
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
 | 
			
		||||
            auto qVal   = static_cast<float> (qParam.getCurrentValue());
 | 
			
		||||
 | 
			
		||||
            switch (typeParam.getCurrentSelectedID())
 | 
			
		||||
            {
 | 
			
		||||
                case 1:     *iir.state = IIR::ArrayCoefficients<float>::makeLowPass  (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 2:     *iir.state = IIR::ArrayCoefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 3:     *iir.state = IIR::ArrayCoefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                default:    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    ProcessorDuplicator<IIR::Filter<float>, IIR::Coefficients<float>> iir;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" };
 | 
			
		||||
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    SliderParameter qParam { { 0.3, 20.0 }, 0.5, 1.0 / std::sqrt(2.0), "Q" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct IIRFilterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    IIRFilterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<IIRFilterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             IIRFilterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      IIR filter demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        IIRFilterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct IIRFilterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    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.0)
 | 
			
		||||
        {
 | 
			
		||||
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
 | 
			
		||||
            auto qVal   = static_cast<float> (qParam.getCurrentValue());
 | 
			
		||||
 | 
			
		||||
            switch (typeParam.getCurrentSelectedID())
 | 
			
		||||
            {
 | 
			
		||||
                case 1:     *iir.state = IIR::ArrayCoefficients<float>::makeLowPass  (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 2:     *iir.state = IIR::ArrayCoefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 3:     *iir.state = IIR::ArrayCoefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                default:    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    ProcessorDuplicator<IIR::Filter<float>, IIR::Coefficients<float>> iir;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" };
 | 
			
		||||
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    SliderParameter qParam { { 0.3, 20.0 }, 0.5, 1.0 / std::sqrt(2.0), "Q" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct IIRFilterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    IIRFilterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<IIRFilterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										302
									
								
								deps/juce/examples/DSP/OscillatorDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										302
									
								
								deps/juce/examples/DSP/OscillatorDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,151 +1,151 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             OscillatorDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Oscillator demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        OscillatorDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct OscillatorDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        gain.setGainDecibels (-6.0f);
 | 
			
		||||
 | 
			
		||||
        for (auto&& oscillator : oscillators)
 | 
			
		||||
        {
 | 
			
		||||
            oscillator.setFrequency (440.f);
 | 
			
		||||
            oscillator.prepare (spec);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        updateParameters();
 | 
			
		||||
 | 
			
		||||
        tempBuffer = AudioBlock<float> (tempBufferMemory, spec.numChannels, spec.maximumBlockSize);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        tempBuffer.copyFrom (context.getInputBlock());
 | 
			
		||||
        tempBuffer.multiplyBy (static_cast<float> (fileMix));
 | 
			
		||||
 | 
			
		||||
        oscillators[currentOscillatorIdx].process (context);
 | 
			
		||||
        context.getOutputBlock().multiplyBy (static_cast<float> (1.0 - fileMix));
 | 
			
		||||
 | 
			
		||||
        context.getOutputBlock().add (tempBuffer);
 | 
			
		||||
 | 
			
		||||
        gain.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        oscillators[currentOscillatorIdx].reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        currentOscillatorIdx = jmin (numElementsInArray (oscillators),
 | 
			
		||||
                                     3 * (accuracy.getCurrentSelectedID() - 1) + (typeParam.getCurrentSelectedID() - 1));
 | 
			
		||||
 | 
			
		||||
        auto freq = static_cast<float> (freqParam.getCurrentValue());
 | 
			
		||||
 | 
			
		||||
        for (auto&& oscillator : oscillators)
 | 
			
		||||
            oscillator.setFrequency (freq);
 | 
			
		||||
 | 
			
		||||
        gain.setGainDecibels (static_cast<float> (gainParam.getCurrentValue()));
 | 
			
		||||
 | 
			
		||||
        fileMix = mixParam.getCurrentValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    Oscillator<float> oscillators[6] =
 | 
			
		||||
    {
 | 
			
		||||
        // No Approximation
 | 
			
		||||
        {[] (float x) { return std::sin (x); }},                   // sine
 | 
			
		||||
        {[] (float x) { return x / MathConstants<float>::pi; }},   // saw
 | 
			
		||||
        {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }},        // square
 | 
			
		||||
 | 
			
		||||
        // Approximated by a wave-table
 | 
			
		||||
        {[] (float x) { return std::sin (x); }, 100},                 // sine
 | 
			
		||||
        {[] (float x) { return x / MathConstants<float>::pi; }, 100}, // saw
 | 
			
		||||
        {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100}       // square
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    int currentOscillatorIdx = 0;
 | 
			
		||||
    Gain<float> gain;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam { {"sine", "saw", "square"}, 1, "Type" };
 | 
			
		||||
    ChoiceParameter accuracy  { {"No Approximation", "Use Wavetable"}, 1, "Accuracy" };
 | 
			
		||||
    SliderParameter freqParam { { 20.0, 24000.0 }, 0.4, 440.0, "Frequency", "Hz" };
 | 
			
		||||
    SliderParameter gainParam { { -100.0, 20.0 }, 3.0, -20.0, "Gain", "dB" };
 | 
			
		||||
    SliderParameter mixParam  { { 0.0, 1.0 }, 1.0, 0.0, "File mix" };
 | 
			
		||||
 | 
			
		||||
    HeapBlock<char> tempBufferMemory;
 | 
			
		||||
    AudioBlock<float> tempBuffer;
 | 
			
		||||
    double fileMix;
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &accuracy, &freqParam, &gainParam, &mixParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct OscillatorDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    OscillatorDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<OscillatorDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             OscillatorDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Oscillator demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        OscillatorDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct OscillatorDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        gain.setGainDecibels (-6.0f);
 | 
			
		||||
 | 
			
		||||
        for (auto&& oscillator : oscillators)
 | 
			
		||||
        {
 | 
			
		||||
            oscillator.setFrequency (440.f);
 | 
			
		||||
            oscillator.prepare (spec);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        updateParameters();
 | 
			
		||||
 | 
			
		||||
        tempBuffer = AudioBlock<float> (tempBufferMemory, spec.numChannels, spec.maximumBlockSize);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        tempBuffer.copyFrom (context.getInputBlock());
 | 
			
		||||
        tempBuffer.multiplyBy (static_cast<float> (fileMix));
 | 
			
		||||
 | 
			
		||||
        oscillators[currentOscillatorIdx].process (context);
 | 
			
		||||
        context.getOutputBlock().multiplyBy (static_cast<float> (1.0 - fileMix));
 | 
			
		||||
 | 
			
		||||
        context.getOutputBlock().add (tempBuffer);
 | 
			
		||||
 | 
			
		||||
        gain.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        oscillators[currentOscillatorIdx].reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        currentOscillatorIdx = jmin (numElementsInArray (oscillators),
 | 
			
		||||
                                     3 * (accuracy.getCurrentSelectedID() - 1) + (typeParam.getCurrentSelectedID() - 1));
 | 
			
		||||
 | 
			
		||||
        auto freq = static_cast<float> (freqParam.getCurrentValue());
 | 
			
		||||
 | 
			
		||||
        for (auto&& oscillator : oscillators)
 | 
			
		||||
            oscillator.setFrequency (freq);
 | 
			
		||||
 | 
			
		||||
        gain.setGainDecibels (static_cast<float> (gainParam.getCurrentValue()));
 | 
			
		||||
 | 
			
		||||
        fileMix = mixParam.getCurrentValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    Oscillator<float> oscillators[6] =
 | 
			
		||||
    {
 | 
			
		||||
        // No Approximation
 | 
			
		||||
        {[] (float x) { return std::sin (x); }},                   // sine
 | 
			
		||||
        {[] (float x) { return x / MathConstants<float>::pi; }},   // saw
 | 
			
		||||
        {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }},        // square
 | 
			
		||||
 | 
			
		||||
        // Approximated by a wave-table
 | 
			
		||||
        {[] (float x) { return std::sin (x); }, 100},                 // sine
 | 
			
		||||
        {[] (float x) { return x / MathConstants<float>::pi; }, 100}, // saw
 | 
			
		||||
        {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100}       // square
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    int currentOscillatorIdx = 0;
 | 
			
		||||
    Gain<float> gain;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam { {"sine", "saw", "square"}, 1, "Type" };
 | 
			
		||||
    ChoiceParameter accuracy  { {"No Approximation", "Use Wavetable"}, 1, "Accuracy" };
 | 
			
		||||
    SliderParameter freqParam { { 20.0, 24000.0 }, 0.4, 440.0, "Frequency", "Hz" };
 | 
			
		||||
    SliderParameter gainParam { { -100.0, 20.0 }, 3.0, -20.0, "Gain", "dB" };
 | 
			
		||||
    SliderParameter mixParam  { { 0.0, 1.0 }, 1.0, 0.0, "File mix" };
 | 
			
		||||
 | 
			
		||||
    HeapBlock<char> tempBufferMemory;
 | 
			
		||||
    AudioBlock<float> tempBuffer;
 | 
			
		||||
    double fileMix;
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &accuracy, &freqParam, &gainParam, &mixParam };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct OscillatorDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    OscillatorDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<OscillatorDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										260
									
								
								deps/juce/examples/DSP/OverdriveDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										260
									
								
								deps/juce/examples/DSP/OverdriveDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,130 +1,130 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             OverdriveDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Overdrive demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        OverdriveDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct OverdriveDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
 | 
			
		||||
        auto& gainUp = overdrive.get<0>();
 | 
			
		||||
        gainUp.setGainDecibels (24);
 | 
			
		||||
 | 
			
		||||
        auto& bias = overdrive.get<1>();
 | 
			
		||||
        bias.setBias (0.4f);
 | 
			
		||||
 | 
			
		||||
        auto& wavShaper = overdrive.get<2>();
 | 
			
		||||
        wavShaper.functionToUse = std::tanh;
 | 
			
		||||
 | 
			
		||||
        auto& dcFilter = overdrive.get<3>();
 | 
			
		||||
        dcFilter.state = IIR::Coefficients<float>::makeHighPass (sampleRate, 5.0);
 | 
			
		||||
 | 
			
		||||
        auto& gainDown = overdrive.get<4>();
 | 
			
		||||
        gainDown.setGainDecibels (-18.0f);
 | 
			
		||||
 | 
			
		||||
        overdrive.prepare (spec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        overdrive.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        overdrive.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            overdrive.get<0>().setGainDecibels (static_cast<float> (inGainParam.getCurrentValue()));
 | 
			
		||||
            overdrive.get<4>().setGainDecibels (static_cast<float> (outGainParam.getCurrentValue()));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    using GainProcessor   = Gain<float>;
 | 
			
		||||
    using BiasProcessor   = Bias<float>;
 | 
			
		||||
    using DriveProcessor  = WaveShaper<float>;
 | 
			
		||||
    using DCFilter        = ProcessorDuplicator<IIR::Filter<float>,
 | 
			
		||||
                                                IIR::Coefficients<float>>;
 | 
			
		||||
 | 
			
		||||
    ProcessorChain<GainProcessor, BiasProcessor, DriveProcessor, DCFilter, GainProcessor> overdrive;
 | 
			
		||||
 | 
			
		||||
    SliderParameter inGainParam  { { -100.0, 60.0 }, 3, 24.0,  "Input Gain",  "dB" };
 | 
			
		||||
    SliderParameter outGainParam { { -100.0, 20.0 }, 3, -18.0, "Output Gain", "dB" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &inGainParam, &outGainParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct OverdriveDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    OverdriveDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<OverdriveDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             OverdriveDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Overdrive demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        OverdriveDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct OverdriveDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
 | 
			
		||||
        auto& gainUp = overdrive.get<0>();
 | 
			
		||||
        gainUp.setGainDecibels (24);
 | 
			
		||||
 | 
			
		||||
        auto& bias = overdrive.get<1>();
 | 
			
		||||
        bias.setBias (0.4f);
 | 
			
		||||
 | 
			
		||||
        auto& wavShaper = overdrive.get<2>();
 | 
			
		||||
        wavShaper.functionToUse = std::tanh;
 | 
			
		||||
 | 
			
		||||
        auto& dcFilter = overdrive.get<3>();
 | 
			
		||||
        dcFilter.state = IIR::Coefficients<float>::makeHighPass (sampleRate, 5.0);
 | 
			
		||||
 | 
			
		||||
        auto& gainDown = overdrive.get<4>();
 | 
			
		||||
        gainDown.setGainDecibels (-18.0f);
 | 
			
		||||
 | 
			
		||||
        overdrive.prepare (spec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        overdrive.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        overdrive.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            overdrive.get<0>().setGainDecibels (static_cast<float> (inGainParam.getCurrentValue()));
 | 
			
		||||
            overdrive.get<4>().setGainDecibels (static_cast<float> (outGainParam.getCurrentValue()));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    using GainProcessor   = Gain<float>;
 | 
			
		||||
    using BiasProcessor   = Bias<float>;
 | 
			
		||||
    using DriveProcessor  = WaveShaper<float>;
 | 
			
		||||
    using DCFilter        = ProcessorDuplicator<IIR::Filter<float>,
 | 
			
		||||
                                                IIR::Coefficients<float>>;
 | 
			
		||||
 | 
			
		||||
    ProcessorChain<GainProcessor, BiasProcessor, DriveProcessor, DCFilter, GainProcessor> overdrive;
 | 
			
		||||
 | 
			
		||||
    SliderParameter inGainParam  { { -100.0, 60.0 }, 3, 24.0,  "Input Gain",  "dB" };
 | 
			
		||||
    SliderParameter outGainParam { { -100.0, 20.0 }, 3, -18.0, "Output Gain", "dB" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &inGainParam, &outGainParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct OverdriveDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    OverdriveDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<OverdriveDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										332
									
								
								deps/juce/examples/DSP/SIMDRegisterDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										332
									
								
								deps/juce/examples/DSP/SIMDRegisterDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,159 +1,173 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             SIMDRegisterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      SIMD register demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        SIMDRegisterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct SIMDRegisterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
 | 
			
		||||
        iirCoefficients = IIR::Coefficients<float>::makeLowPass (sampleRate, 440.0f);
 | 
			
		||||
        iir.reset (new IIR::Filter<SIMDRegister<float>> (iirCoefficients));
 | 
			
		||||
 | 
			
		||||
        interleaved = AudioBlock<SIMDRegister<float>> (interleavedBlockData, 1, spec.maximumBlockSize);
 | 
			
		||||
        zero        = AudioBlock<float> (zeroData, SIMDRegister<float>::size(), spec.maximumBlockSize);
 | 
			
		||||
 | 
			
		||||
        zero.clear();
 | 
			
		||||
 | 
			
		||||
        auto monoSpec = spec;
 | 
			
		||||
        monoSpec.numChannels = 1;
 | 
			
		||||
        iir->prepare (monoSpec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        jassert (context.getInputBlock().getNumSamples()  == context.getOutputBlock().getNumSamples());
 | 
			
		||||
        jassert (context.getInputBlock().getNumChannels() == context.getOutputBlock().getNumChannels());
 | 
			
		||||
 | 
			
		||||
        auto& input  = context.getInputBlock();
 | 
			
		||||
        auto& output = context.getOutputBlock();
 | 
			
		||||
        auto n = (int) input.getNumSamples();
 | 
			
		||||
        auto* inout = channelPointers.getData();
 | 
			
		||||
 | 
			
		||||
        for (size_t ch = 0; ch < SIMDRegister<float>::size(); ++ch)
 | 
			
		||||
            inout[ch] = (ch < input.getNumChannels() ? const_cast<float*> (input.getChannelPointer (ch)) : zero.getChannelPointer (ch));
 | 
			
		||||
 | 
			
		||||
        using DstSampleType = AudioData::Pointer<AudioData::Float32, AudioData::NativeEndian, AudioData::Interleaved,    AudioData::NonConst>;
 | 
			
		||||
        using SrcSampleType = AudioData::Pointer<AudioData::Float32, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::NonConst>;
 | 
			
		||||
 | 
			
		||||
        DstSampleType dstData (interleaved.getChannelPointer (0), (int) interleaved.getNumChannels());
 | 
			
		||||
        SrcSampleType srcData (inout);
 | 
			
		||||
 | 
			
		||||
        dstData.convertSamples (srcData, n);
 | 
			
		||||
 | 
			
		||||
        iir->process (ProcessContextReplacing<SIMDRegister<float>> (interleaved));
 | 
			
		||||
 | 
			
		||||
        for (size_t ch = 0; ch < input.getNumChannels(); ++ch)
 | 
			
		||||
            inout[ch] = output.getChannelPointer (ch);
 | 
			
		||||
 | 
			
		||||
        srcData.convertSamples (dstData, n);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        iir.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
 | 
			
		||||
            auto qVal   = static_cast<float> (qParam.getCurrentValue());
 | 
			
		||||
 | 
			
		||||
            switch (typeParam.getCurrentSelectedID())
 | 
			
		||||
            {
 | 
			
		||||
                case 1:   *iirCoefficients = IIR::ArrayCoefficients<float>::makeLowPass  (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 2:   *iirCoefficients = IIR::ArrayCoefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 3:   *iirCoefficients = IIR::ArrayCoefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                default:  break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    IIR::Coefficients<float>::Ptr iirCoefficients;
 | 
			
		||||
    std::unique_ptr<IIR::Filter<SIMDRegister<float>>> iir;
 | 
			
		||||
 | 
			
		||||
    AudioBlock<SIMDRegister<float>> interleaved;
 | 
			
		||||
    AudioBlock<float> zero;
 | 
			
		||||
 | 
			
		||||
    HeapBlock<char> interleavedBlockData, zeroData;
 | 
			
		||||
    HeapBlock<const float*> channelPointers { SIMDRegister<float>::size() };
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" };
 | 
			
		||||
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    SliderParameter qParam { { 0.3, 20.0 }, 0.5, 0.7, "Q" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct SIMDRegisterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    SIMDRegisterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<SIMDRegisterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             SIMDRegisterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      SIMD register demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        SIMDRegisterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
static T* toBasePointer (SIMDRegister<T>* r) noexcept
 | 
			
		||||
{
 | 
			
		||||
    return reinterpret_cast<T*> (r);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
constexpr auto registerSize = dsp::SIMDRegister<float>::size();
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct SIMDRegisterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
 | 
			
		||||
        iirCoefficients = IIR::Coefficients<float>::makeLowPass (sampleRate, 440.0f);
 | 
			
		||||
        iir.reset (new IIR::Filter<SIMDRegister<float>> (iirCoefficients));
 | 
			
		||||
 | 
			
		||||
        interleaved = AudioBlock<SIMDRegister<float>> (interleavedBlockData, 1, spec.maximumBlockSize);
 | 
			
		||||
        zero        = AudioBlock<float> (zeroData, SIMDRegister<float>::size(), spec.maximumBlockSize);
 | 
			
		||||
 | 
			
		||||
        zero.clear();
 | 
			
		||||
 | 
			
		||||
        auto monoSpec = spec;
 | 
			
		||||
        monoSpec.numChannels = 1;
 | 
			
		||||
        iir->prepare (monoSpec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template <typename SampleType>
 | 
			
		||||
    auto prepareChannelPointers (const AudioBlock<SampleType>& block)
 | 
			
		||||
    {
 | 
			
		||||
        std::array<SampleType*, registerSize> result {};
 | 
			
		||||
 | 
			
		||||
        for (size_t ch = 0; ch < result.size(); ++ch)
 | 
			
		||||
            result[ch] = (ch < block.getNumChannels() ? block.getChannelPointer (ch) : zero.getChannelPointer (ch));
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        jassert (context.getInputBlock().getNumSamples()  == context.getOutputBlock().getNumSamples());
 | 
			
		||||
        jassert (context.getInputBlock().getNumChannels() == context.getOutputBlock().getNumChannels());
 | 
			
		||||
 | 
			
		||||
        const auto& input  = context.getInputBlock();
 | 
			
		||||
        const auto numSamples = (int) input.getNumSamples();
 | 
			
		||||
 | 
			
		||||
        auto inChannels = prepareChannelPointers (input);
 | 
			
		||||
 | 
			
		||||
        using Format = AudioData::Format<AudioData::Float32, AudioData::NativeEndian>;
 | 
			
		||||
 | 
			
		||||
        AudioData::interleaveSamples (AudioData::NonInterleavedSource<Format> { inChannels.data(),                                 registerSize, },
 | 
			
		||||
                                      AudioData::InterleavedDest<Format>      { toBasePointer (interleaved.getChannelPointer (0)), registerSize },
 | 
			
		||||
                                      numSamples);
 | 
			
		||||
 | 
			
		||||
        iir->process (ProcessContextReplacing<SIMDRegister<float>> (interleaved));
 | 
			
		||||
 | 
			
		||||
        auto outChannels = prepareChannelPointers (context.getOutputBlock());
 | 
			
		||||
 | 
			
		||||
        AudioData::deinterleaveSamples (AudioData::InterleavedSource<Format>  { toBasePointer (interleaved.getChannelPointer (0)), registerSize },
 | 
			
		||||
                                        AudioData::NonInterleavedDest<Format> { outChannels.data(),                                registerSize },
 | 
			
		||||
                                        numSamples);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        iir.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
 | 
			
		||||
            auto qVal   = static_cast<float> (qParam.getCurrentValue());
 | 
			
		||||
 | 
			
		||||
            switch (typeParam.getCurrentSelectedID())
 | 
			
		||||
            {
 | 
			
		||||
                case 1:   *iirCoefficients = IIR::ArrayCoefficients<float>::makeLowPass  (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 2:   *iirCoefficients = IIR::ArrayCoefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                case 3:   *iirCoefficients = IIR::ArrayCoefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
 | 
			
		||||
                default:  break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    IIR::Coefficients<float>::Ptr iirCoefficients;
 | 
			
		||||
    std::unique_ptr<IIR::Filter<SIMDRegister<float>>> iir;
 | 
			
		||||
 | 
			
		||||
    AudioBlock<SIMDRegister<float>> interleaved;
 | 
			
		||||
    AudioBlock<float> zero;
 | 
			
		||||
 | 
			
		||||
    HeapBlock<char> interleavedBlockData, zeroData;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" };
 | 
			
		||||
    SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    SliderParameter qParam { { 0.3, 20.0 }, 0.5, 0.7, "Q" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct SIMDRegisterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    SIMDRegisterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<SIMDRegisterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										234
									
								
								deps/juce/examples/DSP/StateVariableFilterDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										234
									
								
								deps/juce/examples/DSP/StateVariableFilterDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,117 +1,117 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             StateVariableFilterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      State variable filter demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        StateVariableFilterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct StateVariableFilterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
        filter.prepare (spec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        filter.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        filter.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            filter.setCutoffFrequency (static_cast<float> (cutoffParam.getCurrentValue()));
 | 
			
		||||
            filter.setResonance       (static_cast<float> (qParam.getCurrentValue()));
 | 
			
		||||
 | 
			
		||||
            switch (typeParam.getCurrentSelectedID() - 1)
 | 
			
		||||
            {
 | 
			
		||||
                case 0:   filter.setType (StateVariableTPTFilterType::lowpass);  break;
 | 
			
		||||
                case 1:   filter.setType (StateVariableTPTFilterType::bandpass); break;
 | 
			
		||||
                case 2:   filter.setType (StateVariableTPTFilterType::highpass); break;
 | 
			
		||||
                default:  jassertfalse;                                                   break;
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    StateVariableTPTFilter<float> filter;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam {{ "Low-pass", "Band-pass", "High-pass" }, 1, "Type" };
 | 
			
		||||
    SliderParameter cutoffParam {{ 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    SliderParameter qParam {{ 0.3, 20.0 }, 0.5, 1.0 / MathConstants<double>::sqrt2, "Resonance" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct StateVariableFilterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    StateVariableFilterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<StateVariableFilterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             StateVariableFilterDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      State variable filter demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        StateVariableFilterDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct StateVariableFilterDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec& spec)
 | 
			
		||||
    {
 | 
			
		||||
        sampleRate = spec.sampleRate;
 | 
			
		||||
        filter.prepare (spec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        filter.process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        filter.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        if (sampleRate != 0.0)
 | 
			
		||||
        {
 | 
			
		||||
            filter.setCutoffFrequency (static_cast<float> (cutoffParam.getCurrentValue()));
 | 
			
		||||
            filter.setResonance       (static_cast<float> (qParam.getCurrentValue()));
 | 
			
		||||
 | 
			
		||||
            switch (typeParam.getCurrentSelectedID() - 1)
 | 
			
		||||
            {
 | 
			
		||||
                case 0:   filter.setType (StateVariableTPTFilterType::lowpass);  break;
 | 
			
		||||
                case 1:   filter.setType (StateVariableTPTFilterType::bandpass); break;
 | 
			
		||||
                case 2:   filter.setType (StateVariableTPTFilterType::highpass); break;
 | 
			
		||||
                default:  jassertfalse;                                                   break;
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    StateVariableTPTFilter<float> filter;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter typeParam {{ "Low-pass", "Band-pass", "High-pass" }, 1, "Type" };
 | 
			
		||||
    SliderParameter cutoffParam {{ 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
 | 
			
		||||
    SliderParameter qParam {{ 0.3, 20.0 }, 0.5, 1.0 / MathConstants<double>::sqrt2, "Resonance" };
 | 
			
		||||
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
 | 
			
		||||
    double sampleRate = 0.0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct StateVariableFilterDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    StateVariableFilterDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<StateVariableFilterDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										198
									
								
								deps/juce/examples/DSP/WaveShaperTanhDemo.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										198
									
								
								deps/juce/examples/DSP/WaveShaperTanhDemo.h
									
									
									
									
										vendored
									
									
								
							@@ -1,99 +1,99 @@
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2020 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             WaveShaperTanhDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Wave shaper tanh demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2019, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        WaveShaperTanhDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct WaveShaperTanhDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec&) {}
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        shapers[currentShaperIdx].process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        for (auto&& shaper : shapers)
 | 
			
		||||
            shaper.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        currentShaperIdx = jmin (numElementsInArray (shapers), accuracy.getCurrentSelectedID() - 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    WaveShaper<float> shapers[2] { { std::tanh }, { FastMathApproximations::tanh } };
 | 
			
		||||
    int currentShaperIdx = 0;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter accuracy {{ "No Approximation", "Use fast-math approximation" }, 1, "Accuracy" };
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &accuracy };  // no params for this demo
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct WaveShaperTanhDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    WaveShaperTanhDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<WaveShaperTanhDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
/*
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
 | 
			
		||||
   This file is part of the JUCE examples.
 | 
			
		||||
   Copyright (c) 2022 - Raw Material Software Limited
 | 
			
		||||
 | 
			
		||||
   The code included in this file is provided under the terms of the ISC license
 | 
			
		||||
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
 | 
			
		||||
   To use, copy, modify, and/or distribute this software for any purpose with or
 | 
			
		||||
   without fee is hereby granted provided that the above copyright notice and
 | 
			
		||||
   this permission notice appear in all copies.
 | 
			
		||||
 | 
			
		||||
   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
 | 
			
		||||
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
   PURPOSE, ARE DISCLAIMED.
 | 
			
		||||
 | 
			
		||||
  ==============================================================================
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 The block below describes the properties of this PIP. A PIP is a short snippet
 | 
			
		||||
 of code that can be read by the Projucer and used to generate a JUCE project.
 | 
			
		||||
 | 
			
		||||
 BEGIN_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
 name:             WaveShaperTanhDemo
 | 
			
		||||
 version:          1.0.0
 | 
			
		||||
 vendor:           JUCE
 | 
			
		||||
 website:          http://juce.com
 | 
			
		||||
 description:      Wave shaper tanh demo using the DSP module.
 | 
			
		||||
 | 
			
		||||
 dependencies:     juce_audio_basics, juce_audio_devices, juce_audio_formats,
 | 
			
		||||
                   juce_audio_processors, juce_audio_utils, juce_core,
 | 
			
		||||
                   juce_data_structures, juce_dsp, juce_events, juce_graphics,
 | 
			
		||||
                   juce_gui_basics, juce_gui_extra
 | 
			
		||||
 exporters:        xcode_mac, vs2022, linux_make
 | 
			
		||||
 | 
			
		||||
 moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1
 | 
			
		||||
 | 
			
		||||
 type:             Component
 | 
			
		||||
 mainClass:        WaveShaperTanhDemo
 | 
			
		||||
 | 
			
		||||
 useLocalCopy:     1
 | 
			
		||||
 | 
			
		||||
 END_JUCE_PIP_METADATA
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "../Assets/DemoUtilities.h"
 | 
			
		||||
#include "../Assets/DSPDemos_Common.h"
 | 
			
		||||
 | 
			
		||||
using namespace dsp;
 | 
			
		||||
 | 
			
		||||
//==============================================================================
 | 
			
		||||
struct WaveShaperTanhDemoDSP
 | 
			
		||||
{
 | 
			
		||||
    void prepare (const ProcessSpec&) {}
 | 
			
		||||
 | 
			
		||||
    void process (const ProcessContextReplacing<float>& context)
 | 
			
		||||
    {
 | 
			
		||||
        shapers[currentShaperIdx].process (context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void reset()
 | 
			
		||||
    {
 | 
			
		||||
        for (auto&& shaper : shapers)
 | 
			
		||||
            shaper.reset();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void updateParameters()
 | 
			
		||||
    {
 | 
			
		||||
        currentShaperIdx = jmin (numElementsInArray (shapers), accuracy.getCurrentSelectedID() - 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //==============================================================================
 | 
			
		||||
    WaveShaper<float> shapers[2] { { std::tanh }, { FastMathApproximations::tanh } };
 | 
			
		||||
    int currentShaperIdx = 0;
 | 
			
		||||
 | 
			
		||||
    ChoiceParameter accuracy {{ "No Approximation", "Use fast-math approximation" }, 1, "Accuracy" };
 | 
			
		||||
    std::vector<DSPDemoParameterBase*> parameters { &accuracy };  // no params for this demo
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct WaveShaperTanhDemo    : public Component
 | 
			
		||||
{
 | 
			
		||||
    WaveShaperTanhDemo()
 | 
			
		||||
    {
 | 
			
		||||
        addAndMakeVisible (fileReaderComponent);
 | 
			
		||||
        setSize (750, 500);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resized() override
 | 
			
		||||
    {
 | 
			
		||||
        fileReaderComponent.setBounds (getLocalBounds());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AudioFileReaderComponent<WaveShaperTanhDemoDSP> fileReaderComponent;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user