【发布时间】:2015-12-27 20:47:45
【问题描述】:
我有一个音频相关的应用程序,它具有多通道混音器,可以一次播放 m4a 文件。 我正在使用 AudioToolBox 框架来流式传输音频,但在 iOS9 上,该框架在我正在流式传输音频文件的混音器渲染回调中引发异常。
有趣的是,使用 iOS9 SDK 编译的应用程序继续在 iOS7/8 设备上完美地传输相同的文件,但不是 iOS9。 现在我无法确定 Apple 是否在 iOS9 中破坏了某些东西,或者我们最终的文件编码错误,但它们在 iOS 7/8 上都可以正常播放,但在 iOS 9 上却不行。
例外:
malloc: *** error for object 0x7fac74056e08: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
它适用于所有其他格式,不会出现任何异常或任何类型的内存错误,但不适用于 m4a 格式,这非常令人惊讶。
这是加载适用于 wav、aif 等格式但不适用于 m4a 的文件的代码:
- (void)loadFiles{
AVAudioFormat *clientFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
sampleRate:kGraphSampleRate
channels:1
interleaved:NO];
for (int i = 0; i < numFiles && i < maxBufs; i++) {
ExtAudioFileRef xafref = 0;
// open one of the two source files
OSStatus result = ExtAudioFileOpenURL(sourceURL[i], &xafref);
if (result || !xafref) {break; }
// get the file data format, this represents the file's actual data format
AudioStreamBasicDescription fileFormat;
UInt32 propSize = sizeof(fileFormat);
result = ExtAudioFileGetProperty(xafref, kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);
if (result) { break; }
// set the client format - this is the format we want back from ExtAudioFile and corresponds to the format
// we will be providing to the input callback of the mixer, therefore the data type must be the same
double rateRatio = kGraphSampleRate / fileFormat.mSampleRate;
propSize = sizeof(AudioStreamBasicDescription);
result = ExtAudioFileSetProperty(xafref, kExtAudioFileProperty_ClientDataFormat, propSize, clientFormat.streamDescription);
if (result) { break; }
// get the file's length in sample frames
UInt64 numFrames = 0;
propSize = sizeof(numFrames);
result = ExtAudioFileGetProperty(xafref, kExtAudioFileProperty_FileLengthFrames, &propSize, &numFrames);
if (result) { break; }
if(i==metronomeBusIndex)
numFrames = (numFrames+6484)*4;
//numFrames = (numFrames * rateRatio); // account for any sample rate conversion
numFrames *= rateRatio;
// set up our buffer
mSoundBuffer[i].numFrames = (UInt32)numFrames;
mSoundBuffer[i].asbd = *(clientFormat.streamDescription);
UInt32 samples = (UInt32)numFrames * mSoundBuffer[i].asbd.mChannelsPerFrame;
mSoundBuffer[i].data = (Float32 *)calloc(samples, sizeof(Float32));
mSoundBuffer[i].sampleNum = 0;
// set up a AudioBufferList to read data into
AudioBufferList bufList;
bufList.mNumberBuffers = 1;
bufList.mBuffers[0].mNumberChannels = 1;
bufList.mBuffers[0].mData = mSoundBuffer[i].data;
bufList.mBuffers[0].mDataByteSize = samples * sizeof(Float32);
// perform a synchronous sequential read of the audio data out of the file into our allocated data buffer
UInt32 numPackets = (UInt32)numFrames;
result = ExtAudioFileRead(xafref, &numPackets, &bufList);
if (result) {
free(mSoundBuffer[i].data);
mSoundBuffer[i].data = 0;
}
// close the file and dispose the ExtAudioFileRef
ExtAudioFileDispose(xafref);
}
// [clientFormat release];
}
如果有人能指出我正确的方向,我该如何调试问题? 我们是否需要以某种特定方式重新编码我们的文件?
【问题讨论】:
-
请更具体地说明您的问题。有什么例外?你依赖什么功能?你考虑过iOS 9 Diff吗?
-
Michael 您现在可以调查一下吗?或者您需要更具体的东西吗?是的,我确实检查了 iOS9 Diff...找不到任何可以帮助我找到解决方案的内容。
-
你做一些
if (result) { break; };哪些检查很好,哪些检查失败?异常在哪里抛出? debugger 告诉我们什么? -
在这一行抛出异常:ExtAudioFileDispose(xafref);并且调试器给出了这个: malloc: *** 对象 0x7fe03c804c08 的错误:释放对象的校验和不正确 - 对象在被释放后可能被修改。 *** 在 malloc_error_break 中设置断点进行调试
标签: core-audio ios9 audiounit m4a