音频单元并写入到文件 [英] Audio Unit and Writing to file
问题描述
我在OS X上创建实时音频音序器应用程序
实时合成器部分是通过使用AURenderCallback实现。
现在我正在做的功能写渲染的结果WAVE文件(44100Hz 16位立体声)。
格式渲染回调函数是44100Hz支持32位立体声浮动交错。
我使用ExtAudioFileWrite写入文件。
但ExtAudioFileWrite函数返回错误code 1768846202;
我搜索1768846202但我无法获取信息。
你能给我一些提示?
感谢您。
下面是code。
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;...而(1){
//使用呈现回调FUNC填充缓冲区。
RenderCallback(个体经营,零,零,0,框架,ioList); //我想创建一个秒的文件。
如果(renderedFrames> = 44100)打破; ERR = ExtAudioFileWrite(outAudioFileRef,框架,ioList);
如果(ERR!=诺尔){
的NSLog(@出错写入文件);
转到errorExit;
}
}
一些错误codeS实际上是四个字符的字符串。核心音频本书提供了一个很好的功能来处理错误。
静态无效CheckError(OSStatus错误,为const char *操作)
{
如果(错误==诺尔)回报;
字符海峡[20];
//看看它似乎是一个4煤焦code
*(UInt32的*)(STR + 1)= CFSwapInt32HostToBig(误差);
如果(isprint判断(STR [1])及&放大器; isprint判断(STR [2])及&放大器; isprint判断(STR [3])及&放大器; isprint判断(STR [4])){
海峡[0] = STR [5] ='\\'';
海峡[6] ='\\ 0';
}其他
//没有,将其格式化为整数
sprintf的(STR,%D,(int)的误差);fprintf中(标准错误,错误:%s(%S)\\ n,操作,STR);出口(1);
}
使用这样的:
CheckError(ExtAudioFileSetProperty(OUTPUTFILE,
kExtAudioFileProperty_ codecManufacturer,
的sizeof(codeC)
&安培; codeC),设置codeC。);
I'm creating real-time audio sequencer app on OS X. Real-time synth part is implemented by using AURenderCallback. Now I'm making function to write rendered result to Wave File (44100Hz 16bit Stereo). Format for render-callback function is 44100Hz 32bit float Stereo interleaved.
I'm using ExtAudioFileWrite to write to file. But ExtAudioFileWrite function returns error code 1768846202;
I searched 1768846202 but I couldn't get information. Would you give me some hints?
Thank you.
Here is code.
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;
}
}
Some of the error codes are actually four character strings. The Core Audio book provides a nice function to handle errors.
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);
}
Use it like this:
CheckError(ExtAudioFileSetProperty(outputFile,
kExtAudioFileProperty_CodecManufacturer,
sizeof(codec),
&codec), "Setting codec.");
这篇关于音频单元并写入到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!