iOS 용 신시사이저를 만드는 중입니다. 놀고 난 후 핵심 오디오를 배우려고 할 때, 나는 머리를 감을 수 없다는 문제가 발생했습니다. 나의 사인파는 규칙적인 간격으로 딸깍 거리는 소음을 일으킨다. Im 추측은 단계와 관련이있다. 주제에 대한 여러 가지 안내서와 책을 살펴 봤는데 모두 올바르게하고 있다고 제안합니다.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;
}
고맙습니다. – Mordapps