本文介绍了Cocoa Touch中的音调生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要生成一种可以操纵频率和波形的音调。总体目标是创建一个基本的钢琴。有谁知道我怎么做到这一点?
I need to generate a tone that I can manipulate frequency and wave. The overall goal is to create a basic piano. Does anyone know how I can achieve this?
我的开发平台是iPhone 2.x
My development platform is the iPhone 2.x
推荐答案
你总是可以从 sin
波开始。 : - )
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() {}
};
这篇关于Cocoa Touch中的音调生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!