Hi all,
I'm playing lots of audio files with AVAudioPlayerNode. While the players are running I start recording.
But recording file mixing all of the audio incoming players+microphone input. I want to isolated input stream,i want to record only mic input.
Is it possible to record only incoming built in microphone when built speaker is running?
How can i isolated input from mic and players output?
My sample code block:
_engine = [[AVAudioEngine alloc] init];
_inputNode= _engine.inputNode;
_outputNode = _engine.outputNode;
_recordingMixer = [[AVAudioMixerNode alloc] init];
[_engine attachNode:_player];
[_engine attachNode:_player1];
[_engine attachNode:_player2];
AVAudioFormat *stereoFormat = [amenFile processingFormat];
AVAudioFormat *stereoFormat1 = [bassFile processingFormat];
AVAudioFormat *stereoFormat2 = [pianoFile processingFormat];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
nil];
_recordingFormat = [[AVAudioFormat alloc] initWithSettings:recordSettings];
AVAudioMixerNode *mainMixer = [_engine mainMixerNode];
/
[_engine connect:_player to:mainMixer format:stereoFormat];
[_engine connect:_player1 to:mainMixer format:stereoFormat1];
[_engine connect:_player2 to:mainMixer format:stereoFormat2];
NSError *error;
if (!_mixerOutputFileURL) _mixerOutputFileURL = [NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingString:@"mixerOutput.m4a"]];
AVAudioMixerNode *mainMixer = [_engine mainMixerNode];
AVAudioFile *mixerOutputFile = [[AVAudioFile alloc] initForWriting:_mixerOutputFileURL settings:_recordingFormat.settings error:&error];
NSAssert(mixerOutputFile != nil, @"mixerOutputFile is nil, %@", [error localizedDescription]);
[_inputNode installTapOnBus: 0 bufferSize:4096 format:[_inputNode inputFormatForBus:0] block:^(AVAudioPCMBuffer *bufferTwo, AVAudioTime *when) {
NSError *error;
NSAssert([mixerOutputFile writeFromBuffer:bufferTwo error:&error], @"error writing buffer two data to file, %@", [error localizedDescription]);
}];
[self startEngine];
_isRecording = YES;