Search code examples
iosavfoundationcore-audiogpuimagethe-amazing-audio-engine

No audio in video recording (using GPUImage) after initializing The Amazing Audio Engine


I'm using two third party tools in my project. One is "The Amazing Audio Engine". I use this for audio filters. The other is GPUImage, or more specifically, GPUImageMovieWriter. When I record videos, I merge an audio recording with the video. This works fine. However, sometimes I do not use The Amazing Audio Engine and just record a normal video using GPUImageMovieWriter. The problem is, even just after initializing The Amazing Audio Engine, the video has only a fraction of a second of audio at the beginning, and then the audio is gone.

+ (STAudioManager *)sharedManager
{
    static STAudioManager *manager = nil;

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!manager)
        {
            manager = [[STAudioManager alloc] init];
            manager.audioController = [[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES];
            manager.audioController.preferredBufferDuration = 0.005;
            manager.audioController.voiceProcessingEnabled = YES;
            manager.audioController.useMeasurementMode = YES;
        }
    });
    return manager;
}

Something is happening when TAAE is initialized. My suspicion is it's something having to do with AVAudioSession as it's a sharedInstance. Any help would be amazing.


Solution

  • Naturally when I finally buckle and post a question, I find my problem.

    Setting the preferredBufferDuration to 0.005 is a bit excessive. Removing this line solved my problem.

    You can learn more about preferredBufferDuration here.