2009-09-03 79 views
2

我正在OS X上創建實時音頻音序器應用程序。 實時合成器部分使用AURenderCallback實現。 現在我正在將渲染結果寫入Wave File (44100Hz 16bit Stereo)。 渲染回調函數的格式是44100Hz 32位浮點立體交錯。音頻單元和寫入文件

我正在使用ExtAudioFileWrite來寫入文件。 但ExtAudioFileWrite函數返回錯誤代碼1768846202;

我搜索了1768846202但我無法獲取信息。 你能給我一些提示嗎?

謝謝。

這是代碼。

outFileFormat.mSampleRate = 44100; 
    outFileFormat.mFormatID = kAudioFormatLinearPCM; 
    outFileFormat.mFormatFlags = 
kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; 
    outFileFormat.mBitsPerChannel = 16; 
    outFileFormat.mChannelsPerFrame = 2; 
    outFileFormat.mFramesPerPacket = 1; 
    outFileFormat.mBytesPerFrame = 
outFileFormat.mBitsPerChannel/8 * outFileFormat.mChannelsPerFrame; 
    outFileFormat.mBytesPerPacket = 
outFileFormat.mBytesPerFrame * outFileFormat.mFramesPerPacket; 

AudioBufferList *ioList; 
    ioList = (AudioBufferList*)calloc(1, sizeof(AudioBufferList) 
     + 2 * sizeof(AudioBuffer)); 
    ioList->mNumberBuffers = 2; 
    ioList->mBuffers[0].mNumberChannels = 1; 
    ioList->mBuffers[0].mDataByteSize = allocByteSize/2; 
    ioList->mBuffers[0].mData = ioDataL; 
ioList->mBuffers[1].mNumberChannels = 1; 
    ioList->mBuffers[1].mDataByteSize = allocByteSize/2; 
    ioList->mBuffers[1].mData = ioDataR; 

... 

while (1) { 
    //Fill buffer by using render callback func. 
    RenderCallback(self, nil, nil, 0, frames, ioList); 

     //i want to create one sec file. 
     if (renderedFrames >= 44100) break; 

    err = ExtAudioFileWrite(outAudioFileRef, frames , ioList); 
    if (err != noErr){ 
    NSLog(@"ERROR AT WRITING TO FILE"); 
    goto errorExit; 
    } 
    } 

回答

1

在您可以進行任何類型的調試之前,您可能需要弄清楚錯誤消息的實際含義。您是否嘗試將該狀態代碼傳遞給GetMacOSStatusErrorString()或GetMacOSStatusCommentString()?它們沒有很好地記錄,但是它們在CoreServices/CarbonCore/Debugging.h中聲明。

+0

我不知道這些方法。我會嘗試他們。謝謝! – 2009-09-05 02:03:15

2

某些錯誤代碼實際上是四個字符的字符串。核心音頻書提供了一個很好的功能來處理錯誤。

static void CheckError(OSStatus error, const char *operation) 
{ 
    if (error == noErr) return; 

    char str[20]; 
    // 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); 

    fprintf(stderr, "Error: %s (%s)\n", operation, str); 

    exit(1); 
} 

使用方法如下:

CheckError(ExtAudioFileSetProperty(outputFile, 
           kExtAudioFileProperty_CodecManufacturer, 
           sizeof(codec), 
           &codec), "Setting codec."); 
+1

如果你運行這樣的函數,你會發現代碼是'insz',你可以在AudioConvert.h中找到:'kAudioConverterErr_InvalidInputSize ='insz''。我喜歡你給它六種不同的尺碼,但它不會告訴你哪一個是錯的。 – 2012-09-28 19:23:30