4

嗨,我一直在尝试从下面的代码创建一个 wav 音频文件,但不断收到错误 Creating file ('fmt?')。有谁可以帮我离开这里吗 ?谢谢。

我的日志: *2012-11-01 13:33:14.183 Novocaine iOS Example[7456:c07] URL: file://localhost/Users/pier/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/01EBF2C0- 2C3A-490D-835E-9C39A3E88E0B/Documents/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");

. . .

4

2 回答 2

1

我不知道为什么,但我做了以下更改并且它起作用了。有人会认为 wav 文件的类型为 kAudioFileWAVType,不是吗?
有没有人愿意对此有所启发?

outputFileDesc.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; //changed


CheckError(ExtAudioFileCreateWithURL(audioFileRef, kAudioFileCAFType, &outputFileDesc, NULL, kAudioFileFlags_EraseFile, &_outputFile), "Creating file"); //changed
于 2012-11-01T08:51:47.263 回答
0

不同寻常的是,它ExtAudioFileCreateWithURL的 WAV 文件实现似乎需要显式设置该kAudioFormatFlagIsPacked标志。

这是不寻常的,因为kAudioFormatFlagIsPacked文档声称该标志隐含在 OP 的案例中:

即使这个标志是明确的,如果AudioStreamBasicDescription被填写,则暗示这个标志被设置,使得字段具有以下关系: ((mBitsPerSample / 8) * mChannelsPerFrame) == mBytesPerFrame

这也很不寻常,因为其他格式,如 CAF,根本不在乎。

TL;DR像这样设置格式标志将修复kAudioFileUnsupportedDataFormatError = 'fmt?'错误:

outputFileDesc.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
于 2020-07-29T23:32:18.937 回答