TAAE1 : How to mute input voice while recording

edited August 2016

I'm recording some musics and my own voice , sometimes i just want recording musics
How can I mute my voice but only record musics?
I'm new on TAAE , I try some way but failed

[AEAudioController addInputReceiver:] and [AEAudioController removeInputReceiver:] is not work
when the output is recording and i remove inputReceiver :

:neutral:

can you help me ? thanks !!!

Comments

  • edited August 2016

    @CoderMaurice,

    I added a UISwitch to enable/disable input recording within Michael Tyson's TheEngineSample project. You can find it here:

    https://github.com/markjeschke/TAAE1-Input-Recording-Switch

    Here's what I did:

    • Added a boolean to set whether the inputRecordEnabled = true or false.
    @property (nonatomic) BOOL inputRecordingEnabled;
    
    • In viewDidLoad:
    _inputRecordingEnabled = _audioController.inputEnabled;
    
    • In cellForRowAtIndexPath, I add another row with a UISwitch to enable and disable the inputRecordingEnabled boolean:
    switch ( indexPath.row ) {
      case 0: {
          cell.textLabel.text = @Input Recording Enabled;
          cell.detailTextLabel.text = @"";
          ((UISwitch*)cell.accessoryView).on = _inputRecordingEnabled;
          [((UISwitch*)cell.accessoryView) addTarget:self action:@selector(inputRecordSwitchChanged:) forControlEvents:UIControlEventValueChanged];
          break;
      }
      case 1: {
          cell.textLabel.text = @Input Playthrough;
          ((UISwitch*)cell.accessoryView).on = _playthrough != nil;
          [((UISwitch*)cell.accessoryView) addTarget:self action:@selector(playthroughSwitchChanged:) forControlEvents:UIControlEventValueChanged];
          break;
      }
    ...
    
    • Updated the returned amount in numberOfRowsInSection:
    case 3:
        return 5 + (_audioController.numberOfInputChannels > 1 ? 1 : 0);
    ...
    
    • Added an inputRecordSwitchChanged method:
    - (void)inputRecordSwitchChanged:(UISwitch*)sender {
        if ( sender.isOn ) {
            _inputRecordingEnabled = true;
        } else {
            _inputRecordingEnabled = false;
        }
    }
    
    • Finally, added the if condition to detect whether the input recording is enabled in the record method:
    - (void)record:(id)sender {
        if ( _recorder ) {
            [_recorder finishRecording];
            [_audioController removeOutputReceiver:_recorder];
            // Remove the input receiver, if _inputRecordingEnabled == true
            if (_inputRecordingEnabled) {
                [_audioController removeInputReceiver:_recorder];
            }
            self.recorder = nil;
            _recordButton.selected = NO;
        } else {
            self.recorder = [[AERecorder alloc] initWithAudioController:_audioController];
            NSArray *documentsFolders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *path = [documentsFolders[0] stringByAppendingPathComponent:@Recording.m4a];
            NSError *error = nil;
            if ( ![_recorder beginRecordingToFileAtPath:path fileType:kAudioFileM4AType error:&error] ) {
                [[[UIAlertView alloc] initWithTitle:@Error 
                                             message:[NSString stringWithFormat:@Couldn't start recording: %@", [error localizedDescription]]
                                            delegate:nil
                                   cancelButtonTitle:nil
                                   otherButtonTitles:@OK, nil] show];
                self.recorder = nil;
                return;
            }
            
            _recordButton.selected = YES;
            
            [_audioController addOutputReceiver:_recorder];
            // Remove the input receiver, if _inputRecordingEnabled == true
            if (_inputRecordingEnabled) {
                [_audioController addInputReceiver:_recorder];
            }
        }
    }
    

    I hope this helps.

    Take care,
    Mark

  • edited August 2016

    @markjeschke

    Sorry, I didn't say my problem clearly.
    I need a real-time switch to set inputRecordingEnabled.
    Do you know how to do it?

    Thank you anyway,
    Maurice

  • @CoderMaurice,

    What's the reason for wanting to change the input during recording? Is this so that you can mute your mic's input during your performance?

    I don't believe the input receiver is meant to be turned on and off in the middle of recording, hence the "Out of buffer space" error. But, @Michael would be a better person to answer that question.

    Good luck,
    Mark

  • @markjeschke

    Yes , you are right .

    For example , I'm recording a lyrical radio program , most of the time I just play background music to
    listeners and speak little. In this case , I prefer to turn off the mic.

    In iPhone's call , you can mute the mic at any moment .
    In TAAE1 ,Is this possible ? @Michael

  • A few options spring to mind, @CoderMaurice:

    If you've only just started the project, then I'd strongly recommend checking out AudioKit, an excellent and less technical audio engine which may suit you better.

    If AudioKit doesn't do it for you, check out The Amazing Audio Engine 2, which is still in beta but is less rigid than TAAE 1 is, although still relatively technical.

    Alternatively, if you're set on TAAE1, try exposing the mixer underlying AERecorder by inserting the following at the top of your class:

    @interface AERecorder (PrivateAdditions)
    @property (nonatomic, strong, readonly) AEMixerBuffer *mixer;
    @end
    

    Then mute/unmute the mic source with:

    - (void)muteMicrophone {
        [self.recorder.mixer setVolume:0 forSource:AEAudioSourceInput];
    }
    
    - (void)unmuteMicrophone {
        [self.recorder.mixer setVolume:1 forSource:AEAudioSourceInput];
    }
    
  • @Michael

    Thank you for your reply.
    The project will soon to the deadline , so I can't spend to much time to change the way.
    I'm interested in TAAE2 and I will try next time !
    Thanks again , for your code !

  • @CoderMaurice,

    I updated my repo with @Michael's AEMixerBuffer code additions. It mutes and unmutes the mic during recording, as expected:

    https://github.com/markjeschke/TAAE1-Input-Recording-Switch

    Enjoy,
    Mark

  • @markjeschke

    Thanks for your quick response! it works!
    This is very helpful!

  • edited August 2016

    @CoderMaurice

    You're welcome! Thanks, @Michael, for the help!

Sign In or Register to comment.