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.

131 lines
4.2KB

  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: OverdriveDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Overdrive 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: OverdriveDemo
  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 OverdriveDemoDSP
  41. {
  42. void prepare (const ProcessSpec& spec)
  43. {
  44. sampleRate = spec.sampleRate;
  45. auto& gainUp = overdrive.get<0>();
  46. gainUp.setGainDecibels (24);
  47. auto& bias = overdrive.get<1>();
  48. bias.setBias (0.4f);
  49. auto& wavShaper = overdrive.get<2>();
  50. wavShaper.functionToUse = std::tanh;
  51. auto& dcFilter = overdrive.get<3>();
  52. dcFilter.state = IIR::Coefficients<float>::makeHighPass (sampleRate, 5.0);
  53. auto& gainDown = overdrive.get<4>();
  54. gainDown.setGainDecibels (-18.0f);
  55. overdrive.prepare (spec);
  56. }
  57. void process (const ProcessContextReplacing<float>& context)
  58. {
  59. overdrive.process (context);
  60. }
  61. void reset()
  62. {
  63. overdrive.reset();
  64. }
  65. void updateParameters()
  66. {
  67. if (! approximatelyEqual (sampleRate, 0.0))
  68. {
  69. overdrive.get<0>().setGainDecibels (static_cast<float> (inGainParam.getCurrentValue()));
  70. overdrive.get<4>().setGainDecibels (static_cast<float> (outGainParam.getCurrentValue()));
  71. }
  72. }
  73. //==============================================================================
  74. using GainProcessor = Gain<float>;
  75. using BiasProcessor = Bias<float>;
  76. using DriveProcessor = WaveShaper<float>;
  77. using DCFilter = ProcessorDuplicator<IIR::Filter<float>,
  78. IIR::Coefficients<float>>;
  79. ProcessorChain<GainProcessor, BiasProcessor, DriveProcessor, DCFilter, GainProcessor> overdrive;
  80. SliderParameter inGainParam { { -100.0, 60.0 }, 3, 24.0, "Input Gain", "dB" };
  81. SliderParameter outGainParam { { -100.0, 20.0 }, 3, -18.0, "Output Gain", "dB" };
  82. std::vector<DSPDemoParameterBase*> parameters { &inGainParam, &outGainParam };
  83. double sampleRate = 0.0;
  84. };
  85. struct OverdriveDemo final : public Component
  86. {
  87. OverdriveDemo()
  88. {
  89. addAndMakeVisible (fileReaderComponent);
  90. setSize (750, 500);
  91. }
  92. void resized() override
  93. {
  94. fileReaderComponent.setBounds (getLocalBounds());
  95. }
  96. AudioFileReaderComponent<OverdriveDemoDSP> fileReaderComponent;
  97. };