gpt4 book ai didi

ios - Objective-c 将参数传递给 IBAction

转载 作者:行者123 更新时间:2023-11-28 22:11:21 25 4
gpt4 key购买 nike

我在 iPhone SDK 上开发实时音频处理,我使用“EZAudio”从麦克风获取数据,然后用高通滤波器过滤它们,最后在“EZAudio”的帮助下绘制它们。

我设置了两个按钮来绘制原始波形和过滤后的波形。我不知道如何将数据从麦克风传递到 -(IBAction)?

这是我的代码:

来自 microphoneDelegate 的数据

-(void)    microphone:(EZMicrophone *)microphone
hasAudioReceived:(float **)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels {
dispatch_async(dispatch_get_main_queue(), ^{

// Update time domain plot
[self.audioPlotTime updateBuffer:buffer[0]
withBufferSize:bufferSize];

});
}

我写的高通滤波器:

-(void)processSampleForHighOrLowPassFilter:(float)bufferSize
withAudioData:(float*)inBuffer
withFilterType:(UInt32)filterType {

float *outBuffer = (float *)malloc(sizeof(float)*bufferSize);

for (int i=0; i<bufferSize; i++) {

outBuffer[i] = (a0 * (inBuffer[i]))
+ (a1 * tmpBufferInIndex[0])
+ (a2 * tmpBufferInIndex[1])
- (b1 * tmpBufferOutIndex[0])
- (b2 * tmpBufferOutIndex[1]);

tmpBufferInIndex[1] = tmpBufferInIndex[0];
tmpBufferInIndex[0] = inBuffer[i];
tmpBufferOutIndex[1] = tmpBufferOutIndex[0];
tmpBufferOutIndex[0] = outBuffer[i];
}

[self.audioPlotHighPassFilter8kHz updateBuffer:outBuffer
withBufferSize:bufferSize];
}

我想用一个按钮触发绘制原始波形和处理后的波形

-(void)plotOriginalWaveForm:(id)sender {
//[self.audioPlot updateBuffer:outBuffer
// withBufferSize:bufferSize];
}

-(void)plot8kHzWaveForm:(id)sender {
//[self.audioPlotHighPassFilter8kHz updateBuffer:outBuffer
// withBufferSize:bufferSize];
}

但是我不明白如何将bufferbufferSize传递给IBAction,因为我会在里面调用plot函数而plot函数需要这两个参数。

如果您能提供一些建议或有任何其他方法可以在 IBAction 中使用来自麦克风的数据,谢谢!

最佳答案

将缓冲区和缓冲区大小信息作为属性存储在您的类中,当您在麦克风委托(delegate)中被调用时设置它们,并在绘制波形时从属性中检索它们,而不是作为参数传递。

编辑以提供可能的示例,具体取决于原始代码周围的类:

在@interface block 中的 .h 文件中:

{
float ** myBuffer;
UInt32 myBufferSize;
}

在你的方法中:

-(void)    microphone:(EZMicrophone *)microphone
hasAudioReceived:(float **)buffer
withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels {

self.myBuffer = buffer;
self.myBufferSize = bufferSize;
dispatch_async(dispatch_get_main_queue(), ^{

// Update time domain plot
[self.audioPlotTime updateBuffer:buffer[0]
withBufferSize:bufferSize];

});
}

-(void)plotOriginalWaveForm:(id)sender {
[self.audioPlot myBuffer
myBufferSize];
}

-(void)plot8kHzWaveForm:(id)sender {
[self.audioPlotHighPassFilter8kHz myBuffer
withBufferSize:myBufferSize];
}

关于ios - Objective-c 将参数传递给 IBAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22856021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com