TAAE2 - number of frames for stack

I'm currently debugging an issue where the render block is currently being called every 92ms. I'd like to see if there is a way to get this to go faster (say in the 20-40ms range).

Currently there are 4096 frames per context->frames;

Is there a way i could reduce the number of frames? My theory is that this should speed up the loop, but I'm wondering if there is a better way.

Thanks =D

    AERenderer *renderer = [AERenderer new];
    self.output = [[AEAudioUnitOutput alloc] initWithRenderer:renderer];

    __block NSDate *date = [NSDate date];

    renderer.block = ^(const AERenderContext * _Nonnull context) {
        AEBufferStack *bufferStack = context->stack;

        const AudioBufferList * bufferList = AEBufferStackPushWithChannels(bufferStack, 1, 2);

        if ( !bufferList ) {
            return;
        }

        double timePassed_ms = [date timeIntervalSinceNow];

        printf("%f\n", timePassed_ms * -1000.0);
        date = [NSDate date];

        float *leftBuffer  = (float*)bufferList->mBuffers[0].mData,
              *rightBuffer = (float*)bufferList->mBuffers[1].mData;


        if (isLoading || isPaused) {
            memset(leftBuffer,  0, bufferList->mBuffers[0].mDataByteSize);
            memset(rightBuffer, 0, bufferList->mBuffers[0].mDataByteSize);
            AERenderContextOutput(context, 1);
            return;
        }

        int32_t *currentStep = [self.modPlayer fillLeftBuffer:leftBuffer
                                              withRightBuffer:rightBuffer
                                                withNumFrames:context->frames];


        AERenderContextOutput(context, 1);

    };

Comments

  • Absolutely - you just need to use AVAudioSession's setPreferredIOBufferDuration:error:. It takes an argument in seconds, and will adjust the buffer to be close to that (maybe not exact, and maybe not at all, though)

  • Thank you, @Michael.

    After looking at my source, i found that i was maxing out the #frames via:

     [audioSession setPreferredIOBufferDuration:audioSession.sampleRate error:NULL];
    

    If i omit it, the loop runs at around 23ms while the app is in the foreground and runs up to 96ms when the app is in the background or hibernated.

    Seems that TAAE2 is adapting nicely per the apple docs.

    Sample log output from my iPhone 6.

    23.168981 // Foreground
    23.181021
    0.799000 // Press the power button
    45.607030 // Transition to full 4096 frames for hibernate
    92.839956
    92.856050
    
  • Ouch... Yep, you're requesting a 44,100 second (12 hour) long buffer duration =) You probably want something like 0.005 or 0.0025 (I usually specify it in frames, like 128.0/sampleRate).

  • Yeah it was a stupid thing on my part. I honestly don't know what i was thinking when I did that.

    facepalm

Sign In or Register to comment.