0

In the environment where the AKSettings.channelCount = 2 an AKMicrophone recording is output to a single channel. So, I'd like to be able to understand how to properly patch or mix the audio in AudioKit, please?

Let's look at the following example, have in mind that I kept it to the bare minimal, so look at it as "pseudo-code", as follows:

        AKSettings.bufferLength = .medium
        AKSettings.channelCount = 2
        AKSettings.setSession(category: .playAndRecord)
        AKNodeRecorder(node: microphone) // or AKMicrophone >>> AKMixer            
        mainMixer.connect(input: mic) // is AKMixer()
        AudioKit.output = mainMixer
        AudioKit.start()

The player (AKPlayer) setup is quite simple:

    player.load(audioFile: audioFile)
    player.isLooping = false
    player.buffering = .always
    player >>> mainMixer

Resulting in the recorded microphone audio to be "panned" left, or played in the left channel! I'd rather be certain about how it works, to be able to make the correct choices, since in an analogue mixer the microphone would be patched to a mono channel, centre in the mix, unless panned left/right. Also, I don't want to change the AKSettings.channelCount to 1, as I'd like to have audio tracks outputting stereo too.

halfer
  • 19,824
  • 17
  • 99
  • 186
punkbit
  • 7,347
  • 10
  • 55
  • 89

1 Answers1

0

I found a couple of solutions for the microphone specifically, but of course, that would be nice to find a good read about how to patch things properly in AudioKit :)

The first working solution is to use the AVAudioFormat, as declared here (https://audiokit.io/docs/Classes/AKMicrophone.html#/c:@M@AudioKit@objc(cs)AKMicrophone(im)initWith:), as follows:

var audioFormat: AVAudioFormat = AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 1)!
var mic = AKMicrophone(with: audioFormat)

We can also use the AKStereoFieldLimiter and limit the channel count to a single:

AKStereoFieldLimiter(mic, amount: 1)

You can then pass it to a AKMixer and patch it to AKNodeRecorder.

There might be other ways, but so far that's what I know.

punkbit
  • 7,347
  • 10
  • 55
  • 89