您好我一直在尝试使用以下代码创建一个wav音频文件,但不断收到错误创建文件('fmt?')。有人可以帮我从这里出去吗 ?谢谢。
我的日志: * 2012-11-01 13:33:14.183 Novocaine iOS示例[7456:c07] URL:file://localhost/Users/pier/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/01EBF2C0-2C3A-490D -835E-9C39A3E88E0B /文档/ testrecording.wav
错误:创建文件('fmt?')*
- (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSamplingRate numChannels:(UInt32)thisNumChannels
{
self = [super init];
if (self)
{
// Zero-out our timer, so we know we're not using our callback yet
self.callbackTimer = nil;
// Open a reference to the audio file
self.audioFileURL = urlToAudioFile;
CFURLRef audioFileRef = (CFURLRef)self.audioFileURL;
AudioStreamBasicDescription outputFileDesc;
// Set a few defaults and presets
self.samplingRate = thisSamplingRate;
self.numChannels = thisNumChannels;
self.currentTime = 0.0;
self.latency = .011609977; // 512 samples / ( 44100 samples / sec ) default
outputFileDesc.mSampleRate = self.samplingRate;
outputFileDesc.mFormatID = kAudioFormatLinearPCM;
outputFileDesc.mFormatFlags = kAudioFormatFlagIsFloat;
outputFileDesc.mBytesPerPacket = 4*self.numChannels;
outputFileDesc.mFramesPerPacket = 1;
outputFileDesc.mBytesPerFrame = 4*self.numChannels;
outputFileDesc.mChannelsPerFrame = self.numChannels;
outputFileDesc.mBitsPerChannel = 32;
CheckError(ExtAudioFileCreateWithURL(audioFileRef, kAudioFileWAVEType, &outputFileDesc, NULL, kAudioFileFlags_EraseFile, &_outputFile), "Creating file");
。 。
答案 0 :(得分:1)
我不知道为什么,但我做了以下更改并且有效。 有人会认为wav文件的类型为kAudioFileWAVType,不是吗? 有人想照亮这个吗?
outputFileDesc.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; //changed
CheckError(ExtAudioFileCreateWithURL(audioFileRef, kAudioFileCAFType, &outputFileDesc, NULL, kAudioFileFlags_EraseFile, &_outputFile), "Creating file"); //changed
答案 1 :(得分:0)
通常,ExtAudioFileCreateWithURL
的WAV文件实现要求明确设置kAudioFormatFlagIsPacked
标志。
这是不寻常的,因为kAudioFormatFlagIsPacked
文档声称在OP的情况下暗含该标志:
即使清除此标志,也表示如果填写
AudioStreamBasicDescription
使得字段具有以下关系,则设置此标志:((mBitsPerSample / 8) * mChannelsPerFrame) == mBytesPerFrame
这也不常见,因为其他格式(例如CAF)不在乎。
TL; DR 设置这种格式标志将解决kAudioFileUnsupportedDataFormatError = 'fmt?'
错误:
outputFileDesc.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;