2013-06-24 48 views
0

我試圖在磁盤上創建一個新文件並使用OSX上的Core Audio框架對其進行記錄。我現在的主要障礙是我無法使用下面的代碼創建文件。我的目標是找出爲什麼下面的代碼不工作,以便我可以繼續在我的項目的其餘部分工作。你可以在下面看到這個代碼的輸出。無法使用AudioFileCreateWithURL()創建音頻文件

string fp = "…path…to…file.../file.wav" 
CFURLRef audioFileURL = CFURLCreateFromFileSystemRepresentation(
     NULL, 
     (const UInt8 *)fp.c_str(), // filename 
     fp.length(),    // number of bytes in filename 
     false    // this is a file, not a directory 
); 

if(audioFileURL == NULL){ 
    cout << endl << "audioFileURL == NULL :("; 
} 

OSStatus retErr = AudioFileCreateWithURL (        
         audioFileURL,           
         df.mFormatID,       
         &aqData.mDataFormat,         
         kAudioFileFlags_EraseFile,       
         &aqData.mAudioFile         
         ); 
cout << endl << "\nAudioFileCreateWithURL error:" << retErr; 

其輸出以下:

AudioFileCreateWithURL error:1954115647 

我沒有任何運氣找出這個錯誤是什麼意思。任何幫助這裏apprecaited。

回答

0

核心音頻錯誤以數字或4字母代碼形式返回。我猜你顯示的奇怪數字是代碼的內存位置。

你需要像這樣來確定和轉換:

static char *FormatError(char *str, OSStatus error) 
    { 
     // see if it appears to be a 4-char-code 
     *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error); 
     if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) { 
      str[0] = str[5] = '\''; 
      str[6] = '\0'; 
     } else 
     // no, format it as an integer 
     sprintf(str, "%d", (int)error); 
     return str; 
    }