2012-07-21 70 views
0

我將this tone generation code添加到我的現有項目,但我做錯了什麼,不知道問題是什麼。代碼在獨立項目中運行良好。沒有以前的功能原型

OSStatus RenderTone(
    void *inRefCon, 
    AudioUnitRenderActionFlags *ioActionFlags, 
    const AudioTimeStamp *inTimeStamp, 
    UInt32 inBusNumber, 
    UInt32 inNumberFrames, 
    AudioBufferList *ioData) 

{ 
    // Fixed amplitude is good enough for our purposes 
    const double amplitude = 0.25; 

    // Get the tone parameters out of the view controller 
    ToneGeneratorViewController *viewController = 
     (ToneGeneratorViewController *)inRefCon; 
    double theta = viewController->theta; 
    double theta_increment = 
     2.0 * M_PI * viewController->frequency/viewController->sampleRate; 

    // This is a mono tone generator so we only need the first buffer 
    const int channel = 0; 
    Float32 *buffer = (Float32 *)ioData->mBuffers[channel].mData; 

    // Generate the samples 
    for (UInt32 frame = 0; frame < inNumberFrames; frame++) 
    { 
     buffer[frame] = sin(theta) * amplitude; 

     theta += theta_increment; 
     if (theta > 2.0 * M_PI) 
     { 
      theta -= 2.0 * M_PI; 
     } 
    } 

    // Store the updated theta back in the view controller 
    viewController->theta = theta; 

    return noErr; 
} 

在控制器在那裏我添加的代碼我只有警告說No previous prototype for function 'RenderTone'(反覆)

我也越來越一些錯誤,但這些都不是設在源文件我已經寫了自己:

enter image description here

任何想法可能會導致那些?

回答

1

將AudioToolbox.framework添加到您的項目中。

+0

這將刪除錯誤,但不是警告。任何想法可以解決這些問題? – networkprofile 2012-07-22 14:48:21

+0

@Sled,這裏是你的ToneGenerator示例,沒有錯誤,沒有警告......享受! http://is.gd/en50Zt – Guru 2012-07-22 16:02:25