I have an array of audio samples in C which I run algorithms on such as low-pass filters. I was thinking of converting my array to Objective-C before working on it. This is mainly because I am more comfortable with that language and it’s conveniences (especially being able to get the length of the array easily and not having to deal with pointers).
I was wondering if there is any reason why this may be a bad idea. Or if there are any disadvantages to doing this that I’m not aware of. Like maybe speed in processing such a large amount of samples (?).
Standard practice is to use a c style array for manipulating an array of audio. This is because if you have to use an Objective-c container object with obj-c messaging to access each element, the performance will be bad, and as you note, the number of samples with audio can be quite large.
This is especially true for real time processing such as processing audio samples that live in the system audio io callback, which have to do the job within a certain number of milliseconds or the sound will cut out.
What you could do is define a struct (or even an objective c class) that has the audio buffer array as well as info elements like size, number of channels, etc, to wrap it together for you in one location. That way when you access the buffer, you don’t need to get into obj-c efficiency issues, and you still have the buffer specification info available.
Here’s an example:
You then just need a call that initializes it.
You could do something with objective-c like: