OpenShot Library | OpenShotAudio 0.2.2
juce_WaveShaper.h
1
2/** @weakgroup juce_dsp-processors
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16 27th April 2017).
17
18 End User License Agreement: www.juce.com/juce-5-licence
19 Privacy Policy: www.juce.com/juce-5-privacy-policy
20
21 Or: You may also use this code under the terms of the GPL v3 (see
22 www.gnu.org/licenses).
23
24 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26 DISCLAIMED.
27
28 ==============================================================================
29*/
30
31namespace juce
32{
33namespace dsp
34{
35
36/**
37 Applies waveshaping to audio samples as single samples or AudioBlocks.
38
39 @tags{DSP}
40*/
41template <typename FloatType, typename Function = FloatType (*) (FloatType)>
43{
44 Function functionToUse;
45
46 //==============================================================================
47 /** Called before processing starts. */
48 void prepare (const ProcessSpec&) noexcept {}
49
50 //==============================================================================
51 /** Returns the result of processing a single sample. */
52 template <typename SampleType>
53 SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType inputSample) const noexcept
54 {
55 return functionToUse (inputSample);
56 }
57
58 /** Processes the input and output buffers supplied in the processing context. */
59 template <typename ProcessContext>
60 void process (const ProcessContext& context) const noexcept
61 {
62 if (context.isBypassed)
63 {
64 if (context.usesSeparateInputAndOutputBlocks())
65 context.getOutputBlock().copyFrom (context.getInputBlock());
66 }
67 else
68 {
69 AudioBlock<FloatType>::process (context.getInputBlock(),
70 context.getOutputBlock(),
71 functionToUse);
72 }
73 }
74
75 void reset() noexcept {}
76};
77
78//==============================================================================
79// Although clang supports C++17, their standard library still has no invoke_result
80// support. Remove the "|| JUCE_CLANG" once clang supports this properly!
81#if (! JUCE_CXX17_IS_AVAILABLE) || JUCE_CLANG
82template <typename Functor>
83static WaveShaper<typename std::result_of<Functor>, Functor> CreateWaveShaper (Functor functionToUse) { return {functionToUse}; }
84#else
85template <typename Functor>
86static WaveShaper<typename std::invoke_result<Functor>, Functor> CreateWaveShaper (Functor functionToUse) { return {functionToUse}; }
87#endif
88
89} // namespace dsp
90} // namespace juce
91
92/** @}*/
static void process(AudioBlock< Src1SampleType > inBlock, AudioBlock< Src2SampleType > outBlock, FunctionType &&function)
Applies a function to each value in an input block, putting the result into an output block.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
Applies waveshaping to audio samples as single samples or AudioBlocks.
void prepare(const ProcessSpec &) noexcept
Called before processing starts.
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType inputSample) const noexcept
Returns the result of processing a single sample.
void process(const ProcessContext &context) const noexcept
Processes the input and output buffers supplied in the processing context.