I’m new to iOS programming and I’m playing around with some code found here: http://code.google.com/p/ios-coreaudio-example/
Basically I’m getting input from the mic and routing it straight to the speakers/headphones. However I want to manipulate the audio before 开发者_Python百科it’s played in the speakers.
I want to access and manipulate mData which is of type void *
and I guess I have to cast it to something else.
Now here's my code:
SInt16* samples = (SInt16*)(tempBuffer.mData); //cast to something usable
for ( int i = 0; i < tempBuffer.mDataByteSize; i++ )
{
NSLog(@"%@", *(samples+i));
}
I’m not even sure what is the best way to access data through the pointer. I have some experience with C++ pointers from school but I’m not sure if it’s any different in Objective-C (I just get EXC_BAD_ACCESS with this code).
Thanks.
When using the RemoteIO Audio Unit, you can use AudioUnitSetProperty with kAudioUnitProperty_StreamFormat to set the desired data type and format for the audio sample frames. Then, since you set the data type, you will know what type to use (cast) when reading samples from the callback buffer.
Also note that the number of short ints or short floats in a buffer is less than the number of bytes (using Apple's C data types).
精彩评论