音频单元和写入文件
我正在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;
}
}
在您可以进行任何类型的调试之前,您可能需要弄清楚错误消息的实际含义。您是否尝试将该状态代码传递给GetMacOSStatusErrorString()或GetMacOSStatusCommentString()?它们没有很好地记录,但是它们在CoreServices/CarbonCore/Debugging.h中声明。
某些错误代码实际上是四个字符的字符串。核心音频书提供了一个很好的功能来处理错误。
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.");
如果你运行这样的函数,你会发现代码是'insz',你可以在AudioConvert.h中找到:'kAudioConverterErr_InvalidInputSize ='insz''。我喜欢你给它六种不同的尺码,但它不会告诉你哪一个是错的。 – 2012-09-28 19:23:30
我不知道这些方法。我会尝试他们。谢谢! – 2009-09-05 02:03:15