Доступ к необработанным аудиоданным с помощью Audio Queue с помощью AudioFileReadPackets

Я пытаюсь получить доступ к необработанным аудиоданным, отправленным в обратный вызов Audio Queue, но после вызова AudioFileReadPackets количество байтов (numBytes) равно 0.

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) {

        //read packets
        UInt32 numBytes;

        OSStatus result = AudioFileReadPackets(aqr->mRecordFile,      // The audio file from which packets of audio data are to be read.
                                               FALSE,                   // Set to true to cache the data. Otherwise, set to false.
                                               &numBytes,               // On output, a pointer to the number of bytes actually returned.
                                               (__bridge AudioStreamPacketDescription*)inPacketDesc,    // A pointer to an array of packet descriptions that have been allocated.
                                               aqr->mRecordPacket,  // The packet index of the first packet you want to be returned.
                                               &inNumPackets,               // On input, a pointer to the number of packets to read. On output, the number of packets actually read.                                           
                                               inBuffer->mAudioData); // A pointer to user-allocated memory.

        inBuffer->mAudioDataByteSize = numBytes;       
        SInt16 *testBuffer = (SInt16*)inBuffer->mAudioData;

        for (int i=0; i < numBytes; i++)
        {
            UInt16 currentData = testBuffer[i];
            printf("Current data in testbuffer is %d", currentData);
        }

    // 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));
}
}

Я могу получить значения от 0 до 4294967296, когда распечатываю только первый индекс testBuffer, поэтому он не кажется пустым. Любые идеи, почему numBytes равен 0 после выполнения AudioFileReadPackets?


person Bae    schedule 29.06.2012    source источник


Ответы (1)


Я все еще не уверен, почему numBytes равен 0, но я нашел работоспособное решение от этот вопрос.

Чтобы получить размер testBuffer, я использовал следующий код:

int sampleCount = inBuffer->mAudioDataBytesCapacity / sizeof(SInt16);
person Bae    schedule 29.06.2012