Folks i have been searching and trying to resolve following problem since a whole day. No success yet
Ok, So i have been using apple sample code project name WiTap
to communicate b/w two devices over wifi using NSInputStreams
and NSOutputStreams
I have been able to transfer data (audio data) b/w devices successfully.
However on the destination device i receive data and fill it in an audio buffer as follows:
bytesRead = [self.inputStream read:anAudioBuffer.mData maxLength:anAudioBuffer.mDataByteSize];
while anAudioBuffer
itself is declared as follows
anAudioBuffer.mNumberChannels = 1;
anAudioBuffer.mDataByteSize = 512 * 2;
anAudioBuffer.mData = malloc( 512 * 2 );
Now i access this audio buffer as someObject.anAudioBuffer
in the AudioUnit Callback from the Apple's sample code
which is as follows
static OSStatus playbackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
// Notes: ioData contains buffers (may be more than one!)
// Fill them up as much as you can. Remember to set the size value in each buffer to match how
// much data is in the buffer.
for (int i=0; i < ioData->mNumberBuffers; i++) { // in practice we will only ever have 1 buffer, since audio format is mono
AudioBuffer buffer = ioData->mBuffers[i];
// copy temporary buffer data to output buffer
UInt32 size = min(buffer.mDataByteSize, someObject.anAudioBuffer.mDataByteSize); // dont copy more data then we have, or then fits
memcpy(buffer.mData, someObject.anAudioBuffer.mData, size);
buffer.mDataByteSize = size; // indicate how much data we wrote in the buffer
// uncomment to hear random noise
/*
UInt16 *frameBuffer = buffer.mData;
for (int j = 0; j < inNumberFrames; j++) {
frameBuffer[j] = arc4random();
}
*/
}
return noErr;
}
Now i want to play the bytes that i copied from someObject.anAudioBuffer
into a local var buffer
I do note that the this section of the code has to do with playing the audio
/*
UInt16 *frameBuffer = buffer.mData;
for (int j = 0; j < inNumberFrames; j++) {
frameBuffer[j] = arc4random();
}
*/
now the arc4random
is used to play static noise. With best of my efforts and searching all over the internet i could not figure out how to play my own bytes and also this piece of code b/w /* */
e.g what is the purpose of this line?
UInt16 *frameBuffer = buffer.mData;
and how do i fill this frameBuffer
with my own data to play.
Can anybody please guide me. Too much of my time is wasted on this seemingly trivial problem.
I can provide more detail, if required.
Waiting in anticipation...