AudioFileReadPackets 错误 -50

AudioFileReadPackets Error -50

我正在播放音频 API,我的第一步是将文件内容读入缓冲区。 我有以下代码,但是当 AudioFileReadPackets 被执行时,我得到 return 代码 -50 我没有得到它,因为在文档中它不存在。 你能给我指出正确的方向吗?任何想法将不胜感激!

    //create url for file
    CFURLRef myFileURL = CFURLCreateWithString(kCFAllocatorDefault, INPUT_FILE, NULL);
    AudioFileID audioFile;
    OSStatus error;

    error = AudioFileOpenURL(myFileURL,kAudioFileReadPermission,0,&audioFile);
    CFRelease(myFileURL);

    if(error != noErr) {
        printf("%d",(int)error);
        exit(1);
    }

    AudioStreamBasicDescription  dataFormat;
    UInt32 size = sizeof(dataFormat);

    error = AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &size, &dataFormat);

    if(error != noErr) {
        printf("%d",(int)error);
        exit(1);
    }

    UInt32 dataSize;
    error = AudioFileGetPropertyInfo(audioFile, kAudioFilePropertyAudioDataPacketCount, &dataSize, NULL);

    if(error != noErr) {
        printf("%d",(int)error);
        exit(1);
    }

    UInt32 packetCount;
    error = AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataPacketCount, &dataSize, &packetCount);

    if(error != noErr) {
        printf("%d",(int)error);
        exit(1);
    }

    printf("File opened, packet count: %d\n", packetCount);
    UInt32 packetsRead = packetCount;
    UInt32 bytesRead = 0;

    if(packetCount > 0) {
        SInt16 audioData = *(SInt16 *)malloc(2 * packetCount);
        error = AudioFileReadPackets(audioFile, false, &bytesRead, NULL, 0, &packetsRead, audioData);

        if(error != noErr) {
            printf("%d",(int)error);
            exit(1);
        }

        printf("Read %d bytes, %d packets",bytesRead,packetsRead);

    }

-50 = paramErr 表示您传递了错误的参数。文档说 AudioFileReadPackets 的第四个参数对于恒定比特率音频只能为 NULL。