The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: FIRFilterDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: FIR filter demo using the DSP module.
  24. dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
  25. juce_audio_processors, juce_audio_utils, juce_core,
  26. juce_data_structures, juce_dsp, juce_events, juce_graphics,
  27. juce_gui_basics, juce_gui_extra
  28. exporters: xcode_mac, vs2022, linux_make
  29. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  30. type: Component
  31. mainClass: FIRFilterDemo
  32. useLocalCopy: 1
  33. END_JUCE_PIP_METADATA
  34. *******************************************************************************/
  35. #pragma once
  36. #include "../Assets/DemoUtilities.h"
  37. #include "../Assets/DSPDemos_Common.h"
  38. using namespace dsp;
  39. //==============================================================================
  40. struct FIRFilterDemoDSP
  41. {
  42. void prepare (const ProcessSpec& spec)
  43. {
  44. sampleRate = spec.sampleRate;
  45. fir.state = FilterDesign<float>::designFIRLowpassWindowMethod (440.0f, sampleRate, 21,
  46. WindowingFunction<float>::blackman);
  47. fir.prepare (spec);
  48. }
  49. void process (const ProcessContextReplacing<float>& context)
  50. {
  51. fir.process (context);
  52. }
  53. void reset()
  54. {
  55. fir.reset();
  56. }
  57. void updateParameters()
  58. {
  59. if (! approximatelyEqual (sampleRate, 0.0))
  60. {
  61. auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
  62. auto windowingMethod = static_cast<WindowingFunction<float>::WindowingMethod> (typeParam.getCurrentSelectedID() - 1);
  63. *fir.state = *FilterDesign<float>::designFIRLowpassWindowMethod (cutoff, sampleRate, 21, windowingMethod);
  64. }
  65. }
  66. //==============================================================================
  67. ProcessorDuplicator<FIR::Filter<float>, FIR::Coefficients<float>> fir;
  68. double sampleRate = 0.0;
  69. SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.4, 440.0f, "Cutoff", "Hz" };
  70. ChoiceParameter typeParam { { "Rectangular", "Triangular", "Hann", "Hamming", "Blackman", "Blackman-Harris", "Flat Top", "Kaiser" },
  71. 5, "Windowing Function" };
  72. std::vector<DSPDemoParameterBase*> parameters { &cutoffParam, &typeParam };
  73. };
  74. struct FIRFilterDemo final : public Component
  75. {
  76. FIRFilterDemo()
  77. {
  78. addAndMakeVisible (fileReaderComponent);
  79. setSize (750, 500);
  80. }
  81. void resized() override
  82. {
  83. fileReaderComponent.setBounds (getLocalBounds());
  84. }
  85. AudioFileReaderComponent<FIRFilterDemoDSP> fileReaderComponent;
  86. };