我正在使用苹果示例代码SpleakHere。在这个代码中有一个名为AQRecorder的函数,它是一个C类。我想将声音字节发送给我拥有的一个Objective-C对象。这个对象通过udp发送数据。这里是我尝试在c代码中执行一个objective-c函数的函数。从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对象。
帮助,请
虽然我wan't能够以发送数据添加对象...我用NSNotification相反在以端口的数据从c对象到objective- c物件
这段代码乱七八糟,如果你想让人们不厌其烦地帮助你,那么不妨将其格式化。 – 2011-06-24 13:28:31