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;
}