使用 Apple 的 MixerHostAudio 示例类时出现问题
对于我的 iPhone 应用程序,我尝试使用 Apple 的 MixerHostAudio 类 混合并播放用户指定的音频文件。
为了使 MixerHostAudio 类播放用户指定的文件,我使用文件的 NSURL 实例化了该类。这对于第一次实例化非常有用,但是当我想通过释放旧的 MixerHostAudio 类并分配新类来更改播放的音频文件时,应用程序会在实例化后几秒钟崩溃并显示 EXC_BAD_ACCESS 。
经过一些调试后,我注意到错误发生在 inputRenderCallback
中,其中 AudioUnitSampleType
(audioDataLeft
和 audioDataRight
)的 soundStructPointerArray
为零。
这是发生错误的代码的一部分:
for (UInt32 frameNumber = 0; frameNumber < inNumberFrames; ++frameNumber) {
outSamplesChannelLeft[frameNumber] = dataInLeft[sampleNumber];
if (isStereo) outSamplesChannelRight[frameNumber] = dataInRight[sampleNumber];
非常感谢任何帮助!
For my iPhone app, I'm trying to use Apple's MixerHostAudio class to mix and play the audio files specified by the user.
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 instantiation.
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];
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在释放
MixerHostAudio
实例之前是否调用了stopAUGraph
?在我看来,dealloc 方法不会自动停止它;那么在释放/释放各个内存位置后将调用回调,这将导致错误的访问崩溃。Did you call
stopAUGraph
before releasing yourMixerHostAudio
instance? It seems to me that thedealloc
method doesn't automatically stop it; then the callback will be called after various memory locations were released/freed, that would cause a bad access crash.