1

这里真正的基本问题:

我见过一堆memset处理结构时使用的 CoreAudio 代码,但我无法弄清楚原因。这是来自 .m ObjC 文件。

这是下面代码块中的行:

memset(&clientFormat, 0, sizeof(clientFormat));

//---------------

    AudioStreamBasicDescription clientFormat;
    if ( sourceFormat.mFormatID == kAudioFormatLinearPCM ) {
    clientFormat = sourceFormat;
    } else {
    memset(&clientFormat, 0, sizeof(clientFormat));
    int sampleSize = sizeof(AudioSampleType);
    clientFormat.mFormatID = kAudioFormatLinearPCM;
    clientFormat.mFormatFlags = kAudioFormatFlagsCanonical;
    clientFormat.mBitsPerChannel = 8 * sampleSize;
    clientFormat.mChannelsPerFrame = sourceFormat.mChannelsPerFrame;
    clientFormat.mFramesPerPacket = 1;
    clientFormat.mBytesPerPacket = clientFormat.mBytesPerFrame = sourceFormat.mChannelsPerFrame * sampleSize;
    clientFormat.mSampleRate = sourceFormat.mSampleRate;
}
4

1 回答 1

1

正如调用的那样,它将内存设置为&clientFormat,长度为sizeof(clientFormat),到0。这是必需的,因为 C 中的内存在0使用malloc()和大多数其他分配函数分配后不会被清除。

于 2012-04-11T02:26:12.463 回答