2014-12-03 2 views
2

응용 프로그램 사운드를 캡처하여 AVAssetWriter에 입력으로 전달하려고합니다.
AudioBufferList를 가져 오기 위해 오디오 장치에 대한 콜백을 설정 중입니다.
이 문제는 AudioBufferList를 CMSampleBufferRef로 변환하는 것으로 시작됩니다. 필수 매개 변수는 카롤CMSampleBufferSetDataBufferFromAudioBufferList 반환 오류 12731



감사
누락되어 있음을 나타냅니다
그것은 항상 오류 -12731 반환은
-(OSStatus) recordingCallbackWithRef:(void*)inRefCon 
          flags:(AudioUnitRenderActionFlags*)flags 
         timeStamp:(const AudioTimeStamp*)timeStamp 
         busNumber:(UInt32)busNumber 
        framesNumber:(UInt32)numberOfFrames 
          data:(AudioBufferList*)data 
{ 

AudioBufferList bufferList; 
bufferList.mNumberBuffers = 1; 
bufferList.mBuffers[0].mData = NULL; 

OSStatus status; 

status = AudioUnitRender(audioUnit, 
         flags, 
         timeStamp, 
         busNumber, 
         numberOfFrames, 
         &bufferList); 
[self checkOSStatus:status]; 

AudioStreamBasicDescription audioFormat; 
// Describe format 
audioFormat.mSampleRate   = 44100.00; 
audioFormat.mFormatID   = kAudioFormatLinearPCM; 
audioFormat.mFormatFlags  = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; 
audioFormat.mFramesPerPacket = 1; 
audioFormat.mChannelsPerFrame = 1; 
audioFormat.mBitsPerChannel  = 16; 
audioFormat.mBytesPerPacket  = 2; 
audioFormat.mBytesPerFrame  = 2; 

CMSampleBufferRef buff = NULL; 
CMFormatDescriptionRef format = NULL; 
CMSampleTimingInfo timing = { CMTimeMake(1, 44100), kCMTimeZero, kCMTimeInvalid }; 

status = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &audioFormat, 0, NULL, 0, NULL, NULL, &format); 
[self checkOSStatus:status]; 

status = CMSampleBufferCreate(kCFAllocatorDefault,NULL,false,NULL,NULL,format,1, 1, &timing, 0, NULL, &buff); 
[self checkOSStatus:status]; 

status = CMSampleBufferSetDataBufferFromAudioBufferList(buff, 
                 kCFAllocatorDefault, 
                 kCFAllocatorDefault, 
                 0, 
                 &bufferList); 

[self checkOSStatus:status]; //Status here is 12731 

//Do something with the buffer 

return noErr; 
} 


편집 : 나는 bufferList.mBuffers을 확인
[0] .mData 그것은 null가 아닌 그래서 아마도 그것은 문제가 아닙니다.

답변

1

인터넷을 통해 답변이없는 비슷한 질문이 있기 때문에.
나는 그것을 풀 수 있었고 녹음은 완전히 작동했다.
내 문제가 잘못된 매개 변수 인 CMSampleBufferCreate으로 전달되었습니다.
1 대신 numSamples가 numberOfFrames와 같아야합니다.

그래서 마지막 호출은 다음과 같습니다

CMSampleBufferCreate(kCFAllocatorDefault,NULL,false,NULL,NULL,format, 
        (CMItemCount)numberOfFrames, 1, &timing, 0, NULL, &buff); 
+0

당신이 당신의'audioUnit'을 정의하는 방법? –