gpt4 book ai didi

core-audio - m4a 音频文件无法在 iOS 9 上播放

转载 作者:行者123 更新时间:2023-12-04 23:58:44 24 4
gpt4 key购买 nike

我有一个音频相关的应用程序,它具有多 channel 混音器,可以一次播放 m4a 文件。我正在使用 AudioToolBox 框架来流式传输音频,但在 iOS9 上,该框架在我正在流式传输音频文件的混音器渲染回调中抛出异常。

有趣的是,使用 iOS9 SDK 编译的应用程序继续在 iOS7/8 设备上完美地流式传输相同的文件,但在 iOS9 上则不然。现在我无法确定 Apple 是否在 iOS9 中破坏了某些东西,或者我们的文件编码错误,但它们在 iOS 7/8 上都可以正常播放,但在 iOS 9 上却不行。

异常(exception):

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.1.beta3 上试了一下,一切似乎都恢复正常了。

尝试一下。让我们知道它是否也适合您。

关于core-audio - m4a 音频文件无法在 iOS 9 上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32859776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com