如何从C函数调用Objective-C方法?(iOS)
我发现了一个关于AudioUnits()的很棒的教程,我已经开始在我的系统上工作了;但是,从RenderTone C函数调用Objective-C方法时遇到问题 在与RenderOne相同的m文件中,我有以下方法:如何从C函数调用Objective-C方法?(iOS),ios,audio,core-audio,Ios,Audio,Core Audio,我发现了一个关于AudioUnits()的很棒的教程,我已经开始在我的系统上工作了;但是,从RenderTone C函数调用Objective-C方法时遇到问题 在与RenderOne相同的m文件中,我有以下方法: - (Float32)signalGenerator:(int)sample withSampleRate:(int)Fs andFrequency:(float)frequency{ 当我尝试从RenderTone函数调用此方法时,XCode会给我以下错误:“使用未声明的标识符‘
- (Float32)signalGenerator:(int)sample withSampleRate:(int)Fs andFrequency:(float)frequency{
当我尝试从RenderTone函数调用此方法时,XCode会给我以下错误:“使用未声明的标识符‘signalGenerator’”。如果它在同一个文件中,为什么它看不到此方法
感谢阅读。在RenderTone()
函数中
ToneGeneratorViewController *viewController = (ToneGeneratorViewController *)inRefCon;
是视图控制器的实例,因此可以调用方法
Float32 x = [viewController signalGenerator:13 withSampleRate:14 andFrequency:15];
从RenderTone()
中。为了让编译器知道该方法,
你也可以
- 将
移动到RenderTone()
块中,或@实现中的GeneratorViewController
- 使用类扩展添加函数原型:
@interface ToneGeneratorViewController () - (Float32)signalGenerator:(int)sample withSampleRate:(int)Fs andFrequency:(float)frequency; @end