使用 Apple 的 MixerHostAudio 类播放音频文件时出现问题
我正在尝试使用 Apple 的 MixerHostAudio 类来混合和播放用户指定的音频文件。
类文件可以在这里找到:http://developer. apple.com/library/ios/#samplecode/MixerHost/Listings/Classes_MixerHostAudio_h.html
为了使 MixerHostAudio 类播放用户指定的文件,我使用文件的 NSURL 实例化了该类。这对于第一次实例化非常有用,但是当我想通过释放旧的 MixerHostAudio 类并分配新的类来更改播放的音频文件时,应用程序会在声音开始播放后几秒崩溃并显示“EXC_BAD_ACCESS”。
经过一些调试后,我注意到错误发生在 inputRenderCallback 中,其中 soundStructPointerArray 的 AudioUnitSampleType(audioDataLeft 和 audioDataRight)为 nil。
这是发生错误的代码的一部分:
for (UInt32 frameNumber = 0; frameNumber < inNumberFrames; ++frameNumber) {
outSamplesChannelLeft[frameNumber] = dataInLeft[sampleNumber];
if (isStereo) outSamplesChannelRight[frameNumber] = dataInRight[sampleNumber];
是否有办法实例化 MixerHostAudio 的多个实例而不会出现错误?
非常感谢任何帮助。
I'm trying to use Apple's MixerHostAudio class to mix and play audio files specified by the user.
The class files can be found here: http://developer.apple.com/library/ios/#samplecode/MixerHost/Listings/Classes_MixerHostAudio_h.html
To make the MixerHostAudio class play the files specified by the user, I instantiated the class with the NSURL of the files. This works great for the first instantiation, however when I wanted to the change the audio files played by releasing the old MixerHostAudio class and allocating a new one the app crashes with "EXC_BAD_ACCESS" seconds after the sound starts to plays.
After doing some debugging, I noticed that the error occurs in inputRenderCallback, where the AudioUnitSampleType (audioDataLeft, and audioDataRight) of the soundStructPointerArray is nil.
This is part of the code where the error occurred:
for (UInt32 frameNumber = 0; frameNumber < inNumberFrames; ++frameNumber) {
outSamplesChannelLeft[frameNumber] = dataInLeft[sampleNumber];
if (isStereo) outSamplesChannelRight[frameNumber] = dataInRight[sampleNumber];
Is there anyway for me to instantiate multiple instances of MixerHostAudio without getting an error??
Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来代码没有重置回调中的所有数据。我不熟悉该源代码,但您应该仔细检查并确保所有内存分配都得到正确处理并且没有过时的指针。特别是寻找那些不应该存在的全局变量或静态变量,因为你说你在崩溃之前实例化了第二个变量。
It sounds like the code isn't resetting all of the data in the callback. I'm not familiar with that source code, but you should go through and make sure all the memory allocations are being handled right and that there aren't stale pointers. Especially look for globals or static variables that are hanging around when they shouldn't be, since you say you instantiate a second one before it crashes.