Audio Controller Default Buffer Size

How can i get my audio controller to default the buffer size to 4096. It does 512 for any filters or channels or blocks or w/e. I know this is probably trivial but i cant find any info on it.
I can do the following but i cant imagine how it would do what i want.

static OSStatus filterCallback(__unsafe_unretained LiveFilter *THIS,
__unsafe_unretained AEAudioController *audioController,
AEAudioFilterProducer producer,
void *producerToken,
const AudioTimeStamp *time,
UInt32 frames,
AudioBufferList *audio) {
NSLog(@Live filter Input frames = %i,(unsigned int)frames);
AEAudioBufferListSetLength(audio, AEAudioStreamBasicDescriptionNonInterleavedFloatStereo, 4096);
// Pull audio
OSStatus status = producer(producerToken, audio, &frames);
if(status != noErr) status;

Thanks
Mitch

Comments

  • Hi Mitch. The buffer duration isn't the right tool for the job, here: you need to use a circular buffer, enqueue samples and dequeue them in the block size you need. The buffer duration is just a hint to the system - you're not guaranteed to get what you ask for, and it can change at any time.

  • Thanks for the response! So are you saying to pretty much allocate a circular buffer, then every callback of my filter add the 512 buffer to the circular array, then I can do my processing every X (32 or 64 or something) callbacks on that circular buffer? At this point I am not adding anything back in, just analyzing pitch and writing to a file in c.

  • Exactly! You'll need two buffers; one to store the unprocessed audio, one to store the processed audio. It looks something like this:

    CircularBuffer inputBuffer;
    CircularBuffer outputBuffer;
    
    callback(int callbackFrames, AudioBuffer audioBuffer) {
      add callbackFrames from audioBuffer to inputBuffer;
      while more than 4096 available frames in inputBuffer:
        pull 4096 frames from inputBuffer;
        process 4096 frames;
        put 4096 frames into outputBuffer;
      pull up to callbackFrames from outputBuffer into end of audioBuffer,
         (padding with silence if necessary);
    }
    
Sign In or Register to comment.