作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在为 iOS 创建一个合成器。在玩弄并尝试学习核心音频之后,我遇到了一个我无法理解的问题。我的正弦波定期发出咔嗒声,我猜这与相位有关。我查看了有关该主题的几本指南和书籍,所有这些都表明我的做法是正确的。
如果有人愿意为我查看我的代码,我们将不胜感激。
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
{
// Get a reference to the object that was passed with the callback
// In this case, the AudioController passed itself so
// that you can access its data.
AudioController *THIS = (AudioController*)inRefCon;
// Get a pointer to the dataBuffer of the AudioBufferList
AudioSampleType *outA = (AudioSampleType *)ioData->mBuffers[0].mData;
float freq = THIS->Frequency;
float phase = THIS->sinPhase;
float envValue;
float sinSignal;
// The amount the phase changes in single sample
double phaseIncrement = 2 * M_PI * freq / kGraphSampleRate;
// Loop through the callback buffer, generating samples
for (UInt32 i = 0; i < inNumberFrames; ++i) {
sinSignal = sin(phase);
envValue = THIS->env.tick();
// Put the sample into the buffer
// Scale the -1 to 1 values float to
// -32767 to 32767 and then cast to an integer
outA[i] = (SInt16)(((sinSignal * 32767.0f) / 2) * envValue);
phase = phase + phaseIncrement;
if (phase >= (2 * M_PI * freq)) {
phase = phase - (2 * M_PI * freq);
}
}
// Store the phase for the next callback.
THIS->sinPhase = phase;
return noErr;
}
最佳答案
相位可能在错误的点上溢出
替换这个:
if (phase >= (2 * M_PI * freq)) {
phase = phase - (2 * M_PI * freq);
}
与
if (phase >= (2 * M_PI)) {
phase = phase - (2 * M_PI);
}
关于iOS 正弦波生成 - 可听见的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10000552/
是否有任何 Javascript 库支持在长时间运行的操作(例如上传)结束时发出通知?通知最好是通用的,这样即使某些技术不起作用(如桌面通知),浏览器仍能设法引起注意。 铃声 桌面通知(Chrome)
我是一名优秀的程序员,十分优秀!