From the reading that I have done, Core Audio relies heavily on callbacks (and C++, but that’s another story).
I understand the concept (sort of) of setting up a function that is called by another function repeatedly to accomplish a task. I just don’t understand how they get set up and how they actually work. Any examples would be appreciated.
There is no ‘callback’ in C – not more than any other generic programming concept.
They’re implemented using function pointers. Here’s an example:
Here, the
populate_arrayfunction takes a function pointer as its third parameter, and calls it to get the values to populate the array with. We’ve written the callbackgetNextRandomValue, which returns a random-ish value, and passed a pointer to it topopulate_array.populate_arraywill call our callback function 10 times and assign the returned values to the elements in the given array.