【发布时间】:2011-06-17 09:43:47
【问题描述】:
我正在使用苹果示例代码SpleakHere。在这段代码中有一个名为 AQRecorder 的类,它是一个 C 类。我想将声音字节发送到我拥有的objective-c 对象。此对象通过 udp 发送 dat。这是我试图在c代码中执行objective-c函数的函数。
void AQRecorder::MyInputBufferHandler( void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp * inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription* inPacketDesc)
{
AQRecorder *aqr = (AQRecorder *)inUserData;
try {
if (inNumPackets > 0) {
// write packets to file
XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize,
inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData),
"AudioFileWritePackets failed");
aqr->mRecordPacket += inNumPackets;
NSData* data=[NSData dataWithBytes:inBuffer->mAudioData length:inBuffer->mAudioDataByteSize];
[(Udp*)udpp sendData:data];
}
// if we're not stopping, re-enqueue the buffe so that it gets filled again
if (aqr->IsRunning())
XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed");
} catch (CAXException e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}
}
虽然 NSData 函数工作正常,但我无法将我的对象 (Udp) 添加到该类,因此无法调用它的函数。我尝试在任何地方声明 Udp 对象(类内,类外,头 .mm 文件,作为 void*...),但没有任何东西可以编译...
虽然我无法添加对象来发送数据...我使用 NSNptification 来将数据从 c 对象移植到 Objective-c 对象。
请帮忙
虽然我无法添加对象来发送数据...我使用 NSNotification 来将数据从 c 对象移植到 Objective-c 对象
【问题讨论】:
-
那段代码乱七八糟,如果你想让人们不厌其烦地帮助你,麻烦格式化一下。
标签: iphone objective-c c core-audio