@@ -211,8 +211,8 @@ class SineWaveGenerator : public SoundGenerator<T>{
211
211
212
212
// / Provides a single sample
213
213
virtual T readSample () override {
214
- float angle = m_cycles + m_phase;
215
- T result = m_amplitude * sine (angle);
214
+ float angle = double_Pi * m_cycles + m_phase;
215
+ T result = m_amplitude * sinf (angle);
216
216
m_cycles += m_frequency * m_deltaTime;
217
217
if (m_cycles > 1.0 ) {
218
218
m_cycles -= 1.0 ;
@@ -261,6 +261,32 @@ class SquareWaveGenerator : public SineWaveGenerator<T> {
261
261
}
262
262
};
263
263
264
+ // / sine approximation.
265
+ float sine (float t) {
266
+ float p = (t - (int )t) - 0 .5f ; // 0 <= p <= 1
267
+ float pp = p * p;
268
+ return (p - 6 .283211f * pp * p + 9 .132843f * pp * pp * p) * -6 .221086f ;
269
+ }
270
+
271
+ template <class T >
272
+ class FastSineGenerator : public SineWaveGenerator <T> {
273
+ public:
274
+ FastSineGenerator (float amplitude = 32767.0 , float phase = 0.0 ) : SineWaveGenerator<T>(amplitude, phase) {
275
+ LOGD (" FastSineGenerator" );
276
+ }
277
+
278
+ virtual T readSample () override {
279
+ float angle = double_Pi * SineWaveGenerator<T>::m_cycles +
280
+ SineWaveGenerator<T>::m_phase;
281
+ T result = SineWaveGenerator<T>::m_amplitude * sine (angle);
282
+ SineWaveGenerator<T>::m_cycles += SineWaveGenerator<T>::m_frequency *
283
+ SineWaveGenerator<T>::m_deltaTime;
284
+ if (SineWaveGenerator<T>::m_cycles > 1.0 ) {
285
+ SineWaveGenerator<T>::m_cycles -= 1.0 ;
286
+ }
287
+ return result;
288
+ }
289
+ };
264
290
265
291
/* *
266
292
* @brief Generates a random noise sound with the help of rand() function.
0 commit comments