我正在尝试为我正在开发的一个简单的波表合成器 iOS 应用程序生成不同的波形。这就是我生成正弦波的方式:
if (waveType == 1) // sine wave
{
//NSLog(@"sine in AU");
for (int i=0;i<n;i++)
{
float x = 0.0; // default to silence
if (toneCount > 0) // or create a sinewave
{
x = testVolume * sinf(ph);
ph = ph + dp;
if (ph > M_PI) { ph -= 2.0 * M_PI; } // sine wave
toneCount -= 1; // decrement tone length counter
}
if (ptrLeft != NULL){
ptrLeft[ i] = x;
}
if (ptrRight != NULL) {
ptrRight[i] = x;
}
}
}
对于方波,我假设这会起作用,但它没有:
if (ph > M_PI) {
ph -= 2.0 * M_PI;
ph >= 0 ? 1.0 : -1.0;
}
我将如何创建锯齿波和三角波,方波哪里出错了?
谢谢,我是 iOS 编程新手,喜欢使用音频。