File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/AudioTools/CoreAudio/AudioEffects Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,41 @@ template <class T> class FastSineGenerator : public SineWaveGenerator<T> {
283
283
}
284
284
};
285
285
286
+
287
+ /* *
288
+ * @brief Sine wave which is based on a fast approximation function.
289
+ * @ingroup generator
290
+ * @author Vivian Leigh Stewart
291
+ * @copyright GPLv3
292
+ * @tparam T
293
+ */
294
+ template <class T > class SawToothGenerator : public SineWaveGenerator <T> {
295
+ public:
296
+ SawToothGenerator (float amplitude = 32767.0 , float phase = 0.0 )
297
+ : SineWaveGenerator<T>(amplitude, phase) {
298
+ LOGD (" SawToothGenerator" );
299
+ }
300
+
301
+ virtual T readSample () override {
302
+ float angle =
303
+ SineWaveGenerator<T>::m_cycles + SineWaveGenerator<T>::m_phase;
304
+ T result = SineWaveGenerator<T>::m_amplitude * saw (angle);
305
+ SineWaveGenerator<T>::m_cycles +=
306
+ SineWaveGenerator<T>::m_frequency * SineWaveGenerator<T>::m_deltaTime;
307
+ if (SineWaveGenerator<T>::m_cycles > 1.0 ) {
308
+ SineWaveGenerator<T>::m_cycles -= 1.0 ;
309
+ }
310
+ return result;
311
+ }
312
+
313
+ protected:
314
+ // / sine approximation.
315
+ inline float saw (float t) {
316
+ float p = (t - (int )t) - 0 .5f ; // 0 <= p <= 1
317
+ return p;
318
+ }
319
+ };
320
+
286
321
/* *
287
322
* @brief Generates a random noise sound with the help of rand() function.
288
323
* @ingroup generator
You can’t perform that action at this time.
0 commit comments