Thursday, June 21, 2012

Programming Tip* OpenGl & Audio

I'm adding video to Say Cheese for the Iphone using openGl, which is up to 100 times faster than Core Image for filters. But I ran into a problem. I'm adding cool sound features to this puppy as well. But there's a conflict with AVAssetWriter and AVAudioSession. Play some audio and your assetwriter quits working.  Well, Say Cheese is the original talking camera app, so this will not do. Spent 3 hours tracking this one down. So here's the simple solution for you poor programmers out there that might be looking for this. 

By the way, I've created a rainhut fork for the GPUImage library on Github. I'm using GPUImage  in this app. Already posted some improvements, or additions if you will, to the GPUImageMovieWriter class.

Back to the solution. You need to enable your audio session to mix well with other. It needs to be nice. Just add this code to your viewDidLoad or wherever you're using these two together.

    UInt32 mixTrue = true;
    OSStatus mixError = 0;
    mixError = AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (mixTrue),  &mixTrue);