Convert void *(void * const mAudioData) to Short * using Objective c?
-
16-04-2021 - |
Question
i have AudioQueueBuffer
's Audio Data which has void * const
format. i want short array (short *
) Audio data for my codec.
How to Convert void * const to Short * in Objective c??? type cast from void to short possible ? or i have to use some byte order conversion like OSReadBigInt16
??? if so sample for conversion? please help me to find solution.
Solution
Yes, Objective-C is just like C for typecasting. That means if you want to interpret your void *
pointer as a short *
pointer, all you need to do is:
(short *)voidPointer
If the bytes aren't in the right order (ie, endianness mismatch), you'll need to deal with that too - there's no way to tell if that's the case based on the information in your question, though.
OTHER TIPS
void*
is a convention for declaring untyped pointers. Such pointers need to be re-interpreted as pointers to some data type. Whether or not it works depends on what you or the API put at the address pointed to by the void*
pointer: if it is a sequence of short
values with no gaps, a simple cast to short*
is going to work; otherwise, you may need to perform additional conversion.