Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an audio queue callback function have to be a C style function? Or can it be an objective C style method?

Does an audio queue callback function have to be a C style function? Or can it be an objective C style method?

like image 327
Darren Findlay Avatar asked Feb 24 '23 15:02

Darren Findlay


2 Answers

Depends entirely on the API; if the API calls for a function, block or method, that is what you must use.

As long as the callback function type is something like:

void (*hollabackman)(AudioGunk*foo, void*context);

And the API for setting up the callback is something like:

setCallback(hollabackman func, void *context);

Then you can:

- myMethod
{
    setCallback(&myCallbackFunc, (void *)self);
}

- (void) hollaedBack: (AudioGunk*) aGunk
{
.....
}

Then:

void myCallbackFunc(AudioGunk *foo, void *context)
{
    MyClass *self = (MyClass *) context;
    [self hollaedBack: foo];
}

I would suggest that you retain self when setting up the callback and only balance it with a release when you tear down the callback.

like image 197
bbum Avatar answered Apr 07 '23 23:04

bbum


CoreAudio (including AudioQueueServices) does not have an ObjectiveC interface - pure C is the answer for directly interfacing with CoreAudio.

You could however create some wrapping C-functions calling a singleton ObjectiveC object method.

like image 40
Till Avatar answered Apr 08 '23 00:04

Till