Convert void *(void * const mAudioData) to Short * using Objective c?

1.1k views Asked by At

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.

2

There are 2 answers

7
Carl Norum On BEST ANSWER

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.

0
Sergey Kalinichenko On

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.