1

Hello i am trying to record audio/video from one device and send to another with NSStream, I have created avcapturesession and generated audio/video data . The video data is sent fine to another device and displayed correct but the audio data is so distorted like very robotic and skipping. I have got audiobufferlist from the cmsamplebufferref and sent thye resukting 2048 bytes data to another device

    CMBlockBufferRef blockBuffer;
            CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &currentInputAudioBufferList, sizeof(currentInputAudioBufferList), NULL, NULL, 0, &blockBuffer);


      if( captureOutput == _captureAudioOutput ){

            for (int y = 0; y < currentInputAudioBufferList.mNumberBuffers; y++) {
                AudioBuffer audioBuffer = currentInputAudioBufferList.mBuffers[y];
                Float32 *frame = (Float32*)audioBuffer.mData;

                [audiodata appendBytes:frame length:audioBuffer.mDataByteSize];



            }

    [self sendMIxedData:audioData]; // for sending audiodata


}

else {

////// sample buffer to image to NSData

  [self sendMIxedData:audioData:imageData];  // for sending images 

}

On the other side i am again converting the data into audiobufferlist and playing with AudioUnit Services.

static OSStatus playbackCallback(void *inRefCon,
                                 AudioUnitRenderActionFlags *ioActionFlags,
                                 const AudioTimeStamp *inTimeStamp,
                                 UInt32 inBusNumber,
                                 UInt32 inNumberFrames,
                                 AudioBufferList *ioData) {




for (int i=0; i < ioData->mNumberBuffers; i++) { 
    AudioBuffer buffer = ioData->mBuffers[0];


    UInt32 size = min(buffer.mDataByteSize, THIS->tempBuffer.mDataByteSize); 
    memcpy(buffer.mData, THIS->tempBuffer.mData, size);
    buffer.mDataByteSize = size; 

}

    return noErr;
}

Here tempbuffer is where i am storing the incoming audio data from NSInputStream . The problem is the the audio played is very distorted and robotic . I have tested audiounitservices in other project where i record and play audio simultaneously with AudioUnit services and audio is very clear there . But on sending through stream it becomes. disorted.

Also when i send just the audio data over stream then it is a bit clear but when i send both images and audio data recieved from avcapturesession delegate then the audio is very distorted.Please help me out . What i am doing wrong ? Also can i send audio/video data at same time rather than at different times and extract that on other side ?

sajwan
  • 333
  • 3
  • 14
  • i have problem with video stream can you show your code? – Rajesh Feb 27 '13 at 08:18
  • Have you checked the size of your buffer? Your problem may be related with the NSStream buffer size. Of what type is your audiodata object? Not sure what your code is supposed to show as I do not see any reference to your blockBuffer in the code you posted. – Tomasz Łoś Mar 31 '13 at 04:26
  • @sajwan, were you able to solve the noise issue? If yes then plz share the solution. – iAmd May 27 '14 at 11:24
  • Please could you tell us how did you solve this problem? Thanks – Pablo Martinez Jan 21 '16 at 16:32
  • No i was not able to solve this issue and left the project – sajwan Jan 22 '16 at 08:39

0 Answers0