2012-10-10 6 views
1

파일을 열고 ExtAudioFileWrite를 사용하여 파일에 데이터를 추가하려고합니다. 자, 초기 작성 (작성시)/변환 작업은 정상적으로 작동하지만 불행히도 이후에 작성하기 위해 파일을 열 수없는 것 같습니다. 파일을 여는 것으로 보이는 함수는 하나만 있습니다 : ExAudioFileOpenURL 읽기 전용입니다. 그래서 필자가 파일을 쓰기 위해 열 수 없다면 파일 끝에 어떻게 쓸 수 있습니까?ExtAudioFileWrite를 사용하여 파일 끝에 쓰기

+0

'AudioFileOpenURL'을 시도한 다음'ExtAudioFileWrapAudioFileID'을 시도 했습니까? – sbooth

답변

0

질문이 잘못되었거나 완전히 이해하지 못했습니다. 그러나 ExtAudioFileWrite를 사용하여 파일에 쓰기를 시작하면 ExtAudioFileWrite를 다시 호출하여 계속 쓸 수 있습니다. 내가 어떤 컴파일러로 코딩으로 벤처에 대한 생각, 희망 당신은 아이디어를

예를 얻을 것이다 :

....variables declaration and your logic..... 

//1.Create File to write output 
ExtAudioFileRef outputFile; 

//+++++++ LOOP to append as many files as you want +++++++// 

//2.Create file reference to files you want to merge 
ExtAudioFileRef audioFileObject = 0; 

//3.open the first file 
ExtAudioFileOpenURL (firstFileURL, &audioFileObject); 

//4.get file properties 
AudioStreamBasicDescription AudioFileFormat = 0; 
UInt64 numberOfPacketsToReadInCurrentFile = 0; 
ExtAudioFileGetProperty(audioFileObject, 
         kExtAudioFileProperty_FileLengthFrames, 
         sizeof(numberOfPacketsToReadInCurrentFile), 
         &numberOfPacketsToReadInCurrentFile 
         ); 

ExtAudioFileGetProperty(audioFileObject, 
         kExtAudioFileProperty_FileDataFormat, 
         sizeof(AudioFileFormat), 
         &AudioFileFormat 
         ); 
//5.Set destination ASBD 
ExtAudioFileSetProperty(audioFileObject, 
         kExtAudioFileProperty_ClientDataFormat, 
         sizeof (importFormat), 
         &importFormat 
         ); 

//6.Set/Create/Allocate Some Buffers 
//use AudioFileFormat to setup your buffers accordingly 

AudioBufferList theBufferList = 0 // bufferList setup (I dont remember that) 

//7.Read the file into the buffer 
ExtAudioFileRead(audioFileObject,&numberOfPacketsToReadInCurrentFile,theBufferList); 

//8.Write the buffer to a File  
ExtAudioFileWrite(outputFile, numberOfPacketsToReadInCurrentFile, theBufferList); 
free(theBufferList); 

//if you want to append more files go to point 2 with the next file URL 

//+++++++CLOSE LOOP+++++++++// 

//once you are done.. just dispose the file and clean up everything left 
ExtAudioFileDispose(outputFile); 

이 컴파일되지 않습니다 같아요. 그러나 당신이 그 아이디어를 얻는 것을 도울 것입니다.

+0

예, 파일을 열어두면 잘 작동합니다. 그러나 닫은 다음 다시 열면 맨 처음부터 씁니다. AudioFile을 직접 사용하여 문제를 해결했지만 확장 버전에는이 기능이 없다고 생각합니다. –

+0

그리고 예를 들어 버퍼를 읽으면 어떤 시점에서 메모리가 문제가 될 것입니다. (내 상황이었습니다) –

+0

내가 말했듯이, 내가 필요한 것을 완전히 이해하지 못하고있을 수도 있습니다. 나는 당신이 그것을 알아 냈기 때문에 기쁘다. 미안 내가 도움이 될 수 없어. – Dan1one