Skip to content

Commit 2053bd6

Browse files
committed
SawToothGenerator
1 parent 80253e9 commit 2053bd6

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

src/AudioTools/CoreAudio/AudioEffects/SoundGenerator.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -222,31 +222,6 @@ template <class T> class SineWaveGenerator : public SoundGenerator<T> {
222222
}
223223
};
224224

225-
/**
226-
* @brief Generates a square wave sound.
227-
* @ingroup generator
228-
* @author Phil Schatzmann
229-
* @copyright GPLv3
230-
*
231-
*/
232-
template <class T> class SquareWaveGenerator : public SineWaveGenerator<T> {
233-
public:
234-
SquareWaveGenerator(float amplitude = 32767.0f, float phase = 0.0f)
235-
: SineWaveGenerator<T>(amplitude, phase) {
236-
LOGD("SquareWaveGenerator");
237-
}
238-
239-
virtual T readSample() {
240-
return value(SineWaveGenerator<T>::readSample(),
241-
SineWaveGenerator<T>::m_amplitude);
242-
}
243-
244-
protected:
245-
// returns amplitude for positive vales and -amplitude for negative values
246-
T value(T value, T amplitude) {
247-
return (value >= 0) ? amplitude : -amplitude;
248-
}
249-
};
250225

251226
/**
252227
* @brief Sine wave which is based on a fast approximation function.
@@ -283,11 +258,37 @@ template <class T> class FastSineGenerator : public SineWaveGenerator<T> {
283258
}
284259
};
285260

261+
/**
262+
* @brief Generates a square wave sound.
263+
* @ingroup generator
264+
* @author Phil Schatzmann
265+
* @copyright GPLv3
266+
*
267+
*/
268+
template <class T> class SquareWaveGenerator : public FastSineGenerator<T> {
269+
public:
270+
SquareWaveGenerator(float amplitude = 32767.0f, float phase = 0.0f)
271+
: FastSineGenerator<T>(amplitude, phase) {
272+
LOGD("SquareWaveGenerator");
273+
}
274+
275+
virtual T readSample() {
276+
return value(FastSineGenerator<T>::readSample(),
277+
FastSineGenerator<T>::m_amplitude);
278+
}
279+
280+
protected:
281+
// returns amplitude for positive vales and -amplitude for negative values
282+
T value(T value, T amplitude) {
283+
return (value >= 0) ? amplitude : -amplitude;
284+
}
285+
};
286+
286287

287288
/**
288-
* @brief Sine wave which is based on a fast approximation function.
289+
* @brief SawToothGenerator
289290
* @ingroup generator
290-
* @author Vivian Leigh Stewart
291+
* @author Phil Schatzmann
291292
* @copyright GPLv3
292293
* @tparam T
293294
*/

0 commit comments

Comments
 (0)