IOS8 AVAudioEngine, how to send microphone data through Multipeer Connectivity?

I want to send microphone audio files through Multipleer Connectivity (iOS 8) and play it through the speaker of the receiving partner. I also configure AVAudioEngine, and I can hear the microphone data from the output of the (top) speaker, but I do not know how to send AVAudioPCMBuffer over the network. Here is my code snippet:

AVAudioInputNode *inputNode =[self.engine inputNode];
AVAudioMixerNode *mainMixer = [self.engine mainMixerNode];
[self.engine connect:inputNode to:mainMixer format:[inputNode inputFormatForBus:0]];

[mainMixer installTapOnBus:0 bufferSize:4096 format:[mainMixer outputFormatForBus:0] 
    block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {

    //==== How to send the PCMBuffer ?? ======//
}];

NSError *error = nil;
[self.engine startAndReturnError:&error];

if(error)
{
    NSLog(@"error: %@", [error localizedDescription]);
}

Am I sending it as NSData or NSStream?

Appreciate the help. thanks.

+5
source share
1 answer

I have not tried this solution:

- (NSOutputStream *)startStreamWithName:(NSString *)streamName
                                 toPeer:(MCPeerID *)peerID
                                  error:(NSError **)error

, buffer.floatChannelData. float NSOutputStream .

:

- (void)session:(MCSession *)session
didReceiveStream:(NSInputStream *)stream
       withName:(NSString *)streamName
       fromPeer:(MCPeerID *)peerID
{
    stream.delegate = self;
    [stream scheduleInRunLoop:[NSRunLoop mainRunLoop] 
                      forMode:NSDefaultRunLoopMode];
    [stream open];
}

, ( ) float, ( ) .

15.10.2014 , : http://robots.thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity

0

All Articles