1 /*******************************************************************************
2  * Copyright 2009-2016 Jörg Müller
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 #pragma once
18 
19 /**
20  * @file Threshold.h
21  * @ingroup fx
22  * The Threshold class.
23  */
24 
25 #include "fx/Effect.h"
26 
27 AUD_NAMESPACE_BEGIN
28 
29 class CallbackIIRFilterReader;
30 
31 /**
32  * This sound Transforms any signal to a square signal by thresholding.
33  */
34 class AUD_API Threshold : public Effect
35 {
36 private:
37 	/**
38 	 * The threshold.
39 	 */
40 	const float m_threshold;
41 
42 	// delete copy constructor and operator=
43 	Threshold(const Threshold&) = delete;
44 	Threshold& operator=(const Threshold&) = delete;
45 
46 public:
47 	/**
48 	 * Creates a new threshold sound.
49 	 * \param sound The input sound.
50 	 * \param threshold The threshold.
51 	 */
52 	Threshold(std::shared_ptr<ISound> sound, float threshold = 0.0f);
53 
54 	/**
55 	 * Returns the threshold.
56 	 */
57 	float getThreshold() const;
58 
59 	virtual std::shared_ptr<IReader> createReader();
60 
61 	/**
62 	 * The thresholdFilter function implements the doFilterIIR callback
63 	 * for the callback IIR filter.
64 	 * @param reader The CallbackIIRFilterReader that executes the callback.
65 	 * @param threshold The threshold value.
66 	 * @return The filtered sample.
67 	 */
68 	static sample_t AUD_LOCAL thresholdFilter(CallbackIIRFilterReader* reader, float* threshold);
69 
70 	/**
71 	 * The endThresholdFilter function implements the endFilterIIR callback
72 	 * for the callback IIR filter.
73 	 * @param threshold The threshold value.
74 	 */
75 	static void AUD_LOCAL endThresholdFilter(float* threshold);
76 };
77 
78 AUD_NAMESPACE_END
79