2012-06-29 2 views
0

를 사용하여 데이터,하지만 난 호출 AudioFileReadPackets 후, 바이트 (하는 numBytes)의 수는 0액세스 원시 오디오 오디오 큐가 나는 오디오 큐 콜백에 전송 원시 오디오 데이터에 액세스를 시도하고있어 AudioFileReadPackets

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)); 
} 
} 
입니다

testBuffer의 첫 번째 색인을 인쇄 할 때 0부터 4294967296 사이의 값을 얻을 수 있으므로 비어 있지 않은 것으로 보입니다. AudioFileReadPackets 실행 후 numBytes가 0 인 이유는 무엇입니까?

답변

0

numBytes가 0 인 이유는 아직도 확실치 않지만 this 질문에서 실행 가능한 해결책을 찾았습니다.

int sampleCount = inBuffer->mAudioDataBytesCapacity/sizeof(SInt16); 
:

는 testBuffer의 크기를 얻으려면 다음 코드를 사용