You could always start with sin
waves. :-)
#include <cmath>
typedef double Sample;
typedef double Time;
class MonoNote {
protected:
Time start, duration;
virtual void internalRender(double now, Sample *mono) = 0;
public:
MonoNote(Time s, Time d) : start(s), duration(d) {}
virtual ~MonoNote() {}
void render(double now, Sample *mono) {
if (start <= now && now < start + duration) {
internalRender(now, mono);
}
}
};
class MonoSinNote : public MonoNote {
Time freq;
Sample amplitude;
protected:
void internalRender(double now, Sample *mono) {
const double v = sin(2*M_PI*(now - start) * freq);
*mono += amplitude*v;
}
public:
MonoSinNote(Time s, Time d, Time f, Sample a) : MonoNote(s, d), freq(f), amplitude(a) {}
~MonoSinNote() {}
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…