What is `inputProcRefCon` in the `AURenderCallbackStruct`?

core-audio, ios

Solution

The refCon is a void (untyped) pointer to arbitrary data, in your example to the C struct backing the calling object. If the inputProc callback function doesn't need any extra parameters (instance variables) from the calling object passed, then you don't need to pass it self, or you can point refCon at some other data (a different C struct or object). But most callbacks do need some parameters.

It's a C void pointer because the API is for real-time code that predates newer Objective C idioms.

Problem

In playing a tone (e.g., here), we have to tell the machine what function will fill the IO buffer: ``` // Set our tone rendering function on the unit AURenderCallbackStruct input; input.inputProc = RenderTone; input.inputProcRefCon = self; err = AudioUnitSetProperty(toneUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &input, sizeof(input)); ``` It's clear that `inputProc` is the procedure from which to take input for the audiounit. But what is `inputProcRefCon` exactly? Would there ever be a case where it cannot be set to `self`?

Original source