在 iOS 核心音频中,API AudioFileWritePackets的inPacketDescriptions
参数定义为“指向音频数据的数据包描述数组的指针”。
它在方法签名中看起来像这样:
const AudioStreamPacketDescription *inPacketDescriptions,
现在 struct AudioStreamPacketDescription 定义如下:
struct AudioStreamPacketDescription
{
SInt64 mStartOffset;
UInt32 mVariableFramesInPacket;
UInt32 mDataByteSize;
};
typedef struct AudioStreamPacketDescription AudioStreamPacketDescription;
我想知道如何创建和填充这样的“指向结构数组的指针”,甚至一旦给定变量,如何读取它。使用苹果的speakHere示例,我在接收变量的位置放置了一个断点,并尝试将其所有内容转储到日志中。这是一个尝试示例:
void AQRecorder::printPacketDescriptionContents(const AudioStreamPacketDescription * inPacketDescriptions, UInt32 inNumberPackets)
{
for (int i = 0; i < inNumberPackets; ++i)
{
NSLog(@"\n----------------\n");
NSLog(@"this is packetDescriptionArray[%d].mStartOffset: %lld", i, (*inPacketDescriptions).mStartOffset);
NSLog(@"this is packetDescriptionArray[%d].mVariableFramesInPacket: %lu", i, (*inPacketDescriptions).mVariableFramesInPacket);
NSLog(@"this is packetDescriptionArray[%d].mDataByteSize: %lu", i, (*inPacketDescriptions).mDataByteSize);
NSLog(@"\n----------------\n");
}
}
有任何想法吗?
更新:这是我试图弄乱它的示例日志..也许它可以帮助回答(注意在底部它一直显示为空..整个事情只是一个包是没有意义的零,因为它是一个由回调返回的变量,应该正确填充,还请注意它告诉我我返回的数据包数量..).. 如果我运行代码,((const AudioStreamPacketDescription *)(inPacketDescriptions +i))->mDataByteSize)
我得到一个 EXC_BAD_ACCESS 错误
(lldb) po **(inPacketDescriptions)
error: indirection requires pointer operand ('const AudioStreamPacketDescription' invalid)
error: 1 errors parsing expression
(lldb) po *(inPacketDescriptions)
(AudioStreamPacketDescription) $1 = [no Objective-C description available]
(lldb) po *(inPacketDescriptions).mStartOffset
error: member reference type 'const AudioStreamPacketDescription *' is a pointer; maybe you meant to use '->'?
error: indirection requires pointer operand ('SInt64' (aka 'long long') invalid)
error: 2 errors parsing expression
(lldb) po (*inPacketDescriptions).mStartOffset
(SInt64) $2 = 0 <nil>
(lldb) po (const AudioStreamPacketDescription *)(inPacketDescriptions +1)
(const class AudioStreamPacketDescription *) $3 = 0x00000010 [no Objective-C description available]
(lldb) po (const AudioStreamPacketDescription *)(inPacketDescriptions +1)->mStartOffset
error: Execution was interrupted, reason: Attempted to dereference an invalid pointer..
The process has been returned to the state before execution.
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +1))->mStartOffset
(SInt64) $5 = 0 <nil>
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +1))->mDataByteSize
(UInt32) $6 = 0 <nil>
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +100))->mDataByteSize
(UInt32) $7 = 0 <nil>
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +500))->mDataByteSize
(UInt32) $8 = 0 <nil>
(lldb) po inPacketDescriptions[0].mStartOffset
error: parent failed to evaluate: parent is NULL
(lldb)
这也是 XCode 检查器中的样子: