You probably wouldn't want to use this algorithm in very many situations. It's advantages are no memory requirement for a wavetable and no interpolation is needed (but about the same amount of work as linear interpolation). However, allowing the frequency to adjusted once the algorithm is running will require some more computation which may render it impractical. There also seems to be a problem with the algorithm at very low frequencies (< 40 Hz.)
The code allows for the frequency, initial phase offset, and amplitude to be specified in the constructor.
See Also:
Please do not redistribute this code. In the event that it contains a bug, this will ensure that it can be fixed without the buggy copies floating around indefinitely.
Last Modified: 6/28/98
/*********************************************************
Sine.h - A simple sinewave generator
Copyright (c) 1998, Scott Lehman, slehman@harmony-central.com
This code may be used and modified freely provided that credit
is given to the author in any public release. Any derivative
programs must be distributed freely and/or the modified source
code made publicly available. All code is provided AS IS and
without warranty of any kind.
*********************************************************/
#ifndef SINE_H
#define SINE_H
#include "Source.h"
class Sine : public Source {
public:
Sine(float amp, float freq, float phase);
void Initialize(void);
void Generate(void);
void Cleanup(void);
~Sine(){;}
private:
float frequency, startPhase, coeff, value1, value2, amplitude;
float * outputSignal;
Sine(void){;}
Sine(Sine&){;}
};
#endif
|
/********************************************************* Sine.cpp - A simple sinewave generator Copyright (c) 1998, Scott Lehman, slehman@harmony-central.com This code may be used and modified freely provided that credit is given to the author in any public release. Any derivative programs must be distributed freely and/or the modified source code made publicly available. All code is provided AS IS and without warranty of any kind. *********************************************************/ #include "Sine.h" #include |