Problem using Apple's MixerHostAudio class to play audio files
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 wit开发者_运维百科h "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.
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.
精彩评论