Macos 音频单元和写入文件
我正在OSX上创建实时音频序列器应用程序。 实时合成部分是通过使用Macos 音频单元和写入文件,macos,audio,Macos,Audio,我正在OSX上创建实时音频序列器应用程序。 实时合成部分是通过使用AURenderCallback实现的。 现在我正在制作一个函数,将渲染结果写入波形文件(44100Hz 16位立体声)。 渲染回调函数的格式为44100Hz 32位浮点立体声交错 我正在使用ExtAudioFileWrite写入文件。 但是ExtAudioFileWrite函数返回错误代码1768846202 我搜索了1768846202,但找不到信息。 你能给我一些提示吗 多谢各位 这是代码 outFileFormat
AURenderCallback
实现的。
现在我正在制作一个函数,将渲染结果写入波形文件(44100Hz 16位立体声)
。
渲染回调函数的格式为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/debugation.h中声明。一些错误代码实际上是四个字符串。Core Audio book提供了一个很好的处理错误的功能
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:
kaudioconverterer\u InvalidInputSize='insz'
中找到。我喜欢你给了它半打不同的尺码,它不会告诉你哪一个是错的。