I am trying to stream some recording from the mic in my iPhone in real-time over NSSocket.
I have callbacks for recording and playback. I am trying to read directly from the buffer using following code:
SInt16 *intFromBuffer;
intFromBuffer = audioBufferList->mBuffers[0].mData;
When I'm trying:
NSLog(@"0x%X", intFromBuffer);
I get for instance: 0xA182E00
And now the important part - playback callback:
static OSStatus playbackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
/**
This is the reference to the object who owns the callback.
*/
AudioProcessor *audioProcessor = (__bridge AudioProcessor*) inRefCon;
// iterate over incoming stream an copy to output stream
for (int i=0; i < ioData->mNumberBuffers; i++) {
AudioBuffer buffer = ioData->mBuffers[i];
// find minimum size
UInt32 size = min(buffer.mDataByteSize, [audioProcessor audioBuffer].mDataByteSize);
intFromBuffer = (SInt16)([NSString stringWithFormat:@"0x%@", data.output]);
memcpy(buffer.mData, intFromBuffer, size); //this works fine!
}
return noErr;
}
But now - how do I get this intFromBuffer to work over the NSStream?
When I try to send it directly as NSString and send it back as NSString and parse it back to SInt16 all I get is noise.
Any ideas? I'm running out of ideas...