2012-07-21 50 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