Question

I have been working through the examples in the Learning Core Audio book. This book does a great job of explaining the API's and how they work, but does not really talk about how to integrate them into Cocoa projects.

I really am not sure how to approach mixing the core audio/midi programming with obj-c classes. Are there any good tutorials out there that explain the standard practice in doing this?

Some of the questions that are in my mind at this point are:

  • If I need a userdata struct, can I replace this with some kind of obj-c instance variables or @properties, or does this have to be a C struct?
  • Where should I place my audio callback functions in my code? Can they just sit some place outside the @implementation?
  • Since the callback functions are written in C, what do I do if I want to call an objective-C function or access a class property within them?
Was it helpful?

Solution

The usual practice is to pass your class instance as the userdata if the callback declares it as void*. Your callback can then cast it as the object and call any methods in it.

OTHER TIPS

C is a proper subset of Objective C. So you can just use C data types and calling conventions to integrate Core audio with Cocoa. C source code can go in separate .c files, as well as inside Objective C implementations. Objective C objects can be treated as pointers to C structs inside a C callback.

Also, using Objective C messaging inside real-time Core Audio callbacks is not recommended.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top