2010-06-23 90 views
0

我有下面的代碼片斷:AudioFileWriteBytes返回錯誤-50隨機

OSStatus status = AudioFileWriteBytes(self.audioFile, FALSE, self.startingByte, &ioNumBytes, theData); 

狀態碼隨機返回諾爾和-50在iPhone模擬器。

它然後工作,如果我重新運行它。

任何指針讚賞爲什麼上面的代碼行爲隨機。

在此先感謝您的幫助。

回答

1

我想我找到了我的問題。

原代碼的問題:

// Start 
OSStatus status = AudioOutputUnitStart(self.ioUnit); 

// Record the audio samples and save it to a file 
[self createFile]; 

新的代碼,解決了這一問題。請注意「的CreateFile」呼喚AudioOutputUnitStart

// Record the audio samples and save it to a file 
[self createFile]; 

// Start 
// Once AudioOutputUnitStart is called, it will start calling callback method quickly. We need to call the above [self createFile] first. 
OSStatus status = AudioOutputUnitStart(self.ioUnit); 

的AudioOutputUnitStart呼籲將音頻樣本寫入文件回調方法之前,首先調用。由於該文件已經在AudioOutputUnitStart之前創建/打開,現在音頻採樣沒有任何錯誤地寫入文件。